diff --git a/.github/workflows/go_app_pull_requests.yml b/.github/workflows/go_app_pull_requests.yml index 7d2e77d..6e66d89 100644 --- a/.github/workflows/go_app_pull_requests.yml +++ b/.github/workflows/go_app_pull_requests.yml @@ -10,6 +10,22 @@ on: description: 'GOPRIVATE env for go commands' required: false type: string + GO_TEST_UNIT_TAGS: + description: "The tags flag for the unit test go test call. Include -tags flag. Example -tags=unit" + type: string + required: false + default: "" + GO_TEST_INTEGRATION_ENABLED: + type: boolean + default: false + GO_TEST_INTEGRATION_TAGS: + description: "The tags flag for the integration test go test call. Include -tags flag. Example -tags=integration" + type: string + default: "-tags=integration" + GO_TEST_INTEGRATION_TIMEOUT: + description: "The duration before tests are stopped" + type: string + default: "10m" secrets: GH_CI_PAT: description: 'Token password for GitHub auth' @@ -17,6 +33,12 @@ on: CODECOV_TOKEN: description: 'Token for Codecov' required: true + ARTIFACT_REGISTRY: + description: 'Artifact Registry address to which to publish (leave blank to not publish)' + required: false + ARTIFACT_REGISTRY_JSON_KEY: + description: 'Key for publishing to Artifact Registry' + required: false env: GOPRIVATE: ${{ inputs.GOPRIVATE }} jobs: @@ -82,42 +104,95 @@ jobs: uses: actions/setup-go@v5 with: go-version: ${{ matrix.go }} - # Use auth to get access to private Git repos for Go code dependencies. + - name: Login to Artifact Registry + env: + ARTIFACT_REGISTRY_JSON_KEY: ${{ secrets.ARTIFACT_REGISTRY_JSON_KEY }} + if: ${{ env.ARTIFACT_REGISTRY_JSON_KEY }} + uses: docker/login-action@v2 + with: + registry: ${{ secrets.ARTIFACT_REGISTRY }} + username: _json_key + password: ${{ secrets.ARTIFACT_REGISTRY_JSON_KEY }} - name: Configure git for private modules env: TOKEN: ${{ secrets.GH_CI_PAT }} GITHUB_USERNAME: ${{ inputs.GH_CI_USER }} - run: git config --global url."https://${GITHUB_USERNAME}:${TOKEN}@github.com".insteadOf + run: + git config --global url."https://${GITHUB_USERNAME}:${TOKEN}@github.com".insteadOf "https://github.com" + # Vendor Go code needed to build app. + - name: go mod vendor + run: go mod vendor # Go vet every Go module. - name: go vet - run: find . -name vendor -prune -o -name go.mod -print | xargs -n1 dirname - | xargs -n1 -I{} bash -c "pushd {}; go vet ./..." + run: + find . -name vendor -prune -o -name go.mod -print | xargs -n1 dirname | xargs -n1 -I{} bash -c "pushd {}; go vet ./..." # Install go-junit-report to format test results. - name: Install go-junit-report run: go install github.com/jstemmer/go-junit-report/v2@v2.1.0 # Run unit test for evet Go module. + - name: build coverage output directories + run: | + mkdir -p coverage/unit + mkdir -p coverage/int - name: go test - run: find . -name vendor -prune -o -name go.mod -print | xargs -n1 dirname - | xargs -n1 -I{} bash -c "pushd {}; go test -coverprofile=coverage.txt --race -v ./..." - | go-junit-report -set-exit-code > junit_report.xml || true - - name: Test Report + run: + find . -name vendor -prune -o -name go.mod -print | xargs -n1 dirname | xargs -n1 -I{} bash -c "pushd {}; go test -cover --race -v ${{ inputs.GO_TEST_UNIT_TAGS }} ./... -args -test.gocoverdir=\"${{ github.workspace }}/coverage/unit\"" + | tee unit_test_output.txt + - name: Build Unit Test Junit report + run: + go-junit-report -in unit_test_output.txt -set-exit-code > junit_report.xml || true + - name: Unit Test Report uses: dorny/test-reporter@v1 if: success() || failure() with: - name: Test Report + name: Unit Test Report path: junit_report.xml reporter: java-junit - - uses: codecov/test-results-action@v1 + - name: Upload unit test coverage results to Codecov + uses: codecov/test-results-action@v1 with: fail_ci_if_error: true # optional (default = false) files: ./junit_report.xml name: junit-report token: ${{ secrets.CODECOV_TOKEN }} + # relies on the tests themselves compiling the binary with `-cover` and setting GOCOVERDIR to /coverage/int + # to seperate out any integration tests + - name: integration tests + if: ${{ inputs.GO_TEST_INTEGRATION_ENABLED }} + run: go test -v ${{ inputs.GO_TEST_INTEGRATION_TAGS }} -timeout ${{ inputs.GO_TEST_INTEGRATION_TIMEOUT }} ./... + | tee integration_test_output.txt + - name: Build Integration Test Junit report + if: ${{ inputs.GO_TEST_INTEGRATION_ENABLED }} + run: go-junit-report -in integration_test_output.txt -set-exit-code > junit_integration_report.xml || true + - name: Integration Test Report + uses: dorny/test-reporter@v1 + if: ${{ inputs.GO_TEST_INTEGRATION_ENABLED }} + with: + name: Integration Test Report + path: junit_integration_report.xml + reporter: java-junit + - name: Upload integration test results to Codecov + if: ${{ inputs.GO_TEST_INTEGRATION_ENABLED }} + uses: codecov/test-results-action@v1 + with: + fail_ci_if_error: true # optional (default = false) + files: ./junit_integration_report.xml + name: junit-integration-report + token: ${{ secrets.CODECOV_TOKEN }} + - name: show coverage output directories + run: | + ls ./coverage/unit + ls ./coverage/int + - name: build coverage.txt + run: go tool covdata textfmt -i=./coverage/int,./coverage/unit -o coverage.txt - name: Upload test coverage results to Codecov uses: codecov/codecov-action@v4 with: token: ${{ secrets.CODECOV_TOKEN }} + files: ./coverage.txt + verbose: true + fail_ci_if_error: true # optional (default = false) docker-build: # # ensures the docker image will build without pushing to the registry diff --git a/.github/workflows/go_app_push_main.yml b/.github/workflows/go_app_push_main.yml index a0a69fb..1ede77e 100644 --- a/.github/workflows/go_app_push_main.yml +++ b/.github/workflows/go_app_push_main.yml @@ -11,6 +11,18 @@ on: description: "GOPRIVATE env for go commands" required: false type: string + GO_TEST_UNIT_TAGS: + description: "The tags flag for the unit test go test call. Include -tags flag. Example -tags=unit" + type: string + required: false + default: "" + GO_TEST_INTEGRATION_ENABLED: + type: boolean + default: false + GO_TEST_INTEGRATION_TAGS: + description: "The tags flag for the integration test go test call. Include -tags flag. Example -tags=integration" + type: string + default: "-tags=integration" secrets: GH_CI_PAT: description: 'Token password for GitHub auth' @@ -18,6 +30,12 @@ on: CODECOV_TOKEN: description: 'Token for Codecov' required: true + ARTIFACT_REGISTRY: + description: 'Artifact Registry address to which to publish (leave blank to not publish)' + required: false + ARTIFACT_REGISTRY_JSON_KEY: + description: 'Key for publishing to Artifact Registry' + required: false env: GOPRIVATE: ${{ inputs.GOPRIVATE }} jobs: @@ -39,6 +57,15 @@ jobs: uses: actions/setup-go@v3 with: go-version: ${{ matrix.go }} + - name: Login to Artifact Registry + env: + ARTIFACT_REGISTRY_JSON_KEY: ${{ secrets.ARTIFACT_REGISTRY_JSON_KEY }} + if: ${{ env.ARTIFACT_REGISTRY_JSON_KEY }} + uses: docker/login-action@v2 + with: + registry: ${{ secrets.ARTIFACT_REGISTRY }} + username: _json_key + password: ${{ secrets.ARTIFACT_REGISTRY_JSON_KEY }} # Use auth to get access to private Git repos for Go code dependencies. - name: Configure git for private modules env: @@ -46,35 +73,74 @@ jobs: GITHUB_USERNAME: ${{ inputs.GH_CI_USER }} run: git config --global url."https://${GITHUB_USERNAME}:${TOKEN}@github.com".insteadOf "https://github.com" + # Vendor Go code needed to build app. + - name: go mod vendor + run: go mod vendor # Go vet every Go module. - name: go vet - run: find . -name vendor -prune -o -name go.mod -print | xargs -n1 dirname - | xargs -n1 -I{} bash -c "pushd {}; go vet ./..." + run: + find . -name vendor -prune -o -name go.mod -print | xargs -n1 dirname | xargs -n1 -I{} bash -c "pushd {}; go vet ./..." # Install go-junit-report to format test results. - name: Install go-junit-report run: go install github.com/jstemmer/go-junit-report/v2@v2.1.0 - # Run unit test for evet Go module. + - name: build coverage output directories + run: | + mkdir -p coverage/unit + mkdir -p coverage/int - name: go test - run: find . -name vendor -prune -o -name go.mod -print | xargs -n1 dirname - | xargs -n1 -I{} bash -c "pushd {}; go test -coverprofile=coverage.txt --race -v ./..." - | go-junit-report -set-exit-code > junit_report.xml || true - - name: Test Report + run: + find . -name vendor -prune -o -name go.mod -print | xargs -n1 dirname | xargs -n1 -I{} bash -c "pushd {}; go test -cover --race -v ${{ inputs.GO_TEST_UNIT_TAGS }} ./... -args -test.gocoverdir=\"${{ github.workspace }}/coverage/unit\"" + | tee unit_test_output.txt + - name: Build Unit Test Junit report + run: + go-junit-report -in unit_test_output.txt -set-exit-code > junit_report.xml || true + - name: Unit Test Report uses: dorny/test-reporter@v1 if: success() || failure() with: - name: Test Report + name: Unit Test Report path: junit_report.xml reporter: java-junit - - uses: codecov/test-results-action@v1 + - name: Upload unit test results to Codecov + uses: codecov/test-results-action@v1 with: fail_ci_if_error: true # optional (default = false) files: ./junit_report.xml name: junit-report token: ${{ secrets.CODECOV_TOKEN }} + # relies on the tests themselves compiling the binary with `-cover` and setting GOCOVERDIR to /coverage/int + # to seperate out any integration tests + - name: integration tests + if: ${{ inputs.GO_TEST_INTEGRATION_ENABLED }} + run: go test -v ${{ inputs.GO_TEST_INTEGRATION_TAGS }} ./... + | tee integration_test_output.txt + - name: Build Integration Test Junit report + if: ${{ inputs.GO_TEST_INTEGRATION_ENABLED }} + run: go-junit-report -in integration_test_output.txt -set-exit-code > junit_integration_report.xml || true + - name: show coverage output directories + run: | + ls ./coverage/unit + ls ./coverage/int + - name: build coverage.txt + run: go tool covdata textfmt -i=./coverage/int,./coverage/unit -o coverage.txt - name: Upload test coverage results to Codecov uses: codecov/codecov-action@v4 with: token: ${{ secrets.CODECOV_TOKEN }} + - name: Integration Test Report + uses: dorny/test-reporter@v1 + if: success() || failure() + with: + name: Integration Test Report + path: junit_integration_report.xml + reporter: java-junit + - name: Upload integration test results to Codecov + uses: codecov/test-results-action@v1 + with: + fail_ci_if_error: true # optional (default = false) + files: ./junit_report.xml + name: junit-report + token: ${{ secrets.CODECOV_TOKEN }} release: # # Create a GitHub Release based on conventional commits. diff --git a/.github/workflows/go_lib_pull_requests.yml b/.github/workflows/go_lib_pull_requests.yml index 5c475f1..71885ec 100644 --- a/.github/workflows/go_lib_pull_requests.yml +++ b/.github/workflows/go_lib_pull_requests.yml @@ -14,6 +14,18 @@ on: description: "Go workspace mode" required: false type: string + GO_TEST_UNIT_TAGS: + description: "The tags flag for the unit test go test call. Include -tags flag. Example -tags=unit" + type: string + required: false + default: "" + GO_TEST_INTEGRATION_ENABLED: + type: boolean + default: false + GO_TEST_INTEGRATION_TAGS: + description: "The tags flag for the integration test go test call. Include -tags flag. Example -tags=integration" + type: string + default: "-tags=integration" secrets: GH_CI_PAT: description: "Token password for GitHub auth" @@ -21,6 +33,12 @@ on: CODECOV_TOKEN: description: 'Token for Codecov' required: true + ARTIFACT_REGISTRY: + description: 'Artifact Registry address to which to publish (leave blank to not publish)' + required: false + ARTIFACT_REGISTRY_JSON_KEY: + description: 'Key for publishing to Artifact Registry' + required: false env: GOPRIVATE: ${{ inputs.GOPRIVATE }} jobs: @@ -89,6 +107,16 @@ jobs: with: go-version: ${{ matrix.go }} # Use auth to get access to private Git repos for Go code dependencies. + # Login to Artifact Registry if we're pushing to it. + - name: Login to Artifact Registry + env: + ARTIFACT_REGISTRY_JSON_KEY: ${{ secrets.ARTIFACT_REGISTRY_JSON_KEY }} + if: ${{ env.ARTIFACT_REGISTRY_JSON_KEY }} + uses: docker/login-action@v2 + with: + registry: ${{ secrets.ARTIFACT_REGISTRY }} + username: _json_key + password: ${{ secrets.ARTIFACT_REGISTRY_JSON_KEY }} - name: Configure git for private modules env: TOKEN: ${{ secrets.GH_CI_PAT }} @@ -96,34 +124,68 @@ jobs: run: git config --global url."https://${GITHUB_USERNAME}:${TOKEN}@github.com".insteadOf "https://github.com" + # Vendor Go code needed to build app. + - name: go mod vendor + run: go mod vendor | go work vendor # Go vet every Go module. - name: go vet run: - find . -name vendor -prune -o -name go.mod -print | xargs -n1 dirname - | xargs -n1 -I{} bash -c "pushd {}; go vet ./..." + find . -name vendor -prune -o -name go.mod -print | xargs -n1 dirname | xargs -n1 -I{} bash -c "pushd {}; go vet ./..." + | go-junit-report -set-exit-code > junit_report.xml || true # Install go-junit-report to format test results. - name: Install go-junit-report run: go install github.com/jstemmer/go-junit-report/v2@v2.1.0 # Run unit test for evet Go module. + - name: build coverage output directories + run: | + mkdir -p coverage/unit + mkdir -p coverage/int - name: go test run: - find . -name vendor -prune -o -name go.mod -print | xargs -n1 dirname - | xargs -n1 -I{} bash -c "pushd {}; go test -coverprofile=coverage.txt --race -v ./..." + find . -name vendor -prune -o -name go.mod -print | xargs -n1 dirname | xargs -n1 -I{} bash -c "pushd {}; go test -cover --race -v ${{ inputs.GO_TEST_UNIT_TAGS }} ./... -args -test.gocoverdir=\"${{ github.workspace }}/coverage/unit\"" | go-junit-report -set-exit-code > junit_report.xml || true - - name: Test Report + - name: Unit Test Report uses: dorny/test-reporter@v1 if: success() || failure() with: - name: Test Report + name: Unit Test Report path: junit_report.xml reporter: java-junit - - uses: codecov/test-results-action@v1 + - name: Upload unit test coverage results to Codecov + uses: codecov/test-results-action@v1 with: fail_ci_if_error: true # optional (default = false) files: ./junit_report.xml name: junit-report token: ${{ secrets.CODECOV_TOKEN }} + # relies on the tests themselves compiling the binary with `-cover` and setting GOCOVERDIR to /coverage/int + # to seperate out any integration tests + - name: integration tests + if: ${{ inputs.GO_TEST_INTEGRATION_ENABLED }} + run: go test -v ${{ inputs.GO_TEST_INTEGRATION_TAGS }} ./... + | go-junit-report -set-exit-code > junit_integration_report.xml || true + - name: show coverage output directories + run: | + ls ./coverage/unit + ls ./coverage/int + - name: build coverage.txt + run: go tool covdata textfmt -i=./coverage/int,./coverage/unit -o coverage.txt - name: Upload test coverage results to Codecov uses: codecov/codecov-action@v4 with: + token: ${{ secrets.CODECOV_TOKEN }} + - name: Integration Test Report + uses: dorny/test-reporter@v1 + if: ${{ inputs.GO_TEST_INTEGRATION_ENABLED }} + with: + name: Integration Test Report + path: junit_integration_report.xml + reporter: java-junit + - name: Upload integration test coverage results to Codecov + if: ${{ inputs.GO_TEST_INTEGRATION_ENABLED }} + uses: codecov/test-results-action@v1 + with: + fail_ci_if_error: true # optional (default = false) + files: ./junit_report.xml + name: junit-report token: ${{ secrets.CODECOV_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/go_lib_push_main.yml b/.github/workflows/go_lib_push_main.yml index 4112b7d..1993fd5 100644 --- a/.github/workflows/go_lib_push_main.yml +++ b/.github/workflows/go_lib_push_main.yml @@ -61,14 +61,15 @@ jobs: find . -name vendor -prune -o -name go.mod -print | xargs -n1 dirname | xargs -n1 -I{} bash -c "pushd {}; go test -coverprofile=coverage.txt --race -v ./..." | go-junit-report -set-exit-code > junit_report.xml || true - - name: Test Report + - name: Unit Test Report uses: dorny/test-reporter@v1 if: success() || failure() with: - name: Test Report + name: Unit Test Report path: junit_report.xml reporter: java-junit - - uses: codecov/test-results-action@v1 + - name: Upload unit test coverage results to Codecov + uses: codecov/test-results-action@v1 with: fail_ci_if_error: true # optional (default = false) files: ./junit_report.xml