Skip to content

mypy_primer comment #467

mypy_primer comment

mypy_primer comment #467

name: mypy_primer comment
permissions:
contents: read
pull-requests: write
on:
workflow_run:
workflows: [mypy_primer run]
types: [completed]
jobs:
comment:
if: ${{ github.event.workflow_run.conclusion == 'success' }}
runs-on: ubuntu-latest
timeout-minutes: 2
steps:
- uses: dawidd6/action-download-artifact@v19
name: download pr-number
with:
name: pr-number
path: ${{ runner.temp }}/artifacts
run_id: ${{ github.event.workflow_run.id }}
- name: parse pr-number
id: pr-number
run: |
if [[ -f ${{ runner.temp }}/artifacts/pr-number ]]
then
echo "pr-number=$(<${{ runner.temp }}/artifacts/pr-number)" >> "$GITHUB_OUTPUT"
fi
- uses: dawidd6/action-download-artifact@v19
name: download mypy_primer.diff
id: download-mypy_primer-diff
if: steps.pr-number.outputs.pr-number
with:
name: mypy_primer-diff
workflow: mypy_primer.yml
path: ${{ runner.temp }}/artifacts
pr: ${{ steps.pr-number.outputs.pr-number }}
workflow_conclusion: completed
allow_forks: true
- name: generate comment content
id: generate-comment
if: ${{ steps.download-mypy_primer-diff.outputs.found_artifact == 'true' }}
run: |
# Guard against malicious mypy_primer results that symlink to a secret
# file on this runner
if [[ -L ${{ runner.temp }}/artifacts/mypy_primer.diff ]]
then
echo "Error: mypy_primer.diff cannot be a symlink"
exit 1
fi
# Note this identifier is used to find the comment to update on
# subsequent runs
echo '<!-- generated-comment mypy_primer -->' >> comment.md
echo '## `mypy_primer` results' >> comment.md
if [ -s "${{ runner.temp }}/artifacts/mypy_primer.diff" ]; then
echo '<details>' >> comment.md
echo '<summary>⚠️ Changes were detected when running mypy on open source projects</summary>' >> comment.md
echo '' >> comment.md
echo '```diff' >> comment.md
cat ${{ runner.temp }}/artifacts/mypy_primer.diff >> comment.md
echo '```' >> comment.md
echo '</details>' >> comment.md
else
echo '✅ No ecosystem changes detected' >> comment.md
fi
echo 'comment<<EOF' >> "$GITHUB_OUTPUT"
cat comment.md >> "$GITHUB_OUTPUT"
echo 'EOF' >> "$GITHUB_OUTPUT"
- name: find existing comment
uses: peter-evans/find-comment@v4.0.0
if: steps.generate-comment.outcome == 'success'
id: find-comment
with:
issue-number: ${{ steps.pr-number.outputs.pr-number }}
comment-author: "github-actions[bot]"
body-includes: "<!-- generated-comment mypy_primer -->"
- name: create or update comment
if: steps.find-comment.outcome == 'success'
uses: peter-evans/create-or-update-comment@v5.0.0
with:
comment-id: ${{ steps.find-comment.outputs.comment-id }}
issue-number: ${{ steps.pr-number.outputs.pr-number }}
body-path: comment.md
edit-mode: replace