-
Notifications
You must be signed in to change notification settings - Fork 0
359 lines (313 loc) · 10.5 KB
/
release.yml
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
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
name: Release
on:
workflow_dispatch:
inputs:
target_version:
type: string
required: false
description: "version | empty = next option"
update_type:
type: choice
required: false
description: "update type"
default: "minor"
options:
- "major"
- "minor"
- "patch"
- "none"
jobs:
preparation:
name: Preparation
runs-on: ubuntu-latest
outputs:
VERSION: ${{ steps.version.outputs.VERSION }}
NEEDS_COMMIT: ${{ steps.commit_info.outputs.NEEDS_COMMIT }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Check secrets
run: |
if [ -z "${{ secrets.GRADLE_KEY }}" ]; then
echo "GRADLE_KEY is not set"
exit 1
fi
if [ -z "${{ secrets.GRADLE_SECRET }}" ]; then
echo "GRADLE_SECRET is not set"
exit 1
fi
- name: Compute version
id: version
env:
TARGET_VERSION: ${{ inputs.target_version }}
UPDATE_TYPE: ${{ inputs.update_type }}
run: |
echo "getting current version"
CURRENT_VERSION=$(grep -oP '^version\s*=\s*"\K[^"]*' build.gradle.kts)
echo "detected current version: $CURRENT_VERSION"
if [[ -z "$CURRENT_VERSION" ]]; then
echo "no current version found"
exit 1
fi
if [[ -z "$TARGET_VERSION" ]]; then
echo "no target version provided, evaluating new version from update type: $UPDATE_TYPE"
case "$UPDATE_TYPE" in
major)
NEW_VERSION=$(echo $CURRENT_VERSION | awk -F. '{$1++; print $1".0.0"}')
;;
minor)
NEW_VERSION=$(echo $CURRENT_VERSION | awk -F. '{$2++; print $1"."$2".0"}')
;;
patch)
NEW_VERSION=$(echo $CURRENT_VERSION | awk -F. '{$3++; print $1"."$2"."$3}')
;;
none)
NEW_VERSION=$CURRENT_VERSION
;;
esac
else
echo "setting new version from target version: $TARGET_VERSION"
NEW_VERSION=$TARGET_VERSION
fi
if ! [[ $NEW_VERSION =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "invalid new version: $NEW_VERSION"
exit 1
fi
echo "using new version: $NEW_VERSION"
echo "VERSION=$NEW_VERSION" >> $GITHUB_OUTPUT
- name: Adjust version
env:
VERSION: ${{ steps.version.outputs.VERSION }}
run: |
if grep -q "^version\s*=\s*\"$VERSION\"" build.gradle.kts; then
echo "version is already set"
else
echo "version is outdated, adjusting build.gradle.kts"
sed -i "s/^version\s*=.*$/version = \"$VERSION\"/g" build.gradle.kts
git diff build.gradle.kts
fi
- name: Check and adjust changelog
env:
VERSION: ${{ steps.version.outputs.VERSION }}
run: |
if grep -qF "## Unreleased" CHANGELOG.md; then
echo "unreleased changelog entry found, adjusting header"
sed -i "s/^## Unreleased.*/## [$VERSION] - $(date +%F)/" CHANGELOG.md
elif grep -qF "## [$VERSION]" CHANGELOG.md; then
echo "existing changelog entry found for version $VERSION"
else
echo "no unreleased changelog entry found or entry for version $VERSION"
exit 1
fi
if ! grep -qF "[$VERSION]: https://" CHANGELOG.md; then
echo "adding changelog link for version $VERSION"
sed -i ':a;/^\n*$/{$d;N;};/\n$/ba' CHANGELOG.md
echo "[$VERSION]: https://github.com/$GITHUB_REPOSITORY/releases/tag/v$VERSION" >> CHANGELOG.md
fi
sed -i "/^## \[$VERSION\]/i ## Unreleased\n- /\n" CHANGELOG.md
git diff CHANGELOG.md
- name: Store commit info
id: commit_info
run: |
if [[ -n $(git diff --name-only build.gradle.kts CHANGELOG.md) ]]; then
NEEDS_COMMIT="true"
else
NEEDS_COMMIT="false"
fi
echo "NEEDS_COMMIT=$NEEDS_COMMIT" >> $GITHUB_OUTPUT
- name: Archive results
run: tar -zcvf preparation.tar.gz build.gradle.kts CHANGELOG.md
- name: Upload results
uses: actions/upload-artifact@v4
with:
name: preparation-artifacts
path: preparation.tar.gz
if-no-files-found: error
retention-days: 3
build:
name: Build
needs: preparation
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Checkout compound action
uses: actions/checkout@v4
with:
repository: AlmostReliable/.github
path: repo
- name: Move compound action
run: |
mv repo/.github/actions .github/actions
rm -rf repo
- name: Download preparation artifacts
uses: actions/download-artifact@v4
with:
name: preparation-artifacts
- name: Extract preparation artifacts
run: tar -zxvf preparation.tar.gz
- name: Setup Java and Gradle
uses: ./.github/actions/gradle-java
with:
java-distribution: "microsoft"
java-version: "21"
branch: ${{ github.event_name == 'pull_request' && 'read_only' || github.ref }}
- name: Assemble the JAR
run: ./gradlew assemble
- name: Move JARs to central directory
run: |
mkdir output
mv -f build/libs/*.jar output/
rm -f output/*-sources.jar
- name: Install changelog parser
uses: taiki-e/install-action@v2
with:
tool: parse-changelog
- name: Parse changelog
env:
VERSION: ${{ needs.preparation.outputs.VERSION }}
run: |
parse-changelog CHANGELOG.md "$VERSION" > output/changelog.md
if [ ! -s output/changelog.md ]; then
echo "Changelog is empty"
exit 1
fi
- name: Archive results
run: tar -zcvf build.tar.gz output
- name: Upload results
uses: actions/upload-artifact@v4
with:
name: build-artifacts
path: build.tar.gz
if-no-files-found: error
retention-days: 3
- name: Job Summary
env:
TARGET_VERSION: ${{ inputs.target_version }}
UPDATE_TYPE: ${{ inputs.update_type }}
VERSION: ${{ needs.preparation.outputs.VERSION }}
run: |
add_head() {
echo "## $1" >> $GITHUB_STEP_SUMMARY
}
add_line() {
echo "- $1" >> $GITHUB_STEP_SUMMARY
}
blank_line() {
echo "" >> $GITHUB_STEP_SUMMARY
}
if [ "$TARGET_VERSION" = "" ]; then
TARGET_VERSION="none"
fi
if [ "$TARGET_VERSION" = "none" ]; then
UPDATE=$UPDATE_TYPE
else
UPDATE="ignored"
fi
add_head "Inputs"
blank_line
add_line "Version: $VERSION"
add_line "Update Type: $UPDATE"
blank_line
add_head "Preparation Information"
blank_line
add_line "New Version: $VERSION"
blank_line
add_head "Build Information"
blank_line
add_line "JAR files: $(find output -maxdepth 1 -type f -name '*.jar' | wc -l)"
add_line "Folder size: $(du -sh output | cut -f1)"
add_line "Archive size: $(du -sh build.tar.gz | cut -f1)"
blank_line
add_head "Changelog"
blank_line
cat output/changelog.md >> $GITHUB_STEP_SUMMARY
blank_line
add_head "Gradle Summary"
commit:
name: Commit changes
if: ${{ needs.preparation.outputs.NEEDS_COMMIT == 'true' }}
needs:
- preparation
- build
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Download preparation artifacts
uses: actions/download-artifact@v4
with:
name: preparation-artifacts
- name: Extract preparation artifacts
run: tar -zxvf preparation.tar.gz
- name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v5.0.0
with:
commit_message: "bump version"
commit_user_name: "AlmostReliable"
file_pattern: "build.gradle.kts CHANGELOG.md"
plugin-portal-release:
name: Plugin Portal Release
needs:
- preparation
- build
- commit
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Download preparation artifacts
uses: actions/download-artifact@v4
with:
name: preparation-artifacts
- name: Extract preparation artifacts
run: tar -zxvf preparation.tar.gz
- name: Checkout compound action
uses: actions/checkout@v4
with:
repository: AlmostReliable/.github
path: repo
- name: Move compound action
run: |
mv repo/.github/actions .github/actions
rm -rf repo
- name: Setup Java and Gradle
uses: ./.github/actions/gradle-java
with:
java-distribution: "microsoft"
java-version: "21"
branch: ${{ github.event_name == 'pull_request' && 'read_only' || github.ref }}
- name: Release
env:
GRADLE_PUBLISH_KEY: ${{ secrets.GRADLE_KEY }}
GRADLE_PUBLISH_SECRET: ${{ secrets.GRADLE_SECRET }}
run: |
./gradlew -Dgradle.publish.key=$GRADLE_PUBLISH_KEY -Dgradle.publish.secret=$GRADLE_PUBLISH_SECRET publishPlugins
github-release:
name: GitHub Release
needs:
- preparation
- commit
- build
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
name: build-artifacts
- name: Extract build artifacts
run: tar -zxvf build.tar.gz
- name: Release on GitHub
uses: Kir-Antipov/mc-publish@v3.3
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
github-tag: v${{ needs.preparation.outputs.VERSION }}
github-commitish: ${{ github.ref }}
files: output/*.jar
name: v${{ needs.preparation.outputs.VERSION }}
version: ${{ needs.preparation.outputs.VERSION }}
changelog-file: output/changelog.md