-
-
Notifications
You must be signed in to change notification settings - Fork 0
249 lines (215 loc) · 7.24 KB
/
ci.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
---
name: CI
on:
push:
branches-ignore:
- gh-pages
pull_request:
branches-ignore:
- gh-pages
workflow_dispatch:
schedule:
- cron: "0 4 * * 1,4"
release:
types:
- published
- created
jobs:
lint:
name: Lint
runs-on: ubuntu-22.04
steps:
- name: Check out codebase
uses: actions/checkout@v4
- name: Install rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
components: clippy,rustfmt
- uses: actions-rs/clippy-check@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
args: --all-features --workspace
- uses: mbrobbel/[email protected]
with:
token: ${{ secrets.GITHUB_TOKEN }}
# cant push to main directly
if: github.ref != 'refs/heads/main'
- name: Run pre-commit checks
uses: pre-commit/[email protected]
docs:
name: "Generate rustdoc"
runs-on: ubuntu-22.04
steps:
- name: Check out codebase
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install rust toolchain
uses: dtolnay/rust-toolchain@stable
- name: Enable cargo caching
uses: Swatinem/rust-cache@v2
- name: Install cargo-make
uses: taiki-e/install-action@v2
with:
tool: [email protected]
- name: Build docs
run: cargo make docs
build-test:
name: Build and Test (${{ matrix.target.name }})
runs-on: ubuntu-22.04
strategy:
matrix:
target:
- name: aarch64-unknown-linux-gnu
- name: x86_64-unknown-linux-gnu
steps:
- name: Check out codebase
uses: actions/checkout@v4
- name: Install rust toolchain
uses: dtolnay/rust-toolchain@stable
- name: Enable cargo caching
uses: Swatinem/rust-cache@v2
with:
key: "{{ matrix.target.name }}"
- name: Install build tools
uses: taiki-e/install-action@v2
with:
- name: Build and Test release binary
run: |
cargo make -p release build-${{ matrix.target.name }}
cargo make -p release test-${{ matrix.target.name }}
- name: Upload binary artifact
uses: actions/upload-artifact@v4
if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v')
with:
name: clouddns-nat-helper.${{ matrix.target.name }}
path: target/${{ matrix.target.name }}/release/clouddns-nat-helper
coverage:
name: Create Test Coverage Report
runs-on: ubuntu-22.04
steps:
- name: Check out codebase
uses: actions/checkout@v4
- name: Install rust toolchain
uses: dtolnay/rust-toolchain@stable
- name: Enable cargo caching
uses: Swatinem/rust-cache@v2
- name: Install build tools
uses: taiki-e/install-action@v2
with:
- name: Build coverage
run: cargo make coverage
- name: Upload coverage report
uses: codecov/codecov-action@v4
with:
files: ./lcov.info
token: ${{ secrets.CODECOV_TOKEN }}
docker:
name: "Publish Docker Image"
runs-on: ubuntu-22.04
if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v')
needs:
- build-test
steps:
- name: Check out codebase
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Create target directories
run: |
mkdir -p target/x86_64-unknown-linux-gnu/release target/aarch64-unknown-linux-gnu/release
- name: Get x86_64-unknown-linux-gnu artifact
uses: actions/download-artifact@v4
with:
name: clouddns-nat-helper.x86_64-unknown-linux-gnu
path: target/x86_64-unknown-linux-gnu/release/clouddns-nat-helper
- name: Get aarch64-unknown-linux-gnu artifact
uses: actions/download-artifact@v4
with:
name: clouddns-nat-helper.aarch64-unknown-linux-gnu
path: target/aarch64-unknown-linux-gnu/release/clouddns-nat-helper
- name: Login to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Login to quay.io
uses: docker/login-action@v3
with:
registry: quay.io
username: ${{ secrets.QUAY_USERNAME }}
password: ${{ secrets.QUAY_TOKEN}}
# version is either the major release ('1'), major + minor ('1.2') or full version ('1.2.3-pre.4')
# Note that no tag '0[-arch]' will be generated, as 0.x versions are unstable and should not be relied upon
- name: Generate docker tags
id: tags
uses: docker/metadata-action@v5
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
images: |
ghcr.io/${{ github.repository }}
quay.io/${{ github.repository }}
tags: |
type=semver,pattern={{version}},enable=${{ startsWith(github.ref, 'refs/tags/v')}}
type=semver,pattern={{major}}.{{minor}},enable=${{ startsWith(github.ref, 'refs/tags/v')}}
type=semver,pattern={{major}},enable=${{ startsWith(github.ref, 'refs/tags/v') && !startsWith(github.ref, 'refs/tags/v0.') }}
latest
- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64,linux/arm64
tags: ${{ steps.tags.outputs.tags }}
push: true
file: Dockerfile.multiarch
gh-release-artifacts:
name: Upload ${{ matrix.target }} to GH Release
if: startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-22.04
needs:
- build-test
strategy:
matrix:
target:
- name: aarch64-unknown-linux-gnu
- name: x86_64-unknown-linux-gnu
steps:
- name: Check out codebase
uses: actions/checkout@v4
- name: Get target binary artifact
uses: actions/download-artifact@v4
with:
name: clouddns-nat-helper.${{ matrix.target.name }}
path: /tmp/clouddns-nat-helper
- name: Create release asset archive
run: tar cvzf binary.tar.gz --directory=/tmp clouddns-nat-helper
- name: Upload release artifact
id: upload-release-asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: binary.tar.gz
asset_name: clouddns-nat-helper-${{ matrix.target.name }}.tar.gz
asset_content_type: application/tar+gzip
publish-crates:
name: "Publish to crates.io"
if: startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-22.04
needs:
- build-test
steps:
- name: Check out codebase
uses: actions/checkout@v4
- name: Install rust toolchain
uses: dtolnay/rust-toolchain@stable
- name: Enable cargo caching
uses: Swatinem/rust-cache@v2
- name: Publish crate
run: cargo publish
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}