From ad3241e30ae4345f4bea9db6fee5ba535156c9b2 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Thu, 30 May 2024 18:53:40 +0200 Subject: [PATCH 1/6] ci: Only run upload_coverage if coverage workflow succeeded --- .github/workflows/upload_coverage.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/upload_coverage.yml b/.github/workflows/upload_coverage.yml index 66a0743b036..c19cd0c6e54 100644 --- a/.github/workflows/upload_coverage.yml +++ b/.github/workflows/upload_coverage.yml @@ -14,6 +14,7 @@ jobs: coverage: name: Upload coverage report runs-on: ubuntu-latest + if: github.event.workflow_run.conclusion == 'success' steps: - name: 'Fetch coverage report from artifacts' id: prepare_report From 0144da7dbdfaca5fcf3949743b8cd089d74ee417 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Thu, 30 May 2024 18:59:53 +0200 Subject: [PATCH 2/6] ci: Normalize indentation in upload_coverage.yml --- .github/workflows/upload_coverage.yml | 30 +++++++++++++-------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/.github/workflows/upload_coverage.yml b/.github/workflows/upload_coverage.yml index c19cd0c6e54..55a2f1269d0 100644 --- a/.github/workflows/upload_coverage.yml +++ b/.github/workflows/upload_coverage.yml @@ -25,9 +25,9 @@ jobs: // List artifacts of the workflow run that triggered this workflow var artifacts = await github.rest.actions.listWorkflowRunArtifacts({ - owner: context.repo.owner, - repo: context.repo.repo, - run_id: context.payload.workflow_run.id, + owner: context.repo.owner, + repo: context.repo.repo, + run_id: context.payload.workflow_run.id, }); let codecovReport = artifacts.data.artifacts.filter((artifact) => { @@ -39,10 +39,10 @@ jobs: } var download = await github.rest.actions.downloadArtifact({ - owner: context.repo.owner, - repo: context.repo.repo, - artifact_id: codecovReport[0].id, - archive_format: 'zip', + owner: context.repo.owner, + repo: context.repo.repo, + artifact_id: codecovReport[0].id, + archive_format: 'zip', }); fs.writeFileSync('codecov_report.zip', Buffer.from(download.data)); @@ -55,10 +55,10 @@ jobs: } var download = await github.rest.actions.downloadArtifact({ - owner: context.repo.owner, - repo: context.repo.repo, - artifact_id: prNumber[0].id, - archive_format: 'zip', + owner: context.repo.owner, + repo: context.repo.repo, + artifact_id: prNumber[0].id, + archive_format: 'zip', }); fs.writeFileSync('pr_number.zip', Buffer.from(download.data)); @@ -71,10 +71,10 @@ jobs: } var download = await github.rest.actions.downloadArtifact({ - owner: context.repo.owner, - repo: context.repo.repo, - artifact_id: commitSha[0].id, - archive_format: 'zip', + owner: context.repo.owner, + repo: context.repo.repo, + artifact_id: commitSha[0].id, + archive_format: 'zip', }); fs.writeFileSync('commit_sha.zip', Buffer.from(download.data)); From f09f5be3a7536ef4bfc92309c398f84555a7691b Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Thu, 30 May 2024 19:18:12 +0200 Subject: [PATCH 3/6] ci: Fix bash syntax in last code_coverage job step It was trying to execute `upload_coverage.yml` before. --- .github/workflows/coverage.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index ef61dec7cdc..14a9e79d3f1 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -145,5 +145,5 @@ jobs: path: codecov_report.json - run: | - echo "The coverage report was stored in Github artifacts." - echo "It will be uploaded to Codecov using `upload_coverage.yml` workflow shortly." + echo 'The coverage report was stored in Github artifacts.' + echo 'It will be uploaded to Codecov using `upload_coverage.yml` workflow shortly.' From 038f6831ea583f427f61d28daf320f4b23245106 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Thu, 30 May 2024 19:32:18 +0200 Subject: [PATCH 4/6] ci: Use one artifact for all coverage files Instead of three separate artifacts. --- .github/workflows/coverage.yml | 26 ++++++-------------- .github/workflows/upload_coverage.yml | 34 --------------------------- 2 files changed, 7 insertions(+), 53 deletions(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 14a9e79d3f1..73816ed7a0d 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -120,29 +120,17 @@ jobs: echo "Storing commit SHA ${{ github.event.pull_request.head.sha }}" echo "${{ github.event.pull_request.head.sha }}" > commit_sha.txt - # Workaround for https://github.com/orgs/community/discussions/25220 - # Triggered sub-workflow is not able to detect the original commit/PR which is available - # in this workflow. - - name: Store PR number in artifacts - uses: actions/upload-artifact@v4 - with: - name: pr_number - path: pr_number.txt - - - name: Store commit SHA in artifacts - uses: actions/upload-artifact@v4 - with: - name: commit_sha - path: commit_sha.txt - - # This stores the coverage report in artifacts. The actual upload to Codecov - # is executed by a different workflow `upload_coverage.yml`. The reason for this - # split is because `on.pull_request` workflows don't have access to secrets. + # This stores the coverage report and metadata in artifacts. + # The actual upload to Codecov is executed by a different workflow `upload_coverage.yml`. + # The reason for this split is because `on.pull_request` workflows don't have access to secrets. - name: Store coverage report in artifacts uses: actions/upload-artifact@v4 with: name: codecov_report - path: codecov_report.json + path: | + codecov_report.json + pr_number.txt + commit_sha.txt - run: | echo 'The coverage report was stored in Github artifacts.' diff --git a/.github/workflows/upload_coverage.yml b/.github/workflows/upload_coverage.yml index 55a2f1269d0..ef730e86a69 100644 --- a/.github/workflows/upload_coverage.yml +++ b/.github/workflows/upload_coverage.yml @@ -46,43 +46,9 @@ jobs: }); fs.writeFileSync('codecov_report.zip', Buffer.from(download.data)); - let prNumber = artifacts.data.artifacts.filter((artifact) => { - return artifact.name == "pr_number"; - }); - - if (prNumber.length != 1) { - throw new Error("Unexpected number of {pr_number} artifacts: " + prNumber.length); - } - - var download = await github.rest.actions.downloadArtifact({ - owner: context.repo.owner, - repo: context.repo.repo, - artifact_id: prNumber[0].id, - archive_format: 'zip', - }); - fs.writeFileSync('pr_number.zip', Buffer.from(download.data)); - - let commitSha = artifacts.data.artifacts.filter((artifact) => { - return artifact.name == "commit_sha"; - }); - - if (commitSha.length != 1) { - throw new Error("Unexpected number of {commit_sha} artifacts: " + commitSha.length); - } - - var download = await github.rest.actions.downloadArtifact({ - owner: context.repo.owner, - repo: context.repo.repo, - artifact_id: commitSha[0].id, - archive_format: 'zip', - }); - fs.writeFileSync('commit_sha.zip', Buffer.from(download.data)); - - id: parse_previous_artifacts run: | unzip codecov_report.zip - unzip pr_number.zip - unzip commit_sha.zip echo "Detected PR is: $( Date: Thu, 30 May 2024 19:34:32 +0200 Subject: [PATCH 5/6] ci: Update coverage workflows to use the right file --- .github/workflows/coverage.yml | 2 +- .github/workflows/upload_coverage.yml | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 73816ed7a0d..63febbdf55d 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -128,7 +128,7 @@ jobs: with: name: codecov_report path: | - codecov_report.json + cobertura.xml pr_number.txt commit_sha.txt diff --git a/.github/workflows/upload_coverage.yml b/.github/workflows/upload_coverage.yml index ef730e86a69..da1447341f7 100644 --- a/.github/workflows/upload_coverage.yml +++ b/.github/workflows/upload_coverage.yml @@ -67,7 +67,6 @@ jobs: uses: codecov/codecov-action@v4 with: token: ${{ secrets.CODECOV_UPLOAD_TOKEN }} - files: ${{ github.workspace }}/codecov_report.json fail_ci_if_error: true # Manual overrides for these parameters are needed because automatic detection # in codecov-action does not work for non-`pull_request` workflows. From eca011e9426ea30c2411379200799c5b1b81eb46 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Thu, 30 May 2024 19:35:35 +0200 Subject: [PATCH 6/6] ci: Error if coverage report files are not found --- .github/workflows/coverage.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 63febbdf55d..c5688ec25cd 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -131,6 +131,7 @@ jobs: cobertura.xml pr_number.txt commit_sha.txt + if-no-files-found: error - run: | echo 'The coverage report was stored in Github artifacts.'