Skip to content

Commit ee5bec1

Browse files
committed
Run integration test workflow on release branch creation
The project uses the standard GitHub Actions convention of providing a major version ref. A branch is used for that purpose. These release branches may contain a subset of the history of the default branch. Although most often this would mirror the history on the `main` branch, in some cases it might be beneficial to cherry-pick the commits ready for release to the release branch, excluding other commits that are not yet ready for release. 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.
1 parent 78f6151 commit ee5bec1

File tree

1 file changed

+41
-1
lines changed

1 file changed

+41
-1
lines changed

.github/workflows/test-integration.yml

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
name: Run integration tests
22

33
on:
4+
create:
5+
46
pull_request:
57
paths:
68
- ".github/workflows/test-integration.yml"
@@ -28,7 +30,32 @@ env:
2830
TESTDATA_REPORTS_PATH: .github/workflows/testdata/reports
2931

3032
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/v[0-9]+$"
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 "result=$RESULT" >> $GITHUB_OUTPUT
55+
3156
default-inputs:
57+
needs: run-determination
58+
if: needs.run-determination.outputs.result == 'true'
3259
runs-on: ubuntu-latest
3360

3461
steps:
@@ -49,6 +76,8 @@ jobs:
4976
uses: ./extras/compile-sketches
5077

5178
all-inputs:
79+
needs: run-determination
80+
if: needs.run-determination.outputs.result == 'true'
5281
runs-on: ubuntu-latest
5382

5483
strategy:
@@ -120,6 +149,8 @@ jobs:
120149

121150
multiple-steps:
122151
name: multiple-steps (${{ matrix.board.source-type }})
152+
needs: run-determination
153+
if: needs.run-determination.outputs.result == 'true'
123154
runs-on: ubuntu-latest
124155

125156
strategy:
@@ -209,6 +240,8 @@ jobs:
209240
- examples/Sweep
210241
211242
python-package-dependency:
243+
needs: run-determination
244+
if: needs.run-determination.outputs.result == 'true'
212245
runs-on: ubuntu-latest
213246

214247
steps:
@@ -239,6 +272,8 @@ jobs:
239272
240273
# Targeted testing for ESP32 boards platform support.
241274
pyserial-dependency:
275+
needs: run-determination
276+
if: needs.run-determination.outputs.result == 'true'
242277
runs-on: ubuntu-latest
243278

244279
steps:
@@ -267,7 +302,10 @@ jobs:
267302
- ${{ env.TESTDATA_SKETCHES_PATH }}/BareMinimum
268303
269304
check-sketches-reports:
270-
needs: all-inputs
305+
needs:
306+
- run-determination
307+
- all-inputs
308+
if: needs.run-determination.outputs.result == 'true'
271309
runs-on: ubuntu-latest
272310

273311
steps:
@@ -334,6 +372,8 @@ jobs:
334372
exit $EXIT_STATUS
335373
336374
expected-failed-compilation:
375+
needs: run-determination
376+
if: needs.run-determination.outputs.result == 'true'
337377
runs-on: ubuntu-latest
338378

339379
steps:

0 commit comments

Comments
 (0)