From df91480f811b33e3c92f75c5263b6824d34786f5 Mon Sep 17 00:00:00 2001 From: Kevin Wooten Date: Sun, 5 Mar 2023 17:42:21 -0700 Subject: [PATCH] Fix test result reporting in workflows --- .github/workflows/pr-build-test.yaml | 13 +-- .github/workflows/pr-report.yaml | 159 --------------------------- .github/workflows/pr-scan.yaml | 66 +++++++++++ 3 files changed, 72 insertions(+), 166 deletions(-) delete mode 100644 .github/workflows/pr-report.yaml create mode 100644 .github/workflows/pr-scan.yaml diff --git a/.github/workflows/pr-build-test.yaml b/.github/workflows/pr-build-test.yaml index bd7ad5b67..6c68dcfb8 100644 --- a/.github/workflows/pr-build-test.yaml +++ b/.github/workflows/pr-build-test.yaml @@ -78,12 +78,11 @@ jobs: - name: Build/Test run: make build-test-${{ matrix.platform }} - - name: Upload Test Results - uses: actions/upload-artifact@v3 + - name: Report Test Results + uses: kdubb/xcresulttool@v1 if: success() || failure() with: - name: test-results-${{ matrix.platform }} - # "./dummy" is included to ensure "TestResults" path is archived - path: | - ./dummy - TestResults/*.xcresult/ + title: Test Results ${{ matrix.platform }} + path: ./TestResults/${{ matrix.platform }}.xcresult + upload-bundles: never + show-code-coverage: false diff --git a/.github/workflows/pr-report.yaml b/.github/workflows/pr-report.yaml deleted file mode 100644 index afddb3f0b..000000000 --- a/.github/workflows/pr-report.yaml +++ /dev/null @@ -1,159 +0,0 @@ -name: PR Report - -on: - workflow_run: - workflows: ["PR Buid/Test"] - types: [completed] - -jobs: - - sonar-scan: - - runs-on: macos-12 - - if: github.event.workflow_run.conclusion == 'success' - - steps: - - - name: Install Tools - run: | - brew install sonar-scanner - env: - HOMEBREW_NO_INSTALL_CLEANUP: 1 - - - name: Get PR Info - uses: potiuk/get-workflow-origin@v1_5 - id: pr_info - with: - token: ${{ secrets.GITHUB_TOKEN }} - sourceRunId: ${{ github.event.workflow_run.id }} - - - name: Checkout PR - uses: actions/checkout@v3 - with: - ref: ${{ steps.pr_info.outputs.mergeCommitSha }} - fetch-depth: 0 - - - name: Download Build - uses: actions/github-script@v6 - with: - script: | - let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({ - owner: context.repo.owner, - repo: context.repo.repo, - run_id: context.payload.workflow_run.id, - }); - let buildResultsArtifact = allArtifacts.data.artifacts.filter((artifact) => { - return artifact.name == "build-results" - })[0]; - let buildResultsDownload = await github.rest.actions.downloadArtifact({ - owner: context.repo.owner, - repo: context.repo.repo, - artifact_id: buildResultsArtifact.id, - archive_format: 'zip', - }); - let fs = require('fs'); - fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/build-results.tar.gz`, Buffer.from(buildResultsDownload.data)); - - - name: Extract Build Results - run: tar -xzf build-results.tar.gz - - - name: Sonar Scanner - run: | - sonar-scanner -Dsonar.scm.revision=${{ steps.pr_info.outputs.sourceHeadSha }} -Dsonar.pullrequest.key=${{ steps.pr_info.outputs.pullRequestNumber }} -Dsonar.pullrequest.branch=${{ steps.pr_info.outputs.sourceHeadBranch }} -Dsonar.pullrequest.base=${{ steps.pr_info.outputs.targetBranch }} - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - - - report-test-results: - - runs-on: macos-12 - - permissions: - checks: write - - steps: - - - name: Get PR Info - uses: potiuk/get-workflow-origin@v1_5 - id: pr_info - with: - token: ${{ secrets.GITHUB_TOKEN }} - sourceRunId: ${{ github.event.workflow_run.id }} - - - name: Download Test Result Archives - uses: actions/github-script@v6 - with: - script: | - let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({ - owner: context.repo.owner, - repo: context.repo.repo, - run_id: context.payload.workflow_run.id, - }); - let testResultArchiveArtifacts = allArtifacts.data.artifacts.filter((artifact) => { - return artifact.name.startsWith("test-results") - }); - let fs = require('fs'); - await Promise.all( - testResultArchiveArtifacts.map(async (artifact) => { - let testResultArchiveDownload = await github.rest.actions.downloadArtifact({ - owner: context.repo.owner, - repo: context.repo.repo, - artifact_id: artifact.id, - archive_format: 'zip', - }); - fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/${artifact.name}.tar.gz`, Buffer.from(testResultArchiveDownload.data)); - }) - ); - - - name: Extract Test Result Archives - run: | - tar -xzf test-results-macos.tar.gz || true - tar -xzf test-results-ios.tar.gz || true - tar -xzf test-results-tvos.tar.gz || true - tar -xzf test-results-watchos.tar.gz || true - - - name: Report macOS Test Results - uses: kdubb/xcresulttool@v1 - continue-on-error: true - with: - repo: ${{ steps.pr_info.outputs.sourceHeadRepo }} - sha: ${{ steps.pr_info.outputs.sourceHeadSha }} - title: Test Results macOS - path: ./TestResults/macOS.xcresult - upload-bundles: never - show-code-coverage: false - - - name: Report iOS Test Results - uses: kdubb/xcresulttool@v1 - continue-on-error: true - with: - repo: ${{ steps.pr_info.outputs.sourceHeadRepo }} - sha: ${{ steps.pr_info.outputs.sourceHeadSha }} - title: Test Results iOS - path: ./TestResults/iOS.xcresult - upload-bundles: never - show-code-coverage: false - - - name: Report tvOS Test Results - uses: kdubb/xcresulttool@v1 - continue-on-error: true - with: - repo: ${{ steps.pr_info.outputs.sourceHeadRepo }} - sha: ${{ steps.pr_info.outputs.sourceHeadSha }} - title: Test Results tvOS - path: ./TestResults/tvOS.xcresult - upload-bundles: never - show-code-coverage: false - - - name: Report watchOS Test Results - uses: kdubb/xcresulttool@v1 - continue-on-error: true - with: - repo: ${{ steps.pr_info.outputs.sourceHeadRepo }} - sha: ${{ steps.pr_info.outputs.sourceHeadSha }} - title: Test Results watchOS - path: ./TestResults/watchOS.xcresult - upload-bundles: never - show-code-coverage: false diff --git a/.github/workflows/pr-scan.yaml b/.github/workflows/pr-scan.yaml new file mode 100644 index 000000000..979982f43 --- /dev/null +++ b/.github/workflows/pr-scan.yaml @@ -0,0 +1,66 @@ +name: PR Scan + +on: + workflow_run: + workflows: ["PR Buid/Test"] + types: [completed] + +jobs: + + sonar-scan: + + runs-on: macos-12 + + if: github.event.workflow_run.conclusion == 'success' + + steps: + + - name: Install Tools + run: | + brew install sonar-scanner + env: + HOMEBREW_NO_INSTALL_CLEANUP: 1 + + - name: Get PR Info + uses: potiuk/get-workflow-origin@v1_5 + id: pr_info + with: + token: ${{ secrets.GITHUB_TOKEN }} + sourceRunId: ${{ github.event.workflow_run.id }} + + - name: Checkout PR + uses: actions/checkout@v3 + with: + ref: ${{ steps.pr_info.outputs.mergeCommitSha }} + fetch-depth: 0 + + - name: Download Build + uses: actions/github-script@v6 + with: + script: | + let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({ + owner: context.repo.owner, + repo: context.repo.repo, + run_id: context.payload.workflow_run.id, + }); + let buildResultsArtifact = allArtifacts.data.artifacts.filter((artifact) => { + return artifact.name == "build-results" + })[0]; + let buildResultsDownload = await github.rest.actions.downloadArtifact({ + owner: context.repo.owner, + repo: context.repo.repo, + artifact_id: buildResultsArtifact.id, + archive_format: 'zip', + }); + let fs = require('fs'); + fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/build-results.tar.gz`, Buffer.from(buildResultsDownload.data)); + + - name: Extract Build Results + run: tar -xzf build-results.tar.gz + + - name: Sonar Scanner + run: | + sonar-scanner -Dsonar.scm.revision=${{ steps.pr_info.outputs.sourceHeadSha }} -Dsonar.pullrequest.key=${{ steps.pr_info.outputs.pullRequestNumber }} -Dsonar.pullrequest.branch=${{ steps.pr_info.outputs.sourceHeadBranch }} -Dsonar.pullrequest.base=${{ steps.pr_info.outputs.targetBranch }} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}