diff --git a/.github/workflows/publish-test.yml b/.github/workflows/publish-test.yml new file mode 100644 index 0000000..e687030 --- /dev/null +++ b/.github/workflows/publish-test.yml @@ -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 }} + +