11name : 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
6+ # https://github.com/open-telemetry/opentelemetry-java-instrumentation/pull/18446
7+ # for the history of why every previous attempt to use that trigger failed.
8+ #
9+ # Practical consequence: adding a `test openj9` / `test windows` label
10+ # doesn't retrigger the build. Push another commit or close/reopen the
11+ # PR to pick it up. `comment-on-test-label.yml` posts a reminder when
12+ # 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+
318on :
419 pull_request :
520 types :
621 - opened
722 - synchronize
823 - reopened
9- - labeled
1024
1125concurrency :
1226 group : build-pull-request-${{ github.event.pull_request.number }}
@@ -16,22 +30,44 @@ permissions:
1630 contents : read
1731
1832jobs :
33+ # Run native tests automatically when the PR touches a library
34+ # instrumentation module with native support (logback-appender, jdbc,
35+ # spring), the native smoke test harness, or the top-level build config
36+ # that affects them.
37+ resolve-native :
38+ runs-on : ubuntu-latest
39+ outputs :
40+ run-native-tests : ${{ steps.filter.outputs.native }}
41+ steps :
42+ - name : Detect native-relevant changes
43+ id : filter
44+ env :
45+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
46+ PR_NUMBER : ${{ github.event.pull_request.number }}
47+ run : |
48+ # `|| true` so an empty result from `grep -v` (everything filtered)
49+ # doesn't fail the step under pipefail.
50+ files=$(
51+ gh api --paginate "/repos/${GITHUB_REPOSITORY}/pulls/${PR_NUMBER}/files" \
52+ --jq '.[].filename' |
53+ grep -Ev '^instrumentation/spring/.+/javaagent/' || true
54+ )
55+ include='^instrumentation/logback/logback-appender-1\.0/library/'
56+ include+='|^instrumentation/jdbc/library/'
57+ include+='|^instrumentation/spring/'
58+ include+='|^smoke-tests-otel-starter/'
59+ include+='|^dependencyManagement/build\.gradle\.kts$'
60+ include+='|^settings\.gradle\.kts$'
61+ if grep -Eq "$include" <<<"$files"; then
62+ echo "native=true" >> "$GITHUB_OUTPUT"
63+ else
64+ echo "native=false" >> "$GITHUB_OUTPUT"
65+ fi
66+
1967 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'
68+ needs : [resolve-native]
2869 uses : ./.github/workflows/reusable-pr-build.yml
2970 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') }}
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') }}
0 commit comments