-
Notifications
You must be signed in to change notification settings - Fork 0
229 lines (200 loc) · 7.94 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
name: CI
on:
workflow_dispatch:
pull_request:
push:
branches: ["master"]
# Ensure this workflow gets cancelled if a newer commit has been pushed on the same branch
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
env:
CARGO_TERM_COLOR: always
RUSTFLAGS: -D warnings
RUSTDOCFLAGS: -D warnings
RUST_BACKTRACE: 1
RUST_LOG: debug
jobs:
check:
strategy:
fail-fast: false
matrix:
include:
- TARGET: x86_64-unknown-linux-gnu
# If you add features to your crate, chances are you want to test for all features for native binaries,
# so that all features are checked and can be build by someone cloning your repository.
# If you build natively it will be a binary, the default binary will have the entrypoint "src/main.rs".
flags: "--all-features --bins"
- TARGET: wasm32-unknown-unknown
# With the current trunk setup, if you add features, the webpage will have the default features.
# You could test for all features too, however that might require a lot of conditional compilation annotations.
# Thus we only test for the default features by default.
# Since we build with trunk the entrypoint will also be the "src/main.rs" file.
flags: "--bin ${{ github.event.repository.name }}"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
targets: ${{matrix.TARGET}}
- uses: Swatinem/rust-cache@v2
- run: cargo check ${{matrix.flags}} --target ${{matrix.TARGET}}
audit:
runs-on: ubuntu-latest
env:
RUST_LOG: '' # Otherwise audit-check errors on attempting to parse the logging output
steps:
- uses: actions/checkout@v4
- name: Install cargo-binstall
uses: cargo-bins/[email protected]
- name: Install Cargo audit
run: cargo binstall cargo-audit
- name: Run Audit
run: cargo audit
test:
name: Test Suite
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: taiki-e/install-action@nextest
- uses: Swatinem/rust-cache@v2
- run: cargo nextest run --workspace --profile ci --run-ignored=all
format:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt
- uses: Swatinem/rust-cache@v2
- run: cargo fmt --all -- --check
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
components: clippy
- uses: Swatinem/rust-cache@v2
- name: Lint native
run: cargo clippy --workspace --all-features -- -D warnings -W clippy::all
- name: Lint WASM
run: |
export CLIPPY_CONF_DIR="$(pwd)/lint/wasm/clippy.toml"
cargo clippy --workspace --all-features --target wasm32-unknown-unknown -- -D warnings -W clippy::all
trunk:
name: trunk
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
targets: wasm32-unknown-unknown
- uses: Swatinem/rust-cache@v2
- name: Download and install Trunk binary
run: wget -qO- https://github.com/thedodd/trunk/releases/latest/download/trunk-x86_64-unknown-linux-gnu.tar.gz | tar -xzf-
- name: Build
run: ./trunk build
build:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- os: macos-latest
# macos-latest seems to already run on arm64(=aarch64):
# https://docs.github.com/en/actions/using-jobs/choosing-the-runner-for-a-job#standard-github-hosted-runners-for-public-repositories
TARGET: aarch64-apple-darwin
- os: macos-13
TARGET: x86_64-apple-darwin
# even though the runner uses arm64, MacOS on arm64 seems to support building for amd64.
# which makes sense, would be bad for devs otherwise.
cross: false
- os: ubuntu-latest
TARGET: aarch64-unknown-linux-gnu
cross: true
- os: ubuntu-latest
TARGET: armv7-unknown-linux-gnueabihf
cross: true
- os: ubuntu-latest
TARGET: x86_64-unknown-linux-gnu
- os: windows-latest
TARGET: x86_64-pc-windows-msvc
EXTENSION: .exe
steps:
- name: Install cross
# Github doesnt have runners with exotic architectures (eg. arm64/aarch64 on anything but macos).
# Thus we use cross.
# It's necessary to use an up-to-date cross from the git repository to avoid glibc problems on linux
# Ref: https://github.com/cross-rs/cross/issues/1510
if: matrix.cross
run: |
echo "Resetting RUSTFLAGS as a temporary fix for: https://github.com/cross-rs/cross/issues/1561"
RUSTFLAGS="" cargo install cross --git https://github.com/cross-rs/cross --rev 1b8cf50d20180c1a394099e608141480f934b7f7
- name: Building ${{ matrix.TARGET }}
run: echo "${{ matrix.TARGET }}"
- uses: actions/checkout@master
- uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.TARGET }}
- uses: Swatinem/rust-cache@v2
with:
# this is required to avoid failures due to caching of artifacts for different architectures
# The reason is the potential usage of cross.
# The cache checks the rustc host which doesn't record us targeting
# different architectures (and native) with cross on the generic ubuntu-latest.
key: ${{ matrix.TARGET }}
- if: ${{ !matrix.cross }}
name: Cargo Build
run: cargo build --verbose --release --target=${{ matrix.TARGET }}
- if: matrix.cross
name: Cross Build
run: cross build --verbose --release --target=${{ matrix.TARGET }}
env:
CROSS_NO_WARNINGS: 0
- name: Rename
run: cp target/${{ matrix.TARGET }}/release/${{ github.event.repository.name }}${{ matrix.EXTENSION }} ${{ github.event.repository.name }}-${{ matrix.TARGET }}${{ matrix.EXTENSION }}
- uses: actions/upload-artifact@master
with:
name: ${{ github.event.repository.name }}-${{ matrix.TARGET }}${{ matrix.EXTENSION }}
path: ${{ github.event.repository.name }}-${{ matrix.TARGET }}${{ matrix.EXTENSION }}
tag-release:
needs: [check, audit, test, format, lint, trunk, build]
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/master' && success()
permissions:
contents: write # This is required to create and push tags
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.PAT_WITH_REPO_SCOPE }}
- name: Get version from Cargo.toml
id: get_version
run: |
VERSION=$(grep '^version = ' Cargo.toml | cut -d '"' -f 2)
echo "VERSION=$VERSION" >> $GITHUB_ENV
- name: Check if tag exists
id: check_tag
run: |
if git rev-parse "v${{ env.VERSION }}" >/dev/null 2>&1; then
echo "Tag already exists"
echo "TAG_EXISTS=true" >> $GITHUB_ENV
else
echo "Tag does not exist"
echo "TAG_EXISTS=false" >> $GITHUB_ENV
fi
- name: Create and push tag
if: env.TAG_EXISTS == 'false'
run: |
git config user.name "${{ github.actor }}"
git config user.email "${{ github.actor }}@users.noreply.github.com"
git tag -a "v${{ env.VERSION }}" -m "Release v${{ env.VERSION }}"
git push origin "v${{ env.VERSION }}"