From d00ace38426ff35661eff4114f447bcd517e0e5c Mon Sep 17 00:00:00 2001 From: Steve Coffman Date: Thu, 20 Jun 2024 15:51:23 -0400 Subject: [PATCH] Add prettier test results (#3148) * Add prettier test results --- .github/workflows/report.yml | 24 ++++++++++ .github/workflows/test.yml | 87 ++++++++++++++++++++++++++++++------ 2 files changed, 97 insertions(+), 14 deletions(-) create mode 100644 .github/workflows/report.yml diff --git a/.github/workflows/report.yml b/.github/workflows/report.yml new file mode 100644 index 00000000000..294f1519e53 --- /dev/null +++ b/.github/workflows/report.yml @@ -0,0 +1,24 @@ +name: test report +on: + workflow_run: + workflows: [build] + types: [completed] + +permissions: + checks: write + +jobs: + checks: + runs-on: ubuntu-latest + steps: + - name: Download Test Report + uses: dawidd6/action-download-artifact@v6 + with: + name: junit-test-results + workflow: ${{ github.event.workflow.id }} + run_id: ${{ github.event.workflow_run.id }} + - name: Publish Test Report + uses: mikepenz/action-junit-report@v3 + with: + commit: ${{github.event.workflow_run.head_sha}} + report_paths: '**/*.xml' diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a2e1162f0fd..20b2b035c90 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -10,6 +10,13 @@ on: concurrency: group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} cancel-in-progress: true +permissions: + # Required: allow read access to the content for analysis. + contents: read + # Optional: allow read access to pull request. Use with `only-new-issues` option. + pull-requests: read + # Optional: allow write access to checks to allow the action to annotate code in the PR. + checks: write jobs: test: strategy: @@ -23,20 +30,72 @@ jobs: - uses: actions/setup-go@v5 with: go-version: ${{ matrix.go }} + # Install gotestsum on the VM running the action. + - name: Setup gotestsum + run: go install gotest.tools/gotestsum@latest - name: Core tests - uses: nick-fields/retry@v3 - with: - max_attempts: 3 - timeout_minutes: 20 - command: | - go mod download - go test -race ./... + shell: bash + run: | + set -euo pipefail + go mod download + gotestsum --jsonfile go_test.json --junitfile report.xml --format-icons=hivis --format=pkgname-and-test-fails -- -race ./... -trimpath - name: Example tests - uses: nick-fields/retry@v3 + shell: bash + if: success() || failure() # always run even if the previous step fails + run: | + cd _examples + go mod download + gotestsum --junitfile ../go_examples_report.xml --format-icons=hivis --format=pkgname-and-test-fails -- -race ./... -trimpath + - name: Upload Test Report + uses: actions/upload-artifact@v4.3.3 + if: always() # always run even if the previous step fails + with: + name: test-junit-${{ matrix.os }}-${{ matrix.go }} + path: '*.xml' + retention-days: 1 + - name: action-junit-report + shell: bash + if: success() || failure() # always run even if the previous step fails + run: | + echo "### mikepenz/action-junit-report! :rocket:" >> $GITHUB_STEP_SUMMARY + - name: Publish Test Report + uses: mikepenz/action-junit-report@v4.3.0 + if: success() || failure() # always run even if the previous step fails + with: + report_paths: | + report.xml + go_examples_report.xml + - name: robherley/go-test-action announcement + shell: bash + if: success() || failure() # always run even if the previous step fails + run: | + echo "### robherley/go-test-action! :rocket:" >> $GITHUB_STEP_SUMMARY +# - name: Annotate tests does not work on pull-requests for security +# if: success() || failure() # always run even if the previous step fails +# uses: guyarb/golang-test-annotations@v0.8.0 +# with: +# test-results: go_test.json + - name: Publish go-test-action Report + if: success() || failure() # always run even if the previous step fails + uses: robherley/go-test-action@v0.4.1 + with: + # Parse an exisiting [test2json](https://pkg.go.dev/cmd/test2json) file, instead of executing go test. + # Will always exit(0) on successful test file parse. + # Optional. No default + fromJSONFile: go_test.json + omit: | + untested + successful + - name: test-summary/action announcement + shell: bash + if: success() || failure() # always run even if the previous step fails + run: | + echo "### test-summary/action! :rocket:" >> $GITHUB_STEP_SUMMARY + - name: Publish Test Summary Report + uses: test-summary/action@v2.3 + if: success() || failure() # always run even if the previous step fails with: - max_attempts: 3 - timeout_minutes: 20 - command: | - cd _examples - go mod download - go test -race ./... + show: "fail, skip" + paths: | + report.xml + go_examples_report.xml