Skip to content

Commit b0b027c

Browse files
committed
Stop using pull_request: labeled to gate optional tests
The labeled trigger caused two issues that combined into recurring CI breakage on PRs that received any label (renovate, dependabot, code-review-sweep, the labeler, or a human applied one): * GitHub evaluates a workflow's `concurrency:` group before its job-level `if:` filter, so a labeled run cancelled the in-progress real build before being filtered out. * Even after a conditional concurrency-group fix, the labeled run's check_suite displaced the in-progress real build's check_suite in the PR Checks UI (GitHub keys that view by workflow file, latest check_suite wins). Concrete failure: PR open-telemetry#18441, run https://github.com/open-telemetry/opentelemetry-java-instrumentation/actions/runs/25156724872 — every job ended within ~2 seconds with no steps executed. Fix: drop `labeled` from the trigger entirely. Read labels from `github.event.pull_request.labels` (which is present on every `pull_request` event) and gate optional jobs by `contains(...)`. Skipped jobs that are listed as required satisfy branch protection, so auto-merge still works. * `test openj9` / `test windows` labels: still consulted, but only at the moments the build naturally runs (opened / synchronize / reopened). Applying a label after the last push no longer re-triggers the build; to pick up the label, close/reopen the PR or push another commit. This trade-off avoids the labeled-event race and the wasted reruns from non-test labels. * `test native` is now detected inline from the PR's changed paths via a new `resolve-native` job that mirrors the former `.github/labeler.yml` `test native` rule. The label is no longer auto-applied; the manual label is still honored as a force-enable. * `.github/labeler.yml` and `.github/workflows/label.yml` are deleted (the labeler's only rule was the `test native` one).
1 parent f0833f0 commit b0b027c

4 files changed

Lines changed: 85 additions & 46 deletions

File tree

.github/labeler.yml

Lines changed: 0 additions & 11 deletions
This file was deleted.
Lines changed: 51 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,26 @@
11
name: Build pull request
22

3+
# Optional test variants (openj9, windows) are gated by `test openj9` /
4+
# `test windows` labels on the PR, read from the event payload. We
5+
# deliberately do NOT subscribe to `pull_request: [labeled]` — see the
6+
# description of PR #18446 for the history of why every previous attempt
7+
# to use that trigger failed.
8+
#
9+
# Practical consequence: a `test openj9` / `test windows` label added
10+
# AFTER the last push doesn't retrigger the build. Push another commit
11+
# or close/reopen the PR to pick it up. `comment-on-test-label.yml`
12+
# posts a reminder when one of those labels is added.
13+
#
14+
# `test native` is detected automatically from the PR's changed paths
15+
# (the `resolve-native` job below). The manual `test native` label is
16+
# still honored as a force-enable.
17+
318
on:
419
pull_request:
520
types:
621
- opened
722
- synchronize
823
- reopened
9-
- labeled
1024

1125
concurrency:
1226
group: build-pull-request-${{ github.event.pull_request.number }}
@@ -16,22 +30,44 @@ permissions:
1630
contents: read
1731

1832
jobs:
33+
# Mirrors the former `.github/labeler.yml` `test native` rule: matches if
34+
# any changed file is in the include set AND no changed file is under
35+
# `instrumentation/spring/**/javaagent/**`.
36+
resolve-native:
37+
runs-on: ubuntu-latest
38+
outputs:
39+
run-native-tests: ${{ steps.filter.outputs.native }}
40+
steps:
41+
- name: Detect native-relevant changes
42+
id: filter
43+
env:
44+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
45+
PR_NUMBER: ${{ github.event.pull_request.number }}
46+
run: |
47+
files=$(
48+
gh api --paginate "/repos/${GITHUB_REPOSITORY}/pulls/${PR_NUMBER}/files" \
49+
--jq '.[].filename'
50+
)
51+
include='^instrumentation/logback/logback-appender-1\.0/library/'
52+
include+='|^instrumentation/jdbc/library/'
53+
include+='|^instrumentation/spring/'
54+
include+='|^smoke-tests-otel-starter/'
55+
include+='|^dependencyManagement/build\.gradle\.kts$'
56+
include+='|^settings\.gradle\.kts$'
57+
exclude='^instrumentation/spring/.+/javaagent/'
58+
if grep -Eq "$include" <<<"$files" && ! grep -Eq "$exclude" <<<"$files"; then
59+
echo "native=true" >> "$GITHUB_OUTPUT"
60+
else
61+
echo "native=false" >> "$GITHUB_OUTPUT"
62+
fi
63+
1964
build:
20-
# On `labeled` events, only proceed when the added label affects what we
21-
# build. All other event types (opened, synchronize, reopened) always
22-
# proceed.
23-
if: |
24-
github.event.action != 'labeled' ||
25-
github.event.label.name == 'test native' ||
26-
github.event.label.name == 'test openj9' ||
27-
github.event.label.name == 'test windows'
65+
needs: [resolve-native]
2866
uses: ./.github/workflows/reusable-pr-build.yml
2967
with:
30-
# it's rare for only the openj9 tests, openj9 smoke variants, the windows
31-
# smoke tests, or the native tests to break, so they are gated by labels.
32-
# `test native` is applied automatically by .github/labeler.yml when the
33-
# PR diff touches native-relevant paths; `test openj9` and `test windows`
34-
# are applied manually.
35-
skip-native-tests: ${{ !contains(github.event.pull_request.labels.*.name, 'test native') }}
68+
# See the design notes at the top of this file for why optional tests
69+
# are gated by reading labels from the event payload (rather than via
70+
# a `labeled` trigger).
71+
skip-native-tests: ${{ !(needs.resolve-native.outputs.run-native-tests == 'true' || contains(github.event.pull_request.labels.*.name, 'test native')) }}
3672
skip-openj9-tests: ${{ !contains(github.event.pull_request.labels.*.name, 'test openj9') }}
3773
skip-windows-smoke-tests: ${{ !contains(github.event.pull_request.labels.*.name, 'test windows') }}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Comment on test-* label
2+
3+
# Posts a reminder when a `test openj9` / `test windows` label is added,
4+
# explaining that `build-pull-request.yml` doesn't retrigger on `labeled`
5+
# events (see the design notes at the top of that file for the rationale).
6+
# Without this, applying the label and waiting would look broken.
7+
#
8+
# Why `pull_request_target` is safe here: this workflow does NOT check out
9+
# or execute any PR code. Its only step is `gh pr comment`. Fork PRs
10+
# therefore can't influence what runs, so the secrets that
11+
# `pull_request_target` would normally expose are not reachable.
12+
13+
on:
14+
pull_request_target:
15+
types: [labeled]
16+
17+
permissions:
18+
contents: read
19+
pull-requests: write
20+
21+
jobs:
22+
comment:
23+
if: |
24+
github.event.label.name == 'test openj9' ||
25+
github.event.label.name == 'test windows'
26+
runs-on: ubuntu-latest
27+
steps:
28+
- name: Post explanatory comment
29+
env:
30+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
31+
PR_NUMBER: ${{ github.event.pull_request.number }}
32+
LABEL: ${{ github.event.label.name }}
33+
run: |
34+
gh pr comment "$PR_NUMBER" --body "The \`$LABEL\` label has been added, but the build only consults test-* labels at the moments it naturally runs (PR opened / synchronize / reopened). To pick up this label, push another commit or close-and-reopen the PR."

.github/workflows/label.yml

Lines changed: 0 additions & 20 deletions
This file was deleted.

0 commit comments

Comments
 (0)