Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit fde91a5

Browse files
committedMay 3, 2022
Run "Check Go Dependencies" workflow on release branch creation
The trunk-based development strategy is used by some tooling projects. 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 branch in the project using that strategy. The reason is that, for the sake of efficiency, the workflow is configured to run only when the processes are relevant to the trigger event (e.g., no need to run it 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 the workflow on the creation of a release branch. This will ensure that the workflow 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 the 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 other workflows.
1 parent 89ebd4c commit fde91a5

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
 

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

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

88
# See: https://docs.github.com/actions/using-workflows/events-that-trigger-workflows
99
on:
10+
create:
1011
push:
1112
paths:
1213
- ".github/workflows/check-go-dependencies-task.ya?ml"
@@ -34,7 +35,32 @@ on:
3435
repository_dispatch:
3536

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

4066
steps:
@@ -83,6 +109,8 @@ jobs:
83109
path: .licenses/
84110

85111
check-deps:
112+
needs: run-determination
113+
if: needs.run-determination.outputs.result == 'true'
86114
runs-on: ubuntu-latest
87115

88116
steps:

0 commit comments

Comments
 (0)
Please sign in to comment.