Skip to content

Commit 2e05715

Browse files
committed
Workflows: use composite actions for common workflow steps
* Print workflow trigger * Check skip labels
1 parent 239e7db commit 2e05715

File tree

7 files changed

+111
-71
lines changed

7 files changed

+111
-71
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Composite action to check if we can skip a job for a PR
2+
3+
This action is meant to be used inside a PR testing workflow, as
4+
5+
```yaml
6+
jobs:
7+
my-testing:
8+
steps:
9+
...
10+
- name: check-pr-labels
11+
if: github.event_name == "pull_request" || github.event_name == "pull_request_review"
12+
uses: ./.github/actions/check-skip-labels
13+
with:
14+
skip_labels: label1,label2,label3
15+
```
16+
17+
The input skip_label is a comma-separated list of labels that, if found
18+
on the PR, will cause this job to terminate immediately with a PASS state.
19+
20+
Ideally, we would like to run this check at the job level, so that we can
21+
skip the job altogether (without using runner time). But while for the
22+
pull_request event we DO have access to the labels from the gh context
23+
(and therefore can check), for pull_request_review we don't, so we need
24+
to ping github for some information
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: 'Check Skip Labels'
2+
description: 'Check for specific skip labels in a pull request'
3+
inputs:
4+
skip_labels:
5+
description: 'Comma-separated list of skip labels'
6+
required: true
7+
8+
runs:
9+
using: "composite"
10+
steps:
11+
- name: Get Pull Request Labels
12+
run: |
13+
echo "Fetching pull request labels..."
14+
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
15+
LABELS="${{ toJson(github.event.pull_request.labels) }}"
16+
elif [[ "${{ github.event_name }}" == "pull_request_review" ]]; then
17+
prNumber="${{ github.payload.pull_request.number }}"
18+
response=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
19+
"https://api.github.com/repos/${{ github.repository }}/pulls/$prNumber")
20+
LABELS=$(echo "$response" | jq -r '.labels | map(.name) | join(",")')
21+
fi
22+
echo "labels=$LABELS" >> $GITHUB_ENV
23+
24+
- name: Check for Skip Labels
25+
run: |
26+
echo "Checking for skip labels..."
27+
IFS=',' read -r -a SKIP_LABELS <<< "${{ inputs.skip_labels }}"
28+
IFS=',' read -r -a LABEL_ARRAY <<< "$labels"
29+
30+
for label in "${SKIP_LABELS[@]}"; do
31+
for pr_label in "${LABEL_ARRAY[@]}"; do
32+
if [[ "$pr_label" == "$label" ]]; then
33+
echo "Found skip label '$label'. Skipping this job."
34+
exit 0 # Exit with success status
35+
fi
36+
done
37+
done
38+
39+
echo "No relevant skip labels found. Continuing with the job."
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Composite action to show the trigger of a workflow
2+
3+
If possible, prints also the user that triggered it
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: 'Show workflow trigger'
2+
description: 'Prints what triggered this workflow'
3+
4+
runs:
5+
using: "composite"
6+
steps:
7+
- name: Print trigger info
8+
uses: actions/github-script@v7
9+
with:
10+
script: |
11+
const eventName = context.eventName;
12+
const actor = context.actor || 'unknown'; // Default to 'unknown' if actor is not defined
13+
let eventAction = 'N/A';
14+
15+
// Determine the event action based on the event type
16+
if (eventName === 'pull_request') {
17+
eventAction = context.payload.action || 'N/A';
18+
} else if (eventName === 'pull_request_review') {
19+
eventAction = context.payload.review.state || 'N/A';
20+
} else if (eventName === 'workflow_dispatch') {
21+
eventAction = 'manual trigger';
22+
} else if (eventName === 'schedule') {
23+
eventAction = 'scheduled trigger';
24+
}
25+
console.log(`The job was triggered by a ${eventName} event.`);
26+
console.log(` - Event action: ${eventAction}`);
27+
console.log(` - Triggered by: ${actor}`);

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

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -31,32 +31,14 @@ concurrency:
3131
jobs:
3232
cpu-gcc:
3333
runs-on: [self-hosted, gcc, ghci-snl-cpu]
34-
# Run this workflow if:
35-
# - workflow_dispatch: user requested this job.
36-
# - schedule: always:
37-
# - pull_request: matching skip label is NOT found
38-
if: |
39-
${{
40-
github.event_name == 'schedule' ||
41-
github.event_name == 'workflow_dispatch' ||
42-
(
43-
github.event_name == 'pull_request' &&
44-
!(
45-
contains(github.event.pull_request.labels.*.name, 'AT: skip all')
46-
)
47-
)
48-
}}
4934
steps:
5035
- name: Show action trigger
51-
uses: actions/github-script@v7
36+
uses: .github/actions/show-workflow-trigger
37+
- name: Check for skip labels
38+
if: github.event_name == "pull_request" || github.event_name == "pull_request_review"
39+
uses: ./github/actions/check-skip-labels
5240
with:
53-
script: |
54-
const eventName = context.eventName;
55-
const eventAction = context.payload.action || 'N/A';
56-
const actor = context.actor;
57-
console.log(`The job was triggered by a ${eventName} event.`);
58-
console.log(` - Event action: ${eventAction}`);
59-
console.log(` - Triggered by: ${actor}`);
41+
skip_labels: 'AT: skip eamxx-all'
6042
- name: Check out the repository
6143
uses: actions/checkout@v4
6244
with:

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

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -49,36 +49,16 @@ jobs:
4949
fail-fast: false
5050
matrix:
5151
build_type: [sp, dbg, fpe, opt]
52-
# Run this workflow if:
53-
# - workflow_dispatch: user requested this job.
54-
# - schedule: always:
55-
# - pull_request: matching skip label is NOT found
56-
if: |
57-
${{
58-
github.event_name == 'schedule' ||
59-
( github.event_name == 'workflow_dispatch' && github.event.inputs.jobs_list == 'gcc-openmp' ) ||
60-
(
61-
github.event_name == 'pull_request' &&
62-
!(
63-
contains(github.event.pull_request.labels.*.name, 'AT: skip gcc') ||
64-
contains(github.event.pull_request.labels.*.name, 'AT: skip openmp') ||
65-
contains(github.event.pull_request.labels.*.name, 'AT: skip eamxx-sa') ||
66-
contains(github.event.pull_request.labels.*.name, 'AT: skip eamxx-all')
67-
)
68-
)
69-
}}
52+
if: ${{ !(github.event_name == 'workflow_dispatch' && github.event.inputs.jobs_list != 'gcc-openmp') }}
7053
name: gcc-openmp / ${{ matrix.build_type }}
7154
steps:
7255
- name: Show action trigger
73-
uses: actions/github-script@v7
56+
uses: .github/actions/show-workflow-trigger
57+
- name: Check for skip labels
58+
if: github.event_name == "pull_request" || github.event_name == "pull_request_review"
59+
uses: ./github/actions/check-skip-labels
7460
with:
75-
script: |
76-
const eventName = context.eventName;
77-
const eventAction = context.payload.action || 'N/A';
78-
const actor = context.actor;
79-
console.log(`The job was triggered by a ${eventName} event.`);
80-
console.log(` - Event action: ${eventAction}`);
81-
console.log(` - Triggered by: ${actor}`);
61+
skip_labels: 'AT: skip gcc,AT: skip openmp,AT: skip eamxx-sa,AT: skip eamxx-all'
8262
- name: Check out the repository
8363
uses: actions/checkout@v4
8464
with:

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

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -57,31 +57,16 @@ jobs:
5757
# Run this workflow if:
5858
# - workflow_dispatch: user requested this job.
5959
# - schedule: always:
60-
# - pull_request: matching skip label is NOT found
61-
if: |
62-
${{
63-
github.event_name == 'schedule' ||
64-
( github.event_name == 'workflow_dispatch' && contains(github.event.inputs.jobs_list, 'gcc-openmp') ) ||
65-
(
66-
github.event_name == 'pull_request' &&
67-
!(
68-
contains(github.event.pull_request.labels.*.name, 'AT: skip gcc') ||
69-
contains(github.event.pull_request.labels.*.name, 'AT: skip eamxx-v1') ||
70-
contains(github.event.pull_request.labels.*.name, 'AT: skip eamxx-all')
71-
)
72-
)
73-
}}
60+
# - pull_request/pull_request_review: matching skip label is NOT found
61+
if: ${{ !(github.event_name == 'workflow_dispatch' && github.event.inputs.jobs_list != 'cpu-gcc') }}
7462
steps:
7563
- name: Show action trigger
76-
uses: actions/github-script@v7
64+
uses: .github/actions/show-workflow-trigger
65+
- name: Check for skip labels
66+
if: github.event_name == "pull_request" || github.event_name == "pull_request_review"
67+
uses: ./github/actions/check-skip-labels
7768
with:
78-
script: |
79-
const eventName = context.eventName;
80-
const eventAction = context.payload.action || 'N/A';
81-
const actor = context.actor;
82-
console.log(`The job was triggered by a ${eventName} event.`);
83-
console.log(` - Event action: ${eventAction}`);
84-
console.log(` - Triggered by: ${actor}`);
69+
skip_labels: 'AT: skip gcc,AT: skip openmp,AT: skip eamxx-sa,AT: skip eamxx-all'
8570
- name: Set CA certificates env var
8671
run: |
8772
# Ensure the operating system is Linux

0 commit comments

Comments
 (0)