#!/bin/sh

go version
export GOFLAGS=-mod=vendor

OPERATOR_PATH=/usr/local/bin/kie-cloud-operator
UI_PATH=/usr/local/bin/console-cr-form
TARDIR=/tmp/scripts/builder

mkdir -p ${TARDIR}/src
tar xfz ${TARDIR}/kie-cloud-operator.tar.gz --strip-components=1 -C ${TARDIR}/src
cd ${TARDIR}/src && pwd

go generate ./...
go vet ./...
go test ./...
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -v -mod=vendor -a -o ${OPERATOR_PATH} ./cmd/manager
if [[ ! -f ${OPERATOR_PATH} ]] ; then
    echo "${OPERATOR_PATH} does not exist, aborting."
    exit 1
fi
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -v -mod=vendor -a -o ${UI_PATH} ./cmd/ui
if [[ ! -f ${UI_PATH} ]] ; then
    echo "${UI_PATH} does not exist, aborting."
    exit 1
fi
