From db1f7d494c00fb3e5779b03b2bf4f5fb4d82696c Mon Sep 17 00:00:00 2001 From: Kevin Minehart <5140827+kminehart@users.noreply.github.com> Date: Wed, 14 May 2025 09:29:38 -0500 Subject: [PATCH] CI: Upload go unit test reports on pushes to main (#105280) * generate junit reports in backend unit tests * add quotes * add my branch for testing * Fix results file * add missing quote * remove my branch --- .github/workflows/backend-unit-tests.yml | 28 ++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/.github/workflows/backend-unit-tests.yml b/.github/workflows/backend-unit-tests.yml index caf230e1f42..bab3fcd675f 100644 --- a/.github/workflows/backend-unit-tests.yml +++ b/.github/workflows/backend-unit-tests.yml @@ -21,7 +21,7 @@ permissions: {} jobs: grafana: - # Run this workflow only for PRs from forks; if it gets merged into `main` or `release-*`, + # Run this workflow only for PRs from forks # the `pr-backend-unit-tests-enterprise` workflow will run instead if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.fork == true strategy: @@ -58,6 +58,7 @@ jobs: grafana-enterprise: # Run this workflow for non-PR events (like pushes to `main` or `release-*`) OR for internal PRs (PRs not from forks) + # If it gets merged into `main` or `release-*`, then a junit test result is uploaded to GCS. if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.fork == false strategy: matrix: @@ -85,6 +86,10 @@ jobs: uses: ./.github/actions/setup-enterprise with: github-app-name: 'grafana-ci-bot' + - run: echo "RESULTS_FILE=$(date --rfc-3339=seconds --utc | sed -s 's/ /-/g')_${SHARD/\//_}.xml" >> "$GITHUB_ENV" + env: + SHARD: ${{ matrix.shard }} + - run: go install github.com/jstemmer/go-junit-report/v2@85bf4716ac1f025f2925510a9f5e9f5bb347c009 - name: Generate Go code run: make gen-go - name: Run unit tests @@ -92,4 +97,23 @@ jobs: SHARD: ${{ matrix.shard }} run: | readarray -t PACKAGES <<< "$(./scripts/ci/backend-tests/shard.sh -N"$SHARD")" - go test -short -timeout=30m "${PACKAGES[@]}" + go test -short -v -timeout=30m "${PACKAGES[@]}" | tee >(go-junit-report -set-exit-code > "$RESULTS_FILE") + - name: Log in to GCS + if: github.event_name == 'push' && github.repository == 'grafana/grafana' && (success() || failure()) + uses: grafana/shared-workflows/actions/login-to-gcs@login-to-gcs-v0.2.0 + with: + service_account: github-junit-uploader@grafanalabs-workload-identity.iam.gserviceaccount.com + bucket: grafana-test-results + - if: github.event_name == 'push' && github.repository == 'grafana/grafana' && (success() || failure()) + run: echo "BUCKET_PATH=go-unit-tests/$(echo ${REF_NAME} | sed 's/\//-/g')" >> "$GITHUB_ENV" + env: + REF_NAME: ${{ github.ref_name }} + - name: Upload test results + if: github.event_name == 'push' && github.repository == 'grafana/grafana' && (success() || failure()) + uses: grafana/shared-workflows/actions/push-to-gcs@push-to-gcs-v0.2.0 + with: + bucket: grafana-test-results + service_account: github-junit-uploader@grafanalabs-workload-identity.iam.gserviceaccount.com + environment: "dev" # Can be dev/prod (defaults to dev) + path: ${{ env.RESULTS_FILE }} + bucket_path: ${{ env.BUCKET_PATH }}