Skip to content

Commit 096ef56

Browse files
committed
Workflows: use gh API to get list of changed files
1 parent 5e8197e commit 096ef56

File tree

3 files changed

+40
-8
lines changed

3 files changed

+40
-8
lines changed

.github/workflows/eamxx-sa-testing.yml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,15 @@ jobs:
6464
".github/workflows/eamxx-sa-testing.yml"
6565
)
6666
pattern=$(IFS=\|; echo "${paths[*]}")
67-
changed_files=$(git diff --name-only ${{ github.event.before }} ${{ github.sha }})
68-
if [[ $changed_files =~ ^($pattern) ]]; then
67+
68+
# Use the GitHub API to get the list of changed files
69+
response=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
70+
"https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.number }}/files")
71+
72+
# Extract the filenames from the response
73+
changed_files=$(echo "$response" | jq -r '.[].filename')
74+
75+
if echo "$changed_files" | grep -qE "^($pattern)"; then
6976
echo "value=true" >> $GITHUB_OUTPUT
7077
else
7178
echo "value=false" >> $GITHUB_OUTPUT

.github/workflows/eamxx-scripts-tests.yml

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ jobs:
3131
run: |
3232
# For non-pull_request events, no need to check files
3333
if [[ "${{ github.event_name }}" != "pull_request" ]]; then
34-
# If not a PR event, set value to true and exit early
3534
echo "value=true" >> $GITHUB_OUTPUT
3635
exit 0 # Early exit
3736
fi
@@ -45,8 +44,15 @@ jobs:
4544
)
4645
4746
pattern=$(IFS=\|; echo "${paths[*]}")
48-
changed_files=$(git diff --name-only ${{ github.event.before }} ${{ github.sha }})
49-
if [[ $changed_files =~ ^($pattern) ]]; then
47+
48+
# Use the GitHub API to get the list of changed files
49+
response=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
50+
"https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.number }}/files")
51+
52+
# Extract the filenames from the response
53+
changed_files=$(echo "$response" | jq -r '.[].filename')
54+
55+
if echo "$changed_files" | grep -qE "^($pattern)"; then
5056
echo "value=true" >> $GITHUB_OUTPUT
5157
else
5258
echo "value=false" >> $GITHUB_OUTPUT
@@ -80,3 +86,15 @@ jobs:
8086
./scripts/scripts-tests -f -m ghci-snl-cpu
8187
./scripts/cime-nml-tests
8288
fi
89+
90+
91+
92+
93+
94+
95+
96+
97+
98+
99+
100+

.github/workflows/eamxx-v1-testing.yml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ jobs:
3939
run: |
4040
# For non-pull_request events, no need to check files
4141
if [[ "${{ github.event_name }}" != "pull_request" ]]; then
42-
# If not a PR event, set value to true and exit early
4342
echo "value=true" >> $GITHUB_OUTPUT
4443
exit 0 # Early exit
4544
fi
@@ -56,9 +55,17 @@ jobs:
5655
"externals/YAKL"
5756
".github/workflows/eamxx-v1-testing.yml"
5857
)
58+
5959
pattern=$(IFS=\|; echo "${paths[*]}")
60-
changed_files=$(git diff --name-only ${{ github.event.before }} ${{ github.sha }})
61-
if [[ $changed_files =~ ^($pattern) ]]; then
60+
61+
# Use the GitHub API to get the list of changed files
62+
response=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
63+
"https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.number }}/files")
64+
65+
# Extract the filenames from the response
66+
changed_files=$(echo "$response" | jq -r '.[].filename')
67+
68+
if echo "$changed_files" | grep -qE "^($pattern)"; then
6269
echo "value=true" >> $GITHUB_OUTPUT
6370
else
6471
echo "value=false" >> $GITHUB_OUTPUT

0 commit comments

Comments
 (0)