Skip to content

post-coverage-to-pr #3225

post-coverage-to-pr

post-coverage-to-pr #3225

name: post-coverage-to-pr
on:
workflow_run:
workflows:
- ci
types:
- completed
jobs:
code-coverage:
runs-on: ubuntu-latest
steps:
- name: Fetch code coverage results
uses: actions/github-script@v7
id: fetch-code-coverage-results
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 is_pull_request = 'false';
let matchedArtifacts = allArtifacts.data.artifacts.filter((artifact) => {
return artifact.name == "code-coverage-results"
});
if (matchedArtifacts.length > 0) {
let download = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: matchedArtifacts[0].id,
archive_format: 'zip',
});
let fs = require('fs');
fs.writeFileSync(
`${process.env.GITHUB_WORKSPACE}/code-coverage-results.zip`,
Buffer.from(download.data)
);
is_pull_request = 'true';
}
core.info('Setting output: is_pull_request=' + is_pull_request);
core.setOutput('is_pull_request', is_pull_request);
- name: Unzip code coverage results
if: steps.fetch-code-coverage-results.outputs.is_pull_request == 'true'
run: unzip code-coverage-results.zip
- name: Load pull request ID
uses: actions/github-script@v7
id: load-pull-request-id
if: steps.fetch-code-coverage-results.outputs.is_pull_request == 'true'
with:
script: |
let fs = require('fs');
let pull_request_id = fs.readFileSync(
`${process.env.GITHUB_WORKSPACE}/pull_request_id`
);
core.info('pull_request_id=' + pull_request_id);
if (pull_request_id == '') {
core.error('pull_request_id is empty');
} else {
core.info('Setting output: pull_request_id=' + pull_request_id);
core.setOutput('pull_request_id', Number(pull_request_id));
}
- name: Update PR with code coverage results
uses: marocchino/sticky-pull-request-comment@v2
if: steps.fetch-code-coverage-results.outputs.is_pull_request == 'true'
with:
number: ${{ steps.load-pull-request-id.outputs.pull_request_id }}
recreate: true
path: code-coverage-results.md