Skip to content

Commit 0d15966

Browse files
committed
Run relevant workflows on release branch creation
The trunk-based development strategy is used by this project. The release branches may contain a subset of the history of the default branch. The status of the GitHub Actions workflows should be evaluated before making a release. However, this is not so simple as checking the status of the commit at the tip of the release branch. The reason is that, for the sake of efficiency, the workflows are configured to run only when the processes are relevant to the trigger event (e.g., no need to run unit tests for a change to the readme). In the case of the default branch, you can simply set the workflow runs filter to that branch and then check the result of the latest run of each workflow of interest. However, that was not possible to do with the release branch since it might be that the workflow was never run in that branch. The status of the latest run of the workflow in the default branch might not match the status for the release branch if the release branch does not contain the full history. For this reason, it will be helpful to trigger all relevant workflows on the creation of a release branch. This will ensure that each of those workflows will always have at least one run in the release branch. Subsequent commits pushed to the branch can run based on their usual trigger filters and the status of the latest run of each workflow in the branch will provide an accurate indication of the state of that branch. Branches are created for purposes other than releases, most notably feature branches to stage work for a pull request. Because the collection of workflows in a Tooling project are often very comprehensive, it would not be convenient or efficient to run them on the creation of every feature branch. Unfortunately, GitHub Actions does not support filters on the `create` event of branch creation like it does for the `push` and `pull_request` events. There is support for a `branches` filter of the `push` event, but that filter is an AND to the `paths` filter and this application requires an OR. For this reason, the workflows must be triggered by the creation of any branch. The unwanted job runs are prevented by adding a `run-determination` job with the branch filter handled by Bash commands. The other jobs of the workflow use this `run-determination` job as a dependency, only running when it indicates they should via a job output. Because this minimal `run-determination` job runs very quickly, it is roughly equivalent to the workflow having been skipped entirely for non-release branch creations. This approach has been in use for some time already in the versioned "Deploy Website" workflows.
1 parent 094e2de commit 0d15966

9 files changed

+267
-4
lines changed

.github/workflows/check-certificates.yml

+43-4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ name: Check Certificates
33

44
# See: https://docs.github.com/actions/writing-workflows/choosing-when-your-workflow-runs/events-that-trigger-workflows
55
on:
6+
create:
67
push:
78
paths:
89
- ".github/workflows/check-certificates.ya?ml"
@@ -20,12 +21,50 @@ env:
2021
EXPIRATION_WARNING_PERIOD: 30
2122

2223
jobs:
24+
run-determination:
25+
runs-on: ubuntu-latest
26+
outputs:
27+
result: ${{ steps.determination.outputs.result }}
28+
permissions: {}
29+
steps:
30+
- name: Determine if the rest of the workflow should run
31+
id: determination
32+
run: |
33+
RELEASE_BRANCH_REGEX="refs/heads/[0-9]+.[0-9]+.x"
34+
REPO_SLUG="arduino/arduino-lint"
35+
if [[
36+
(
37+
# Only run on branch creation when it is a release branch.
38+
# The `create` event trigger doesn't support `branches` filters, so it's necessary to use Bash instead.
39+
"${{ github.event_name }}" != "create" ||
40+
"${{ github.ref }}" =~ $RELEASE_BRANCH_REGEX
41+
) &&
42+
(
43+
# Only run when the workflow will have access to the certificate secrets.
44+
# This could be done via a GitHub Actions workflow conditional, but makes more sense to do it here as well.
45+
(
46+
"${{ github.event_name }}" != "pull_request" &&
47+
"${{ github.repository }}" == "$REPO_SLUG"
48+
) ||
49+
(
50+
"${{ github.event_name }}" == "pull_request" &&
51+
"${{ github.event.pull_request.head.repo.full_name }}" == "$REPO_SLUG"
52+
)
53+
)
54+
]]; then
55+
# Run the other jobs.
56+
RESULT="true"
57+
else
58+
# There is no need to run the other jobs.
59+
RESULT="false"
60+
fi
61+
62+
echo "result=$RESULT" >> $GITHUB_OUTPUT
63+
2364
check-certificates:
2465
name: ${{ matrix.certificate.identifier }}
25-
# Only run when the workflow will have access to the certificate secrets.
26-
if: >
27-
(github.event_name != 'pull_request' && github.repository == 'arduino/arduino-lint') ||
28-
(github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == 'arduino/arduino-lint')
66+
needs: run-determination
67+
if: needs.run-determination.outputs.result == 'true'
2968
runs-on: ubuntu-latest
3069
permissions: {}
3170
strategy:

