Skip to content

Commit dbafda6

Browse files
Update gradle.yml
1 parent 15a82d0 commit dbafda6

1 file changed

Lines changed: 56 additions & 21 deletions

File tree

‎.github/workflows/gradle.yml‎

Lines changed: 56 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ name: Java CI with Gradle
22

33
on:
44
push:
5-
branches: ["main"]
5+
branches: [ main ]
66
pull_request:
7-
branches: ["main"]
7+
branches: [ main ]
88

99
jobs:
10+
# 1. Build and upload both JARs as a single "built-jars" artifact
1011
build:
1112
runs-on: ubuntu-latest
1213
steps:
@@ -25,29 +26,63 @@ jobs:
2526
path: |
2627
~/.gradle/caches
2728
~/.gradle/wrapper
28-
key: ${{ runner.os }}-gradle-${{ hashFiles('**/gradle/wrapper/gradle-wrapper.properties', '**/build.gradle.kts', '**/settings.gradle.kts') }}
29+
key: ${{ runner.os }}-gradle-${{ hashFiles('**/gradle/wrapper/gradle-wrapper.properties', '**/*.gradle*', '**/*.kts') }}
2930
restore-keys: |
3031
${{ runner.os }}-gradle-
3132
3233
- name: Build project
3334
run: ./gradlew build --no-daemon
3435

35-
- name: Find and upload JARs
36-
env:
37-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
36+
- name: Upload all JARs together
37+
uses: actions/upload-artifact@v4
38+
with:
39+
name: built-jars
40+
path: versions/1.8.9-forge/build/libs/*.jar
41+
42+
# 2. Download the grouped artifact and list exactly 2 JARs
43+
find-jars:
44+
needs: build
45+
runs-on: ubuntu-latest
46+
outputs:
47+
jar-array: ${{ steps.set-jars.outputs.jar-array }}
48+
steps:
49+
- name: Download built-jars artifact
50+
uses: actions/download-artifact@v4
51+
with:
52+
name: built-jars
53+
path: libs
54+
55+
- name: Discover and export JAR filenames
56+
id: set-jars
3857
run: |
39-
cd versions/1.8.9-forge/build/libs/
40-
jar_files=(*.jar)
41-
echo "Found ${#jar_files[@]} JAR files"
42-
43-
for jar in "${jar_files[@]}"; do
44-
echo "Uploading $jar..."
45-
artifact_name="${jar%.*}"
46-
echo "::group::Uploading $artifact_name"
47-
48-
# Use the GitHub CLI to upload as artifact
49-
gh run upload "$jar" --name "$artifact_name" || \
50-
echo "::warning::Failed to upload $jar"
51-
52-
echo "::endgroup::"
53-
done
58+
cd libs
59+
# Gather all *.jar into bash array
60+
jars=( *.jar )
61+
count=${#jars[@]}
62+
if [ "$count" -ne 2 ]; then
63+
echo "❌ Expected 2 JARs but found $count" >&2
64+
exit 1
65+
fi
66+
# Build JSON array: ["a.jar","b.jar"]
67+
printf -v json '["%s"]' "$(IFS='","'; echo "${jars[*]}")"
68+
echo "jar-array=$json" >> $GITHUB_OUTPUT
69+
70+
# 3. Re-download and upload each JAR as its own artifact
71+
upload-individual:
72+
needs: find-jars
73+
runs-on: ubuntu-latest
74+
strategy:
75+
matrix:
76+
jar: ${{ fromJson(needs.find-jars.outputs.jar-array) }}
77+
steps:
78+
- name: Download built-jars artifact
79+
uses: actions/download-artifact@v4
80+
with:
81+
name: built-jars
82+
path: libs
83+
84+
- name: Upload ${{ matrix.jar }}
85+
uses: actions/upload-artifact@v4
86+
with:
87+
name: ${{ matrix.jar }}
88+
path: libs/${{ matrix.jar }}

0 commit comments

Comments
 (0)