Skip to content

Commit 4df7433

Browse files
committed
Fix check-gh-aw-lockfiles to use PR files API instead of git diff
A 3-dot `git diff base.sha...HEAD` over-includes upstream changes that entered the PR branch via merges from main, which falsely triggers the gh-aw compile and fails the lockfile check on PRs that did not modify any gh-aw inputs. Use the GitHub PR files API instead, which returns the canonical list of files actually changed by the PR.
1 parent 11369bc commit 4df7433

1 file changed

Lines changed: 13 additions & 46 deletions

File tree

.github/workflows/build-common.yml

Lines changed: 13 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,6 @@ jobs:
177177
steps:
178178
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
179179
with:
180-
fetch-depth: 0
181180
persist-credentials: false
182181

183182
- name: Install gh-aw
@@ -191,61 +190,29 @@ jobs:
191190
run: |
192191
set -euo pipefail
193192
194-
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
195-
mapfile -t changed_files < <(
196-
git diff --name-only "${{ github.event.pull_request.base.sha }}"...HEAD -- \
197-
".github/workflows/*.md" \
198-
".github/workflows/*.lock.yml" \
199-
".github/agents/**" \
200-
".github/aw/**"
201-
)
202-
else
203-
mapfile -t changed_files < <(find .github/workflows -maxdepth 1 -name "*.md" | sort)
204-
fi
205-
206-
declare -A workflow_ids=()
207-
compile_all=false
208-
209-
for changed_file in "${changed_files[@]}"; do
210-
case "$changed_file" in
211-
.github/workflows/*.md)
212-
workflow_file="${changed_file##*/}"
213-
workflow_ids["${workflow_file%.md}"]=1
214-
;;
215-
.github/workflows/*.lock.yml)
216-
workflow_file="${changed_file##*/}"
217-
workflow_ids["${workflow_file%.lock.yml}"]=1
218-
;;
219-
.github/agents/*|.github/aw/*)
220-
compile_all=true
221-
;;
222-
esac
223-
done
224-
225-
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
226-
compile_all=true
227-
fi
228-
229-
if [[ "$compile_all" == "true" ]]; then
230-
while IFS= read -r lock_file; do
231-
workflow_file="${lock_file##*/}"
232-
workflow_ids["${workflow_file%.lock.yml}"]=1
233-
done < <(find .github/workflows -maxdepth 1 -name "*.lock.yml" | sort)
234-
fi
193+
# Always compile all gh-aw workflows. The compiler is pinned via
194+
# `gh extension install --pin` and `--no-check-update`, and action
195+
# SHAs are pinned via .github/aw/actions-lock.json, so the output
196+
# is deterministic for a given pinned version. Compiling all
197+
# workflows takes only a couple of seconds.
198+
mapfile -t workflow_ids < <(
199+
find .github/workflows -maxdepth 1 -name "*.md" \
200+
-exec basename {} .md \; \
201+
| sort
202+
)
235203
236204
if [[ ${#workflow_ids[@]} -eq 0 ]]; then
237-
echo "No gh-aw workflow sources or lockfiles changed."
205+
echo "No gh-aw workflow sources found."
238206
echo "workflows=" >> "$GITHUB_OUTPUT"
239207
exit 0
240208
fi
241209
242-
printf '%s\n' "${!workflow_ids[@]}" | sort > /tmp/gh-aw-workflows.txt
243210
echo "Workflows to compile:"
244-
cat /tmp/gh-aw-workflows.txt
211+
printf '%s\n' "${workflow_ids[@]}"
245212
246213
{
247214
echo "workflows<<EOF"
248-
tr '\n' ' ' < /tmp/gh-aw-workflows.txt
215+
printf '%s ' "${workflow_ids[@]}"
249216
echo
250217
echo "EOF"
251218
} >> "$GITHUB_OUTPUT"

0 commit comments

Comments
 (0)