From 97525f5e743f0e7fb1c90eddb02705b302046ab0 Mon Sep 17 00:00:00 2001 From: Niels de Vos Date: Mon, 4 Oct 2021 15:58:13 +0200 Subject: [PATCH] ci: add `make go-test-api` to GitHub Action Signed-off-by: Niels de Vos --- .github/workflows/go-test.yaml | 7 +++++++ Makefile | 2 +- scripts/test-go.sh | 7 ++++--- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/.github/workflows/go-test.yaml b/.github/workflows/go-test.yaml index 2f25304b7..f28f89eb4 100644 --- a/.github/workflows/go-test.yaml +++ b/.github/workflows/go-test.yaml @@ -13,3 +13,10 @@ jobs: - uses: actions/checkout@v2 - name: go-test run: CONTAINER_CMD=docker make containerized-test TARGET=go-test + go-test-api: + name: go-test-api + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: go-test-api + run: CONTAINER_CMD=docker make containerized-test TARGET=go-test-api diff --git a/Makefile b/Makefile index edb06dead..065e527c4 100644 --- a/Makefile +++ b/Makefile @@ -103,7 +103,7 @@ go-test: check-env TEST_COVERAGE="$(TEST_COVERAGE)" GO_COVER_DIR="$(GO_COVER_DIR)" GO_TAGS="$(GO_TAGS)" ./scripts/test-go.sh go-test-api: check-env - @pushd api/deploy/ocp && go test -v ./... && popd + @pushd api && ../scripts/test-go.sh && popd mod-check: check-env @echo 'running: go mod verify' diff --git a/scripts/test-go.sh b/scripts/test-go.sh index 9dd18e1b1..379c6de56 100755 --- a/scripts/test-go.sh +++ b/scripts/test-go.sh @@ -1,12 +1,13 @@ #!/bin/bash -GOPACKAGES="$(go list -mod=vendor ./... | grep -v -e vendor -e e2e)" +MOD_VENDOR=$(test -d vendor && echo '-mod=vendor') +GOPACKAGES="$(go list "${MOD_VENDOR}" ./... | grep -v -e vendor -e e2e)" COVERFILE="${GO_COVER_DIR}/profile.cov" # no special options, exec to go test w/ all pkgs if [[ "${TEST_EXITFIRST}" != "yes" && -z "${TEST_COVERAGE}" ]]; then # shellcheck disable=SC2086 - exec go test "${GO_TAGS}" -mod=vendor -v ${GOPACKAGES} + exec go test ${GO_TAGS} ${MOD_VENDOR} -v ${GOPACKAGES} fi # our options are set so we need to handle each go package one @@ -20,7 +21,7 @@ failed=0 for gopackage in ${GOPACKAGES}; do echo "--- testing: ${gopackage} ---" # shellcheck disable=SC2086 - go test "${GO_TAGS}" -mod=vendor -v ${GOTESTOPTS[*]} "${gopackage}" || ((failed += 1)) + go test "${GO_TAGS}" "${MOD_VENDOR}" -v ${GOTESTOPTS[*]} "${gopackage}" || ((failed += 1)) if [[ -f cover.out ]]; then # Append to coverfile grep -v "^mode: count" cover.out >>"${COVERFILE}"