-
Notifications
You must be signed in to change notification settings - Fork 14
530 lines (457 loc) · 17.6 KB
/
nightlies.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
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
name: Nightlies
on:
push:
branches:
- master
- actions
pull_request:
branches:
- '*'
schedule:
- cron: '0 0 * * *'
jobs:
setup:
name: 'build settings'
runs-on: ubuntu-latest
outputs:
settings: ${{ steps.settings.outputs.settings }}
deploy: ${{ steps.settings.outputs.deploy }}
env:
# Bump this value when a rebuild of nightlies (of the
# same compiler commits) has to be done.
nightlies_revision: 4
steps:
- name: Checkout nightlies
uses: actions/checkout@v4
with:
path: nightlies
- name: Generate version matrix
shell: bash
run: |
# Tracked branches
branches=( 'devel' 'version-2-0' 'version-1-6')
getHash() {
git ls-remote "https://github.com/$1" "$2" | cut -f 1
}
{
for branch in "${branches[@]}"; do
jq --null-input \
--arg branch "$branch" \
--arg commit "$(getHash nim-lang/Nim "$branch")" \
'{ branch: $branch, commit: $commit }'
done
} | jq -s '.' | tee versions.json
- name: Restore build settings
uses: actions/cache@v4
with:
path: settings
key: build-settings-${{ hashFiles('versions.json') }}-${{ env.nightlies_revision }}
restore-keys: build-settings-
- name: Generate build settings
id: settings
shell: bash
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
deploy=false
case '${{ github.event_name }}' in
schedule)
deploy=true
;;
push)
message=$(
cd nightlies
git show -s --format=%s '${{ github.ref }}'
)
if [[ $message == *'[deploy]'* ]]; then
deploy=true
else
deploy=false
fi
esac
declare -A refs
while IFS='=' read -r branch commit; do
refs[$branch]=$commit
done <<< "$(jq -r '.[] | .branch + "=" + .commit' versions.json)"
mkdir -p settings
# Delete older branch settings (if they were restored)
find settings -mindepth 1 -maxdepth 1 $(printf "! -name %q.json " "${!refs[@]}")
declare -A environment=(
[SOURCE_CODE_EPOCH]=$(date -u +%s)
)
for branch in "${!refs[@]}"; do
savedCommit=
savedNightliesRev=
savedBuildRevision=
commit=${refs[$branch]}
buildRevision=0
if [[ -e "settings/$branch.json" ]]; then
savedSettings=$(< "settings/$branch.json")
savedCommit=$(jq -r '.commit' <<< "$savedSettings")
savedNightliesRev=$(jq '.nightlies_revision // 0' <<< "$savedSettings")
savedBuildRevision=$(jq '.build_revision // -1' <<< "$savedSettings")
if [[ $savedNightliesRev -ne $nightlies_revision ]]; then
buildRevision=$(($savedBuildRevision + 1))
fi
fi
if [[ $savedCommit != "$commit" || $savedNightliesRev -ne $nightlies_revision ]]; then
echo "::group::Generating build settings for branch $branch"
{
{
for var in "${!environment[@]}"; do
jq --null-input \
--arg variable "$var" \
--arg value "${environment[$var]}" \
'{ ($variable): $value }'
done
} | jq -s '{ environment: (reduce .[] as $item (null; . + $item)) }'
tag=$(date -u --date="@${environment[SOURCE_CODE_EPOCH]}" +%F)-$branch-$commit
# Don't add revision to tags for now.
# if [[ $buildRevision -gt 0 ]]; then
# tag=$tag-$buildRevision
# fi
jq --null-input --arg tag "$tag" '{ release: $tag }'
jq --null-input --argjson nightlies_revision "$nightlies_revision" '{ nightlies_revision: $nightlies_revision }'
jq --null-input --argjson build_revision "$buildRevision" '{ build_revision: $build_revision }'
if [[ "$tag" == version-2-0 ]]; then
jq --null-input --argjson csources "nim-lang/csources_v2" '{ csources: $csources }'
fi
if [[ "$tag" == devel ]]; then
jq --null-input --argjson csources "nim-lang/csources_v2" '{ csources: $csources }'
fi
} | jq -s --arg commit "$commit" 'reduce .[] as $item ({ commit: $commit }; . + $item)' > "settings/$branch.json"
else
echo "::group::Stored settings for branch $branch @ $commit found."
fi
jq --arg branch "$branch" '.[] | select(.branch == $branch)' versions.json | jq -s 'add' - "settings/$branch.json" | tee -a settings.json
echo "::endgroup::"
done
echo "settings=$(jq -sc '.' settings.json)" >> $GITHUB_OUTPUT
echo "deploy=$deploy" >> $GITHUB_OUTPUT
sourceArchive:
needs: setup
strategy:
fail-fast: false
matrix:
setting: ${{ fromJson(needs.setup.outputs.settings) }}
name: 'source (${{ matrix.setting.branch }}, ${{ matrix.setting.commit }})'
runs-on: ubuntu-latest
env: ${{ matrix.setting.environment }}
steps:
- name: Checkout nightlies
uses: actions/checkout@v4
with:
path: nightlies
- name: 'Install dependencies'
run: |
sudo apt-get update
sudo apt-get install -y hub
- name: Restore Nim from cache
id: nim-cache
uses: actions/cache@v4
with:
path: nim/output/nim-*.tar.xz
key: 'source-${{ matrix.setting.commit }}-${{ matrix.setting.build_revision }}'
- name: Checkout Nim
if: steps.nim-cache.outputs.cache-hit != 'true'
uses: actions/checkout@v4
with:
repository: nim-lang/Nim
ref: ${{ matrix.setting.commit }}
path: nim
- name: Get csources version
if: steps.nim-cache.outputs.cache-hit != 'true'
id: csources-version
shell: bash
run: |
csources_repo=${{ matrix.setting.csources }}
# if one is not set, use csources_v1
: "${csources_repo:=nim-lang/csources_v1}"
csources_commit=$(git ls-remote "https://github.com/$csources_repo" master | cut -f 1)
if [[ -f nim/config/build_config.txt ]]; then
. nim/config/build_config.txt
csources_repo=${nim_csourcesUrl#https://github.com/}
csources_repo=${csources_repo%.git}
csources_commit=$nim_csourcesHash
fi
echo "repo=$csources_repo" >> $GITHUB_OUTPUT
echo "commit=$csources_commit" >> $GITHUB_OUTPUT
- name: Restore csources from cache
if: steps.nim-cache.outputs.cache-hit != 'true'
id: csources-cache
uses: actions/cache@v4
with:
path: csources/bin
key: >
csources-${{ runner.os }}-${{ steps.csources-version.outputs.repo }}-${{ steps.csources-version.outputs.commit }}
- name: Checkout csources
if: >
steps.nim-cache.outputs.cache-hit != 'true' &&
steps.csources-cache.outputs.cache-hit != 'true'
uses: actions/checkout@v4
with:
repository: ${{ steps.csources-version.outputs.repo }}
ref: ${{ steps.csources-version.outputs.commit }}
path: csources
- name: Setup environment
shell: bash
run: echo '${{ github.workspace }}/nim/bin' >> "$GITHUB_PATH"
- name: Build 1-stage csources compiler
if: steps.nim-cache.outputs.cache-hit != 'true'
shell: bash
run: |
if [[ ! -e csources/bin/nim ]]; then
make -C csources -j $(nproc) CC=gcc
else
echo 'Using prebuilt csources'
fi
cp csources/bin/nim nim/bin
- name: Build compiler
if: steps.nim-cache.outputs.cache-hit != 'true'
shell: bash
run: |
cd nim
nim c koch
./koch boot -d:release
- name: Generate csources
if: steps.nim-cache.outputs.cache-hit != 'true'
shell: bash
run: |
cd nim
./koch csources -d:danger '-d:gitHash:${{ matrix.setting.commit }}'
- name: Bundle external sources
if: steps.nim-cache.outputs.cache-hit != 'true'
shell: bash
run: |
cd nim
version=$(nim secret --hints:off <<< 'echo NimVersion; quit 0')
major=${version%%.*}
minor=${version#*.}
minor=${minor%.*}
patch=${version##*.}
./koch nimble
# Only Nim >= 1.4.0 bundles fusion.
if [[ $major -ge 1 && $minor -ge 4 ]]; then
./koch fusion
fi
- name: Build source archive
if: steps.nim-cache.outputs.cache-hit != 'true'
shell: bash
run: |
cd nim
./koch xz
mkdir -p output
source=$(basename build/nim-*.tar.xz)
version=${source%.tar.xz}
version=${version#nim-}
cp build/$source output/nim-$version.tar.xz
- name: Publish release
if: needs.setup.outputs.deploy == 'true'
shell: bash
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
if ! hub -C nightlies release show '${{ matrix.setting.release }}' >/dev/null 2>&1; then
cat << EOF | hub -C nightlies release create -a nim/output/* -F - '${{ matrix.setting.release }}' >/dev/null
Nightly build on $(date -u --date="@$SOURCE_CODE_EPOCH" "+%F") for branch ${{ matrix.setting.branch }}
Commit: https://github.com/nim-lang/Nim/commit/${{ matrix.setting.commit }}
Generated release binaries will be uploaded as they're made available.
EOF
else
echo "Release '${{ matrix.setting.release }}' has already been created, skipping."
fi
- name: Upload source archive to artifacts
uses: actions/upload-artifact@v3
with:
name: 'nim-${{ matrix.setting.commit }}'
path: nim/output/*
build:
needs: [ setup, sourceArchive ]
strategy:
fail-fast: false
matrix:
setting: ${{ fromJson(needs.setup.outputs.settings) }}
target:
- os: linux
triple: x86_64-linux-musl
- os: linux
triple: i686-linux-musl
- os: linux
triple: aarch64-linux-musl
- os: linux
triple: armv7l-linux-musleabihf
- os: macosx
triple: x86_64-apple-darwin14
- os: windows
triple: x86_64-w64-mingw32
- os: windows
triple: i686-w64-mingw32
include:
- target:
os: linux
builder: ubuntu-20.04
- target:
os: macosx
builder: macos-11
- target:
os: windows
builder: windows-2019
env: ${{ matrix.setting.environment }}
name: '${{ matrix.target.triple }} (${{ matrix.setting.branch }}, ${{ matrix.setting.commit }})'
runs-on: ${{ matrix.builder }}
steps:
- name: Checkout build scripts
uses: actions/checkout@v4
with:
path: nightlies
- name: Cache build outputs
id: built
uses: actions/cache@v4
with:
path: output
key: >
output-${{ hashFiles('nightlies/lib.sh') }}-${{ hashFiles('nightlies/build-release.sh') }}-${{ matrix.target.triple }}-${{ matrix.setting.commit }}-${{ matrix.setting.build_revision }}
- name: Cache dependencies
if: steps.built.outputs.cache-hit != 'true'
uses: actions/cache@v4
with:
path: external
key: >
deps-${{ hashFiles('nightlies/lib.sh') }}-${{ hashFiles('nightlies/deps.sh') }}-${{ hashFiles('nightlies/buildreq.txt') }}-${{ runner.os }}-${{ matrix.target.triple }}-${{ matrix.setting.build_revision }}
- name: Install dependencies
if: steps.built.outputs.cache-hit != 'true'
shell: bash
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: nightlies/deps.sh -t '${{ matrix.target.triple }}'
- name: Download generated source package
if: steps.built.outputs.cache-hit != 'true'
uses: actions/download-artifact@v3
with:
name: 'nim-${{ matrix.setting.commit }}'
path: source
- name: Extract source package
if: steps.built.outputs.cache-hit != 'true'
id: source
shell: bash
run: |
source=( source/nim-*.tar.xz )
version=${source[0]##*nim-}
version=${version%%.tar.xz}
case '${{ runner.os }}' in
'Windows')
7z x -so "${source[0]}" | 7z x -si -ttar -aoa
;;
*)
tar xJf "${source[0]}"
;;
esac
echo "version=$version" >> $GITHUB_OUTPUT
- name: Setup environment
if: steps.built.outputs.cache-hit != 'true'
shell: bash
run: |
echo "-d:gitHash:\"${{ matrix.setting.commit }}\"" >> external/nim.cfg
- name: Build release binaries
if: steps.built.outputs.cache-hit != 'true'
shell: bash
run: |
nightlies/build-release.sh 'nim-${{ steps.source.outputs.version }}'
- name: Prepare binaries for uploads
id: release
shell: bash
run: |
source nightlies/lib.sh
artifact=$(< output/nim.txt)
echo "artifact=$artifact" >> $GITHUB_OUTPUT
# Github Actions work based on native Windows path, so we're doing
# some quick conversions here.
echo "artifact_nativepath=$(nativepath "$artifact")" >> $GITHUB_OUTPUT
- name: Upload release binaries
if: needs.setup.outputs.deploy == 'true'
shell: bash
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
cd nightlies
if ! gh release view '${{ matrix.setting.release }}' | grep "$(basename '${{ steps.release.outputs.artifact }}')" >/dev/null 2>&1; then
gh release upload '${{ matrix.setting.release }}' '${{ steps.release.outputs.artifact }}'
else
echo "Binary already released for tag '${{ matrix.setting.release }}', not overwritting."
fi
- name: Upload binaries to artifacts
uses: actions/upload-artifact@v3
with:
name: 'binaries-${{ matrix.setting.branch }}-${{ matrix.setting.commit }}'
path: '${{ steps.release.outputs.artifact_nativepath }}'
latestTag:
needs: [ setup, build ]
strategy:
fail-fast: false
matrix:
setting: ${{ fromJson(needs.setup.outputs.settings) }}
if: needs.setup.outputs.deploy == 'true'
name: 'Update latest tags for ${{ matrix.setting.release }}'
runs-on: ubuntu-latest
steps:
- name: Store build settings
shell: bash
run: |
cat <<< '${{ toJson(matrix.setting) }}' > setting.json
- name: Check whether deployment was done for this setting set
id: deploy-cache
uses: actions/cache@v4
with:
path: setting.json
key: deploy-${{ hashFiles('setting.json') }}-${{ env.nightlies_revision }}
- name: Checkout nightlies
if: steps.deploy-cache.outputs.cache-hit != 'true'
uses: actions/checkout@v4
with:
path: nightlies
- name: Download generated source package
if: steps.deploy-cache.outputs.cache-hit != 'true'
uses: actions/download-artifact@v3
with:
name: 'nim-${{ matrix.setting.commit }}'
path: source
- name: Download built binaries from artifacts
if: steps.deploy-cache.outputs.cache-hit != 'true'
uses: actions/download-artifact@v3
with:
name: 'binaries-${{ matrix.setting.branch }}-${{ matrix.setting.commit }}'
path: binaries
- name: 'Push latest-${{ matrix.setting.branch }} tag'
if: steps.deploy-cache.outputs.cache-hit != 'true'
shell: bash
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
tag='latest-${{ matrix.setting.branch }}'
mkdir -p assets
source=("$GITHUB_WORKSPACE"/source/*)
# Rename the source archive as source.tar.xz
mv -v "${source[0]}" "assets/source.tar.xz"
for artifact in binaries/*; do
# Trim version from artifact name
shortName=${artifact#*nim-*-}
mv -v "$artifact" "assets/$shortName"
done
cat << EOF > release-notes.md
This release is an alias for the latest successful nightly build \
for branch \`${{ matrix.setting.branch }}\`: https://github.com/${{ github.repository }}/releases/tag/${{ matrix.setting.release }}
Each \`latest-\` alias is guaranteed to contain binaries for all \
supported architectures.
EOF
cd nightlies
# By deleting and recreating the tag, Github recognize it as the true
# "latest" tags.
echo "Deleting release $tag (errors are ignored)"
gh release delete -y "$tag" || :
git push --delete origin "$tag" || :
echo "Publishing $tag"
gh release create \
-t 'Latest successful build for branch ${{ matrix.setting.branch }}' \
-F "$GITHUB_WORKSPACE/release-notes.md" \
"$tag" \
"$GITHUB_WORKSPACE/assets"/*