-
Notifications
You must be signed in to change notification settings - Fork 0
602 lines (558 loc) · 24.5 KB
/
main.yaml
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
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
name: Main
permissions:
contents: read
packages: write
on:
push:
branches: ["main"]
pull_request:
branches: ["main"]
release:
types: [published]
workflow_dispatch:
env:
CARGO_TERM_COLOR: always
RUST_BACKTRACE: full
RUST_LOG: debug
COLORBT_SHOW_HIDDEN: 1
VCPKG_BINARY_SOURCES: "clear;x-gha,readwrite"
DATABASE_URL: "postgres://postgres:postgres@localhost:5432/postgres"
AWS_ACCESS_KEY_ID: minioadmin
AWS_SECRET_ACCESS_KEY: minioadmin
AWS_REGION: us-east-1
AWS_ENDPOINT_URL: http://localhost:9000
AWS_USE_PATH_STYLE_ENDPOINT: true
MINIO_ROOT_USER: minioadmin
MINIO_ROOT_PASSWORD: minioadmin
POSTGRES_VERSION: 17
jobs:
build-linux:
strategy:
fail-fast: false
matrix:
platform:
- target: x86_64-unknown-linux-gnu
command: cargo
- target: aarch64-unknown-linux-gnu
command: cross
- target: x86_64-unknown-linux-musl
command: cross
- target: aarch64-unknown-linux-musl
command: cross
runs-on: ubuntu-latest
env:
CROSS_CONTAINER_OPTS: "--network=host"
services:
postgres:
image: postgres:17
env:
POSTGRES_PASSWORD: postgres
POSTGRES_HOST_AUTH_METHOD: md5
POSTGRES_INITDB_ARGS: --auth-host=md5
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
--name postgres
ports:
- 5432:5432
s3:
image: bitnami/minio:2024.11.7
env:
MINIO_ROOT_USER: ${{ env.MINIO_ROOT_USER }}
MINIO_ROOT_PASSWORD: ${{ env.MINIO_ROOT_PASSWORD }}
ports:
- 9000:9000
steps:
- uses: actions/checkout@v4
- name: Export GitHub Actions cache environment variables
uses: actions/github-script@v7
with:
script: |
core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || '');
core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || '');
- name: Extract build information
id: build
env:
TARGET: ${{ matrix.platform.target }}
run: |
echo "env=${TARGET##*-}" >> "$GITHUB_OUTPUT"
echo "arch=$(echo $TARGET | cut -d '-' -f1)" >> "$GITHUB_OUTPUT"
echo "docker-arch=${{ startsWith(matrix.platform.target, 'x86_64') && 'amd64' || 'arm64' }}" >> "$GITHUB_OUTPUT"
echo "profile=${{ (github.event_name == 'release' || github.event_name == 'workflow_dispatch') && 'release' || 'dev' }}" >> "$GITHUB_OUTPUT"
echo "output-dir=${{ (github.event_name == 'release' || github.event_name == 'workflow_dispatch') && 'release' || 'debug' }}" >> "$GITHUB_OUTPUT"
- name: Extract rust toolchain
id: toolchain
run: |
echo "channel=$(grep channel rust-toolchain.toml | awk -F' = ' '{printf $2}' | tr -d '\"')" >> "$GITHUB_OUTPUT"
- uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ steps.toolchain.outputs.channel }}
- uses: Swatinem/rust-cache@v2
with:
key: ${{ matrix.platform.target }}-${{ steps.build.outputs.profile }}
save-if: ${{ github.ref == 'refs/heads/main' }}
- name: Increase postgres max connection
run: |
docker exec postgres psql -U postgres -d postgres -c "ALTER SYSTEM SET max_connections = '1000'";
docker exec postgres psql -U postgres -d postgres -c "ALTER SYSTEM SET shared_buffers = '2048MB'";
docker restart postgres
- name: Setup arm64 environment
run: |
sudo apt install --assume-yes gcc-aarch64-linux-gnu g++-aarch64-linux-gnu
sudo ln -s ${{ github.workspace }}/vcpkg/cross-pkg-config /usr/bin/aarch64-linux-gnu-pkg-config
aarch64-linux-gnu-pkg-config --version
if: ${{ matrix.platform.target == 'aarch64-unknown-linux-gnu' }}
- name: Setup musl environment
run: |
wget -c https://github.com/xmake-mirror/musl.cc/releases/download/20210202/${{ steps.build.outputs.arch }}-linux-musl-cross.linux.tgz -O - | tar -xz
sudo ln -s ${{ github.workspace }}/${{ steps.build.outputs.arch }}-linux-musl-cross/bin/${{ steps.build.outputs.arch }}-linux-musl-g++ /usr/bin/${{ steps.build.outputs.arch }}-linux-musl-g++
sudo ln -s ${{ github.workspace }}/${{ steps.build.outputs.arch }}-linux-musl-cross/bin/${{ steps.build.outputs.arch }}-linux-musl-gcc /usr/bin/${{ steps.build.outputs.arch }}-linux-musl-gcc
${{ steps.build.outputs.arch }}-linux-musl-gcc --version
${{ steps.build.outputs.arch }}-linux-musl-g++ --version
sudo ln -s ${{ github.workspace }}/vcpkg/cross-pkg-config /usr/bin/${{ steps.build.outputs.arch }}-linux-musl-pkg-config
${{ steps.build.outputs.arch }}-linux-musl-pkg-config --version
if: ${{ steps.build.outputs.env == 'musl' }}
- name: Install vcpkg build deps
run: sudo apt-get --assume-yes install nasm
- name: Install cargo-vcpkg
uses: taiki-e/cache-cargo-install-action@v2
with:
tool: cargo-vcpkg
- name: Build vcpkg dependencies
run: |
cargo vcpkg --verbose build --manifest-path nghe-backend/Cargo.toml --target ${{ matrix.platform.target }}
- name: Install cross
if: ${{ matrix.platform.command == 'cross' }}
uses: taiki-e/cache-cargo-install-action@v2
with:
tool: cross
git: https://github.com/cross-rs/cross
rev: 19be83481fd3e50ea103d800d72e0f8eddb1c90c
locked: false
- name: Install cargo-nextest
if: ${{ matrix.platform.command == 'cargo' }}
uses: taiki-e/install-action@nextest
- name: Build and test
run: |
${{ matrix.platform.command }} build --locked --target ${{ matrix.platform.target }} --profile ${{ steps.build.outputs.profile }}
if [[ ${{ matrix.platform.command }} == 'cross' ]]; then
cross-util run --target ${{ matrix.platform.target }} -- '/usr/bin/cargo-nextest nextest run --locked --target ${{ matrix.platform.target }} --profile ci --cargo-profile ${{ steps.build.outputs.profile }} --workspace'
else
cargo nextest run --locked --target ${{ matrix.platform.target }} --profile ci --cargo-profile ${{ steps.build.outputs.profile }} --workspace
fi
env:
LASTFM_KEY: ${{ steps.build.outputs.docker-arch == 'amd64' && secrets.LASTFM_KEY || '' }}
SPOTIFY_ID: ${{ steps.build.outputs.docker-arch == 'amd64' && secrets.SPOTIFY_ID || '' }}
SPOTIFY_SECRET: ${{ steps.build.outputs.docker-arch == 'amd64' && secrets.SPOTIFY_SECRET || '' }}
- name: Upload test report to Codecov
if: success() || failure()
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: target/nextest/ci/junit.xml
disable_search: true
report_type: "test_results"
fail_ci_if_error: true
- name: Upload build artifact
uses: actions/upload-artifact@v4
with:
name: ${{ steps.build.outputs.docker-arch }}-${{ steps.build.outputs.env }}
path: ${{ github.workspace }}/target/${{ matrix.platform.target }}/${{ steps.build.outputs.output-dir }}/nghe_backend
retention-days: 1
build-docker:
runs-on: ubuntu-latest
needs: [build-linux]
if: ${{ vars.BUILD_DOCKER != '' }}
env:
DOCKER_BUILD_RECORD_UPLOAD: false
steps:
- uses: actions/checkout@v4
- name: Download build artifact for docker
uses: actions/download-artifact@v4
with:
path: ${{ github.workspace }}/artifact/
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
# GNU
- name: Extract metadata for Docker gnu
id: meta-gnu
uses: docker/metadata-action@v5
with:
images: |
name=ghcr.io/${{ github.repository }}-gnu
tags: |
type=ref,event=pr
type=semver,pattern={{version}}
type=raw,value=develop,enable={{is_default_branch}}
- name: Build and push gnu
uses: docker/build-push-action@v6
with:
context: .
file: ci/docker/Dockerfile
build-args: |
BASE_IMAGE=debian:12.8-slim
TARGET_ENV=gnu
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta-gnu.outputs.tags }}
# Musl
- name: Extract metadata for Docker musl
id: meta-musl
uses: docker/metadata-action@v5
with:
images: |
name=ghcr.io/${{ github.repository }}-musl
tags: |
type=ref,event=pr
type=semver,pattern={{version}}
type=raw,value=develop,enable={{is_default_branch}}
- name: Build and push musl
uses: docker/build-push-action@v6
with:
context: .
file: ci/docker/Dockerfile
build-args: |
BASE_IMAGE=alpine:3.21.0
TARGET_ENV=musl
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta-musl.outputs.tags }}
build-freebsd:
strategy:
fail-fast: false
matrix:
version:
- "14.2"
- "13.4"
runs-on: ubuntu-latest
env:
TARGET: x86_64-unknown-freebsd
services:
postgres:
image: postgres:17
env:
POSTGRES_PASSWORD: postgres
POSTGRES_HOST_AUTH_METHOD: md5
POSTGRES_INITDB_ARGS: --auth-host=md5
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
--name postgres
ports:
- 5432:5432
s3:
image: bitnami/minio:2024.11.7
env:
MINIO_ROOT_USER: ${{ env.MINIO_ROOT_USER }}
MINIO_ROOT_PASSWORD: ${{ env.MINIO_ROOT_PASSWORD }}
ports:
- 9000:9000
steps:
- name: Remove unused packages
run: |
sudo rm -rf /usr/share/dotnet
sudo rm -rf /usr/local/lib/android
sudo rm -rf /opt/ghc
sudo rm -rf /opt/hostedtoolcache
sudo rm -rf /usr/local/share/edge_driver
sudo rm -rf /usr/local/share/gecko_driver
sudo rm -rf /usr/local/share/chromium
sudo rm -rf /usr/local/share/chromedriver-linux64
sudo rm -rf /usr/local/share/vcpkg
sudo rm -rf /usr/local/lib/python*
sudo rm -rf /usr/local/lib/node_modules
sudo rm -rf /usr/local/julia*
sudo rm -rf /usr/share/vim
sudo rm -rf /usr/share/postgresql
sudo rm -rf /usr/share/man
sudo rm -rf /usr/share/apache-maven-*
sudo rm -rf /usr/share/R
sudo rm -rf /usr/share/alsa
sudo rm -rf /usr/share/miniconda
sudo rm -rf /usr/share/grub
sudo rm -rf /usr/share/gradle-*
sudo rm -rf /usr/share/locale
sudo rm -rf /usr/share/texinfo
sudo rm -rf /usr/share/kotlinc
sudo rm -rf /usr/share/swift
sudo rm -rf /usr/share/doc
sudo rm -rf /usr/share/az_9.3.0
sudo rm -rf /usr/share/sbt
sudo rm -rf /usr/share/ri
sudo rm -rf /usr/share/icons
sudo rm -rf /usr/share/java
sudo rm -rf /usr/share/fonts
sudo rm -rf /usr/lib/google-cloud-sdk
sudo rm -rf /usr/lib/jvm
sudo rm -rf /usr/lib/mono
sudo rm -rf /usr/lib/R
sudo rm -rf /usr/lib/postgresql
sudo rm -rf /usr/lib/heroku
sudo rm -rf /usr/lib/gcc
sudo docker image prune --all --force
- uses: actions/checkout@v4
- name: Export GitHub Actions cache environment variables
uses: actions/github-script@v7
with:
script: |
core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || '');
core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || '');
- name: Extract build information
id: build
run: |
echo "env=${TARGET##*-}" >> "$GITHUB_OUTPUT"
echo "target=${TARGET}" >> "$GITHUB_OUTPUT"
echo "profile=${{ (github.event_name == 'release' || github.event_name == 'workflow_dispatch') && 'release' || 'dev' }}" >> "$GITHUB_OUTPUT"
echo "output-dir=${{ (github.event_name == 'release' || github.event_name == 'workflow_dispatch') && 'release' || 'debug' }}" >> "$GITHUB_OUTPUT"
- name: Extract rust toolchain
id: toolchain
run: |
echo "channel=$(grep channel rust-toolchain.toml | awk -F' = ' '{printf $2}' | tr -d '\"')" >> "$GITHUB_OUTPUT"
- uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ steps.toolchain.outputs.channel }}
- uses: Swatinem/rust-cache@v2
with:
key: ${{ steps.build.outputs.target }}-${{ matrix.version }}-${{ steps.build.outputs.profile }}
save-if: ${{ github.ref == 'refs/heads/main' }}
- name: Increase postgres max connection
run: |
docker exec postgres psql -U postgres -d postgres -c "ALTER SYSTEM SET max_connections = '1000'";
docker exec postgres psql -U postgres -d postgres -c "ALTER SYSTEM SET shared_buffers = '2048MB'";
docker restart postgres
- name: Build and test
uses: cross-platform-actions/[email protected]
env:
DATABASE_URL: "postgres://postgres:[email protected]:5432/postgres"
AWS_ENDPOINT_URL: "http://10.0.2.2:9000"
with:
operating_system: freebsd
version: ${{ matrix.version }}
environment_variables: "CARGO_TERM_COLOR RUST_BACKTRACE RUST_LOG COLORBT_SHOW_HIDDEN DATABASE_URL AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_REGION AWS_ENDPOINT_URL AWS_USE_PATH_STYLE_ENDPOINT"
shell: "bash"
cpu_count: 4
image_url: https://github.com/vnghia/nghe-freebsd-builder/releases/download/v0.0.13/freebsd-${{ matrix.version }}-x86-64.qcow2
run: |
sudo chown -R $(id -u):$(id -g) /root/
export PATH="/root/.cargo/bin/:$PATH"
mkdir -p target/vcpkg-archives
mkdir -p ~/.cache/vcpkg/
ln -s target/vcpkg-archives ~/.cache/vcpkg/archives
cargo install cargo-vcpkg
cargo vcpkg --verbose build --manifest-path nghe-backend/Cargo.toml --target ${{ steps.build.outputs.target }}
curl -LsSf https://get.nexte.st/latest/freebsd | tar zxf - -C /root/.cargo/bin/
cargo build --locked --target ${{ steps.build.outputs.target }} --profile ${{ steps.build.outputs.profile }}
cargo nextest run --locked --target ${{ steps.build.outputs.target }} --profile ci --cargo-profile ${{ steps.build.outputs.profile }} --workspace
- name: Upload test report to Codecov
if: success() || failure()
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: target/nextest/ci/junit.xml
disable_search: true
report_type: "test_results"
fail_ci_if_error: true
- name: Upload build artifact
uses: actions/upload-artifact@v4
with:
name: amd64-${{ steps.build.outputs.env }}-${{ matrix.version }}
path: ${{ github.workspace }}/target/${{ steps.build.outputs.target }}/${{ steps.build.outputs.output-dir }}/nghe_backend
retention-days: 1
build-windows:
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
- name: Export GitHub Actions cache environment variables
uses: actions/github-script@v7
with:
script: |
core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || '');
core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || '');
- name: Extract build information
id: build
run: |
echo "profile=${{ (github.event_name == 'release' || github.event_name == 'workflow_dispatch') && 'release' || 'dev' }}" >> $env:GITHUB_OUTPUT
echo "output-dir=${{ (github.event_name == 'release' || github.event_name == 'workflow_dispatch') && 'release' || 'debug' }}" >> $env:GITHUB_OUTPUT
- name: Extract rust toolchain
id: toolchain
shell: bash
run: |
echo "channel=$(grep channel rust-toolchain.toml | awk -F' = ' '{printf $2}' | tr -d '\"')" >> "$GITHUB_OUTPUT"
- uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ steps.toolchain.outputs.channel }}
- uses: Swatinem/rust-cache@v2
with:
key: x86_64-pc-windows-msvc-${{ steps.build.outputs.profile }}
save-if: ${{ github.ref == 'refs/heads/main' }}
- name: Install and setup postgres
run: |
curl https://get.enterprisedb.com/postgresql/postgresql-${{ env.POSTGRES_VERSION }}.2-2-windows-x64-binaries.zip --output postgresql.zip
7z x postgresql.zip
$env:PGDATA = "$PWD\pgsql\data"
$env:PGPASSWORD = "postgres"
echo $env:PGPASSWORD > pwfile
pgsql\bin\initdb --username=postgres --encoding="UTF-8" --locale="en_US.UTF-8" --pwfile=pwfile
pgsql\bin\pg_ctl start
pgsql\bin\psql -U postgres -d postgres -c "ALTER SYSTEM SET max_connections = '1000'"
pgsql\bin\psql -U postgres -d postgres -c "ALTER SYSTEM SET shared_buffers = '2048MB'"
pgsql\bin\pg_ctl restart
echo "$PWD\pgsql\bin" >> $env:GITHUB_PATH
echo "$PWD\pgsql\lib" >> $env:GITHUB_PATH
echo "PQ_LIB_DIR=$PWD\pgsql\lib" >> $env:GITHUB_ENV
- name: Install and setup minio
run: |
curl https://dl.min.io/server/minio/release/windows-amd64/minio.exe --output minio.exe
- name: Install cargo-vcpkg
uses: taiki-e/cache-cargo-install-action@v2
with:
tool: cargo-vcpkg
- name: Build vcpkg dependencies
run: |
cargo vcpkg --verbose build --manifest-path nghe-backend\Cargo.toml --target x86_64-pc-windows-msvc
- name: Install cargo-nextest
uses: taiki-e/install-action@nextest
- name: Build and test
run: |
.\minio.exe server data &
cargo build --locked --target x86_64-pc-windows-msvc --profile ${{ steps.build.outputs.profile }}
cargo nextest run --locked --target x86_64-pc-windows-msvc --profile ci --cargo-profile ${{ steps.build.outputs.profile }} --workspace
env:
LASTFM_KEY: ${{ secrets.LASTFM_KEY }}
SPOTIFY_ID: ${{ secrets.SPOTIFY_ID }}
SPOTIFY_SECRET: ${{ secrets.SPOTIFY_SECRET }}
- name: Upload test report to Codecov
if: success() || failure()
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: target\nextest\ci\junit.xml
disable_search: true
report_type: "test_results"
fail_ci_if_error: true
- name: Upload build artifact
uses: actions/upload-artifact@v4
with:
name: amd64-windows
path: ${{ github.workspace }}\target\x86_64-pc-windows-msvc\${{ steps.build.outputs.output-dir }}\nghe_backend.exe
retention-days: 1
build-macos:
strategy:
fail-fast: false
matrix:
platform:
- target: x86_64-apple-darwin
os: macos-13
vcpkg-target: x64-osx-release
- target: aarch64-apple-darwin
os: macos-14
vcpkg-target: arm64-osx-release
runs-on: ${{ matrix.platform.os }}
env:
HOMEBREW_NO_AUTO_UPDATE: 1
steps:
- uses: actions/checkout@v4
- name: Export GitHub Actions cache environment variables
uses: actions/github-script@v7
with:
script: |
core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || '');
core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || '');
- name: Extract build information
id: build
env:
TARGET: ${{ matrix.platform.target }}
run: |
echo "env=${TARGET##*-}" >> "$GITHUB_OUTPUT"
echo "docker-arch=${{ startsWith(matrix.platform.target, 'x86_64') && 'amd64' || 'arm64' }}" >> "$GITHUB_OUTPUT"
echo "profile=${{ (github.event_name == 'release' || github.event_name == 'workflow_dispatch') && 'release' || 'dev' }}" >> "$GITHUB_OUTPUT"
echo "output-dir=${{ (github.event_name == 'release' || github.event_name == 'workflow_dispatch') && 'release' || 'debug' }}" >> "$GITHUB_OUTPUT"
- name: Extract rust toolchain
id: toolchain
run: |
echo "channel=$(grep channel rust-toolchain.toml | awk -F' = ' '{printf $2}' | tr -d '\"')" >> "$GITHUB_OUTPUT"
- uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ steps.toolchain.outputs.channel }}
- uses: Swatinem/rust-cache@v2
with:
key: ${{ matrix.platform.target }}-${{ steps.build.outputs.profile }}
save-if: ${{ github.ref == 'refs/heads/main' }}
- name: Install and setup postgres
run: |
brew install postgresql@${{ env.POSTGRES_VERSION }}
brew link postgresql@${{ env.POSTGRES_VERSION }}
export PGDATA="$RUNNER_TEMP/pgdata"
initdb --username=postgres --encoding="UTF-8" --locale="en_US.UTF-8" --pwfile=<(echo postgres)
pg_ctl start
psql -U postgres -d postgres -c "ALTER SYSTEM SET max_connections = '1000'"
psql -U postgres -d postgres -c "ALTER SYSTEM SET shared_buffers = '2048MB'"
pg_ctl restart
- name: Install and setup minio
run: |
brew install minio/stable/minio
minio server data &
- name: Install vcpkg build deps
run: brew install nasm
- name: Install cargo-vcpkg
uses: taiki-e/cache-cargo-install-action@v2
with:
tool: cargo-vcpkg
- name: Build vcpkg dependencies
run: |
cargo vcpkg --verbose build --manifest-path nghe-backend/Cargo.toml --target ${{ matrix.platform.target }}
- name: Install cargo-nextest
uses: taiki-e/install-action@nextest
- name: Build and test
run: |
cargo build --locked --target ${{ matrix.platform.target }} --profile ${{ steps.build.outputs.profile }}
cargo nextest run --locked --target ${{ matrix.platform.target }} --profile ci --cargo-profile ${{ steps.build.outputs.profile }} --workspace
env:
LASTFM_KEY: ${{ steps.build.outputs.docker-arch == 'arm64' && secrets.LASTFM_KEY || '' }}
SPOTIFY_ID: ${{ steps.build.outputs.docker-arch == 'arm64' && secrets.SPOTIFY_ID || '' }}
SPOTIFY_SECRET: ${{ steps.build.outputs.docker-arch == 'arm64' && secrets.SPOTIFY_SECRET || '' }}
- name: Upload test report to Codecov
if: success() || failure()
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: target/nextest/ci/junit.xml
disable_search: true
report_type: "test_results"
fail_ci_if_error: true
- name: Upload build artifact
uses: actions/upload-artifact@v4
with:
name: ${{ steps.build.outputs.docker-arch }}-${{ steps.build.outputs.env }}
path: ${{ github.workspace }}/target/${{ matrix.platform.target }}/${{ steps.build.outputs.output-dir }}/nghe_backend
retention-days: 1
upload-release:
runs-on: ubuntu-latest
needs: [build-linux, build-freebsd, build-windows, build-macos]
if: ${{ github.event_name == 'release' }}
permissions:
contents: write
steps:
- uses: actions/checkout@v4
- name: Download build artifact for release
uses: actions/download-artifact@v4
with:
path: ${{ github.workspace }}/artifact/
- name: Upload artifact
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
find artifact/ -mindepth 1 -maxdepth 1 -type d -exec zip -r --move --test {}.zip {} \;
gh release upload ${{ github.ref_name }} artifact/amd64-gnu.zip artifact/arm64-gnu.zip artifact/amd64-musl.zip artifact/arm64-musl.zip artifact/amd64-freebsd-14.0.zip artifact/amd64-freebsd-13.2.zip artifact/amd64-darwin.zip artifact/arm64-darwin.zip artifact/amd64-windows.zip artifact/frontend.zip