-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding action to publish test results (#12)
Signed-off-by: Nathan Lee <[email protected]>
- Loading branch information
1 parent
0ee6872
commit a3520fe
Showing
1 changed file
with
81 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json | ||
name: Publish Unit Test | ||
on: | ||
workflow_run: | ||
workflows: [Unit Test] | ||
types: | ||
- completed | ||
|
||
jobs: | ||
test: | ||
name: Publish | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: 'Download artifacts' | ||
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 matchArtifactTestResults = allArtifacts.data.artifacts.filter((artifact) => { | ||
return artifact.name == "unit-test-results" | ||
})[0]; | ||
let matchArtifactEventFile = allArtifacts.data.artifacts.filter((artifact) => { | ||
return artifact.name == "event-file" | ||
})[0]; | ||
let downloadTestResults = await github.rest.actions.downloadArtifact({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
artifact_id: matchArtifactTestResults.id, | ||
archive_format: 'zip', | ||
}); | ||
let downloadEventFile = await github.rest.actions.downloadArtifact({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
artifact_id: matchArtifactEventFile.id, | ||
archive_format: 'zip', | ||
}); | ||
let fs = require('fs'); | ||
fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/unit-test-results.zip`, Buffer.from(downloadTestResults.data)); | ||
fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/event.json.zip`, Buffer.from(downloadEventFile.data)); | ||
- name: Unzip artifacts | ||
run: unzip unit-test-results.zip && unzip event.json.zip | ||
|
||
# - name: Publish Unit Test Results | ||
# uses: EnricoMi/publish-unit-test-result-action@v2 | ||
# if: always() | ||
# with: | ||
# check_name: "Test Execution Results" | ||
# junit_files: "unittest.junit.xml" | ||
# commit: ${{ github.event.workflow_run.head_sha }} | ||
# event_file: event.json | ||
# event_name: ${{ github.event.workflow_run.event }} | ||
# compare_to_earlier_commit: false | ||
|
||
- name: Publish Unit Test Results | ||
uses: scacap/action-surefire-report@v1 | ||
if: ( github.event.workflow_run.event == 'push' ) || ( github.event.repository.full_name != github.event.workflow_run.repository.full_name) | ||
with: | ||
report_paths: "**/*.junit.xml" | ||
check_name: "Unit Test Report" | ||
commit: ${{ github.event.workflow_run.head_sha }} | ||
|
||
- name: Get PR Number | ||
if: github.event.workflow_run.event == 'pull_request' | ||
run: | | ||
NUM="$(jq -r ".number" event.json)" | ||
echo "TEST_PR_NUMBER=$NUM" >> $GITHUB_ENV | ||
- name: Add Coverage PR Comment | ||
uses: marocchino/sticky-pull-request-comment@v2 | ||
if: github.event.workflow_run.event == 'pull_request' | ||
with: | ||
path: code-coverage-results.md | ||
number: ${{ env.TEST_PR_NUMBER }} | ||
|
||
|