1
+ name : Create Release Asset
2
+
3
+ # Trigger the workflow only when a release is published
4
+ on :
5
+ release :
6
+ types : [published] # Only run when a release goes from draft/pre-release to published, or is created as published
7
+
8
+ permissions :
9
+ contents : write # Allow workflow to write release assets
10
+
11
+ jobs :
12
+ build-and-upload :
13
+ runs-on : ubuntu-latest
14
+ steps :
15
+ # 1. Checkout Repository code
16
+ - name : Checkout code at release tag
17
+ uses : actions/checkout@v4
18
+
19
+ # 2. Set up JDK (Must match the version used for building)
20
+ - name : Set up JDK 21
21
+ uses : actions/setup-java@v4
22
+ with :
23
+ java-version : ' 21'
24
+ distribution : ' temurin'
25
+
26
+ # 3. Give permission to gradle to execute commands
27
+ - name : Grant execute permission for gradlew
28
+ run : chmod +x gradlew
29
+
30
+ # Setup Gradle - This action handles caching and executing gradle tasks
31
+ # It automatically finds and uses ./gradlew
32
+ - name : Setup Gradle and Build Plugin Jar
33
+ uses : gradle/actions/setup-gradle@v4 # Use v4 or latest stable version
34
+
35
+ # Gradle with the new updates doesn't support arguments
36
+ - name : Build jar
37
+ run : ./gradlew shadowJar
38
+
39
+ # 5. Find the specific Shadow Jar file and extract its name
40
+ - name : Find Shadow Jar and Extract Name
41
+ id : find_jar
42
+ run : |
43
+ JAR_PATH=$(find plugin/build/libs -maxdepth 1 -name '*.jar' -printf "%s %p\n" | sort -nr | head -n 1 | awk '{print $2}')
44
+ if [ -z "$JAR_PATH" ]; then
45
+ echo "Error: Could not find the shadow JAR file in plugin/build/libs/"
46
+ exit 1
47
+ fi
48
+ JAR_FILENAME=$(basename "$JAR_PATH")
49
+ echo "Found JAR path: $JAR_PATH"
50
+ echo "Found JAR filename: $JAR_FILENAME"
51
+ echo "path=$JAR_PATH" >> $GITHUB_OUTPUT
52
+ echo "filename=$JAR_FILENAME" >> $GITHUB_OUTPUT
53
+ shell : bash
54
+
55
+ # 6. Upload the Shadow Jar as a release asset
56
+ - name : Upload Release Asset
57
+ uses : svenstaro/upload-release-action@v2
58
+ with :
59
+ repo_token : ${{ secrets.GITHUB_TOKEN }} # Provided by GitHub Actions automatically
60
+ file : ${{ steps.find_jar.outputs.path }} # The path to the JAR found in the previous step
61
+ asset_name : ${{ steps.find_jar.outputs.filename }} # Use the filename extracted earlier
62
+ tag : ${{ github.ref }} # The git tag associated with the release that triggered the workflow
63
+ overwrite : true # Optional: Replace asset with the same name if it already exists
0 commit comments