Skip to content

Commit add709c

Browse files
committed
Workflows: reworked actions and ways to skip eamxx testing jobs
* Do not check labels in an action. * Implement get-labels mini-action * Add "check" jobs that, for PRs, verify that * The PR touches relevant jobs * The PR does not have "skip" labels
1 parent e902e38 commit add709c

File tree

9 files changed

+268
-140
lines changed

9 files changed

+268
-140
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Composite action to check if testing for this PR is relevant based on touched paths
2+
3+
This action is meant to be used inside a PR testing workflow, as
4+
5+
```yaml
6+
jobs:
7+
check_paths:
8+
steps:
9+
- name: check_relevance
10+
if: ${{ github.event_name == "pull_request" }}
11+
uses: ./.github/actions/check-pr-paths
12+
with:
13+
paths: |
14+
path1
15+
path2
16+
testing:
17+
needs: check_paths
18+
if: ${{ github.event_name != "pull_request" || needs.check_paths.outputs.touched == 'true'}}
19+
steps:
20+
- name: testing
21+
```
22+
The input `paths1 is a list of paths that the action uses to see if
23+
the PR changes any relevant file. The action sets an output `touched`,
24+
which is `true` if the PR touches any of the listed paths and `false`
25+
otherwise.
26+
27+
This action allows to skip an entire workflow, but, unlike using a 'paths' filter at the
28+
workflow trigger level, it ensures that the workflow DOES run,
29+
hence avoiding the issue where certain checks are not present on the PR.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: check-pr-paths
2+
description: 'Check that the PR modifies relevant files'
3+
inputs:
4+
paths:
5+
description: 'List of paths that are considered relevant'
6+
required: true
7+
default: ''
8+
token:
9+
description: 'GitHub token for authentication'
10+
required: true
11+
outputs:
12+
touched:
13+
description: 'Output indicating if this testing for PR is relevant'
14+
value: ${{ steps.check_paths.outputs.value }}
15+
16+
# Note: inputs are available as env vars in the shell run steps, convertet to uppercase
17+
runs:
18+
using: "composite"
19+
steps:
20+
- name: check_paths
21+
shell: bash
22+
env:
23+
PR_NUMBER: ${{ github.event.number }}
24+
GITHUB_REPO: ${{ github.repository }}
25+
TOKEN: ${{ inputs.token }}
26+
run: |
27+
# Convert the input paths into an array, and create a regex from it
28+
IFS=$'\n' read -r -a paths <<< "$INPUT_PATHS"
29+
pattern=$(IFS=\|; echo "${paths[*]}")
30+
31+
# Use the GitHub API to get the list of changed files
32+
response=$(curl -s -H "Authorization: token $TOKEN" \
33+
"https://api.github.com/repos/$GITHUB_REPO/pulls/$PR_NUMBER/files")
34+
35+
# Extract filenames using grep and sed
36+
changed_files=$(echo "$response" | grep -o '"filename": *"[^"]*"' | sed 's/"filename": *//; s/"//g')
37+
38+
# Check for matches and echo the matching files
39+
matching_files=$(echo "$changed_files" | grep -E "^($pattern)" || echo "")
40+
if [[ -n "$matching_files" ]]; then
41+
echo "Found relevant files: $matching_files" # Print the matching files
42+
echo "touched=true" >> $GITHUB_OUTPUT
43+
else
44+
echo "No relevant files touched by this PR."
45+
echo "touched=false" >> $GITHUB_OUTPUT
46+
fi

.github/actions/check-skip-labels/README.md

Lines changed: 0 additions & 24 deletions
This file was deleted.

.github/actions/check-skip-labels/action.yml

Lines changed: 0 additions & 48 deletions
This file was deleted.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Composite action to retrieve labels of a PR if event is `pull_request`
2+
3+
This action is meant to be used inside a PR testing workflow, as
4+
5+
```yaml
6+
jobs:
7+
get_labels:
8+
steps:
9+
- name: get_labels
10+
uses: ./.github/actions/get-labels
11+
testing:
12+
needs: get_labels
13+
if: ${{ github.event_name != "pull_request" ||
14+
!contains(needs.get_labels.outputs.labels,"label1" ||
15+
!contains(needs.get_labels.outputs.labels,"label1" }}
16+
```
17+
The action sets the output `labels`, which is a comma-separated list
18+
containing the PR labels. If the event that triggered the workflow is
19+
not a PR, the output will be an empty string
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: get-labels
2+
description: 'Check that the PR modifies does not have skip labels'
3+
outputs:
4+
labels:
5+
description: 'Comma-separated list of labels on the PR or empty string (if not a PR event)'
6+
value: ${{ steps.get_labels.outputs.labels }}
7+
8+
# Note: inputs are available as env vars in the shell run steps, convertet to uppercase
9+
runs:
10+
using: "composite"
11+
steps:
12+
- name: get_labels
13+
shell: sh
14+
env:
15+
PR_LABELS: ${{ toJson(github.event.pull_request.labels.*.name) }} # Pass PR label names as JSON
16+
run: |
17+
echo 'labels=\"$(echo \"$PR_LABELS\" | jq -r "join(\",\")")\"' >> $GITHUB_OUTPUT

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

Lines changed: 52 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,6 @@ on:
55
pull_request:
66
branches: [ master ]
77
types: [opened, synchronize, ready_for_review, reopened]
8-
paths:
9-
- components/eamxx/**
10-
- components/eam/src/physics/rrtmgp/**
11-
- components/eam/src/physics/p3/scream/**
12-
- components/eam/src/physics/cam/**
13-
- .github/workflows/eamxx-standalone-testing.yml
14-
- externals/ekat/**
15-
- externals/scorpio/**
16-
- externals/haero/**
17-
- externals/YAKL/**
18-
- components/eam/src/physics/rrtmgp/external/**
198

209
# Manual run is used to bless
2110
workflow_dispatch:
@@ -48,15 +37,51 @@ env:
4837
submit: ${{ github.event_name == 'schedule' && 'true' || 'false' }} # Submit to cdash only for nightlies
4938

5039
jobs:
40+
pr_relevant:
41+
runs-on: ubuntu-latest # This job can run anywhere
42+
outputs:
43+
value: ${{ steps.check_paths.outputs.touched }}
44+
steps:
45+
- name: check_paths
46+
if: ${{ github.event_name == "pull_request" }}
47+
uses: ./.github/actions/check-pr-relevance
48+
with:
49+
paths: |
50+
components/eamxx
51+
components/eam/src/physics/rrtmgp
52+
components/eam/src/physics/p3/scream
53+
components/eam/src/physics/cam
54+
components/eam/src/physics/rrtmgp/external
55+
externals/ekat
56+
externals/scorpio
57+
externals/haero
58+
externals/YAKL
59+
.github/workflows/eamxx-sa-testing.yml
60+
get_labels:
61+
runs-on: ubuntu-latest
62+
outputs: ${{ steps.get_labels.outputs.labels }}
63+
steps:
64+
- name: get_labels
65+
uses: ./.github/actions/get-labels
5166
gcc-openmp:
67+
needs: pr_relevant, get_labels
68+
if: ${{
69+
(github.event_name == 'pull_request' &&
70+
needs.pr_relevant.outputs.value=='true' &&
71+
!contains(needs.get_labels.outputs.labels,'CI: skip gcc') &&
72+
!contains(needs.get_labels.outputs.labels,'CI: skip openmp') &&
73+
!contains(needs.get_labels.outputs.labels,'CI: skip eamxx-sa') &&
74+
!contains(needs.get_labels.outputs.labels,'CI: skip eamxx-all')) ||
75+
(github.event_name == 'workflow_dispatch' &&
76+
github.event.inputs.job_to_run == 'gcc-openmp' ||
77+
github.event.inputs.job_to_run == 'all') ||
78+
github.event_name == 'schedule'
79+
}}
5280
runs-on: [self-hosted, ghci-snl-cpu, gcc]
5381
strategy:
5482
fail-fast: false
5583
matrix:
5684
build_type: [sp, dbg, fpe, opt]
57-
if: ${{ github.event_name != 'workflow_dispatch' ||
58-
github.event.inputs.job_to_run == 'gcc-openmp' ||
59-
github.event.inputs.job_to_run == 'all' }}
6085
name: gcc-openmp / ${{ matrix.build_type }}
6186
steps:
6287
- name: Check out the repository
@@ -67,13 +92,6 @@ jobs:
6792
submodules: recursive
6893
- name: Show action trigger
6994
uses: ./.github/actions/show-workflow-trigger
70-
- name: Check for skip labels
71-
if: ${{ github.event_name == 'pull_request' || github.event_name == 'pull_request_review' }}
72-
uses: ./.github/actions/check-skip-labels
73-
with:
74-
skip_labels: 'AT: skip gcc,AT: skip openmp,AT: skip eamxx-sa,AT: skip eamxx-all'
75-
token: ${{ secrets.GITHUB_TOKEN }}
76-
pr_number: ${{ github.event.pull_request.number }}
7795
- name: Set test-all inputs based on event specs
7896
run: |
7997
echo "generate=false" >> $GITHUB_ENV
@@ -91,14 +109,24 @@ jobs:
91109
submit: ${{ env.submit }}
92110
cmake-configs: Kokkos_ENABLE_OPENMP=ON
93111
gcc-cuda:
112+
needs: pr_relevant, get_labels
113+
if: ${{
114+
(github.event_name == 'pull_request' &&
115+
needs.pr_relevant.outputs.value=='true' &&
116+
!contains(needs.get_labels.outputs.labels,'CI: skip gcc') &&
117+
!contains(needs.get_labels.outputs.labels,'CI: skip cuda') &&
118+
!contains(needs.get_labels.outputs.labels,'CI: skip eamxx-sa') &&
119+
!contains(needs.get_labels.outputs.labels,'CI: skip eamxx-all')) ||
120+
(github.event_name == 'workflow_dispatch' &&
121+
github.event.inputs.job_to_run == 'gcc-cuda' ||
122+
github.event.inputs.job_to_run == 'all') ||
123+
github.event_name == 'schedule'
124+
}}
94125
runs-on: [self-hosted, ghci-snl-cuda, cuda, gcc]
95126
strategy:
96127
fail-fast: false
97128
matrix:
98129
build_type: [sp, dbg, opt]
99-
if: ${{ github.event_name != 'workflow_dispatch' ||
100-
github.event.inputs.job_to_run == 'gcc-cuda' ||
101-
github.event.inputs.job_to_run == 'all' }}
102130
name: gcc-cuda / ${{ matrix.build_type }}
103131
steps:
104132
- name: Check out the repository
@@ -109,13 +137,6 @@ jobs:
109137
submodules: recursive
110138
- name: Show action trigger
111139
uses: ./.github/actions/show-workflow-trigger
112-
- name: Check for skip labels
113-
if: ${{ github.event_name == 'pull_request' || github.event_name == 'pull_request_review' }}
114-
uses: ./.github/actions/check-skip-labels
115-
with:
116-
skip_labels: 'AT: skip gcc,AT: skip cuda,AT: skip eamxx-sa,AT: skip eamxx-all'
117-
token: ${{ secrets.GITHUB_TOKEN }}
118-
pr_number: ${{ github.event.pull_request.number }}
119140
- name: Set test-all inputs based on event specs
120141
run: |
121142
echo "generate=false" >> $GITHUB_ENV

0 commit comments

Comments
 (0)