-
Notifications
You must be signed in to change notification settings - Fork 0
385 lines (367 loc) · 13.6 KB
/
ci.yml
File metadata and controls
385 lines (367 loc) · 13.6 KB
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
name: CI
on:
push:
branches: [main, develop]
pull_request:
branches: [main, develop]
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
env:
CARGO_TERM_COLOR: always
RUSTFLAGS: -D warnings
jobs:
version:
name: Version
runs-on: ubuntu-latest
outputs:
semver: ${{ steps.gitversion.outputs.semVer }}
major: ${{ steps.gitversion.outputs.major }}
minor: ${{ steps.gitversion.outputs.minor }}
patch: ${{ steps.gitversion.outputs.patch }}
prerelease: ${{ steps.gitversion.outputs.preReleaseLabel }}
nuget: ${{ steps.gitversion.outputs.semVer }}
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Verify GitVersion and Cargo baseline versions are aligned
run: ./scripts/check-version-sync.sh
- uses: gittools/actions/gitversion/setup@v4.3.3
with:
versionSpec: '6.x'
- id: gitversion
uses: gittools/actions/gitversion/execute@v4.3.3
fmt:
name: rustfmt
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'
steps:
- uses: actions/checkout@v6
- run: rustup component add rustfmt
- run: cargo fmt --all -- --check
clippy:
name: clippy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
with:
submodules: true
- uses: Swatinem/rust-cache@v2
- run: rustup component add clippy
- run: cargo clippy --all-targets --all-features -- -D warnings
clippy-strict:
name: clippy strict
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
with:
submodules: true
- uses: Swatinem/rust-cache@v2
- run: rustup component add clippy
- run: cargo clippy --workspace --lib --bins --examples -- -D warnings -D clippy::unwrap_used -D clippy::expect_used
clippy-pedantic:
name: clippy pedantic (advisory)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
with:
submodules: true
- uses: Swatinem/rust-cache@v2
- run: rustup component add clippy
- name: Run pedantic audit (non-blocking)
run: |
cargo clippy --workspace --all-targets --all-features -- -D warnings -W clippy::pedantic || {
echo "::warning::Pedantic lint debt detected (non-blocking advisory job)."
}
rust-test:
name: Rust tests (${{ matrix.name }})
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
name: Linux x64
cache_key: linux-test
- os: windows-latest
name: Windows x64
cache_key: windows-test
- os: macos-latest
name: macOS
cache_key: macos-test
steps:
- uses: actions/checkout@v6
with:
submodules: true
- uses: Swatinem/rust-cache@v2
with:
key: ${{ matrix.cache_key }}
- run: cargo test --release
rust-artifacts:
name: Rust artifacts (${{ matrix.name }})
if: github.event_name == 'push'
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
name: Linux x64
cache_key: linux-artifacts
artifact_name: linux-x64
artifact_path: |
target/release/libsurge.so
target/release/surge
target/release/surge-installer
target/release/surge-installer-ui
target/release/surge-supervisor
- os: ubuntu-24.04-arm
name: Linux arm64
cache_key: linux-arm64-artifacts
artifact_name: linux-arm64
artifact_path: |
target/release/libsurge.so
target/release/surge
target/release/surge-installer
target/release/surge-installer-ui
target/release/surge-supervisor
- os: windows-latest
name: Windows x64
cache_key: windows-artifacts
artifact_name: win-x64
artifact_path: |
target/release/surge.dll
target/release/surge.dll.lib
target/release/surge.exe
target/release/surge-installer.exe
target/release/surge-installer-ui.exe
target/release/surge-supervisor.exe
- os: macos-latest
name: macOS
cache_key: macos-artifacts
artifact_name: osx-x64
artifact_path: |
target/release/libsurge.dylib
target/release/surge
target/release/surge-installer
target/release/surge-installer-ui
target/release/surge-supervisor
steps:
- uses: actions/checkout@v6
with:
submodules: true
- uses: Swatinem/rust-cache@v2
with:
key: ${{ matrix.cache_key }}
- run: cargo build --release
- name: Upload artifacts
uses: actions/upload-artifact@v7
with:
name: ${{ matrix.artifact_name }}
path: ${{ matrix.artifact_path }}
dotnet:
name: .NET
runs-on: ubuntu-latest
needs: [version]
defaults:
run:
working-directory: dotnet
steps:
- uses: actions/checkout@v6
with:
submodules: true
- uses: actions/setup-dotnet@v5
with:
dotnet-version: '10.0.x'
- uses: actions/cache@v5
with:
path: ~/.nuget/packages
key: nuget-${{ hashFiles('dotnet/Directory.Packages.props') }}
restore-keys: nuget-
- run: dotnet restore
- run: dotnet format --verify-no-changes --verbosity diagnostic
- run: dotnet build --no-restore --configuration Release -p:Version=${{ needs.version.outputs.semver }}
- run: dotnet test --no-build --configuration Release --verbosity normal
nuget:
name: Publish NuGet
runs-on: ubuntu-latest
needs: [version, clippy, clippy-strict, rust-test, rust-artifacts, dotnet]
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop')
defaults:
run:
working-directory: dotnet
steps:
- uses: actions/checkout@v6
with:
submodules: true
- uses: actions/setup-dotnet@v5
with:
dotnet-version: '10.0.x'
- uses: actions/cache@v5
with:
path: ~/.nuget/packages
key: nuget-${{ hashFiles('dotnet/Directory.Packages.props') }}
restore-keys: nuget-
- name: Pack
run: dotnet pack Surge.NET/Surge.NET.csproj --configuration Release -p:Version=${{ needs.version.outputs.nuget }} --output ../nupkgs
- name: Push to NuGet
run: dotnet nuget push ../nupkgs/*.nupkg --source nuget.org --api-key ${{ secrets.PETERSUNDE_NUGET_ORG_API_KEY }} --skip-duplicate
cargo-crates-io-publish:
name: Publish Cargo (crates.io)
runs-on: ubuntu-latest
needs: [version, clippy, clippy-strict, rust-test, rust-artifacts, dotnet]
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop')
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
steps:
- uses: actions/checkout@v6
with:
submodules: true
- uses: Swatinem/rust-cache@v2
- name: Validate crates.io API token
run: |
if [ -z "${CARGO_REGISTRY_TOKEN}" ]; then
echo "CARGO_REGISTRY_TOKEN secret is required for crates.io publish."
exit 1
fi
- name: Set version
run: |
sed -i 's/^version = ".*"/version = "${{ needs.version.outputs.semver }}"/' Cargo.toml
sed -i -E 's|surge-core = \{ path = "crates/surge-core", version = ".*"(, registry = "surge")? \}|surge-core = { path = "crates/surge-core", version = "${{ needs.version.outputs.semver }}" }|' Cargo.toml
cargo generate-lockfile
- name: Publish surge-core to crates.io
run: cargo publish -p surge-core --allow-dirty
- name: Publish surge-cli to crates.io
run: |
for attempt in $(seq 1 10); do
if cargo publish -p surge-cli --allow-dirty; then
exit 0
fi
if [ "${attempt}" -eq 10 ]; then
echo "Failed to publish surge-cli after waiting for surge-core to sync on crates.io."
exit 1
fi
sleep $((attempt * 5))
done
cargo-cloudsmith-publish:
name: Publish Cargo (Cloudsmith)
runs-on: ubuntu-latest
needs: [version, clippy, clippy-strict, rust-test, rust-artifacts, dotnet]
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop')
env:
CLOUDSMITH_API_KEY: ${{ secrets.CLOUDSMITH_API_KEY }}
CLOUDSMITH_NAMESPACE: finter-as
CLOUDSMITH_REPOSITORY: surge
CARGO_REGISTRIES_SURGE_INDEX: sparse+https://cargo.cloudsmith.io/finter-as/surge/
CARGO_REGISTRIES_SURGE_TOKEN: ${{ secrets.CLOUDSMITH_API_KEY }}
steps:
- uses: actions/checkout@v6
with:
submodules: true
- uses: Swatinem/rust-cache@v2
- name: Validate Cloudsmith API key
run: |
if [ -z "${CLOUDSMITH_API_KEY}" ]; then
echo "CLOUDSMITH_API_KEY secret is required for cargo publish."
exit 1
fi
- name: Set version
run: |
sed -i 's/^version = ".*"/version = "${{ needs.version.outputs.semver }}"/' Cargo.toml
sed -i -E 's|surge-core = \{ path = "crates/surge-core", version = ".*"(, registry = "surge")? \}|surge-core = { path = "crates/surge-core", version = "${{ needs.version.outputs.semver }}", registry = "surge" }|' Cargo.toml
cargo generate-lockfile
- name: Install Cloudsmith CLI
run: |
python3 -m pip install --upgrade pip
python3 -m pip install cloudsmith-cli
- name: Ensure Cloudsmith repository exists
run: |
if ! cloudsmith repos list "${CLOUDSMITH_NAMESPACE}" --output-format json --api-key "${CLOUDSMITH_API_KEY}" | jq -e --arg slug "${CLOUDSMITH_REPOSITORY}" '.data[] | select(.slug == $slug)' >/dev/null; then
cat > cloudsmith-repo.json <<EOF
{"name":"surge","description":"Public Cargo registry for Surge pre-releases","repository_type_str":"Public","slug":"surge"}
EOF
cloudsmith repos create "${CLOUDSMITH_NAMESPACE}" cloudsmith-repo.json --api-key "${CLOUDSMITH_API_KEY}"
fi
- name: Publish surge-core to Cloudsmith Cargo registry
run: |
cargo publish -p surge-core --registry surge --allow-dirty
- name: Publish surge-supervisor to Cloudsmith Cargo registry
run: |
for attempt in $(seq 1 10); do
if cargo publish -p surge-supervisor --registry surge --allow-dirty; then
exit 0
fi
if [ "${attempt}" -eq 10 ]; then
echo "Failed to publish surge-supervisor after waiting for surge-core to sync in registry."
exit 1
fi
sleep $((attempt * 5))
done
- name: Publish surge-installer to Cloudsmith Cargo registry
run: |
for attempt in $(seq 1 10); do
if cargo publish -p surge-installer --registry surge --allow-dirty; then
exit 0
fi
if [ "${attempt}" -eq 10 ]; then
echo "Failed to publish surge-installer after waiting for surge-core to sync in registry."
exit 1
fi
sleep $((attempt * 5))
done
- name: Publish surge-installer-ui to Cloudsmith Cargo registry
run: |
for attempt in $(seq 1 10); do
if cargo publish -p surge-installer-ui --registry surge --allow-dirty; then
exit 0
fi
if [ "${attempt}" -eq 10 ]; then
echo "Failed to publish surge-installer-ui after waiting for surge-core to sync in registry."
exit 1
fi
sleep $((attempt * 5))
done
- name: Publish surge-cli to Cloudsmith Cargo registry
run: |
for attempt in $(seq 1 10); do
if cargo publish -p surge-cli --registry surge --allow-dirty; then
exit 0
fi
if [ "${attempt}" -eq 10 ]; then
echo "Failed to publish surge-cli after waiting for surge-core to sync in registry."
exit 1
fi
sleep $((attempt * 5))
done
release:
name: Draft Release
runs-on: ubuntu-latest
needs: [version, clippy, clippy-strict, rust-test, rust-artifacts, dotnet]
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
permissions:
contents: write
steps:
- uses: actions/checkout@v6
- name: Download all artifacts
uses: actions/download-artifact@v8
with:
path: artifacts
- name: Package release assets
run: |
cd artifacts
tar czf ../surge-linux-x64.tar.gz -C linux-x64 .
tar czf ../surge-osx-x64.tar.gz -C osx-x64 .
cd win-x64 && zip -r ../../surge-win-x64.zip . && cd ..
- name: Create draft release
uses: softprops/action-gh-release@v2
with:
tag_name: v${{ needs.version.outputs.semver }}
name: v${{ needs.version.outputs.semver }}
draft: true
generate_release_notes: true
files: |
surge-linux-x64.tar.gz
surge-osx-x64.tar.gz
surge-win-x64.zip
include/surge/surge_api.h