Skip to content

Commit cb858f9

Browse files
Start only the matching e2e suite when its label is added
Adding test-e2e, test-ark or test-ngts to an open pull request currently does nothing. The workflow uses `on: pull_request: {}`, which takes the default activity types of opened, synchronize and reopened. There is no `labeled`, so the label sits on the pull request and no run starts. Re-running the workflow does not help either, because a re-run replays the original event payload, which had no labels. The only way through is to close and reopen the pull request, or push a commit. The failure mode is silent, so it looks like the job is broken. Add `labeled` to the activity types, and make each job decide what a label event means for it: - verify and test skip, because a label says nothing about the code. - each e2e job runs only when github.event.label.name, the single label that was just added, is its own label. github.event.action is null on push and on workflow_dispatch, so both guards only ever exclude the label event. Behaviour on push, on workflow_dispatch and on opened/synchronize/reopened is unchanged, so an e2e suite whose label is already on the pull request still re-runs on every new commit. The trigger itself cannot be filtered by label name, so adding an unrelated label still creates a workflow run. Every job in it skips, and a skipped job never claims a runner. One ordering note: add keep-e2e-cluster before test-e2e, not after. Adding it afterwards starts nothing, because it matches no job. Signed-off-by: Richard Wall <richard.wall@cyberark.com>
1 parent da60d34 commit cb858f9

1 file changed

Lines changed: 40 additions & 4 deletions

File tree

.github/workflows/tests.yaml

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,30 @@ name: tests
22
on:
33
push:
44
branches: [master]
5-
pull_request: {}
5+
# `labeled` is not one of the default activity types, so without it adding
6+
# test-e2e, test-ark or test-ngts to an open pull request starts nothing, and
7+
# re-running does not help because a re-run replays the original, unlabelled
8+
# payload.
9+
# Why?: https://docs.github.com/en/actions/reference/workflows-and-actions/events-that-trigger-workflows#pull_request
10+
# > By default, a workflow only runs when a pull_request event's activity
11+
# > type is opened, synchronize, or reopened.
12+
#
13+
# A label event starts only the one e2e job named by the label; see the `if:`
14+
# on each job below. There is no way to filter the trigger itself by label
15+
# name, so an unrelated label still starts a run, but every job skips and a
16+
# skipped job never claims a runner.
17+
pull_request:
18+
types: [opened, synchronize, reopened, labeled]
619
# Lets us run the e2e suites against master, which the label gates below
720
# cannot do: they read github.event.pull_request.labels, which is empty for
821
# a push. Needed before tagging a release.
922
workflow_dispatch: {}
1023
jobs:
1124
verify:
25+
# Adding a label says nothing about the code, so there is nothing new to
26+
# verify. `github.event.action` is null on push and on workflow_dispatch,
27+
# so this only ever excludes the label event.
28+
if: github.event.action != 'labeled'
1229
runs-on: ubuntu-latest
1330
timeout-minutes: 15
1431

@@ -39,6 +56,8 @@ jobs:
3956
- run: make -j verify
4057

4158
test:
59+
# See `verify`.
60+
if: github.event.action != 'labeled'
4261
runs-on: ubuntu-latest
4362
timeout-minutes: 15
4463

@@ -84,7 +103,14 @@ jobs:
84103
# where the e2e fails with a 400 error relating to "conflicting tagging values"
85104
# The test is flaky, not broken and re-running eventually makes it pass - but that delays progress on
86105
# other unrelated work.
87-
if: github.event_name == 'workflow_dispatch' || contains(github.event.pull_request.labels.*.name, 'test-ark')
106+
# Runs when the label is added, and thereafter on every push while it is
107+
# still on the pull request. `github.event.label` names only the label that
108+
# was just added, so adding one e2e label does not start the other suites.
109+
if: >-
110+
github.event_name == 'workflow_dispatch'
111+
|| github.event.label.name == 'test-ark'
112+
|| (github.event.action != 'labeled'
113+
&& contains(github.event.pull_request.labels.*.name, 'test-ark'))
88114
runs-on: ubuntu-latest
89115
timeout-minutes: 30
90116
steps:
@@ -122,7 +148,12 @@ jobs:
122148

123149
ngts-test-e2e:
124150
# TEMPORARY: require an explicit label to test NGTS until we have a stable test environment
125-
if: github.event_name == 'workflow_dispatch' || contains(github.event.pull_request.labels.*.name, 'test-ngts')
151+
# See `ark-test-e2e`.
152+
if: >-
153+
github.event_name == 'workflow_dispatch'
154+
|| github.event.label.name == 'test-ngts'
155+
|| (github.event.action != 'labeled'
156+
&& contains(github.event.pull_request.labels.*.name, 'test-ngts'))
126157
runs-on: ubuntu-latest
127158
timeout-minutes: 30
128159
steps:
@@ -157,7 +188,12 @@ jobs:
157188
NGTS_TSG_URL: https://1806660206.ngts.qa.venafi.io
158189

159190
test-e2e:
160-
if: github.event_name == 'workflow_dispatch' || contains(github.event.pull_request.labels.*.name, 'test-e2e')
191+
# See `ark-test-e2e`.
192+
if: >-
193+
github.event_name == 'workflow_dispatch'
194+
|| github.event.label.name == 'test-e2e'
195+
|| (github.event.action != 'labeled'
196+
&& contains(github.event.pull_request.labels.*.name, 'test-e2e'))
161197
runs-on: ubuntu-latest
162198
# A healthy run takes about 15 minutes. The backstop matters because the job
163199
# holds a GKE cluster for as long as it runs, and the default is 6 hours.

0 commit comments

Comments
 (0)