-
Notifications
You must be signed in to change notification settings - Fork 46
370 lines (365 loc) · 13.8 KB
/
build-and-deploy.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
360
361
362
363
364
365
366
367
368
369
370
name: CI/CD Process
on:
workflow_call:
workflow_dispatch:
jobs:
compute-build-ref:
runs-on: ubuntu-22.04
outputs:
build-ref: ${{ steps.compute-build-ref.outputs.build-ref }}
steps:
- name: Compute build ref
id: compute-build-ref
run: echo "${{ github.workflow }}-${{ github.event.number || github.ref }}" >> $GITHUB_OUTPUT
select-java-version:
outputs:
java-version: ${{ steps.java-version.outputs.java-version }}
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Compute Java version
id: java-version
run: ruby -e 'puts("java-version=#{/^minJavaVersion\s*=\s*(\d+)$/.match(File.read("gradle.properties"))[1]}")' >> $GITHUB_OUTPUT
# Complete build, including testing, static analysis, and packaging
build:
needs:
- select-java-version
- compute-build-ref
strategy:
fail-fast: false
matrix:
os: [ windows-2022, macos-12, ubuntu-22.04 ]
runs-on: ${{ matrix.os }}
timeout-minutes: 180
concurrency:
group: build-${{ matrix.os }}-${{ needs.compute-build-ref.outputs.build-ref }}
cancel-in-progress: true
steps:
- name: Checkout
uses: danysk/[email protected]
- uses: DanySK/[email protected]
with:
pre-build-command: ./gradlew kotlinUpgradeYarnLock --parallel
# check that all tasks used in subsequent phases are there
build-command: |
COMMAND="./gradlew \
build clean close \
hugoBuild \
performWebsiteStringReplacements \
publishKotlinOSSRHPublicationToGithubRepository \
release \
shadowJar \
uploadKotlinOSSRH uploadKotlinMultiplatform uploadJvm uploadJs \
--dry-run
"
eval $COMMAND || eval $COMMAND
check-command: |
./gradlew check --parallel || ./gradlew check --parallel
clean-command: |
./gradlew clean --parallel || ./gradlew clean --parallel || true
java-version: ${{ needs.select-java-version.outputs.java-version }}
should-run-codecov: ${{ contains('Linux', runner.os) }}
should-deploy: false
should-validate-wrapper: ${{ contains('Linux', runner.os) }}
- name: Generate fatjars and platform-specific packages
run: ./gradlew shadowJar jpackageFull --parallel
- name: Upload fatjars built on Linux
if: ${{ runner.os == 'Linux' }}
uses: actions/[email protected]
with:
name: fat-jars-${{ needs.compute-build-ref.outputs.build-ref }}
path: build/shadow/*
if-no-files-found: error
- name: Upload platform-specific packages
uses: actions/[email protected]
with:
name: installer-package-${{ runner.os }}-${{ needs.compute-build-ref.outputs.build-ref }}
path: build/package/*
if-no-files-found: error
# Performs a dry-deployment on Central if credentials are available
test-deploy:
needs:
- select-java-version
- compute-build-ref
runs-on: ubuntu-22.04
if: >-
!github.event.repository.fork
&& (
github.event_name != 'pull_request'
|| github.event.pull_request.head.repo.full_name == github.repository
)
timeout-minutes: 120
concurrency:
group: test-deploy-${{ needs.compute-build-ref.outputs.build-ref }}
cancel-in-progress: true
steps:
- name: Checkout
uses: danysk/[email protected]
- uses: DanySK/[email protected]
with:
build-command: ./gradlew kotlinUpgradeYarnLock --parallel
check-command: true
deploy-command: |
COMMAND="./gradlew uploadJvm uploadJs uploadKotlinOSSRH uploadKotlinMultiplatform close drop --parallel"
eval "$COMMAND" || eval "$COMMAND" || eval "$COMMAND"
java-version: ${{ needs.select-java-version.outputs.java-version }}
should-run-codecov: false
should-deploy: true
should-validate-wrapper: false
maven-central-password: ${{ secrets.MAVEN_CENTRAL_PASSWORD }}
signing-key: ${{ secrets.SIGNING_KEY }}
signing-password: ${{ secrets.SIGNING_PASSWORD }}
# Test packages correctness
test-packages:
needs:
- compute-build-ref
- select-java-version
- build
strategy:
matrix:
os: [ windows-2022, macos-12, ubuntu-22.04 ]
fail-fast: false
runs-on: ${{ matrix.os }}
concurrency:
group: test-packages-${{ needs.compute-build-ref.outputs.build-ref }}
cancel-in-progress: true
steps:
- name: Checkout
uses: danysk/[email protected]
- name: Setup Java
uses: actions/[email protected]
with:
java-version: ${{ needs.select-java-version.outputs.java-version }}
distribution: 'temurin'
- name: Install bsdtar
if: runner.os == 'Linux'
run: sudo apt update && sudo apt install libarchive-tools
- name: Download packages
uses: actions/[email protected]
with:
name: installer-package-${{ runner.os }}-${{ needs.compute-build-ref.outputs.build-ref }}
path: build/package/
merge-multiple: true
- name: Test package
shell: bash
run: ./gradlew testJpackageOutput --info
# Test PKGBUILD for aur release
test-aur-package:
needs:
- compute-build-ref
- select-java-version
- build
runs-on: ubuntu-22.04
container:
image: archlinux:base-devel-20240101.0.204074
concurrency:
group: test-aur-release-${{ needs.compute-build-ref.outputs.build-ref }}
cancel-in-progress: true
steps:
- name: Setup arch
run: |
sudo pacman --noconfirm -Syu
sudo pacman --noconfirm -Sy git rpm-tools
- run: git config --system --add safe.directory /__w/Alchemist/Alchemist # https://github.com/actions/checkout/issues/1169
- name: Checkout
uses: danysk/[email protected]
- name: Setup Java
uses: actions/[email protected]
with:
java-version: ${{ needs.select-java-version.outputs.java-version }}
distribution: 'temurin'
- name: Download packages
uses: actions/[email protected]
with:
pattern: installer-package-${{ runner.os }}-${{ needs.compute-build-ref.outputs.build-ref }}
path: build/package/
merge-multiple: true
- name: Generate PKGBUILD
run: ./gradlew generatePKGBUILD -DgeneratePKGBUILD.testSource=true
- name: Makepkg Build and Check
uses: edlanglois/pkgbuild-action@v1
with:
pkgdir: build/package
- name: Test installation
working-directory: build/package
run: |
sudo pacman -U --noconfirm alchemist-*.zst
(sudo pacman -Q | grep -q alchemist && echo "Success! Alchemist found in the package list") || exit 1
(/usr/bin/alchemist --help | grep -q options_list && echo "Success! Alchemist available") || exit 2
# Builds the website and verifies link sanity
build-website:
needs:
- select-java-version
- compute-build-ref
runs-on: ubuntu-22.04
timeout-minutes: 30
concurrency:
group: build-website-${{ needs.compute-build-ref.outputs.build-ref }}
cancel-in-progress: true
steps:
- name: Checkout
uses: danysk/[email protected]
- uses: DanySK/[email protected]
with:
build-command: |
for i in 1 2 3 4 5; do
./gradlew hugoBuild --parallel && break || sleep 120
if [ "$i" = 5 ]; then
false
fi
done
check-command: true
java-version: ${{ needs.select-java-version.outputs.java-version }}
should-run-codecov: false
should-deploy: false
should-validate-wrapper: false
- name: Tar files
run: tar -cvf website.tar build/website
- name: Upload website
uses: actions/[email protected]
with:
name: website-${{ needs.compute-build-ref.outputs.build-ref }}
path: website.tar
- uses: DanySK/[email protected]
with:
build-command: |
check-command: |
# Temporarily disable checks on kdoc/javadoc: too many bugs in Dokka.
# See:
# https://github.com/Kotlin/dokka/issues/2320
# https://github.com/Kotlin/dokka/issues/2321
# https://github.com/Kotlin/dokka/issues/2322
# https://github.com/Kotlin/dokka/issues/2323
# Once everything gets fixed, lychee could simply run on '/website/**/*.html'
FILES="$(
find build/website/ -name '*.html' |
grep -v /kdoc/ |
grep -v /javadoc/ |
grep -v /tags/ |
sed -e 's#^build##'
)"
for file in $FILES; do
# Ignore all meta tags containing absolute links
perl -i -pe 's/<meta.*\"http.*\".*>//g' "build/$file"
done
CHECK_LINKS="docker run --rm -v ""$(pwd)/build/website:/website"" -e GITHUB_TOKEN lycheeverse/lychee:0.10.3 $(echo "$FILES") --exclude-file /website/lycheeignore -m 100 --accept 403,429,500,502,503"
for i in 1 2 3 4 5; do
$(echo $CHECK_LINKS) && break || sleep 30
if [ "$i" = 5 ]; then
false
fi
done
java-version: ${{ needs.select-java-version.outputs.java-version }}
should-run-codecov: false
should-deploy: false
should-validate-wrapper: false
# Performs a release if needed
release:
concurrency:
# Only one release job at a time per branch, as only master releases.
# Strictly sequential.
group: release-${{ github.event.number || github.ref }}
needs:
- compute-build-ref
- select-java-version
- build
- build-website
- test-deploy
- test-packages
- test-aur-package
concurrency:
# Only one release job at a time per branch, as only master releases.
# Strictly sequential.
group: release-${{ needs.compute-build-ref.outputs.build-ref }}
runs-on: ubuntu-22.04
if: >-
!github.event.repository.fork
&& (
github.event_name != 'pull_request'
|| github.event.pull_request.head.repo.full_name == github.repository
)
steps:
- name: Checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
submodules: recursive
token: ${{ secrets.DEPLOYMENT_TOKEN }}
- name: Checkout the docs
if: contains(github.repository, 'AlchemistSimulator/Alchemist')
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
path: website-${{ needs.compute-build-ref.outputs.build-ref }}
fetch-depth: 0
persist-credentials: true
repository: AlchemistSimulator/alchemistsimulator.github.io
token: ${{ secrets.DEPLOYMENT_TOKEN }}
- name: Download website artifact
uses: actions/[email protected]
with:
name: website-${{ needs.compute-build-ref.outputs.build-ref }}
- name: Download packages
uses: actions/[email protected]
with:
pattern: installer-package-*-${{ needs.compute-build-ref.outputs.build-ref }}
path: build/package/
merge-multiple: true
- name: Download fatJars
uses: actions/[email protected]
with:
name: fat-jars-${{ needs.compute-build-ref.outputs.build-ref }}
path: build/shadow/
merge-multiple: true
- name: Find the version of Node from package.json
id: node-version
run: echo "version=$(jq -r .engines.node package.json)" >> $GITHUB_OUTPUT
- name: Install Node
uses: actions/[email protected]
with:
node-version: ${{ steps.node-version.outputs.version }}
- uses: DanySK/[email protected]
with:
java-version: ${{ needs.select-java-version.outputs.java-version }}
build-command: |
ls -ahl
echo Copying the new website
tar -xf website.tar
echo Copying git information
mv website/.git build/website/.git
# git -C build/website/ status
echo Removing old website
rm -rf website
echo Adding changes to the stage
git -C build/website/ add .
# git -C build/website/ status
check-command: true
deploy-command: |
npm install
npx semantic-release
should-run-codecov: false
should-deploy: true
should-validate-wrapper: false
github-token: ${{ secrets.DEPLOYMENT_TOKEN }}
maven-central-password: ${{ secrets.MAVEN_CENTRAL_PASSWORD }}
signing-key: ${{ secrets.SIGNING_KEY }}
signing-password: ${{ secrets.SIGNING_PASSWORD }}
custom-secret-0: ${{ secrets.AUR_USERNAME }}
custom-secret-1: ${{ secrets.AUR_EMAIL }}
custom-secret-2: ${{ secrets.AUR_SSH_PRIVATE_KEY }}
success:
runs-on: ubuntu-22.04
needs:
- build
- build-website
- release
- test-deploy
- test-packages
- test-aur-package
if: >-
always() && (
contains(join(needs.*.result, ','), 'failure')
|| !contains(join(needs.*.result, ','), 'cancelled')
)
steps:
- name: Verify that there were no failures
run: ${{ !contains(join(needs.*.result, ','), 'failure') }}