This repository has been archived by the owner on Jan 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
281 lines (230 loc) · 9.63 KB
/
ci.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
name: CI
on:
push:
branches: [ main ]
tags: [ '*' ]
pull_request:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
target:
- x86_64-unknown-linux-gnu
- aarch64-unknown-linux-gnu
- armv7-unknown-linux-gnueabihf
- aarch64-linux-android
linker: [ static, dynamic ]
steps:
- uses: actions/checkout@v4
- uses: actions/cache@v4
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-${{ matrix.target }}-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-${{ matrix.target }}-
- uses: dtolnay/rust-toolchain@nightly
- name: Install cross
run: cargo install --force cross --git https://github.com/cross-rs/cross
# run: wget -cO - https://github.com/cross-rs/cross/releases/latest/download/cross-x86_64-unknown-linux-gnu.tar.gz | tar -xz
- run: cargo install --force cargo-deb
if: matrix.linker == 'dynamic'
# - run: cargo install --force cargo-generate-rpm
- name: Find Version
if: startsWith(github.ref, 'refs/tags/')
id: meta
uses: docker/metadata-action@v5
with:
images: image
tags: type=semver,pattern={{version}}
- name: Set Cargo.toml version
if: startsWith(github.ref, 'refs/tags/')
run: |
sed -i'' "s/0\\.0\\.0-git/${{ steps.meta.outputs.version }}/" zia-client/Cargo.toml
sed -i'' "s/0\\.0\\.0-git/${{ steps.meta.outputs.version }}/" zia-common/Cargo.toml
sed -i'' "s/0\\.0\\.0-git/${{ steps.meta.outputs.version }}/" zia-server/Cargo.toml
sed -i'' "s/0\\.0\\.0-git/${{ steps.meta.outputs.version }}/" Cargo.lock
- name: Configure for static
run: |
if [[ '${{ matrix.linker }}' == 'static' ]]; then
echo 'RUSTFLAGS=-C target-feature=+crt-static' >> $GITHUB_ENV
echo 'NAME_PREFIX=_static' >> $GITHUB_ENV
fi
- name: Build
run: cross build --release --target ${{ matrix.target }}
- name: Build deb
if: matrix.linker == 'dynamic'
run: |
cargo deb --no-build --no-strip --target ${{ matrix.target }} -p zia-client
cargo deb --no-build --no-strip --target ${{ matrix.target }} -p zia-server
# - name: Build rpm
# run: |
# cargo generate-rpm --target ${{ matrix.target }} -p zia-client
# cargo generate-rpm --target ${{ matrix.target }} -p zia-server
- name: Rename binary
run: |
mv target/${{ matrix.target }}/release/zia-client zia-client_${{ matrix.target }}${{ env.NAME_PREFIX }}
mv target/${{ matrix.target }}/release/zia-server zia-server_${{ matrix.target }}${{ env.NAME_PREFIX }}
- name: Upload Artifact (client)
uses: actions/upload-artifact@v4
with:
name: zia-client_${{ matrix.target }}${{ env.NAME_PREFIX }}
path: zia-client_${{ matrix.target }}${{ env.NAME_PREFIX }}
- name: Upload Artifact (server)
uses: actions/upload-artifact@v4
with:
name: zia-server_${{ matrix.target }}${{ env.NAME_PREFIX }}
path: zia-server_${{ matrix.target }}${{ env.NAME_PREFIX }}
- name: Upload Artifact deb (client)
if: matrix.linker == 'dynamic'
uses: actions/upload-artifact@v4
with:
name: zia-client_${{ matrix.target }}.deb
path: target/${{ matrix.target }}/debian/zia-client_*.deb
- name: Upload Artifact deb (server)
if: matrix.linker == 'dynamic'
uses: actions/upload-artifact@v4
with:
name: zia-server_${{ matrix.target }}.deb
path: target/${{ matrix.target }}/debian/zia-server_*.deb
- uses: alexellis/[email protected]
if: startsWith(github.ref, 'refs/tags/')
env:
GITHUB_TOKEN: ${{ github.token }}
with:
asset_paths: '["zia-client_${{ matrix.target }}${{ env.NAME_PREFIX }}","zia-server_${{ matrix.target }}${{ env.NAME_PREFIX }}","target/${{ matrix.target }}/debian/zia-client_${{ steps.meta.outputs.version }}_*.deb","target/${{ matrix.target }}/debian/zia-server_${{ steps.meta.outputs.version }}_*.deb"]'
build-native:
needs: [ build ]
runs-on: ${{ format('{0}-latest', matrix.os) }}
strategy:
matrix:
os: [ windows, macos ]
steps:
- uses: actions/checkout@v4
- uses: actions/cache@v4
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-
- uses: dtolnay/rust-toolchain@nightly
- name: Find Version
if: startsWith(github.ref, 'refs/tags/')
id: meta
uses: docker/metadata-action@v5
with:
images: image
tags: type=semver,pattern={{version}}
- name: Set Cargo.toml version
if: startsWith(github.ref, 'refs/tags/')
run: |
perl -pi -w -e "s/0\\.0\\.0-git/${{ steps.meta.outputs.version }}/g;" zia-client/Cargo.toml
perl -pi -w -e "s/0\\.0\\.0-git/${{ steps.meta.outputs.version }}/g;" zia-common/Cargo.toml
perl -pi -w -e "s/0\\.0\\.0-git/${{ steps.meta.outputs.version }}/g;" zia-server/Cargo.toml
perl -pi -w -e "s/0\\.0\\.0-git/${{ steps.meta.outputs.version }}/g;" Cargo.lock
- name: Build
run: cargo build --release
- name: Rename binary
if: matrix.os != 'windows'
run: |
mv target/release/zia-client zia-client_${{ matrix.os }}_x86_64
mv target/release/zia-server zia-server_${{ matrix.os }}_x86_64
- name: Rename binary (win)
if: matrix.os == 'windows'
run: |
mv target/release/zia-client.exe zia-client_${{ matrix.os }}_x86_64.exe
mv target/release/zia-server.exe zia-server_${{ matrix.os }}_x86_64.exe
- name: Upload Artifact (client)
uses: actions/upload-artifact@v4
with:
name: zia-client_${{ matrix.os }}_x86_64
path: zia-client_${{ matrix.os }}_x86_64*
- name: Upload Artifact (server)
uses: actions/upload-artifact@v4
with:
name: zia-server_${{ matrix.os }}_x86_64
path: zia-server_${{ matrix.os }}_x86_64*
- uses: alexellis/[email protected]
if: startsWith(github.ref, 'refs/tags/')
env:
GITHUB_TOKEN: ${{ github.token }}
with:
asset_paths: '["zia-client_${{ matrix.os }}_x86_64*","zia-server_${{ matrix.os }}_x86_64*"]'
build-docker:
needs: [ build ]
runs-on: ubuntu-latest
strategy:
matrix:
component: [ client, server ]
permissions:
packages: write
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
- name: Organize binaries
run: |
mkdir -p ctx/linux/amd64 ctx/linux/arm64 ctx/linux/arm/v7
mv zia-${{ matrix.component }}_x86_64-unknown-linux-gnu/zia-${{ matrix.component }}_x86_64-unknown-linux-gnu ctx/linux/amd64/zia-${{ matrix.component }}
mv zia-${{ matrix.component }}_aarch64-unknown-linux-gnu/zia-${{ matrix.component }}_aarch64-unknown-linux-gnu ctx/linux/arm64/zia-${{ matrix.component }}
mv zia-${{ matrix.component }}_armv7-unknown-linux-gnueabihf/zia-${{ matrix.component }}_armv7-unknown-linux-gnueabihf ctx/linux/arm/v7/zia-${{ matrix.component }}
chmod +x ctx/linux/amd64/zia-${{ matrix.component }}
chmod +x ctx/linux/arm64/zia-${{ matrix.component }}
chmod +x ctx/linux/arm/v7/zia-${{ matrix.component }}
tree ctx
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
ghcr.io/${{ github.repository_owner }}/zia-${{ matrix.component }}
tags: |
type=edge
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
- uses: docker/setup-qemu-action@v3
- uses: docker/setup-buildx-action@v3
- name: Cache Docker layers
uses: actions/cache@v4
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-${{ matrix.component }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-${{ matrix.component }}-buildx-
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
if: github.event_name != 'pull_request'
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ github.token }}
- name: Build
uses: docker/build-push-action@v6
with:
file: Dockerfile.gh-actions
context: ctx
platforms: linux/amd64,linux/arm64,linux/arm/v7
build-args: COMPONENT=${{ matrix.component }}
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new
- name: Move cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache