Skip to content

Commit 22504dc

Browse files
committed
Run relevant workflows on release branch creation
This is a follow up to the original campaign to provide release branch coverage. The trigger on release branch creation system was added only to the most critical workflows at that time. Since then, the system has proven itself through several releases. A new critical "Check Go Dependencies" workflow was added which was missing the trigger due to being created prior to the campaign, but then staged until after it. While updating that workflow, I took the time to review all the remaining workflows for ones that might provide valuable information for project evaluation prior to release. I identified several additional workflows that, while not critical, still might reveal problems with the project at its state in the release branch. So I also added it to those. --- 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 8900f88 commit 22504dc

21 files changed

+608
-10
lines changed

.github/workflows/check-license.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ env:
99

1010
# See: https://docs.github.com/actions/using-workflows/events-that-trigger-workflows
1111
on:
12+
create:
1213
push:
1314
paths:
1415
- ".github/workflows/check-license.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
check-license:
58+
needs: run-determination
59+
if: needs.run-determination.outputs.result == 'true'
3460
runs-on: ubuntu-latest
3561

3662
steps:

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ name: Check Markdown
33

44
# See: https://docs.github.com/actions/using-workflows/events-that-trigger-workflows
55
on:
6+
create:
67
push:
78
paths:
89
- ".github/workflows/check-markdown-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
lint:
58+
needs: run-determination
59+
if: needs.run-determination.outputs.result == 'true'
3460
runs-on: ubuntu-latest
3561

3662
steps:
@@ -50,6 +76,8 @@ jobs:
5076
run: task markdown:lint
5177

5278
links:
79+
needs: run-determination
80+
if: needs.run-determination.outputs.result == 'true'
5381
runs-on: ubuntu-latest
5482

5583
steps:

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

Lines changed: 28 additions & 0 deletions
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-python-task.ya?ml"
@@ -31,7 +32,32 @@ on:
3132
repository_dispatch:
3233

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

3763
steps:
@@ -59,6 +85,8 @@ jobs:
5985
run: task python:lint
6086

6187
formatting:
88+
needs: run-determination
89+
if: needs.run-determination.outputs.result == 'true'
6290
runs-on: ubuntu-latest
6391

6492
steps:

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ name: Check Shell Scripts
33

44
# See: https://docs.github.com/actions/using-workflows/events-that-trigger-workflows
55
on:
6+
create:
67
push:
78
paths:
89
- ".github/workflows/check-shell-task.ya?ml"
@@ -24,8 +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
lint:
2852
name: ${{ matrix.configuration.name }}
53+
needs: run-determination
54+
if: needs.run-determination.outputs.result == 'true'
2955
runs-on: ubuntu-latest
3056

3157
env:
@@ -88,6 +114,8 @@ jobs:
88114
run: task --silent shell:check SHELLCHECK_FORMAT=${{ matrix.configuration.format }}
89115

90116
formatting:
117+
needs: run-determination
118+
if: needs.run-determination.outputs.result == 'true'
91119
runs-on: ubuntu-latest
92120

93121
steps:
@@ -131,6 +159,8 @@ jobs:
131159
run: git diff --color --exit-code
132160

133161
executable:
162+
needs: run-determination
163+
if: needs.run-determination.outputs.result == 'true'
134164
runs-on: ubuntu-latest
135165

136166
steps:

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

Lines changed: 26 additions & 0 deletions
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
- ".yamllint*"
@@ -43,8 +44,33 @@ on:
4344
repository_dispatch:
4445

4546
jobs:
47+
run-determination:
48+
runs-on: ubuntu-latest
49+
outputs:
50+
result: ${{ steps.determination.outputs.result }}
51+
steps:
52+
- name: Determine if the rest of the workflow should run
53+
id: determination
54+
run: |
55+
RELEASE_BRANCH_REGEX="refs/heads/[0-9]+.[0-9]+.x"
56+
# The `create` event trigger doesn't support `branches` filters, so it's necessary to use Bash instead.
57+
if [[
58+
"${{ github.event_name }}" != "create" ||
59+
"${{ github.ref }}" =~ $RELEASE_BRANCH_REGEX
60+
]]; then
61+
# Run the other jobs.
62+
RESULT="true"
63+
else
64+
# There is no need to run the other jobs.
65+
RESULT="false"
66+
fi
67+
68+
echo "::set-output name=result::$RESULT"
69+
4670
check:
4771
name: ${{ matrix.configuration.name }}
72+
needs: run-determination
73+
if: needs.run-determination.outputs.result == 'true'
4874
runs-on: ubuntu-latest
4975

5076
strategy:

workflow-templates/check-certificates.yml

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ name: Check Certificates
33

44
# See: https://docs.github.com/actions/using-workflows/events-that-trigger-workflows
55
on:
6+
create:
67
push:
78
paths:
89
- ".github/workflows/check-certificates.ya?ml"
@@ -20,13 +21,50 @@ env:
2021
EXPIRATION_WARNING_PERIOD: 30
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+
# TODO: Update repository name.
34+
REPO_SLUG="REPO_OWNER/REPO_NAME"
35+
if [[
36+
(
37+
# Only run on branch creation when it is a release branch.
38+
# The `create` event trigger doesn't support `branches` filters, so it's necessary to use Bash instead.
39+
"${{ github.event_name }}" != "create" ||
40+
"${{ github.ref }}" =~ $RELEASE_BRANCH_REGEX
41+
) &&
42+
(
43+
# Only run when the workflow will have access to the certificate secrets.
44+
# This could be done via a GitHub Actions workflow conditional, but makes more sense to do it here as well.
45+
(
46+
"${{ github.event_name }}" != "pull_request" &&
47+
"${{ github.repository }}" == "$REPO_SLUG"
48+
) ||
49+
(
50+
"${{ github.event_name }}" == "pull_request" &&
51+
"${{ github.event.pull_request.head.repo.full_name }}" == "$REPO_SLUG"
52+
)
53+
)
54+
]]; then
55+
# Run the other jobs.
56+
RESULT="true"
57+
else
58+
# There is no need to run the other jobs.
59+
RESULT="false"
60+
fi
61+
62+
echo "::set-output name=result::$RESULT"
63+
2364
check-certificates:
2465
name: ${{ matrix.certificate.identifier }}
25-
# Only run when the workflow will have access to the certificate secrets.
26-
# TODO: Update repository name.
27-
if: >
28-
(github.event_name != 'pull_request' && github.repository == 'REPO_OWNER/REPO_NAME') ||
29-
(github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == 'REPO_OWNER/REPO_NAME')
66+
needs: run-determination
67+
if: needs.run-determination.outputs.result == 'true'
3068
runs-on: ubuntu-latest
3169
strategy:
3270
fail-fast: false

workflow-templates/check-go-dependencies-task.yml

Lines changed: 28 additions & 0 deletions
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"
@@ -31,7 +32,32 @@ on:
3132
repository_dispatch:
3233

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

3763
steps:
@@ -80,6 +106,8 @@ jobs:
80106
path: .licenses/
81107

82108
check-deps:
109+
needs: run-determination
110+
if: needs.run-determination.outputs.result == 'true'
83111
runs-on: ubuntu-latest
84112

85113
steps:

workflow-templates/check-license.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ env:
1010

1111
# See: https://docs.github.com/actions/using-workflows/events-that-trigger-workflows
1212
on:
13+
create:
1314
push:
1415
paths:
1516
- ".github/workflows/check-license.ya?ml"
@@ -31,7 +32,32 @@ on:
3132
repository_dispatch:
3233

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

3763
steps:

0 commit comments

Comments
 (0)