1+ name : Build and Release
2+
3+ on :
4+ push :
5+ branches : [ main, master ]
6+ paths-ignore :
7+ - ' **.md'
8+ - ' .gitignore'
9+ - ' LICENSE'
10+ pull_request :
11+ branches : [ main, master ]
12+ paths-ignore :
13+ - ' **.md'
14+ - ' .gitignore'
15+ - ' LICENSE'
16+ workflow_dispatch :
17+
18+ jobs :
19+ build :
20+ runs-on : ubuntu-latest
21+ permissions :
22+ contents : write
23+ packages : write
24+
25+ steps :
26+ - name : Checkout code
27+ uses : actions/checkout@v4
28+ with :
29+ fetch-depth : 0
30+
31+ - name : Set up JDK 21
32+ uses : actions/setup-java@v4
33+ with :
34+ java-version : ' 21'
35+ distribution : ' temurin'
36+ cache : gradle
37+
38+ - name : Validate Gradle wrapper
39+ uses : gradle/wrapper-validation-action@v2
40+
41+ - name : Setup Gradle
42+ uses : gradle/actions/setup-gradle@v3
43+
44+ - name : Make Gradle wrapper executable
45+ run : chmod +x ./gradlew
46+
47+ - name : Extract version
48+ id : extract_version
49+ run : |
50+ VERSION=$(grep "^version = " build.gradle | sed "s/version = '\(.*\)'/\1/")
51+ echo "VERSION=$VERSION" >> $GITHUB_ENV
52+ echo "version=$VERSION" >> $GITHUB_OUTPUT
53+ COMMIT_SHA_SHORT=$(git rev-parse --short HEAD)
54+ echo "COMMIT_SHA_SHORT=$COMMIT_SHA_SHORT" >> $GITHUB_ENV
55+ echo "Version: $VERSION (Commit: $COMMIT_SHA_SHORT)"
56+
57+ - name : Check if tag exists
58+ id : check_tag
59+ run : |
60+ if git rev-parse "v${{ env.VERSION }}" >/dev/null 2>&1; then
61+ echo "exists=true" >> $GITHUB_OUTPUT
62+ echo "Tag v${{ env.VERSION }} already exists"
63+ else
64+ echo "exists=false" >> $GITHUB_OUTPUT
65+ echo "Tag v${{ env.VERSION }} does not exist"
66+ fi
67+
68+ - name : Build with Gradle
69+ run : ./gradlew clean build --no-daemon
70+
71+ - name : Run tests
72+ run : ./gradlew test --no-daemon
73+
74+ - name : Upload build artifacts
75+ uses : actions/upload-artifact@v4
76+ with :
77+ name : PluginUpdateCore-${{ env.VERSION }}-build-${{ env.COMMIT_SHA_SHORT }}
78+ path : build/libs/*.jar
79+ retention-days : 90
80+
81+ - name : Upload test reports on failure
82+ if : failure()
83+ uses : actions/upload-artifact@v4
84+ with :
85+ name : test-reports-${{ env.COMMIT_SHA_SHORT }}
86+ path : build/reports/tests/
87+ retention-days : 7
88+
89+ - name : Create Git Tag
90+ if : github.event_name == 'push' && steps.check_tag.outputs.exists == 'false'
91+ run : |
92+ git config user.name "github-actions[bot]"
93+ git config user.email "github-actions[bot]@users.noreply.github.com"
94+ git tag -a "v${{ env.VERSION }}" -m "Release version ${{ env.VERSION }}"
95+ git push origin "v${{ env.VERSION }}"
96+
97+ - name : Create GitHub Release
98+ if : github.event_name == 'push' && steps.check_tag.outputs.exists == 'false'
99+ uses : softprops/action-gh-release@v2
100+ with :
101+ tag_name : v${{ env.VERSION }}
102+ name : Release v${{ env.VERSION }}
103+ body : |
104+ ## PluginUpdateCore v${{ env.VERSION }}
105+
106+ ### 📦 Artifacts
107+ - Main JAR: `PluginUpdateCore-${{ env.VERSION }}.jar`
108+ - Sources JAR: `PluginUpdateCore-${{ env.VERSION }}-sources.jar`
109+ - Javadoc JAR: `PluginUpdateCore-${{ env.VERSION }}-javadoc.jar`
110+
111+ ### 📝 Changes
112+ Built from commit: `${{ env.COMMIT_SHA_SHORT }}`
113+
114+ ### 📚 Documentation
115+ See [README.md](https://github.com/${{ github.repository }}/blob/main/README.md) for usage instructions.
116+
117+ ### 🔗 Maven Dependency
118+ ```xml
119+ <dependency>
120+ <groupId>com.github.NighterDevelopment</groupId>
121+ <artifactId>PluginUpdateCore</artifactId>
122+ <version>${{ env.VERSION }}</version>
123+ </dependency>
124+ ```
125+
126+ ### 🔗 Gradle Dependency (Kotlin DSL)
127+ ```kotlin
128+ implementation("com.github.NighterDevelopment:PluginUpdateCore:${{ env.VERSION }}")
129+ ```
130+
131+ ### 🔗 Gradle Dependency (Groovy)
132+ ```groovy
133+ implementation 'com.github.NighterDevelopment:PluginUpdateCore:${{ env.VERSION }}'
134+ ```
135+ draft : false
136+ prerelease : false
137+ files : |
138+ build/libs/*.jar
139+ fail_on_unmatched_files : false
140+ env :
141+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
142+
143+ - name : Release Summary
144+ if : github.event_name == 'push'
145+ run : |
146+ if [ "${{ steps.check_tag.outputs.exists }}" == "true" ]; then
147+ echo "✅ Build completed successfully"
148+ echo "ℹ️ Release v${{ env.VERSION }} already exists, skipping release creation"
149+ else
150+ echo "✅ Build completed successfully"
151+ echo "🚀 Release v${{ env.VERSION }} created successfully"
152+ echo "📦 Artifacts uploaded to GitHub Release"
153+ fi
0 commit comments