Skip to content

Commit 7b247e1

Browse files
committed
Run relevant workflows on release branch creation
The trunk-based development strategy is used by this project. The release branch 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 the project are 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 "Deploy Website" workflow.
1 parent 61c3094 commit 7b247e1

5 files changed

+140
-0
lines changed

.github/workflows/check-code-generation-task.yml

+26
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ env:
55
GO_VERSION: "1.16"
66

77
on:
8+
create:
89
push:
910
paths:
1011
- ".github/workflows/check-code-generation-task.ya?ml"
@@ -23,7 +24,32 @@ on:
2324
- "etc/schemas/**/*.json"
2425

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

2955
steps:

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

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

88
# See: https://docs.github.com/en/actions/reference/events-that-trigger-workflows
99
on:
10+
create:
1011
push:
1112
paths:
1213
- ".github/workflows/check-go-task.ya?ml"
@@ -25,7 +26,32 @@ on:
2526
repository_dispatch:
2627

2728
jobs:
29+
run-determination:
30+
runs-on: ubuntu-latest
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 "::set-output name=result::$RESULT"
51+
2852
check-errors:
53+
needs: run-determination
54+
if: needs.run-determination.outputs.result == 'true'
2955
runs-on: ubuntu-latest
3056

3157
steps:
@@ -47,6 +73,8 @@ jobs:
4773
run: task go:vet
4874

4975
check-outdated:
76+
needs: run-determination
77+
if: needs.run-determination.outputs.result == 'true'
5078
runs-on: ubuntu-latest
5179

5280
steps:
@@ -71,6 +99,8 @@ jobs:
7199
run: git diff --color --exit-code
72100

73101
check-style:
102+
needs: run-determination
103+
if: needs.run-determination.outputs.result == 'true'
74104
runs-on: ubuntu-latest
75105

76106
steps:
@@ -95,6 +125,8 @@ jobs:
95125
run: task --silent go:lint
96126

97127
check-formatting:
128+
needs: run-determination
129+
if: needs.run-determination.outputs.result == 'true'
98130
runs-on: ubuntu-latest
99131

100132
steps:
@@ -120,6 +152,8 @@ jobs:
120152

121153
check-config:
122154
name: check-config (${{ matrix.module.path }})
155+
needs: run-determination
156+
if: needs.run-determination.outputs.result == 'true'
123157
runs-on: ubuntu-latest
124158

125159
strategy:

.github/workflows/publish-go-tester-task.yml

+26
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ name: Publish Tester Build
33

44
# See: https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows
55
on:
6+
create:
67
push:
78
paths:
89
- ".github/workflows/publish-go-tester-task.ya?ml"
@@ -28,7 +29,32 @@ env:
2829
BUILDS_ARTIFACT: build-artifacts
2930

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

3460
steps:

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

+27
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"
@@ -33,7 +34,33 @@ on:
3334
repository_dispatch:
3435

3536
jobs:
37+
run-determination:
38+
runs-on: ubuntu-latest
39+
outputs:
40+
result: ${{ steps.determination.outputs.result }}
41+
steps:
42+
- name: Determine if the rest of the workflow should run
43+
id: determination
44+
run: |
45+
RELEASE_BRANCH_REGEX="refs/heads/[0-9]+.[0-9]+.x"
46+
# The `create` event trigger doesn't support `branches` filters, so it's necessary to use Bash instead.
47+
if [[ \
48+
"${{ github.event_name }}" != "create" || \
49+
"${{ github.ref }}" =~ $RELEASE_BRANCH_REGEX \
50+
]]; then
51+
# Run the other jobs.
52+
RESULT="true"
53+
else
54+
# There is no need to run the other jobs.
55+
RESULT="false"
56+
fi
57+
58+
echo "::set-output name=result::$RESULT"
59+
3660
test:
61+
needs: run-determination
62+
if: needs.run-determination.outputs.result == 'true'
63+
3764
strategy:
3865
matrix:
3966
operating-system:

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

+27
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"
@@ -29,7 +30,33 @@ on:
2930
repository_dispatch:
3031

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

0 commit comments

Comments
 (0)