Skip to content

Commit f359893

Browse files
committed
Run relevant workflows on release branch creation
The trunk-based development strategy is used by some tooling projects. 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 3639d77 commit f359893

5 files changed

+134
-0
lines changed

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

+26
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,32 @@ on:
1213
repository_dispatch:
1314

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

1844
steps:

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

+28
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ name: Check npm
33

44
# See: https://docs.github.com/en/actions/reference/events-that-trigger-workflows
55
on:
6+
create:
67
push:
78
paths:
89
- ".github/workflows/check-npm-task.ya?ml"
@@ -27,8 +28,33 @@ permissions:
2728
contents: read
2829

2930
jobs:
31+
run-determination:
32+
runs-on: ubuntu-latest
33+
outputs:
34+
result: ${{ steps.determination.outputs.result }}
35+
steps:
36+
- name: Determine if the rest of the workflow should run
37+
id: determination
38+
run: |
39+
RELEASE_BRANCH_REGEX="refs/heads/[0-9]+.[0-9]+.x"
40+
# The `create` event trigger doesn't support `branches` filters, so it's necessary to use Bash instead.
41+
if [[
42+
"${{ github.event_name }}" != "create" ||
43+
"${{ github.ref }}" =~ $RELEASE_BRANCH_REGEX
44+
]]; then
45+
# Run the other jobs.
46+
RESULT="true"
47+
else
48+
# There is no need to run the other jobs.
49+
RESULT="false"
50+
fi
51+
52+
echo "result=$RESULT" >> $GITHUB_OUTPUT
53+
3054
validate:
3155
name: validate (${{ matrix.project.path }})
56+
needs: run-determination
57+
if: needs.run-determination.outputs.result == 'true'
3258
runs-on: ubuntu-latest
3359

3460
strategy:
@@ -61,6 +87,8 @@ jobs:
6187
6288
check-sync:
6389
name: check-sync (${{ matrix.project.path }})
90+
needs: run-determination
91+
if: needs.run-determination.outputs.result == 'true'
6492
runs-on: ubuntu-latest
6593

6694
strategy:

.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/using-workflows/events-that-trigger-workflows
55
on:
6+
create:
67
push:
78
paths:
89
- ".github/workflows/check-prettier-formatting-task.ya?ml"
@@ -204,7 +205,33 @@ on:
204205
repository_dispatch:
205206

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

210237
steps:

.github/workflows/check-taskfiles.yml

+26
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"
@@ -26,8 +27,33 @@ on:
2627
repository_dispatch:
2728

2829
jobs:
30+
run-determination:
31+
runs-on: ubuntu-latest
32+
outputs:
33+
result: ${{ steps.determination.outputs.result }}
34+
steps:
35+
- name: Determine if the rest of the workflow should run
36+
id: determination
37+
run: |
38+
RELEASE_BRANCH_REGEX="refs/heads/[0-9]+.[0-9]+.x"
39+
# The `create` event trigger doesn't support `branches` filters, so it's necessary to use Bash instead.
40+
if [[
41+
"${{ github.event_name }}" != "create" ||
42+
"${{ github.ref }}" =~ $RELEASE_BRANCH_REGEX
43+
]]; then
44+
# Run the other jobs.
45+
RESULT="true"
46+
else
47+
# There is no need to run the other jobs.
48+
RESULT="false"
49+
fi
50+
51+
echo "result=$RESULT" >> $GITHUB_OUTPUT
52+
2953
validate:
3054
name: Validate ${{ matrix.file }}
55+
needs: run-determination
56+
if: needs.run-determination.outputs.result == 'true'
3157
runs-on: ubuntu-latest
3258

3359
strategy:

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

+27
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

2249
steps:

0 commit comments

Comments
 (0)