Skip to content

Commit

Permalink
add the PR annotate-r workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
JacksonBurns committed Oct 30, 2023
1 parent b706fcc commit 6a6b56d
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions .github/workflows/annotate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Annotate pull request with regression summaries
# Takes a regression summary from a workflow run and annotates the pull request with it
# The pull request number is taken from the first line of the summary.txt file.
# The summary file is in an artifact called regression_summary associated
# with the workflow run that triggered this workflow.
# based on https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#using-data-from-the-triggering-workflow

on:
workflow_run:
workflows:
- Continuous Integration
types:
- completed

run-name: Annotate "${{ github.event.workflow_run.display_title }}"

jobs:
on-success:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.event == 'pull_request' }}
steps:
- run: echo 'The triggering workflow passed'
- name: 'Download regression_summary artifact'
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 matchArtifact = allArtifacts.data.artifacts.filter((artifact) => {
return artifact.name == "regression_summary"
})[0];
let download = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: matchArtifact.id,
archive_format: 'zip',
});
let fs = require('fs');
fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/regression_summary.zip`, Buffer.from(download.data));
- name: 'Unzip artifact'
run: unzip regression_summary.zip

- name: 'Get pull request number'
run: |
echo "PR_NUMBER=$( head -n 1 summary.txt )" >> $GITHUB_ENV
# remove the first line from the file
sed -i '1d' summary.txt
- name: Write summary to pull request as a comment
uses: thollander/actions-comment-pull-request@v2
with:
filePath: summary.txt
pr_number: ${{ env.PR_NUMBER }}

- name: Report the github.event.workflow_run as json
if: ${{ failure() }}
run: echo $JSON
env:
JSON: ${{ toJson(github.event.workflow_run) }}

0 comments on commit 6a6b56d

Please sign in to comment.