Skip to content

Commit 7409a14

Browse files
ci(aur): stop executing code from the workflow_run checkout (CodeQL #5)
1 parent 2adb7b1 commit 7409a14

1 file changed

Lines changed: 25 additions & 9 deletions

File tree

.github/workflows/aur-publish.yml

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,29 @@ jobs:
2626
runs-on: ubuntu-latest
2727
steps:
2828
- name: Check out repo
29+
# No ref: on workflow_run this checks out the default branch, so the
30+
# only code this privileged job executes (scripts/regenerate_srcinfo.py
31+
# below) comes from trusted master — never from the triggering commit
32+
# (CodeQL actions/untrusted-checkout). The release commit's files are
33+
# extracted as plain data in the next step.
2934
uses: actions/checkout@v7
30-
with:
31-
# On workflow_run, checkout's default is the default branch — NOT
32-
# the commit the Publish run built. Pin to that commit so the
33-
# version read below is the same one publish.yml's tag guard
34-
# verified. Falls back to github.ref for workflow_dispatch.
35-
ref: ${{ github.event.workflow_run.head_sha || github.ref }}
35+
36+
- name: Extract release files from the triggering commit
37+
# The version + PKGBUILD must come from the exact commit the Publish
38+
# run built — the same one its tag guard verified — but only as DATA
39+
# via `git show`; nothing from that commit is checked out or executed.
40+
env:
41+
HEAD_SHA: ${{ github.event.workflow_run.head_sha }}
42+
run: |
43+
if [ -n "$HEAD_SHA" ]; then
44+
git fetch --depth=1 origin "$HEAD_SHA"
45+
git show "$HEAD_SHA:src/ytm_player/__init__.py" > /tmp/release_init.py
46+
git show "$HEAD_SHA:aur/PKGBUILD" > /tmp/release_pkgbuild
47+
else
48+
# workflow_dispatch: no upstream run — use the checked-out files.
49+
cp src/ytm_player/__init__.py /tmp/release_init.py
50+
cp aur/PKGBUILD /tmp/release_pkgbuild
51+
fi
3652
3753
# The version comes from __version__ — the same source of truth the
3854
# Publish workflow's tag guard checks. The pkgver= line in aur/PKGBUILD
@@ -41,9 +57,9 @@ jobs:
4157
- name: Read version from package
4258
id: version
4359
run: |
44-
PKGVER=$(grep -oP '^__version__\s*=\s*"\K[^"]+' src/ytm_player/__init__.py || true)
60+
PKGVER=$(grep -oP '^__version__\s*=\s*"\K[^"]+' /tmp/release_init.py || true)
4561
if [ -z "$PKGVER" ]; then
46-
echo "::error::Could not read __version__ from src/ytm_player/__init__.py"
62+
echo "::error::Could not read __version__ from the release commit's src/ytm_player/__init__.py"
4763
exit 1
4864
fi
4965
echo "pkgver=$PKGVER" >> "$GITHUB_OUTPUT"
@@ -77,7 +93,7 @@ jobs:
7793
7894
- name: Copy PKGBUILD and regenerate .SRCINFO
7995
run: |
80-
cp aur/PKGBUILD /tmp/aur-repo/PKGBUILD
96+
cp /tmp/release_pkgbuild /tmp/aur-repo/PKGBUILD
8197
# Force the real version into the pushed PKGBUILD — the pkgver= in
8298
# aur/PKGBUILD is a placeholder and may be stale (the v2.0.0 lesson).
8399
# regenerate_srcinfo.py emits this literal line into .SRCINFO.

0 commit comments

Comments
 (0)