Skip to content

Commit c8b8f07

Browse files
committedSep 14, 2022
Add release branch validation support to GitHub Actions workflows
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). For this reason, it is necessary to to trigger all relevant workflows on the creation of a release branch. This project does not use release branches, so does not benefit from the added support for them. However, these workflows are designed to be reusable for any Arduino tooling project with the minimum amount of project-specific configuration. The benefits of reduced installation and maintenance effort that comes from this standardization outweigh any harm done by asset content that is superfluous for a specific project.
1 parent 74bb001 commit c8b8f07

File tree

4 files changed

+110
-0
lines changed

4 files changed

+110
-0
lines changed
 

‎.github/workflows/check-license.yml

+26
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ env:
88

99
# See: https://docs.github.com/actions/using-workflows/events-that-trigger-workflows
1010
on:
11+
create:
1112
push:
1213
paths:
1314
- ".github/workflows/check-license.ya?ml"
@@ -32,7 +33,32 @@ on:
3233
repository_dispatch:
3334

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

3864
steps:

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

+28
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-shell-task.yml

+30
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

+26
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*"
@@ -46,8 +47,33 @@ on:
4647
repository_dispatch:
4748

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

5379
strategy:

0 commit comments

Comments
 (0)
Please sign in to comment.