Skip to content

display analysis

display analysis #360

# Never check out the PR code here. This workflow has write permissions.
# Always review any changes to this PR or the accompanying tagbot.py script critically
name: display analysis
on:
workflow_run:
workflows: ['analyze']
types: [completed]
concurrency:
group: "${{ github.workflow }}-${{ github.event.pull_request.number }}"
cancel-in-progress: true
jobs:
display_analysis:
if: >
github.event.workflow_run.conclusion == 'success'
runs-on: ubuntu-24.04
permissions:
pull-requests: write
steps:
- name: Download analysis artifact
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c
with:
name: analysis
run-id: ${{ github.event.workflow_run.id }}
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Label and diff comment
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
run: |
export PR=$(jq -r '.pr' analysis.json)
echo "Updating information for PR=$PR"
# labels
echo "Correcting labels"
gh pr edit "$PR" --add-label "$(jq -r '.labels | join(",")' analysis.json)" || true
gh pr edit "$PR" --remove-label "$(jq -r '.not_labels | join(",")' analysis.json)" || true
# diff comment
export MARKER="<!-- diff -->"
COMMENT=$(jq -r '.diff // empty' analysis.json)
COMMENT_ID=$(
gh api "repos/$GH_REPO/issues/$PR/comments" \
| jq -r '.[] | select(.body | startswith(env.MARKER)) | .id' \
| head -n1
)
echo "COMMENT_ID = $COMMENT_ID"
if [ -z "$COMMENT" ]; then
if [ -n "$COMMENT_ID" ]; then
echo "Delete comment"
gh api -X DELETE "repos/$GH_REPO/issues/comments/$COMMENT_ID"
fi
exit 0
fi
BODY="${MARKER}"$'\n'"${COMMENT}"
# GitHub comment body hard limit ~= 65536 chars
if [ "${#BODY}" -gt 65000 ]; then
echo "Diff comment too long (${#BODY} chars)"
BODY="${MARKER}"$'\n'"Diff comment too long (${#BODY} chars)"
fi
if [ -n "$COMMENT_ID" ]; then
echo "Update existing comment"
jq -n --arg body "$BODY" '{body:$body}' \
| gh api \
--method PATCH \
--input - \
"repos/$GH_REPO/issues/comments/$COMMENT_ID"
else
echo "Create new comment"
gh pr comment "$PR" --body "$BODY"
fi