ReportTestResults #312
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: ReportTestResults | |
| on: | |
| workflow_run: | |
| workflows: | |
| - PullRequest | |
| types: | |
| - completed | |
| permissions: | |
| contents: read | |
| actions: read | |
| checks: write | |
| jobs: | |
| Report: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: 'Add default settings to node calls' | |
| shell: bash | |
| run: | | |
| # | |
| # The later used dorny/test-reporter action can throw the following exception when enough tests have been | |
| # executed: | |
| # RangeError: Maximum call stack size exceeded | |
| # | |
| # We explicitly increase the stack max. stack size here to work around this issue. | |
| # | |
| which node | |
| node --version | |
| mv /usr/local/bin/node /usr/local/bin/node_org | |
| echo '#!/bin/bash' >> /usr/local/bin/node | |
| echo '/usr/local/bin/node_org --stack-size=4096 $@' >> /usr/local/bin/node | |
| cat /usr/local/bin/node | |
| chmod +x /usr/local/bin/node | |
| which node | |
| node --version | |
| # No checkout: nothing here reads a repository file. The artifact is fetched through the API and written | |
| # to the workspace, which exists anyway. Checking out the HEAD repo/ref also broke on fork PRs, where | |
| # actions/checkout refuses to place a fork's code in a workflow_run context holding the base repo's token | |
| # and secrets - and opting into that ("pwn request") to obtain files nothing uses would be a bad trade. | |
| # Download the artifact manually and feed it to dorny/test-reporter as local files. | |
| - name: 'Download Test Results' | |
| id: DownloadTestResults | |
| uses: actions/github-script@v8 | |
| with: | |
| script: | | |
| var allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| run_id: context.payload.workflow_run.id, | |
| }); | |
| console.log('context.repo.owner = ' + context.repo.owner); | |
| console.log('context.repo.repo = ' + context.repo.repo); | |
| var artifacts = allArtifacts.data.artifacts.filter((artifact) => { | |
| return artifact.name == "test-results"; | |
| }); | |
| if (artifacts.length > 0) { | |
| var download = await github.rest.actions.downloadArtifact({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| artifact_id: artifacts[0].id, | |
| archive_format: 'zip', | |
| }); | |
| var fs = require('fs'); | |
| fs.writeFileSync('${{ github.workspace }}/test-results.zip', Buffer.from(download.data)); | |
| core.setOutput('hasTestResultsArtifact', 'true'); | |
| } | |
| - name: 'Extract Artifact' | |
| id: ExtractArtifact | |
| if: steps.DownloadTestResults.outputs.hasTestResultsArtifact == 'true' | |
| shell: pwsh | |
| run: | | |
| Expand-Archive test-results.zip -DestinationPath './test-results' -Force | |
| dir -Recurse | Select-Object -ExpandProperty FullName | |
| - name: 'Publish Test Report' | |
| if: steps.ExtractArtifact.conclusion == 'success' | |
| uses: dorny/test-reporter@v3 | |
| env: | |
| # | |
| # Can throw the following exception, when enough tests have been executed: | |
| # FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory | |
| # | |
| # We explicitly increase the max. heap size here to work around this issue. | |
| # | |
| NODE_OPTIONS: --max-old-space-size=8192 | |
| with: | |
| name: 'All Tests' | |
| # artifact: test-results | |
| # use '**/*.trx' for artifact and 'test-results/**/*.trx' for local files | |
| path: 'test-results/**/*.trx' | |
| reporter: dotnet-trx | |
| only-summary: 'true' | |
| fail-on-error: 'false' | |
| fail-on-empty: 'true' |