From 1334b65bdfca7bb23e7c95c446f9ad3746fb0e7c Mon Sep 17 00:00:00 2001 From: Jelle Spijker Date: Tue, 5 Dec 2023 07:17:21 +0100 Subject: [PATCH] Post the unit test result on PR's Contributes to CURA-10831 --- .github/workflows/unit-test-post.yml | 85 +++------------------------- 1 file changed, 8 insertions(+), 77 deletions(-) diff --git a/.github/workflows/unit-test-post.yml b/.github/workflows/unit-test-post.yml index 36c1d5acfd..119ca30f33 100644 --- a/.github/workflows/unit-test-post.yml +++ b/.github/workflows/unit-test-post.yml @@ -1,82 +1,13 @@ name: unit-test-post on: - workflow_run: - workflows: [ "unit-test" ] - types: [ completed ] + workflow_run: + workflows: [ "unit-test" ] + types: [ completed ] jobs: - publish-test-results: - if: ${{ github.event.workflow_run.event == 'pull_request' && 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 pr_env - unzip test-result.zip -d pr_env - echo "pr_id=$(cat pr_env/pr-id.txt)" >> $GITHUB_ENV - echo "pr_head_repo=$(cat pr_env/pr-head-repo.txt)" >> $GITHUB_ENV - echo "pr_head_ref=$(cat pr_env/pr-head-ref.txt)" >> $GITHUB_ENV - - - uses: actions/checkout@v3 - with: - repository: ${{ env.pr_head_repo }} - ref: ${{ env.pr_head_ref }} - persist-credentials: false - - - name: Redownload 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: Extract analysis results - run: | - mkdir -p tests - unzip test-result.zip -d tests - - - 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 ${{ steps.test-results.outputs.json && fromJSON( steps.test-results.outputs.json ).conclusion }}" + publish-test-results: + uses: ultimaker/cura-workflows/.github/workflows/unit-test-post.yml@CURA-10831 + with: + event: ${{ github.event.workflow_run.event }} + conclusion: ${{ github.event.workflow_run.conclusion }}