-
Notifications
You must be signed in to change notification settings - Fork 27
322 lines (281 loc) · 11.2 KB
/
auto-build-publish-release.yml
File metadata and controls
322 lines (281 loc) · 11.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
name: Auto Build, Publish, Releasing
on:
workflow_dispatch:
inputs:
publishMaven:
description: 'Whether to publish to Maven'
required: true
type: boolean
default: true
publishCurseForgeAndModrinth:
description: 'Whether to publish to CurseForge and Modrinth'
required: true
type: boolean
default: true
versionType:
description: 'Version type'
required: true
type: choice
options:
- 'alpha'
- 'beta'
- 'release'
default: 'alpha'
dryRun:
description: 'Dry run (build only, no publishing)'
required: false
type: boolean
default: false
env:
JAVA_VERSION: '21'
JAVA_DISTRIBUTION: 'temurin'
jobs:
validate:
name: Validate & Pre-checks
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}
should-publish: ${{ steps.check.outputs.should-publish }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true
- name: Set up JDK
uses: actions/setup-java@v4
with:
java-version: ${{ env.JAVA_VERSION }}
distribution: ${{ env.JAVA_DISTRIBUTION }}
- name: Validate Gradle wrapper
uses: gradle/actions/wrapper-validation@v4
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4
with:
cache-read-only: false
- name: Grant execute permission
run: chmod +x gradlew
- name: Get version from gradle.properties
id: version
run: |
if [ -f "gradle.properties" ]; then
VERSION=$(grep -E "^mod_version\s*=" gradle.properties | cut -d'=' -f2 | tr -d ' ')
if [ -z "$VERSION" ]; then
echo "❌ Could not find mod_version in gradle.properties"
exit 1
fi
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "Project version: $VERSION"
else
echo "❌ gradle.properties not found, falling back to Gradle command"
VERSION=$(./gradlew -q printVersion)
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "Project version: $VERSION"
fi
- name: Check publish conditions
id: check
run: |
SHOULD_PUBLISH="false"
if [[ "${{ inputs.dryRun }}" == "false" && ("${{ inputs.publishMaven }}" == "true" || "${{ inputs.publishCurseForgeAndModrinth }}" == "true") ]]; then
SHOULD_PUBLISH="true"
fi
echo "should-publish=$SHOULD_PUBLISH" >> $GITHUB_OUTPUT
echo "Should publish: $SHOULD_PUBLISH"
build:
name: Build & Test
runs-on: ubuntu-latest
needs: validate
strategy:
matrix:
include:
- name: "Main Build"
gradle-tasks: "build test"
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 1000
fetch-tags: true
- name: Set up JDK
uses: actions/setup-java@v4
with:
java-version: ${{ env.JAVA_VERSION }}
distribution: ${{ env.JAVA_DISTRIBUTION }}
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4
with:
cache-read-only: false
- name: Grant execute permission
run: chmod +x gradlew
- name: Build and test
run: ./gradlew ${{ matrix.gradle-tasks }} --stacktrace --info --parallel
env:
GRADLE_OPTS: "-Dorg.gradle.daemon=true -Dorg.gradle.parallel=true -Dorg.gradle.configureondemand=true"
- name: Upload build artifacts
uses: actions/upload-artifact@v4
if: always()
with:
name: build-artifacts-${{ matrix.name }}
path: |
build/libs/
build/reports/
retention-days: 7
- name: Upload test results
uses: actions/upload-artifact@v4
if: always()
with:
name: test-results-${{ matrix.name }}
path: build/test-results/
retention-days: 7
publish-maven:
name: Publish to Maven
runs-on: ubuntu-latest
needs: [validate, build]
if: ${{ needs.validate.outputs.should-publish == 'true' && inputs.publishMaven }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 1000
fetch-tags: true
- name: Set up JDK
uses: actions/setup-java@v4
with:
java-version: ${{ env.JAVA_VERSION }}
distribution: ${{ env.JAVA_DISTRIBUTION }}
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4
with:
cache-read-only: true
- name: Grant execute permission
run: chmod +x gradlew
- name: Publish to Maven
run: ./gradlew publish --stacktrace
env:
MAVEN_PASS: ${{ secrets.MAVEN_PASS }}
MAVEN_USER: ${{ secrets.MAVEN_USER }}
GRADLE_OPTS: "-Dorg.gradle.daemon=true"
- name: Maven publish summary
run: |
echo "## Maven Publish Summary" >> $GITHUB_STEP_SUMMARY
echo "- Version: ${{ needs.validate.outputs.version }}" >> $GITHUB_STEP_SUMMARY
echo "- Status: ✅ Published successfully" >> $GITHUB_STEP_SUMMARY
publish-platforms:
name: Publish to CurseForge & Modrinth
runs-on: ubuntu-latest
needs: [validate, build]
if: ${{ needs.validate.outputs.should-publish == 'true' && inputs.publishCurseForgeAndModrinth }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 1000
fetch-tags: true
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
name: build-artifacts-Main Build
path: build/
- name: Verify build artifacts
run: |
if [ ! -d "build/libs" ] || [ -z "$(ls -A build/libs)" ]; then
echo "❌ Build artifacts not found!"
echo "Available files in build/:"
find build/ -type f -name "*.jar" || echo "No JAR files found"
exit 1
fi
echo "✅ Build artifacts verified:"
ls -la build/libs/
- name: Publish to CurseForge and Modrinth
uses: Kir-Antipov/mc-publish@v3.3
with:
modrinth-id: gzevkJbM
modrinth-token: ${{ secrets.MODRINTH_TOKEN }}
curseforge-id: 871522
curseforge-token: ${{ secrets.CURSEFORGE_TOKEN }}
files: |
forge/build/libs/!(*-@(all|sources|javadoc|dev-shadow)).jar
forge/build/libs/*-@(all|sources|javadoc|dev-shadow).jar
name: Photon2-${{ needs.validate.outputs.version }}-neoforge
version: mc1.21.1-${{ needs.validate.outputs.version }}-neoforge
version-type: ${{ inputs.versionType }}
changelog-file: CHANGELOG.*
loaders: |
neoforge
game-versions: |
${{ github.ref_name }}
1.21.1
game-version-filter: none
java: |
21
retry-attempts: 3
retry-delay: 10000
fail-mode: fail
- name: Platform publish summary
run: |
echo "## Platform Publish Summary" >> $GITHUB_STEP_SUMMARY
echo "- Version: ${{ needs.validate.outputs.version }}" >> $GITHUB_STEP_SUMMARY
echo "- Version Type: ${{ inputs.versionType }}" >> $GITHUB_STEP_SUMMARY
echo "- Platforms: CurseForge & Modrinth" >> $GITHUB_STEP_SUMMARY
echo "- Status: ✅ Published successfully" >> $GITHUB_STEP_SUMMARY
summary:
name: Build & Publish Summary
runs-on: ubuntu-latest
needs: [validate, build, publish-maven, publish-platforms]
if: always()
steps:
- name: Generate final summary
run: |
echo "# 🚀 Build & Publish Results" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "## 📋 Configuration" >> $GITHUB_STEP_SUMMARY
echo "- **Version**: ${{ needs.validate.outputs.version }}" >> $GITHUB_STEP_SUMMARY
echo "- **Version Type**: ${{ inputs.versionType }}" >> $GITHUB_STEP_SUMMARY
echo "- **Dry Run**: ${{ inputs.dryRun }}" >> $GITHUB_STEP_SUMMARY
echo "- **Maven Publish**: ${{ inputs.publishMaven }}" >> $GITHUB_STEP_SUMMARY
echo "- **Platform Publish**: ${{ inputs.publishCurseForgeAndModrinth }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "## 📊 Job Results" >> $GITHUB_STEP_SUMMARY
VALIDATE_STATUS="${{ needs.validate.result }}"
BUILD_STATUS="${{ needs.build.result }}"
MAVEN_STATUS="${{ needs.publish-maven.result }}"
PLATFORM_STATUS="${{ needs.publish-platforms.result }}"
echo "- **Validation**: $([ "$VALIDATE_STATUS" == "success" ] && echo "✅ Success" || echo "❌ $VALIDATE_STATUS")" >> $GITHUB_STEP_SUMMARY
echo "- **Build**: $([ "$BUILD_STATUS" == "success" ] && echo "✅ Success" || echo "❌ $BUILD_STATUS")" >> $GITHUB_STEP_SUMMARY
if [[ "${{ inputs.publishMaven }}" == "true" && "${{ inputs.dryRun }}" == "false" ]]; then
echo "- **Maven Publish**: $([ "$MAVEN_STATUS" == "success" ] && echo "✅ Success" || echo "❌ $MAVEN_STATUS")" >> $GITHUB_STEP_SUMMARY
fi
if [[ "${{ inputs.publishCurseForgeAndModrinth }}" == "true" && "${{ inputs.dryRun }}" == "false" ]]; then
echo "- **Platform Publish**: $([ "$PLATFORM_STATUS" == "success" ] && echo "✅ Success" || echo "❌ $PLATFORM_STATUS")" >> $GITHUB_STEP_SUMMARY
fi
if [[ "$BUILD_STATUS" == "success" ]]; then
if [[ "${{ inputs.dryRun }}" == "true" ]]; then
echo "" >> $GITHUB_STEP_SUMMARY
echo "## 🔍 Dry Run Completed" >> $GITHUB_STEP_SUMMARY
echo "Build completed successfully. No publishing was performed." >> $GITHUB_STEP_SUMMARY
else
echo "" >> $GITHUB_STEP_SUMMARY
echo "## 🎉 All Operations Completed Successfully!" >> $GITHUB_STEP_SUMMARY
fi
else
echo "" >> $GITHUB_STEP_SUMMARY
echo "## ❌ Some Operations Failed" >> $GITHUB_STEP_SUMMARY
echo "Please check the job logs for details." >> $GITHUB_STEP_SUMMARY
fi
- name: Check overall status
run: |
if [[ "${{ needs.build.result }}" != "success" ]]; then
echo "Build failed, marking workflow as failed"
exit 1
fi
if [[ "${{ inputs.dryRun }}" == "false" ]]; then
if [[ "${{ inputs.publishMaven }}" == "true" && "${{ needs.publish-maven.result }}" != "success" ]]; then
echo "Maven publish failed, marking workflow as failed"
exit 1
fi
if [[ "${{ inputs.publishCurseForgeAndModrinth }}" == "true" && "${{ needs.publish-platforms.result }}" != "success" ]]; then
echo "Platform publish failed, marking workflow as failed"
exit 1
fi
fi
echo "All requested operations completed successfully!"