Skip to content

Commit 24c0cd5

Browse files
ABI check comment for pull requests from forks too (#240)
testpr.yaml's abi-comment job was skipped for pull requests from forks, whose runs only get a read-only token (e.g. #235). Post the comment from a separate workflow_run workflow instead, which runs from main with a write token, for all pull requests. It never checks out or runs pull-request code: the abi-check-*.md artifacts and the branch name come from the pull request's run, so they are only used as the comment text, and the pull request is looked up from the API (open, head at the built commit) rather than taken from the artifacts. A cancelled run (a newer push) posts nothing. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent ea09493 commit 24c0cd5

3 files changed

Lines changed: 85 additions & 61 deletions

File tree

‎.github/workflows/abi-comment.yaml‎

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# The ABI checks of a pull request's build (testpr.yaml) as one pull-request comment,
2+
# updated on every push. A separate workflow_run workflow, so that pull requests from
3+
# forks get the comment too: their own runs only have a read-only token.
4+
#
5+
# This runs with a write token, so it never checks out or runs pull-request code. The
6+
# abi-check-*.md artifacts and the run's branch name come from the pull request (a fork
7+
# can change testpr.yaml in its pull request), so they are only data: the comment text,
8+
# and the pull request is looked up from the API, not taken from the artifacts.
9+
name: ABI check comment
10+
11+
on:
12+
workflow_run:
13+
workflows: [Build]
14+
types: [completed]
15+
16+
permissions: {}
17+
18+
jobs:
19+
comment:
20+
name: ABI check comment
21+
if: ${{ github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion != 'cancelled' }}
22+
runs-on: ubuntu-latest
23+
permissions:
24+
actions: read
25+
pull-requests: write
26+
concurrency:
27+
group: abi-comment-${{ github.event.workflow_run.head_repository.full_name }}-${{ github.event.workflow_run.head_branch }}
28+
steps:
29+
- name: Find the pull request
30+
id: pr
31+
env:
32+
GH_TOKEN: ${{ github.token }}
33+
REPO: ${{ github.repository }}
34+
HEAD_OWNER: ${{ github.event.workflow_run.head_repository.owner.login }}
35+
HEAD_BRANCH: ${{ github.event.workflow_run.head_branch }}
36+
HEAD_SHA: ${{ github.event.workflow_run.head_sha }}
37+
run: |
38+
# the open pull request whose head is still the commit that was built
39+
pr=$(gh api -X GET "repos/$REPO/pulls" -f state=open -f head="$HEAD_OWNER:$HEAD_BRANCH" \
40+
-q ".[] | select(.head.sha == \"$HEAD_SHA\") | .number" | head -1)
41+
if [ -z "$pr" ]; then echo "No open pull request at $HEAD_SHA (newer push or closed)"; fi
42+
echo "number=$pr" >> "$GITHUB_OUTPUT"
43+
- uses: actions/download-artifact@v7
44+
if: ${{ steps.pr.outputs.number != '' }}
45+
with:
46+
pattern: abi-check-*
47+
merge-multiple: true
48+
path: abi
49+
run-id: ${{ github.event.workflow_run.id }}
50+
github-token: ${{ github.token }}
51+
- name: Post or update the comment
52+
if: ${{ steps.pr.outputs.number != '' }}
53+
env:
54+
GH_TOKEN: ${{ github.token }}
55+
REPO: ${{ github.repository }}
56+
PR: ${{ steps.pr.outputs.number }}
57+
run: |
58+
shopt -s nullglob
59+
files=(abi/abi-check-*.md)
60+
marker='<!-- robostack-abi-check -->'
61+
existing=$(gh api "repos/$REPO/issues/$PR/comments" --paginate -q ".[] | select(.body | startswith(\"$marker\")) | .id" | head -1)
62+
# no comment for pull requests that build nothing released before
63+
if ! grep -q '^| package |' "${files[@]}" /dev/null && [ -z "$existing" ]; then exit 0; fi
64+
{
65+
echo "$marker"
66+
echo "### ABI check (linux-64)"
67+
echo
68+
# GitHub's comment limit is 65536 characters
69+
cat "${files[@]}" | head -c 60000
70+
echo "<details><summary>About this check</summary>"
71+
echo
72+
echo "Each package this pull request built, compared with its newest released build (\`tools/abi_check.py\`, libabigail):"
73+
echo "- **compatible** / **additions**: the package can be bumped on its own;"
74+
echo "- **soname** / **incompatible**: the packages that depend on it need a rebuild (build number bump) in the same pull request."
75+
echo
76+
echo "Exported symbols are compared (the released packages are stripped, so struct layouts aren't); unchanged installed headers rule out layout and inline changes, changed ones are listed for review. Dependents to rebuild are the released ones linking to a changed library. A changed pin is part of the comparison."
77+
echo
78+
echo "</details>"
79+
} > body.md
80+
if [ -n "$existing" ]; then
81+
gh api -X PATCH "repos/$REPO/issues/comments/$existing" -F body=@body.md > /dev/null
82+
else
83+
gh api "repos/$REPO/issues/$PR/comments" -F body=@body.md > /dev/null
84+
fi

‎.github/workflows/testpr.yaml‎

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -357,66 +357,6 @@ jobs:
357357
sleep 15
358358
done
359359
360-
# The ABI checks of all distributions as one pull-request comment, updated on every
361-
# push. Pull requests from forks get a read-only token, so the job is skipped for them:
362-
# they only have the job summaries.
363-
abi-comment:
364-
name: ABI check comment
365-
needs: build
366-
if: ${{ always() && github.event_name == 'pull_request' && needs.build.result != 'skipped' && github.event.pull_request.head.repo.full_name == github.repository }}
367-
runs-on: ubuntu-latest
368-
continue-on-error: true
369-
permissions:
370-
actions: read
371-
pull-requests: write
372-
steps:
373-
- uses: actions/checkout@v6
374-
with:
375-
persist-credentials: false
376-
- name: Disable git auto-maintenance
377-
run: git config --global maintenance.auto false && git config --global gc.auto 0
378-
- uses: prefix-dev/setup-pixi@v0.11.0
379-
with:
380-
locked: true # the lock file must match pixi.toml
381-
pixi-version: v0.81.0
382-
cache-write: false # saved from main only (pixi-cache.yaml)
383-
- uses: actions/download-artifact@v7
384-
with:
385-
pattern: abi-check-*
386-
merge-multiple: true
387-
- name: Post or update the comment
388-
env:
389-
GH_TOKEN: ${{ github.token }}
390-
REPO: ${{ github.repository }}
391-
PR: ${{ github.event.pull_request.number }}
392-
run: |
393-
shopt -s nullglob
394-
files=(abi-check-*.md)
395-
marker='<!-- robostack-abi-check -->'
396-
existing=$(pixi run gh api "repos/$REPO/issues/$PR/comments" --paginate -q ".[] | select(.body | startswith(\"$marker\")) | .id" | head -1)
397-
# no comment for pull requests that build nothing released before
398-
if ! grep -q '^| package |' "${files[@]}" /dev/null && [ -z "$existing" ]; then exit 0; fi
399-
{
400-
echo "$marker"
401-
echo "### ABI check (linux-64)"
402-
echo
403-
cat "${files[@]}"
404-
echo "<details><summary>About this check</summary>"
405-
echo
406-
echo "Each package this pull request built, compared with its newest released build (\`tools/abi_check.py\`, libabigail):"
407-
echo "- **compatible** / **additions**: the package can be bumped on its own;"
408-
echo "- **soname** / **incompatible**: the packages that depend on it need a rebuild (build number bump) in the same pull request."
409-
echo
410-
echo "Exported symbols are compared (the released packages are stripped, so struct layouts aren't); unchanged installed headers rule out layout and inline changes, changed ones are listed for review. Dependents to rebuild are the released ones linking to a changed library. A changed pin is part of the comparison."
411-
echo
412-
echo "</details>"
413-
} > body.md
414-
if [ -n "$existing" ]; then
415-
pixi run gh api -X PATCH "repos/$REPO/issues/comments/$existing" -F body=@body.md > /dev/null
416-
else
417-
pixi run gh api "repos/$REPO/issues/$PR/comments" -F body=@body.md > /dev/null
418-
fi
419-
420360
# One stable check for branch protection / auto-merge: the build matrix differs
421361
# from PR to PR, so require this job instead of the individual builds.
422362
all-green:

‎tools/maintenance.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -841,7 +841,7 @@ def rebuild_packages(packages: list[str], distros: list[str], with_dependents: b
841841

842842

843843
ABI_MARKER = "<!-- robostack-abi-check -->"
844-
ABI_AUTHOR = "github-actions[bot]" # testpr.yaml's abi-comment job posts with the workflow token
844+
ABI_AUTHOR = "github-actions[bot]" # abi-comment.yaml posts with the workflow token
845845

846846

847847
def abi_rebuilds(comment: str) -> dict[str, dict[str, int]]:

0 commit comments

Comments
 (0)