diff --git a/.github/workflows/unit-test-post.yml b/.github/workflows/unit-test-post.yml new file mode 100644 index 0000000000..d5dcd5e9d6 --- /dev/null +++ b/.github/workflows/unit-test-post.yml @@ -0,0 +1,50 @@ +name: printer-linter-pr-post + +on: + workflow_run: + workflows: [ "unit-test" ] + types: [ completed ] + +jobs: + publish-test-results: + if: ${{ github.event.workflow_run.conclusion == 'success' }} + runs-on: ubuntu-latest + + steps: + - name: Download analysis results + uses: actions/github-script@v3.1.0 + with: + script: | + let artifacts = await github.actions.listWorkflowRunArtifacts({ + owner: context.repo.owner, + repo: context.repo.repo, + run_id: ${{github.event.workflow_run.id }}, + }); + let matchArtifact = artifacts.data.artifacts.filter((artifact) => { + return artifact.name == "test-result" + })[0]; + let download = await github.actions.downloadArtifact({ + owner: context.repo.owner, + repo: context.repo.repo, + artifact_id: matchArtifact.id, + archive_format: "zip", + }); + let fs = require("fs"); + fs.writeFileSync("${{github.workspace}}/test-result.zip", Buffer.from(download.data)); + + - name: Set environment variables + run: | + mkdir tests + unzip test-result.zip -d tests + echo "pr_id=$(cat tests/pr-id.txt)" >> $GITHUB_ENV + echo "pr_head_repo=$(cat tests/pr-head-repo.txt)" >> $GITHUB_ENV + echo "pr_head_ref=$(cat tests/pr-head-ref.txt)" >> $GITHUB_ENV + + - name: Publish Unit Test Results + id: test-results + uses: EnricoMi/publish-unit-test-result-action@v1 + with: + files: "tests/**/*.xml" + + - name: Conclusion + run: echo "Conclusion is ${{ fromJSON( steps.test-results.outputs.json ).conclusion }}" diff --git a/.github/workflows/unit-test.yml b/.github/workflows/unit-test.yml index 4f7d077432..bc1933e3c7 100644 --- a/.github/workflows/unit-test.yml +++ b/.github/workflows/unit-test.yml @@ -1,6 +1,5 @@ --- name: unit-test -# FIXME: This should be a reusable workflow on: push: @@ -76,6 +75,8 @@ jobs: steps: - name: Checkout uses: actions/checkout@v3 + with: + fetch-depth: 2 - name: Setup Python and pip uses: actions/setup-python@v4 @@ -136,45 +137,21 @@ jobs: pytest --junitxml=junit_cura.xml working-directory: tests + - name: Save PR metadata + if: always() + run: | + echo ${{ github.event.number }} > pr-id.txt + echo ${{ github.event.pull_request.head.repo.full_name }} > pr-head-repo.txt + echo ${{ github.event.pull_request.head.ref }} > pr-head-ref.txt + working-directory: tests + - name: Upload Test Results if: always() uses: actions/upload-artifact@v3 with: - name: Test Results - path: "tests/**/*.xml" - - publish-test-results: - permissions: - contents: read # to fetch code (actions/checkout) - checks: write - pull-requests: write # to comment on pull request - - runs-on: ubuntu-20.04 - needs: [ testing ] - if: success() || failure() - - steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Setup Python and pip - uses: actions/setup-python@v4 - with: - python-version: '3.10.x' - architecture: 'x64' - cache: 'pip' - cache-dependency-path: .github/workflows/requirements-conan-package.txt - - - name: Download Artifacts - uses: actions/download-artifact@v3 - with: - path: artifacts - - - name: Publish Unit Test Results - id: test-results - uses: EnricoMi/publish-unit-test-result-action@v1 - with: - files: "artifacts/**/*.xml" - - - name: Conclusion - run: echo "Conclusion is ${{ fromJSON( steps.test-results.outputs.json ).conclusion }}" + name: test-result + path: | + tests/**/*.xml + tests/pr-id.txt + tests/pr-head-repo.txt + tests/pr-head-ref.txt \ No newline at end of file