@@ -29,16 +29,41 @@ permissions:
2929 contents : read
3030
3131jobs :
32+ # Computes which JDK versions the build job's matrix should cover. This lives in its
33+ # own job because the `matrix` context is not available in a job-level `if:`, so the
34+ # release*-branches-skip-21 rule can't be expressed as a condition on the build job
35+ # itself - see https://github.com/orgs/community/discussions/37883. Instead we shrink
36+ # the matrix itself before it reaches the build job.
37+ prep :
38+ runs-on : ubuntu-latest
39+ outputs :
40+ java : ${{ steps.set-matrix.outputs.java }}
41+ steps :
42+ - name : Determine JDK matrix
43+ id : set-matrix
44+ env :
45+ EVENT_NAME : ${{ github.event_name }}
46+ REF_NAME : ${{ github.ref_name }}
47+ BASE_REF : ${{ github.base_ref }}
48+ run : |
49+ # release* branches stay JDK 17 only until they adopt JDK 21 too,
50+ # since trunk fixes must stay backportable to them.
51+ if { [ "$EVENT_NAME" = "push" ] && [[ "$REF_NAME" == release* ]]; } || \
52+ { [ "$EVENT_NAME" = "pull_request" ] && [[ "$BASE_REF" == release* ]]; }; then
53+ echo 'java=[17]' >> "$GITHUB_OUTPUT"
54+ else
55+ echo 'java=[17,21]' >> "$GITHUB_OUTPUT"
56+ fi
57+
3258 build :
3359 # trunk builds sourceCompatibility/targetCompatibility 17 bytecode (see build.gradle),
3460 # but is matrix-tested on both the JDK 17 runtime it targets and the JDK 21 runtime
35- # it may adopt later. release* branches stay JDK 17 only until they make that same move,
36- # since trunk fixes must stay backportable to them.
37- if : ${{ !(matrix.java == 21 && ((github.event_name == 'push' && startsWith(github.ref_name, 'release')) || (github.event_name == 'pull_request' && startsWith(github.base_ref, 'release')))) }}
61+ # it may adopt later.
62+ needs : prep
3863 strategy :
3964 fail-fast : false
4065 matrix :
41- java : [ 17, 21 ]
66+ java : ${{ fromJson(needs.prep.outputs.java) }}
4267
4368 runs-on : ubuntu-latest
4469
0 commit comments