Skip to content

Commit 1985936

Browse files
per1234cmaglie
andauthored
[skip changelog] Run relevant workflows on release branch creation (#1400)
* [skip changelog] Run relevant workflows on release branch creation The trunk-based development strategy is employed by this repository. This means that 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 the Go 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 workflows are 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 website deployment workflow. * [skip changlog] Simplify jobs run determination logic Co-authored-by: Cristian Maglie <[email protected]> Co-authored-by: Cristian Maglie <[email protected]>
1 parent 408cee8 commit 1985936

6 files changed

+172
-0
lines changed

Diff for: .github/workflows/check-go-task.yml

+36
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,8 +26,33 @@ 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:
2953
name: check-errors (${{ matrix.module.path }})
54+
needs: run-determination
55+
if: needs.run-determination.outputs.result == 'true'
3056
runs-on: ubuntu-latest
3157

3258
strategy:
@@ -62,6 +88,8 @@ jobs:
6288

6389
check-outdated:
6490
name: check-outdated (${{ matrix.module.path }})
91+
needs: run-determination
92+
if: needs.run-determination.outputs.result == 'true'
6593
runs-on: ubuntu-latest
6694

6795
strategy:
@@ -100,6 +128,8 @@ jobs:
100128

101129
check-style:
102130
name: check-style (${{ matrix.module.path }})
131+
needs: run-determination
132+
if: needs.run-determination.outputs.result == 'true'
103133
runs-on: ubuntu-latest
104134

105135
strategy:
@@ -138,6 +168,8 @@ jobs:
138168

139169
check-formatting:
140170
name: check-formatting (${{ matrix.module.path }})
171+
needs: run-determination
172+
if: needs.run-determination.outputs.result == 'true'
141173
runs-on: ubuntu-latest
142174

143175
strategy:
@@ -176,6 +208,8 @@ jobs:
176208

177209
check-config:
178210
name: check-config (${{ matrix.module.path }})
211+
needs: run-determination
212+
if: needs.run-determination.outputs.result == 'true'
179213
runs-on: ubuntu-latest
180214

181215
strategy:
@@ -208,6 +242,8 @@ jobs:
208242
# Do a simple "smoke test" build for the modules with no other form of validation
209243
build:
210244
name: build (${{ matrix.module.path }})
245+
needs: run-determination
246+
if: needs.run-determination.outputs.result == 'true'
211247
runs-on: ubuntu-latest
212248

213249
strategy:

Diff for: .github/workflows/check-i18n-task.yml

+26
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-i18n-task.ya?ml"
@@ -26,7 +27,32 @@ 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 "::set-output name=result::$RESULT"
52+
2953
check:
54+
needs: run-determination
55+
if: needs.run-determination.outputs.result == 'true'
3056
runs-on: ubuntu-latest
3157

3258
steps:

Diff for: .github/workflows/check-protobuf-task.yml

+30
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-protobuf-task.ya?ml"
@@ -20,7 +21,32 @@ on:
2021
repository_dispatch:
2122

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

2652
steps:
@@ -54,6 +80,8 @@ jobs:
5480
run: task protoc:compile
5581

5682
check:
83+
needs: run-determination
84+
if: needs.run-determination.outputs.result == 'true'
5785
runs-on: ubuntu-latest
5886

5987
steps:
@@ -81,6 +109,8 @@ jobs:
81109
run: task protoc:check
82110

83111
check-formatting:
112+
needs: run-determination
113+
if: needs.run-determination.outputs.result == 'true'
84114
runs-on: ubuntu-latest
85115

86116
steps:

Diff for: .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:

Diff for: .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:

Diff for: .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)