.github/workflows/check-general-formatting-task.yml

+27
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ name: Check General Formatting
33

44
# See: https://docs.github.com/actions/writing-workflows/choosing-when-your-workflow-runs/events-that-trigger-workflows
55
on:
6+
create:
67
push:
78
pull_request:
89
schedule:
@@ -12,7 +13,33 @@ on:
1213
repository_dispatch:
1314

1415
jobs:
16+
run-determination:
17+
runs-on: ubuntu-latest
18+
permissions: {}
19+
outputs:
20+
result: ${{ steps.determination.outputs.result }}
21+
steps:
22+
- name: Determine if the rest of the workflow should run
23+
id: determination
24+
run: |
25+
RELEASE_BRANCH_REGEX="refs/heads/[0-9]+.[0-9]+.x"
26+
# The `create` event trigger doesn't support `branches` filters, so it's necessary to use Bash instead.
27+
if [[
28+
"${{ github.event_name }}" != "create" ||
29+
"${{ github.ref }}" =~ $RELEASE_BRANCH_REGEX
30+
]]; then
31+
# Run the other jobs.
32+
RESULT="true"
33+
else
34+
# There is no need to run the other jobs.
35+
RESULT="false"
36+
fi
37+
38+
echo "result=$RESULT" >> $GITHUB_OUTPUT
39+
1540
check:
41+
needs: run-determination
42+
if: needs.run-determination.outputs.result == 'true'
1643
runs-on: ubuntu-latest
1744
permissions:
1845
contents: read

.github/workflows/check-license.yml

+27
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ env:
88

99
# See: https://docs.github.com/actions/writing-workflows/choosing-when-your-workflow-runs/events-that-trigger-workflows
1010
on:
11+
create:
1112
push:
1213
paths:
1314
- ".github/workflows/check-license.ya?ml"
@@ -29,7 +30,33 @@ on:
2930
repository_dispatch:
3031

3132
jobs:
33+
run-determination:
34+
runs-on: ubuntu-latest
35+
permissions: {}
36+
outputs:
37+
result: ${{ steps.determination.outputs.result }}
38+
steps:
39+
- name: Determine if the rest of the workflow should run
40+
id: determination
41+
run: |
42+
RELEASE_BRANCH_REGEX="refs/heads/[0-9]+.[0-9]+.x"
43+
# The `create` event trigger doesn't support `branches` filters, so it's necessary to use Bash instead.
44+
if [[
45+
"${{ github.event_name }}" != "create" ||
46+
"${{ github.ref }}" =~ $RELEASE_BRANCH_REGEX
47+
]]; then
48+
# Run the other jobs.
49+
RESULT="true"
50+
else
51+
# There is no need to run the other jobs.
52+
RESULT="false"
53+
fi
54+
55+
echo "result=$RESULT" >> $GITHUB_OUTPUT
56+
3257
check-license:
58+
needs: run-determination
59+
if: needs.run-determination.outputs.result == 'true'
3360
runs-on: ubuntu-latest
3461
permissions:
3562
contents: read

.github/workflows/check-markdown-task.yml

+29
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ env:
77

88
# See: https://docs.github.com/actions/writing-workflows/choosing-when-your-workflow-runs/events-that-trigger-workflows
99
on:
10+
create:
1011
push:
1112
paths:
1213
- ".github/workflows/check-markdown-task.ya?ml"
@@ -34,7 +35,33 @@ on:
3435
repository_dispatch:
3536

