|
1 | | -name: Build with Gradle |
| 1 | +name: Build |
2 | 2 |
|
3 | 3 | on: |
4 | 4 | push: |
| 5 | + branches: [main, master, develop] # ignore noise from short-lived feature branches |
5 | 6 | pull_request: |
6 | 7 | workflow_dispatch: |
7 | 8 |
|
| 9 | +# Cancel any in-progress run on the same branch/PR when a new one is triggered. |
| 10 | +# This prevents redundant builds piling up while you're actively pushing. |
| 11 | +concurrency: |
| 12 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 13 | + cancel-in-progress: true |
| 14 | + |
8 | 15 | env: |
9 | | - FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true # opt into Node.js 24 ahead of the June 2026 forced migration |
| 16 | + FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true # opt into Node.js 24 ahead of June 2026 forced migration |
10 | 17 |
|
11 | 18 | jobs: |
12 | 19 | build: |
13 | 20 | runs-on: ubuntu-latest |
14 | | - outputs: |
15 | | - jars: ${{ steps.collect.outputs.jars }} # JSON array of filenames (basenames) |
16 | 21 | permissions: |
17 | 22 | contents: read |
| 23 | + |
18 | 24 | steps: |
19 | 25 | - name: Checkout |
20 | 26 | uses: actions/checkout@v4 |
21 | 27 |
|
22 | | - - name: Set up JDK |
| 28 | + - name: Set up JDK 21 |
23 | 29 | uses: actions/setup-java@v4 |
24 | 30 | with: |
25 | 31 | distribution: temurin |
26 | 32 | java-version: '21' |
27 | 33 |
|
28 | 34 | - name: Set up Gradle |
29 | | - uses: gradle/actions/setup-gradle@v4 # v4 supports Node.js 24 |
| 35 | + uses: gradle/actions/setup-gradle@v4 |
30 | 36 |
|
31 | 37 | - name: Build |
32 | | - run: ./gradlew --no-daemon shadowJar # gradlew is already executable after checkout |
| 38 | + run: | |
| 39 | + chmod +x ./gradlew |
| 40 | + ./gradlew --no-daemon shadowJar |
33 | 41 |
|
34 | | - - name: Collect runtime JARs (flatten) |
| 42 | + - name: Collect JARs |
35 | 43 | run: | |
36 | 44 | mkdir -p jars |
37 | | - # collect jars from all subprojects; exclude sources/javadoc/tests/plain |
38 | 45 | find . -path "*/build/libs/*.jar" -type f \ |
39 | 46 | ! -name "*-sources.jar" \ |
40 | 47 | ! -name "*-javadoc.jar" \ |
41 | 48 | ! -name "*-tests.jar" \ |
42 | 49 | ! -name "*-plain.jar" \ |
43 | 50 | -exec cp {} jars/ \; |
44 | 51 |
|
45 | | - - name: Make list of JAR filenames (JSON) |
46 | | - id: collect |
47 | | - shell: bash |
48 | | - run: | |
49 | | - files=() |
50 | | - while IFS= read -r -d '' f; do |
51 | | - files+=("$(basename "$f")") |
52 | | - done < <(find jars -type f -name "*.jar" -print0 | sort -z) |
53 | | -
|
54 | | - if [ ${#files[@]} -eq 0 ]; then |
55 | | - json='[]' |
56 | | - else |
57 | | - # Use jq if available for safe JSON construction, otherwise fall back to printf |
58 | | - if command -v jq &>/dev/null; then |
59 | | - json=$(printf '%s\n' "${files[@]}" | jq -R . | jq -sc .) |
60 | | - else |
61 | | - printf -v json '[%s]' "$(printf '"%s",' "${files[@]}" | sed 's/,$//')" |
62 | | - fi |
63 | | - fi |
64 | | -
|
65 | | - echo "jars=$json" >> "$GITHUB_OUTPUT" |
66 | | -
|
67 | | - - name: Upload temporary combined artifact |
68 | | - if: steps.collect.outputs.jars != '[]' |
| 52 | + - name: Upload JARs |
69 | 53 | uses: actions/upload-artifact@v4 |
70 | 54 | with: |
71 | | - name: all-jars |
| 55 | + name: jars-${{ github.sha }} # include commit SHA so each run's artifact is uniquely identifiable |
72 | 56 | path: jars/*.jar |
73 | 57 | if-no-files-found: error |
74 | | - retention-days: 1 # only needed as a staging area for upload-each; no need to keep it longer |
75 | | - |
76 | | - upload-each: |
77 | | - needs: build |
78 | | - if: needs.build.outputs.jars != '[]' |
79 | | - runs-on: ubuntu-latest |
80 | | - permissions: |
81 | | - contents: read |
82 | | - strategy: |
83 | | - fail-fast: false |
84 | | - matrix: |
85 | | - jar: ${{ fromJSON(needs.build.outputs.jars) }} |
86 | | - steps: |
87 | | - - name: Download combined artifact |
88 | | - uses: actions/download-artifact@v4 |
89 | | - with: |
90 | | - name: all-jars |
91 | | - path: jars |
92 | | - |
93 | | - - name: Upload ${{ matrix.jar }} as its own artifact |
94 | | - uses: actions/upload-artifact@v4 |
95 | | - with: |
96 | | - name: ${{ matrix.jar }} |
97 | | - path: jars/${{ matrix.jar }} |
98 | | - if-no-files-found: error |
99 | 58 | retention-days: 14 |
0 commit comments