Skip to content

Commit 435a801

Browse files
committed
build: Refactor GitHub Actions workflow for dependencies
Updated to checkout the code first since not all workflows(merge_queue) will check have the PR_URL setting set. Then grab the shas from the relevant event payload and use those to get the list of affected files.
1 parent 87c8e55 commit 435a801

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

.github/workflows/check-consistent-dependencies.yml

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,27 @@ jobs:
1919
runs-on: ubuntu-24.04
2020

2121
steps:
22+
# Always checkout the code because we don't always have a PR url.
23+
- uses: actions/checkout@v5
24+
2225
# Only run remaining steps if there are changes to requirements/**
2326
- name: "Decide whether to short-circuit"
24-
env:
25-
GH_TOKEN: "${{ github.token }}"
26-
PR_URL: "${{ github.event.pull_request.html_url }}"
2727
run: |
28-
paths=$(gh pr diff "$PR_URL" --name-only)
29-
echo $'Paths touched in PR:\n'"$paths"
28+
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
29+
BASE_SHA="${{ github.event.pull_request.base.sha }}"
30+
else
31+
BASE_SHA="${{ github.event.merge_group.base_sha }}"
32+
fi
33+
34+
# Fetch the base sha so we can compare. It's not checked checkout by
35+
# default.
36+
git fetch origin "$BASE_SHA"
3037
3138
# The ^"? is because git may quote weird file paths
32-
matched="$(echo "$paths" | grep -P '^"?((requirements/)|(scripts/.*?/requirements/))' || true)"
33-
echo $'Relevant paths:\n'"$matched"
34-
if [[ -n "$matched" ]]; then
35-
echo "RELEVANT=true" >> "$GITHUB_ENV"
39+
if git diff --name-only "$BASE_SHA" | grep -P '^"?((requirements/)|(scripts/.*?/requirements/))'; then
40+
echo "RELEVANT=true" >> "$GITHUB_ENV"
3641
fi
3742
38-
- uses: actions/checkout@v5
39-
if: ${{ env.RELEVANT == 'true' }}
40-
4143
- uses: actions/setup-python@v5
4244
if: ${{ env.RELEVANT == 'true' }}
4345
with:

0 commit comments

Comments
 (0)