Skip to content

Commit 2f03532

Browse files
committed
Run relevant workflows on release branch creation
Since this project does not use the trunk-based development strategy at the moment, this change does not provide any benefit outside of facilitating syncs with the upstream "template" project assets. It will not have any significant effect, since it only results in the additional full workflow run being triggered on the creation of a branch with the release style of name format. Explanation of the reason for the change as it applies to these files being intended to be generally applicable to any project: 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 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 62cafe4 commit 2f03532

File tree

3 files changed

+88
-0
lines changed

3 files changed

+88
-0
lines changed

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

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

77
# See: https://docs.github.com/en/actions/reference/events-that-trigger-workflows
88
on:
9+
create:
910
push:
1011
paths:
1112
- ".github/workflows/check-go-task.yml"
@@ -27,8 +28,33 @@ on:
2728
repository_dispatch:
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 "::set-output name=result::$RESULT"
53+
3054
check-errors:
3155
name: check-errors (${{ matrix.module.path }})
56+
needs: run-determination
57+
if: needs.run-determination.outputs.result == 'true'
3258
runs-on: ubuntu-latest
3359

3460
strategy:
@@ -60,6 +86,8 @@ jobs:
6086

6187
check-outdated:
6288
name: check-outdated (${{ matrix.module.path }})
89+
needs: run-determination
90+
if: needs.run-determination.outputs.result == 'true'
6391
runs-on: ubuntu-latest
6492

6593
strategy:
@@ -94,6 +122,8 @@ jobs:
94122

95123
check-style:
96124
name: check-style (${{ matrix.module.path }})
125+
needs: run-determination
126+
if: needs.run-determination.outputs.result == 'true'
97127
runs-on: ubuntu-latest
98128

99129
strategy:
@@ -128,6 +158,8 @@ jobs:
128158

129159
check-formatting:
130160
name: check-formatting (${{ matrix.module.path }})
161+
needs: run-determination
162+
if: needs.run-determination.outputs.result == 'true'
131163
runs-on: ubuntu-latest
132164

133165
strategy:
@@ -162,6 +194,8 @@ jobs:
162194

163195
check-config:
164196
name: check-config (${{ matrix.module.path }})
197+
needs: run-determination
198+
if: needs.run-determination.outputs.result == 'true'
165199
runs-on: ubuntu-latest
166200

167201
strategy:

.github/workflows/test-go-integration-task.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ env:
99

1010
# See: https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows
1111
on:
12+
create:
1213
push:
1314
paths:
1415
- ".github/workflows/test-go-integration-task.ya?ml"
@@ -40,7 +41,32 @@ on:
4041
repository_dispatch:
4142

4243
jobs:
44+
run-determination:
45+
runs-on: ubuntu-latest
46+
outputs:
47+
result: ${{ steps.determination.outputs.result }}
48+
steps:
49+
- name: Determine if the rest of the workflow should run
50+
id: determination
51+
run: |
52+
RELEASE_BRANCH_REGEX="refs/heads/[0-9]+.[0-9]+.x"
53+
# The `create` event trigger doesn't support `branches` filters, so it's necessary to use Bash instead.
54+
if [[ \
55+
"${{ github.event_name }}" != "create" || \
56+
"${{ github.ref }}" =~ $RELEASE_BRANCH_REGEX \
57+
]]; then
58+
# Run the other jobs.
59+
RESULT="true"
60+
else
61+
# There is no need to run the other jobs.
62+
RESULT="false"
63+
fi
64+
65+
echo "::set-output name=result::$RESULT"
66+
4367
test:
68+
needs: run-determination
69+
if: needs.run-determination.outputs.result == 'true'
4470
runs-on: ubuntu-latest
4571

4672
env:

.github/workflows/test-go-task.yml

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

88
# See: https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows
99
on:
10+
create:
1011
push:
1112
paths:
1213
- ".github/workflows/test-go-task.ya?ml"
@@ -27,7 +28,32 @@ on:
2728
repository_dispatch:
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 "::set-output name=result::$RESULT"
53+
3054
build:
55+
needs: run-determination
56+
if: needs.run-determination.outputs.result == 'true'
3157
runs-on: ubuntu-latest
3258

3359
steps:
@@ -57,6 +83,8 @@ jobs:
5783

5884
test:
5985
name: test (${{ matrix.module.path }} - ${{ matrix.operating-system }})
86+
needs: run-determination
87+
if: needs.run-determination.outputs.result == 'true'
6088

6189
strategy:
6290
fail-fast: false

0 commit comments

Comments
 (0)