Skip to content

Commit 59157c1

Browse files
authored
Run relevant workflows on release branch creation (#110)
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 trigger workflows based on their usual 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 every 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 f2739d3 commit 59157c1

File tree

4 files changed

+106
-0
lines changed

4 files changed

+106
-0
lines changed

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

+27
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ env:
66

77
# See: https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows
88
on:
9+
create:
910
push:
1011
paths:
1112
- ".github/workflows/check-go-cross-build-task.ya?ml"
@@ -24,7 +25,33 @@ on:
2425
repository_dispatch:
2526

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

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

+26
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ env:
1010

1111
# See: https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows
1212
on:
13+
create:
1314
push:
1415
paths:
1516
- ".github/workflows/publish-go-tester-task.ya?ml"
@@ -30,7 +31,32 @@ on:
3031
repository_dispatch:
3132

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

3662
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

+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

0 commit comments

Comments
 (0)