3637
jobs:
38+
run-determination:
39+
runs-on: ubuntu-latest
40+
permissions: {}
41+
outputs:
42+
result: ${{ steps.determination.outputs.result }}
43+
steps:
44+
- name: Determine if the rest of the workflow should run
45+
id: determination
46+
run: |
47+
RELEASE_BRANCH_REGEX="refs/heads/[0-9]+.[0-9]+.x"
48+
# The `create` event trigger doesn't support `branches` filters, so it's necessary to use Bash instead.
49+
if [[
50+
"${{ github.event_name }}" != "create" ||
51+
"${{ github.ref }}" =~ $RELEASE_BRANCH_REGEX
52+
]]; then
53+
# Run the other jobs.
54+
RESULT="true"
55+
else
56+
# There is no need to run the other jobs.
57+
RESULT="false"
58+
fi
59+
60+
echo "result=$RESULT" >> $GITHUB_OUTPUT
61+
3762
lint:
63+
needs: run-determination
64+
if: needs.run-determination.outputs.result == 'true'
3865
runs-on: ubuntu-latest
3966
permissions:
4067
contents: read
@@ -56,6 +83,8 @@ jobs:
5683
run: task markdown:lint
5784

5885
links:
86+
needs: run-determination
87+
if: needs.run-determination.outputs.result == 'true'
5988
runs-on: ubuntu-latest
6089
permissions:
6190
contents: read

.github/workflows/check-mkdocs-task.yml

+27
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ env:
99

1010
# See: https://docs.github.com/actions/writing-workflows/choosing-when-your-workflow-runs/events-that-trigger-workflows
1111
on:
12+
create:
1213
push:
1314
paths:
1415
- ".github/workflows/check-mkdocs-task.ya?ml"
@@ -35,7 +36,33 @@ on:
3536
repository_dispatch:
3637

3738
jobs:
39+
run-determination:
40+
runs-on: ubuntu-latest
41+
permissions: {}
42+
outputs:
43+
result: ${{ steps.determination.outputs.result }}
44+
steps:
45+
- name: Determine if the rest of the workflow should run
46+
id: determination
47+
run: |
48+
RELEASE_BRANCH_REGEX="refs/heads/[0-9]+.[0-9]+.x"
49+
# The `create` event trigger doesn't support `branches` filters, so it's necessary to use Bash instead.
50+
if [[
51+
"${{ github.event_name }}" != "create" ||
52+
"${{ github.ref }}" =~ $RELEASE_BRANCH_REGEX
53+
]]; then
54+
# Run the other jobs.
55+
RESULT="true"
56+
else
57+
# There is no need to run the other jobs.
58+
RESULT="false"
59+
fi
60+
61+
echo "result=$RESULT" >> $GITHUB_OUTPUT
62+
3863
check:
64+
needs: run-determination
65+
if: needs.run-determination.outputs.result == 'true'
3966
runs-on: ubuntu-latest
4067
permissions:
4168
contents: read

.github/workflows/check-prettier-formatting-task.yml

+27
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ name: Check Prettier Formatting
33

44
# See: https://docs.github.com/actions/writing-workflows/choosing-when-your-workflow-runs/events-that-trigger-workflows
55
on:
6+
create:
67
push:
78
paths:
89
- ".github/workflows/check-prettier-formatting-task.ya?ml"
@@ -199,7 +200,33 @@ on:
199200
repository_dispatch:
200201

201202
jobs:
203+
run-determination:
204+
runs-on: ubuntu-latest
205+
permissions: {}
206+
outputs:
207+
result: ${{ steps.determination.outputs.result }}
208+
steps:
209+
- name: Determine if the rest of the workflow should run
210+
id: determination
211+
run: |
212+
RELEASE_BRANCH_REGEX="refs/heads/[0-9]+.[0-9]+.x"
213+
# The `create` event trigger doesn't support `branches` filters, so it's necessary to use Bash instead.
214+
if [[
215+
"${{ github.event_name }}" != "create" ||
216+
"${{ github.ref }}" =~ $RELEASE_BRANCH_REGEX
217+
]]; then
218+
# Run the other jobs.
219+
RESULT="true"
220+
else
221+
# There is no need to run the other jobs.
222+
RESULT="false"
223+
fi
224+
225+
echo "result=$RESULT" >> $GITHUB_OUTPUT
226+
202227
check:
228+
needs: run-determination
229+
if: needs.run-determination.outputs.result == 'true'
203230
runs-on: ubuntu-latest
204231
permissions:
205232
contents: read

