-
Notifications
You must be signed in to change notification settings - Fork 21
387 lines (361 loc) · 13 KB
/
rust.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
#
# References:
# - https://github.com/marketplace/actions/get-the-latest-release-upload-url-tag-date
# - https://github.com/actions/upload-artifact
# - https://github.com/marketplace/actions/yet-another-upload-release-asset-action
# - https://github.com/marketplace/actions/download-a-build-artifact
#
# Its called 'build' so that the README badge displays nicely
name: build
# Update the RUST_VERSION here and in the Makefile when we upgrade
env:
CARGO_TERM_COLOR: always
RUST_VERSION: 1.78.0
on:
push:
branches:
- master
pull_request:
branches:
- master
release:
types: [ created ]
jobs:
get_version:
name: Get unFTP version
runs-on: ubuntu-latest
outputs:
version: ${{ steps.get_latest_tag.outputs.version }}
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0 # Otherwise we get a 'fatal: No names found, cannot describe anything.' error.
- name: Get latest tag
id: get_latest_tag
run: |
tag=$(git describe --tags)
echo "version=$tag" >> $GITHUB_OUTPUT
format:
name: Check Formatting
runs-on: ubuntu-latest
if: ${{ github.ref != 'refs/heads/master' }}
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Install Rust toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: ${{ env.RUST_VERSION }}
override: true
default: true
components: rustfmt
- name: Check formatting
uses: actions-rs/cargo@v1
with:
command: fmt
args: --all -- --check
clippy:
name: Run Clippy
runs-on: ubuntu-latest
if: ${{ github.ref != 'refs/heads/master' }}
steps:
- name: Checkout sources
uses: actions/checkout@v3
with:
persist-credentials: false
- name: Install rust toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: ${{ env.RUST_VERSION }}
override: true
default: true
components: clippy
- uses: actions-rs/cargo@v1
with:
command: clippy
args: --all-features --workspace -- -D warnings
test:
name: Run Tests
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v3
- name: Install rust toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: ${{ env.RUST_VERSION }}
override: true
default: true
components: clippy
- name: Install build dependencies
run: sudo apt-get update && sudo apt-get install -y libpam-dev
- name: Run tests
run: cargo test --verbose --workspace --all --all-features
- name: Build Docs
run: cargo doc --all-features --workspace --no-deps
build-linux-gnu:
runs-on: ubuntu-latest
name: Build for Linux (GNU)
needs: get_version
env:
target: x86_64-unknown-linux-gnu
BUILD_VERSION: ${{ needs.get_version.outputs.version }}
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0 # Otherwise the code that retrieves the git version doesn't work
- name: Install Rust toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: ${{ env.RUST_VERSION }}
override: true
default: true
target: ${{ env.target }}
- name: Install build dependencies
run: sudo apt-get update && sudo apt-get install -y libpam-dev
- name: Build for Linux (GNU)
run: cargo build --no-default-features --features gnu --release --target=${{ env.target }}
- name: Rename
run: mv target/${{ env.target }}/release/unftp target/${{ env.target }}/release/unftp_${{ env.target }}
- name: Upload build artifacts
uses: actions/upload-artifact@v3
with:
name: unftp_${{ env.target }}
path: target/${{ env.target }}/release/unftp_${{ env.target }}
build-linux-musl:
runs-on: ubuntu-latest
name: Build for Linux (MUSL)
needs: get_version
env:
target: x86_64-unknown-linux-musl
BUILD_VERSION: ${{ needs.get_version.outputs.version }}
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0 # Otherwise the code that retrieves the git version doesn't work
- name: Install Rust toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: ${{ env.RUST_VERSION }}
override: true
default: true
target: ${{ env.target }}
- name: Install build dependencies
run: sudo apt-get update && sudo apt-get install -y musl-tools
- name: Build for Linux (MUSL)
run: RUSTFLAGS="-C target-feature=+crt-static" cargo build --no-default-features --features docker --release --target=${{ env.target }}
- name: Rename
run: mv target/${{ env.target }}/release/unftp target/${{ env.target }}/release/unftp_${{ env.target }}
- name: Upload build artifacts
uses: actions/upload-artifact@v3
with:
name: unftp_${{ env.target }}
path: target/${{ env.target }}/release/unftp_${{ env.target }}
build-windows:
runs-on: windows-latest
name: Build for Windows
needs: get_version
env:
trget: x86_64-pc-windows-msvc
BUILD_VERSION: ${{ needs.get_version.outputs.version }}
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0 # Otherwise the code that retrieves the git version doesn't work
- name: Install Rust toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: ${{ env.RUST_VERSION }}
override: true
default: true
target: ${{ env.trget }}
- name: Build for Windows
run: cargo build --release --target=${{ env.trget }} --features rest_auth,jsonfile_auth
- name: Rename
run: ren "target\${{ env.trget }}\release\unftp.exe" "unftp_${{ env.trget }}.exe"
- name: Upload build artifacts
uses: actions/upload-artifact@v3
with:
name: unftp_${{ env.trget }}.exe
path: target/${{ env.trget }}/release/unftp_${{ env.trget }}.exe
build-macos-intel:
runs-on: macos-latest
name: Build for macOS (Intel)
needs: get_version
env:
target: x86_64-apple-darwin
BUILD_VERSION: ${{ needs.get_version.outputs.version }}
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0 # Otherwise the code that retrieves the git version doesn't work
- name: Install Rust toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: ${{ env.RUST_VERSION }}
override: true
default: true
target: ${{ env.target }}
- name: Build for macOS (Intel)
run: cargo build --release --target=${{ env.target }} --features rest_auth,jsonfile_auth,cloud_storage
- name: Rename
run: mv target/${{ env.target }}/release/unftp target/${{ env.target }}/release/unftp_${{ env.target }}
- name: Upload build artifacts
uses: actions/upload-artifact@v3
with:
name: unftp_${{ env.target }}
path: target/${{ env.target }}/release/unftp_${{ env.target }}
build-macos-arm:
runs-on: macos-latest
name: Build for macOS (ARM)
needs: get_version
env:
target: aarch64-apple-darwin
BUILD_VERSION: ${{ needs.get_version.outputs.version }}
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0 # Otherwise the code that retrieves the git version doesn't work
- name: Install Rust toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: ${{ env.RUST_VERSION }}
override: true
default: true
target: ${{ env.target }}
- name: Install Rosetta
if: runner.os == 'macOS' && runner.arch == 'arm64'
run: softwareupdate --install-rosetta --agree-to-license
- name: Build
run: cargo build --release --target=${{ env.target }} --features rest_auth,jsonfile_auth,cloud_storage
- name: Rename
run: mv target/${{ env.target }}/release/unftp target/${{ env.target }}/release/unftp_${{ env.target }}
- name: Upload build artifacts
uses: actions/upload-artifact@v3
with:
name: unftp_${{ env.target }}
path: target/${{ env.target }}/release/unftp_${{ env.target }}
upload-release-binaries:
if: ${{ github.event_name == 'release' }} # Testing: if: ${{ github.ref == 'refs/heads/hannes/upload' }}
runs-on: ubuntu-latest
strategy:
matrix:
build:
- x86_64-unknown-linux-gnu
- x86_64-unknown-linux-musl
- x86_64-apple-darwin
- aarch64-apple-darwin
- x86_64-pc-windows-msvc
env:
file_name: unftp_${{ matrix.build }}${{ contains(matrix.build, 'windows') && '.exe' || '' }}
file_dir: ./${{ matrix.build }}
needs:
- build-linux-gnu
- build-linux-musl
- build-macos-intel
- build-macos-arm
- build-windows
name: Upload Release Artifacts
steps:
# For testing:
# - name: Gets latest created release info
# id: latest_release_info
# uses: jossef/action-latest-release-info@v1.2.1
# env:
# GITHUB_TOKEN: ${{ github.token }}
- name: Download
uses: actions/download-artifact@v2
with:
name: ${{ env.file_name }}
path: ${{ env.file_dir }}
- name: Calculate MD5 checksum
id: calculate_checksum
run: md5sum ${{ env.file_dir }}/${{ env.file_name }} > ${{ env.file_dir }}/${{ env.file_name }}.md5
- name: Upload
uses: shogo82148/actions-upload-release-asset@v1
with:
upload_url: ${{ github.event.release.upload_url }} # Testing: ${{ steps.latest_release_info.outputs.upload_url }}
asset_path: ${{ env.file_dir }}/${{ env.file_name }}
asset_name: ${{ env.file_name }}
asset_content_type: application/octet-stream
- name: Upload MD5
uses: shogo82148/actions-upload-release-asset@v1
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: ${{ env.file_dir }}/${{ env.file_name }}.md5
asset_name: ${{ env.file_name }}.md5
asset_content_type: text/plain
build-docker-images:
if: ${{ github.event_name == 'release' }} # Testing if: ${{ github.ref == 'refs/heads/hannes/docker-actions' }}
runs-on: ubuntu-latest
needs:
- build-linux-musl
- get_version
env:
BUILD_VERSION: ${{ needs.get_version.outputs.version }}
name: Build docker images
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Download linux musl
uses: actions/download-artifact@v2
with:
name: unftp_x86_64-unknown-linux-musl
path: ./x86_64-unknown-linux-musl
- name: Change file permission
run: chmod +x ./x86_64-unknown-linux-musl/unftp_x86_64-unknown-linux-musl
- name: Build Docker image
run: docker build -t bolcom/unftp:${{ env.BUILD_VERSION }}-scratch -f packaging/docker/scratch.Dockerfile.ci .
- name: Save Docker image as tar
run: docker save -o docker-image-scratch.tar bolcom/unftp:${{ env.BUILD_VERSION }}-scratch
- name: Upload scratch tar image
uses: actions/upload-artifact@v2
with:
name: docker-image-scratch
path: docker-image-scratch.tar
- name: Login to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and push scratch image
uses: docker/build-push-action@v2
with:
context: .
file: ./packaging/docker/scratch.Dockerfile.ci
push: true
tags: bolcom/unftp:${{ env.BUILD_VERSION }}-scratch
- name: Build and push alpine image
uses: docker/build-push-action@v2
with:
context: .
file: ./packaging/docker/alpine.Dockerfile.ci
push: true
tags: bolcom/unftp:${{ env.BUILD_VERSION }}-alpine
- name: Build and push alpine-istio image
uses: docker/build-push-action@v2
with:
context: .
file: ./packaging/docker/alpine-istio.Dockerfile.ci
push: true
tags: bolcom/unftp:${{ env.BUILD_VERSION }}-alpine-istio
- name: Build and push alpine-debug image
uses: docker/build-push-action@v2
with:
context: .
file: ./packaging/docker/alpine-debug.Dockerfile.ci
push: true
tags: bolcom/unftp:${{ env.BUILD_VERSION }}-alpine-debug
- name: Build and push Scratch image
uses: docker/build-push-action@v2
with:
context: .
file: ./packaging/docker/alpine-istio-debug.Dockerfile.ci
push: true
tags: bolcom/unftp:${{ env.BUILD_VERSION }}-alpine-istio-debug