Skip to content

Commit 3cfb128

Browse files
committed
Add release branch coverage to workflows
The trunk-based development strategy is used by some tooling projects (e.g., Arduino CLI). Their 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 fully 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. Release branches are not used in this project at this time so the changes are not relevant here. However, the infrastructure maintenance is easiest if the number of modifications to the "template" workflows is kept to the minimum, so the changes are pulled from the upstream files even when not needed.
1 parent bd5792b commit 3cfb128

8 files changed

+220
-0
lines changed

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ name: Check General Formatting
33

44
# See: https://docs.github.com/actions/using-workflows/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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ env:
88

99
# See: https://docs.github.com/actions/using-workflows/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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ name: Check Markdown
33

44
# See: https://docs.github.com/actions/using-workflows/events-that-trigger-workflows
55
on:
6+
create:
67
push:
78
paths:
89
- ".github/workflows/check-markdown-task.ya?ml"
@@ -30,7 +31,33 @@ on:
3031
repository_dispatch:
3132

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

5481
links:
82+
needs: run-determination
83+
if: needs.run-determination.outputs.result == 'true'
5584
runs-on: ubuntu-latest
5685
permissions:
5786
contents: read

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ name: Check Prettier Formatting
33

44
# See: https://docs.github.com/actions/using-workflows/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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ env:
77

88
# See: https://docs.github.com/actions/using-workflows/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-taskfiles.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ name: Check Taskfiles
33

44
# See: https://docs.github.com/actions/using-workflows/events-that-trigger-workflows
55
on:
6+
create:
67
push:
78
paths:
89
- ".github/workflows/check-taskfiles.ya?ml"
@@ -18,8 +19,34 @@ on:
1819
repository_dispatch:
1920

2021
jobs:
22+
run-determination:
23+
runs-on: ubuntu-latest
24+
permissions: {}
25+
outputs:
26+
result: ${{ steps.determination.outputs.result }}
27+
steps:
28+
- name: Determine if the rest of the workflow should run
29+
id: determination
30+
run: |
31+
RELEASE_BRANCH_REGEX="refs/heads/[0-9]+.[0-9]+.x"
32+
# The `create` event trigger doesn't support `branches` filters, so it's necessary to use Bash instead.
33+
if [[
34+
"${{ github.event_name }}" != "create" ||
35+
"${{ github.ref }}" =~ $RELEASE_BRANCH_REGEX
36+
]]; then
37+
# Run the other jobs.
38+
RESULT="true"
39+
else
40+
# There is no need to run the other jobs.
41+
RESULT="false"
42+
fi
43+
44+
echo "result=$RESULT" >> $GITHUB_OUTPUT
45+
2146
validate:
2247
name: Validate ${{ matrix.file }}
48+
needs: run-determination
49+
if: needs.run-determination.outputs.result == 'true'
2350
runs-on: ubuntu-latest
2451
permissions:
2552
contents: read

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ env:
77

88
# See: https://docs.github.com/actions/using-workflows/events-that-trigger-workflows
99
on:
10+
create:
1011
push:
1112
paths:
1213
- ".yamllint*"
@@ -43,8 +44,34 @@ on:
4344
repository_dispatch:
4445

4546
jobs:
47+
run-determination:
48+
runs-on: ubuntu-latest
49+
permissions: {}
50+
outputs:
51+
result: ${{ steps.determination.outputs.result }}
52+
steps:
53+
- name: Determine if the rest of the workflow should run
54+
id: determination
55+
run: |
56+
RELEASE_BRANCH_REGEX="refs/heads/[0-9]+.[0-9]+.x"
57+
# The `create` event trigger doesn't support `branches` filters, so it's necessary to use Bash instead.
58+
if [[
59+
"${{ github.event_name }}" != "create" ||
60+
"${{ github.ref }}" =~ $RELEASE_BRANCH_REGEX
61+
]]; then
62+
# Run the other jobs.
63+
RESULT="true"
64+
else
65+
# There is no need to run the other jobs.
66+
RESULT="false"
67+
fi
68+
69+
echo "result=$RESULT" >> $GITHUB_OUTPUT
70+
4671
check:
4772
name: ${{ matrix.configuration.name }}
73+
needs: run-determination
74+
if: needs.run-determination.outputs.result == 'true'
4875
runs-on: ubuntu-latest
4976
permissions:
5077
contents: read

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ env:
77

88
# See: https://docs.github.com/actions/using-workflows/events-that-trigger-workflows
99
on:
10+
create:
1011
push:
1112
pull_request:
1213
schedule:
@@ -16,7 +17,33 @@ on:
1617
repository_dispatch:
1718

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

0 commit comments

Comments
 (0)