.github/workflows/check-python-task.yml

+29
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ env:
77

88
# See: https://docs.github.com/actions/writing-workflows/choosing-when-your-workflow-runs/events-that-trigger-workflows
99
on:
10+
create:
1011
push:
1112
paths:
1213
- ".github/workflows/check-python-task.ya?ml"
@@ -31,7 +32,33 @@ on:
3132
repository_dispatch:
3233

3334
jobs:
35+
run-determination:
36+
runs-on: ubuntu-latest
37+
permissions: {}
38+
outputs:
39+
result: ${{ steps.determination.outputs.result }}
40+
steps:
41+
- name: Determine if the rest of the workflow should run
42+
id: determination
43+
run: |
44+
RELEASE_BRANCH_REGEX="refs/heads/[0-9]+.[0-9]+.x"
45+
# The `create` event trigger doesn't support `branches` filters, so it's necessary to use Bash instead.
46+
if [[
47+
"${{ github.event_name }}" != "create" ||
48+
"${{ github.ref }}" =~ $RELEASE_BRANCH_REGEX
49+
]]; then
50+
# Run the other jobs.
51+
RESULT="true"
52+
else
53+
# There is no need to run the other jobs.
54+
RESULT="false"
55+
fi
56+
57+
echo "result=$RESULT" >> $GITHUB_OUTPUT
58+
3459
lint:
60+
needs: run-determination
61+
if: needs.run-determination.outputs.result == 'true'
3562
runs-on: ubuntu-latest
3663
permissions:
3764
contents: read
@@ -61,6 +88,8 @@ jobs:
6188
run: task python:lint
6289

6390
formatting:
91+
needs: run-determination
92+
if: needs.run-determination.outputs.result == 'true'
6493
runs-on: ubuntu-latest
6594
permissions:
6695
contents: read

.github/workflows/check-shell-task.yml

+31
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ name: Check Shell Scripts
33

44
# See: https://docs.github.com/actions/writing-workflows/choosing-when-your-workflow-runs/events-that-trigger-workflows
55
on:
6+
create:
67
push:
78
paths:
89
- ".github/workflows/check-shell-task.ya?ml"
@@ -24,8 +25,34 @@ on:
2425
repository_dispatch:
2526

2627
jobs:
28+
run-determination:
29+
runs-on: ubuntu-latest
30+
permissions: {}
31+
outputs:
32+
result: ${{ steps.determination.outputs.result }}
33+
steps:
34+
- name: Determine if the rest of the workflow should run
35+
id: determination
36+
run: |
37+
RELEASE_BRANCH_REGEX="refs/heads/[0-9]+.[0-9]+.x"
38+
# The `create` event trigger doesn't support `branches` filters, so it's necessary to use Bash instead.
39+
if [[
40+
"${{ github.event_name }}" != "create" ||
41+
"${{ github.ref }}" =~ $RELEASE_BRANCH_REGEX
42+
]]; then
43+
# Run the other jobs.
44+
RESULT="true"
45+
else
46+
# There is no need to run the other jobs.
47+
RESULT="false"
48+
fi
49+
50+
echo "result=$RESULT" >> $GITHUB_OUTPUT
51+
2752
lint:
2853
name: ${{ matrix.configuration.name }}
54+
needs: run-determination
55+
if: needs.run-determination.outputs.result == 'true'
2956
runs-on: ubuntu-latest
3057
permissions:
3158
contents: read
@@ -90,6 +117,8 @@ jobs:
90117
run: task --silent shell:check SHELLCHECK_FORMAT=${{ matrix.configuration.format }}
91118

92119
formatting:
120+
needs: run-determination
121+
if: needs.run-determination.outputs.result == 'true'
93122
runs-on: ubuntu-latest
94123
permissions:
95124
contents: read
@@ -135,6 +164,8 @@ jobs:
135164
run: git diff --color --exit-code
136165

137166
executable:
167+
needs: run-determination
168+
if: needs.run-determination.outputs.result == 'true'
138169
runs-on: ubuntu-latest
139170
permissions:
140171
contents: read

0 commit comments

Comments
 (0)