Post coverage comment #217
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Post coverage comment | |
on: | |
workflow_run: | |
workflows: ["continuous-integration"] | |
types: | |
- completed | |
jobs: | |
test: | |
name: "Run tests & display coverage" | |
runs-on: ubuntu-latest | |
permissions: | |
pull-requests: write | |
contents: write # needed to edit the comment vs opening multiple ones | |
actions: read | |
steps: | |
- name: "Get the triggering workflow run details" | |
id: get-run | |
uses: octokit/request-action@v2.x | |
with: | |
route: GET /repos/${{ github.repository }}/actions/runs/${{ github.event.workflow_run.id }} | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: "Check if the trigger was a PR event" | |
run: | | |
TRIGGER_EVENT=$(echo '${{ steps.get-run.outputs.data }}' | jq -r '.event') | |
if [[ "$TRIGGER_EVENT" != "pull_request" ]]; then | |
echo "Workflow was not triggered by a PR, skipping coverage comment." | |
exit 78 # Exiting with a neutral status | |
fi | |
# this needs the .coverage file so we download from the CI workflow artifacts | |
- name: "Download coverage data 📥" | |
uses: actions/download-artifact@v4 | |
with: | |
pattern: coverage-data-* | |
merge-multiple: true | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
run-id: ${{ github.event.workflow_run.id }} | |
- name: "Post coverage comment" | |
uses: py-cov-action/python-coverage-comment-action@v3 | |
with: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
GITHUB_PR_RUN_ID: ${{ github.event.workflow_run.id }} |