2018-06-28 08:40:18 +03:00
PWD := $( shell pwd )
PARENT_DIR := $( shell dirname $( PWD) )
2018-07-03 20:10:13 +03:00
VERSION ?= $( shell ../scripts/get-version.sh)
2020-04-16 04:24:50 +03:00
PLUGINS_BRANCH ?= master
2018-06-28 08:40:18 +03:00
OUTPUT_DIR := _output
2020-06-03 07:06:23 +03:00
HAS_GOX := $( shell command -v gox; )
2021-05-17 03:29:11 +03:00
HAS_GINKGO := $( shell command -v ginkgo; )
2020-06-03 07:06:23 +03:00
2021-03-17 18:09:03 +03:00
i f e q ( $ { C I } , t r u e )
2023-05-10 16:47:57 +03:00
CLI_EXT_BIN_DIR := /build/_cli_ext_output
2021-03-17 18:09:03 +03:00
e l s e
2023-05-10 16:47:57 +03:00
CLI_EXT_BIN_DIR := ../cli-ext/bin
2021-03-17 18:09:03 +03:00
e n d i f
2018-06-29 16:09:21 +03:00
.PHONY : deps
2018-06-28 08:40:18 +03:00
# get dependencies
deps :
2019-12-12 08:37:26 +03:00
go mod download
2018-06-28 08:40:18 +03:00
2021-10-13 17:38:07 +03:00
.PHONY : lint
lint :
2021-12-01 13:00:11 +03:00
golangci-lint run --timeout 10m
2021-10-13 17:38:07 +03:00
2018-06-28 08:40:18 +03:00
# build cli locally, for all given platform/arch
2018-06-29 16:09:21 +03:00
.PHONY : build
2018-07-20 14:00:25 +03:00
build : export CGO_ENABLED =0
2021-03-17 18:09:03 +03:00
build : copy -cli -ext
2018-06-28 08:40:18 +03:00
build :
2021-05-03 10:59:49 +03:00
i f n d e f H A S _ G O X
cd ~ && go get github.com/mitchellh/gox && cd -
e n d i f
2021-06-16 14:44:15 +03:00
gox -ldflags '-X github.com/hasura/graphql-engine/cli/v2/version.BuildVersion=$(VERSION) -X github.com/hasura/graphql-engine/cli/v2/plugins.IndexBranchRef=$(PLUGINS_BRANCH) -s -w -extldflags "-static"' \
2021-07-14 11:53:54 +03:00
-osarch= "linux/amd64 darwin/amd64 windows/amd64 linux/arm64 darwin/arm64" \
2018-07-17 20:00:26 +03:00
-output= " $( OUTPUT_DIR) / $( VERSION) /cli-hasura-{{.OS}}-{{.Arch}} " \
2018-06-28 08:40:18 +03:00
./cmd/hasura/
2018-06-29 16:09:21 +03:00
# compress
.PHONY : compress
compress :
2021-12-02 13:20:39 +03:00
ls $( OUTPUT_DIR) /$( VERSION) /cli-hasura-* | grep -v darwin | grep -v windows | xargs upx
2018-06-29 16:09:21 +03:00
2018-07-10 13:01:02 +03:00
# to be executed in circle-ci only
ci-copy-binary :
2018-07-17 20:00:26 +03:00
mkdir -p /build/_cli_output/binaries
cp $( OUTPUT_DIR) /$( VERSION) /cli-hasura-* /build/_cli_output/binaries
2018-07-10 13:01:02 +03:00
echo " $( VERSION) " > /build/_cli_output/version.txt
2021-03-17 18:09:03 +03:00
.PHONY : build -cli -ext
build-cli-ext :
cd ../cli-ext && make deps && make build
.PHONY : clean -cli -ext
clean-cli-ext :
2023-05-10 16:47:57 +03:00
git clean -fx ./internal/cliext/static-bin
2021-03-17 18:09:03 +03:00
.PHONY : copy -cli -ext
2023-05-10 16:47:57 +03:00
copy-cli-ext : ./internal /cliext /static -bin /linux /amd 64/cli -ext ./internal /cliext /static -bin /linux /arm 64/cli -ext ./internal /cliext /static -bin /darwin /amd 64/cli -ext ./internal /cliext /static -bin /darwin /arm 64/cli -ext ./internal /cliext /static -bin /windows /amd 64/cli -ext .exe
./internal/cliext/static-bin/linux/amd64/cli-ext : $( CLI_EXT_BIN_DIR ) /cli -ext -linux -amd 64
cp $< $@
./internal/cliext/static-bin/linux/arm64/cli-ext : $( CLI_EXT_BIN_DIR ) /cli -ext -linux -arm 64
cp $< $@
./internal/cliext/static-bin/darwin/amd64/cli-ext : $( CLI_EXT_BIN_DIR ) /cli -ext -darwin -amd 64
cp $< $@
./internal/cliext/static-bin/darwin/arm64/cli-ext : $( CLI_EXT_BIN_DIR ) /cli -ext -darwin -arm 64
cp $< $@
./internal/cliext/static-bin/windows/amd64/cli-ext.exe : $( CLI_EXT_BIN_DIR ) /cli -ext -windows -amd 64
cp $< $@
2021-03-17 18:09:03 +03:00
2018-06-28 08:40:18 +03:00
# run tests
2018-06-29 16:09:21 +03:00
.PHONY : test
2021-03-17 18:09:03 +03:00
test : copy -cli -ext
2021-09-27 16:34:09 +03:00
echo "--- :: run test"
2021-06-03 16:26:28 +03:00
if [ -z " ${ HASURA_TEST_CLI_HGE_DOCKER_IMAGE } " ] ; then echo "Please set HASURA_TEST_CLI_HGE_DOCKER_IMAGE env for populating testutil.HasuraDockerImage and run test" ; exit 1; fi
2022-03-22 15:02:12 +03:00
go test -count= 1 -ldflags " -X github.com/hasura/graphql-engine/cli/v2/version.BuildVersion= $( VERSION) " -v -tags= " ${ TEST_TAGS } " ` go list ./... | grep -v integration_test | grep -v commands`
2021-03-17 18:09:03 +03:00
integration_tests_config_v3 : copy -cli -ext
2021-09-27 16:34:09 +03:00
echo "--- :: run integration_tests_config_v3"
2021-06-03 16:26:28 +03:00
if [ -z " ${ HASURA_TEST_CLI_HGE_DOCKER_IMAGE } " ] ; then echo "Please set HASURA_TEST_CLI_HGE_DOCKER_IMAGE env for populating testutil.HasuraDockerImage and run test" ; exit 1; fi
2022-03-22 15:02:12 +03:00
go test -count= 1 -ldflags " -X github.com/hasura/graphql-engine/cli/v2/version.BuildVersion= $( VERSION) " -v -tags= " ${ TEST_TAGS } " -run Commands/config= v3 ./integration_test
2021-03-17 18:09:03 +03:00
integration_tests_config_v2 : copy -cli -ext
2021-09-27 16:34:09 +03:00
echo "--- :: run integration_tests_config_v2"
2021-06-03 16:26:28 +03:00
if [ -z " ${ HASURA_TEST_CLI_HGE_DOCKER_IMAGE } " ] ; then echo "Please set HASURA_TEST_CLI_HGE_DOCKER_IMAGE env for populating testutil.HasuraDockerImage and run test" ; exit 1; fi
2022-03-22 15:02:12 +03:00
go test -count= 1 -ldflags " -X github.com/hasura/graphql-engine/cli/v2/version.BuildVersion= $( VERSION) " -v -tags= " ${ TEST_TAGS } " -run Commands/config= v2 ./integration_test
2021-05-17 03:29:11 +03:00
test-e2e :
2021-09-27 16:34:09 +03:00
echo "--- :: run e2e tests"
2021-05-17 03:29:11 +03:00
i f n d e f H A S _ G I N K G O
cd ~ && go get github.com/onsi/ginkgo/ginkgo && cd -
e n d i f
2022-04-25 16:05:26 +03:00
cd commands && ginkgo -p -v -failFast $( ARGS)
2021-05-17 03:29:11 +03:00
test-all : test integration_tests_config_v 2 integration_tests_config_v 3 test -e 2e
2018-06-28 08:40:18 +03:00
# clean the output directory
2018-06-29 16:09:21 +03:00
.PHONY : clean
2018-06-28 08:40:18 +03:00
clean :
rm -rf " $( OUTPUT_DIR) "
2018-06-29 16:09:21 +03:00
.PHONY : all
2023-05-10 16:47:57 +03:00
all : deps build -cli -ext build test
2018-06-28 08:40:18 +03:00
# build cli inside a docker container
all-in-docker :
docker build -t hasura-graphql-cli-builder -f build/builder.dockerfile build
docker run --rm -it \
-v $( PARENT_DIR) :/go/src/github.com/hasura/graphql-engine \
hasura-graphql-cli-builder \
make all