-
Notifications
You must be signed in to change notification settings - Fork 0
399 lines (363 loc) · 15.3 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
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
VCPKG_BINARY_SOURCES: "clear;x-gha,readwrite"
RUST_TOOLCHAIN: nightly-2024-03-22
DATABASE_URL: "postgres://postgres:postgres@localhost:5432/postgres"
jobs:
build-frontend:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ env.RUST_TOOLCHAIN }}
- uses: actions/setup-node@v4
with:
node-version: 20
cache: "npm"
cache-dependency-path: ${{ github.workspace }}/frontend/package-lock.json
- name: Build tailwindcss
working-directory: ${{ github.workspace }}/frontend
run: |
npm ci
npm run build
- name: Install dioxus-cli
uses: taiki-e/cache-cargo-install-action@v1
with:
tool: dioxus-cli
- name: Build frontend
run: |
dx build --verbose --profile ${{ (github.event_name == 'release' || github.event_name == 'workflow_dispatch') && 'release' || 'dev' }}
- name: Upload build artifact
uses: actions/upload-artifact@v4
with:
name: frontend
path: ${{ github.workspace }}/frontend/dist/
retention-days: 1
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:16
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
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 || '');
- uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ env.RUST_TOOLCHAIN }}
- name: Extract build information
id: build
env:
TARGET: ${{ matrix.platform.target }}
run: |
echo "env=${TARGET##*-}" >> "$GITHUB_OUTPUT"
echo "arch=$(echo $TARGET | awk '{print $1}')" >> "$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"
- uses: Swatinem/rust-cache@v2
with:
key: ${{ matrix.platform.target }}-${{ steps.build.outputs.profile }}
- name: Increase postgres max connection
run: |
docker exec -i postgres bash << EOF
sed -i -e 's/max_connections = 100/max_connections = 1000/' /var/lib/postgresql/data/postgresql.conf
sed -i -e 's/shared_buffers = 128MB/shared_buffers = 2GB/' /var/lib/postgresql/data/postgresql.conf
EOF
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 x64 musl environment
run: |
sudo apt install --assume-yes musl-tools
sudo ln -s ${{ github.workspace }}/vcpkg/cross-pkg-config /usr/bin/x86_64-linux-musl-pkg-config
x86_64-linux-musl-pkg-config --version
if: ${{ matrix.platform.target == 'x86_64-unknown-linux-musl' }}
# TODO: Rename binary after https://github.com/microsoft/vcpkg/issues/36094 is fixed
- name: Setup arm64 musl environment
run: |
wget -c https://github.com/xmake-mirror/musl.cc/releases/download/20210202/aarch64-linux-musl-cross.linux.tgz -O - | tar -xz
sudo ln -s ${{ github.workspace }}/aarch64-linux-musl-cross/bin/aarch64-linux-musl-g++ /usr/bin/aarch64-linux-gnu-g++
sudo ln -s ${{ github.workspace }}/aarch64-linux-musl-cross/bin/aarch64-linux-musl-gcc /usr/bin/aarch64-linux-gnu-gcc
aarch64-linux-gnu-gcc --version
aarch64-linux-gnu-g++ --version
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-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@v1
with:
tool: cargo-vcpkg
- name: Build vcpkg dependencies
run: |
cargo vcpkg --verbose build --target ${{ matrix.platform.target }}
- name: Install cross
if: ${{ matrix.platform.command == 'cross' }}
uses: taiki-e/cache-cargo-install-action@v1
with:
tool: cross
git: https://github.com/cross-rs/cross
rev: 085092c
- name: Build and test
run: |
${{ matrix.platform.command }} build --locked --target ${{ matrix.platform.target }} --profile ${{ steps.build.outputs.profile }}
${{ matrix.platform.command }} test --locked --target ${{ matrix.platform.target }} --profile ${{ steps.build.outputs.profile }} -p nghe -p nghe-types
- 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
retention-days: 1
build-docker:
runs-on: ubuntu-latest
needs: [build-frontend, build-linux]
if: ${{ vars.BUILD_DOCKER != '' }}
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@v5
with:
context: .
file: ci/docker/Dockerfile
build-args: |
BASE_IMAGE=debian:12.5-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@v5
with:
context: .
file: ci/docker/Dockerfile
build-args: |
BASE_IMAGE=alpine:3.19.1
TARGET_ENV=musl
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta-musl.outputs.tags }}
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 || '');
- uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ env.RUST_TOOLCHAIN }}
- 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
- uses: Swatinem/rust-cache@v2
with:
key: x86_64-pc-windows-msvc-${{ steps.build.outputs.profile }}
- name: Install and setup postgres
run: |
curl https://get.enterprisedb.com/postgresql/postgresql-16.2-1-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 = '2GB'"
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 cargo-vcpkg
uses: taiki-e/cache-cargo-install-action@v1
with:
tool: cargo-vcpkg
- name: Build vcpkg dependencies
run: |
cargo vcpkg --verbose build --target x86_64-pc-windows-msvc
- name: Build and test
run: |
cargo build --locked --target x86_64-pc-windows-msvc --profile ${{ steps.build.outputs.profile }}
cargo test --locked --target x86_64-pc-windows-msvc --profile ${{ steps.build.outputs.profile }} -p nghe -p nghe-types
- 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.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
HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK: 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 || '');
- uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ env.RUST_TOOLCHAIN }}
- 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"
- uses: Swatinem/rust-cache@v2
with:
key: ${{ matrix.platform.target }}-${{ steps.build.outputs.profile }}
- name: Install and setup postgres
run: |
brew uninstall --force postgresql
brew uninstall --force postgresql@14
brew install postgresql@16
brew link postgresql@16
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 = '2GB'"
pg_ctl restart
- name: Install vcpkg build deps
run: brew install nasm
- name: Install cargo-vcpkg
uses: taiki-e/cache-cargo-install-action@v1
with:
tool: cargo-vcpkg
- name: Build vcpkg dependencies
run: |
cargo vcpkg --verbose build --target ${{ matrix.platform.target }}
- name: Build and test
run: |
cargo build --locked --target ${{ matrix.platform.target }} --profile ${{ steps.build.outputs.profile }}
cargo test --locked --target ${{ matrix.platform.target }} --profile ${{ steps.build.outputs.profile }} -p nghe -p nghe-types
- 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
retention-days: 1
upload-release:
runs-on: ubuntu-latest
needs: [build-frontend, build-linux, 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-darwin.zip artifact/arm64-darwin.zip artifact/amd64-windows.zip artifact/frontend.zip