Skip to content

Commit 2d2d408

Browse files
committed
Run relevant workflows on release branch creation
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 763018c commit 2d2d408

11 files changed

+304
-0
lines changed

.github/workflows/test-python-poetry-task.yml

+26
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-python-poetry-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
test:
55+
needs: run-determination
56+
if: needs.run-determination.outputs.result == 'true'
3157
runs-on: ubuntu-latest
3258

3359
steps:

workflow-templates/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,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:
@@ -59,6 +85,8 @@ jobs:
5985

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

6492
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:
@@ -129,6 +159,8 @@ jobs:
129159

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

134166
strategy:
@@ -164,6 +196,8 @@ jobs:
164196

165197
check-config:
166198
name: check-config (${{ matrix.module.path }})
199+
needs: run-determination
200+
if: needs.run-determination.outputs.result == 'true'
167201
runs-on: ubuntu-latest
168202

169203
strategy:

workflow-templates/dependabot/workflow-template-copies/.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,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:
@@ -59,6 +85,8 @@ jobs:
5985

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

6492
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:
@@ -129,6 +159,8 @@ jobs:
129159

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

134166
strategy:
@@ -164,6 +196,8 @@ jobs:
164196

165197
check-config:
166198
name: check-config (${{ matrix.module.path }})
199+
needs: run-determination
200+
if: needs.run-determination.outputs.result == 'true'
167201
runs-on: ubuntu-latest
168202

169203
strategy:

workflow-templates/dependabot/workflow-template-copies/.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:

workflow-templates/dependabot/workflow-template-copies/.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:

workflow-templates/dependabot/workflow-template-copies/.github/workflows/test-go-task.yml

+26
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,8 +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:
3357
name: test (${{ matrix.module.path }} - ${{ matrix.operating-system }})
58+
needs: run-determination
59+
if: needs.run-determination.outputs.result == 'true'
3460

3561
strategy:
3662
fail-fast: false

workflow-templates/dependabot/workflow-template-copies/.github/workflows/test-python-poetry-task.yml

+26
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-python-poetry-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
test:
55+
needs: run-determination
56+
if: needs.run-determination.outputs.result == 'true'
3157
runs-on: ubuntu-latest
3258

3359
steps:

0 commit comments

Comments
 (0)