-
Notifications
You must be signed in to change notification settings - Fork 1
303 lines (290 loc) · 9.92 KB
/
Copy pathrust.yml
File metadata and controls
303 lines (290 loc) · 9.92 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
name: CI
on:
push:
branches: [master]
pull_request:
branches: [master]
env:
CARGO_TERM_COLOR: always
RUST_BACKTRACE: 1
jobs:
fmt:
name: Rustfmt
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt
- name: Check formatting
run: cargo fmt --all -- --check
clippy:
name: Clippy
runs-on: ubuntu-latest
strategy:
matrix:
include:
- features: ""
name: default
- features: ttl-nix
name: ttl-nix
- features: ttl-pnet
name: ttl-pnet
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
components: clippy
- uses: Swatinem/rust-cache@v2
with:
key: clippy-${{ matrix.name }}
- name: Clippy (${{ matrix.name }})
run: |
if [ -n "${{ matrix.features }}" ]; then
cargo clippy --all --tests --features ${{ matrix.features }} -- -D warnings
else
cargo clippy --all --tests -- -D warnings
fi
shell: bash
test:
name: Test (${{ matrix.os }}, ${{ matrix.rust }})
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
rust: stable
features: --all-features
- os: ubuntu-latest
rust: beta
features: --all-features
- os: macos-latest
rust: stable
features: ""
- os: windows-latest
rust: stable
features: ""
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.rust }}
- uses: Swatinem/rust-cache@v2
with:
key: test-${{ matrix.os }}-${{ matrix.rust }}
- name: Install Npcap SDK (Windows)
if: matrix.os == 'windows-latest'
shell: pwsh
run: |
Invoke-WebRequest -Uri "https://npcap.com/dist/npcap-sdk-1.13.zip" -OutFile "$env:TEMP/npcap-sdk.zip"
Expand-Archive -Path "$env:TEMP/npcap-sdk.zip" -DestinationPath "C:/npcap-sdk"
echo "LIB=C:/npcap-sdk/Lib/x64" >> $env:GITHUB_ENV
- name: Run tests
run: cargo test --verbose ${{ matrix.features }}
test-features:
name: Test Features
runs-on: ubuntu-latest
strategy:
matrix:
include:
- features: ""
name: default
- features: ttl-nix
name: ttl-nix
- features: ttl-pnet
name: ttl-pnet
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
with:
key: test-features-${{ matrix.name }}
- name: Test (${{ matrix.name }})
run: |
if [ -n "${{ matrix.features }}" ]; then
cargo test --verbose --features ${{ matrix.features }}
else
cargo test --verbose
fi
shell: bash
build-release:
name: Build Release (${{ matrix.target }})
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
- os: macos-latest
target: x86_64-apple-darwin
- os: windows-latest
target: x86_64-pc-windows-msvc
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- uses: Swatinem/rust-cache@v2
with:
key: release-${{ matrix.target }}
- name: Install Npcap SDK (Windows)
if: matrix.os == 'windows-latest'
shell: pwsh
run: |
Invoke-WebRequest -Uri "https://npcap.com/dist/npcap-sdk-1.13.zip" -OutFile "$env:TEMP/npcap-sdk.zip"
Expand-Archive -Path "$env:TEMP/npcap-sdk.zip" -DestinationPath "C:/npcap-sdk"
echo "LIB=C:/npcap-sdk/Lib/x64" >> $env:GITHUB_ENV
- name: Build release
run: cargo build --release --target ${{ matrix.target }}
msrv:
name: MSRV Check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@1.93.0
- uses: Swatinem/rust-cache@v2
with:
key: msrv
- name: Check MSRV
run: cargo check --all-features
doc:
name: Documentation
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
with:
key: doc
- name: Build documentation
run: cargo doc --no-deps --all-features
env:
RUSTDOCFLAGS: -D warnings
package-deb:
name: Package DEB
runs-on: ubuntu-latest
needs: [test]
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
with:
key: package-deb
- name: Build release binary
run: cargo build --release --all-features
- name: Build DEB package
run: |
PKG_NAME=stamp-suite
PKG_VERSION=0.5.0
PKG_DIR="${PKG_NAME}_${PKG_VERSION}-1_amd64"
mkdir -p "${PKG_DIR}/DEBIAN"
mkdir -p "${PKG_DIR}/usr/bin"
mkdir -p "${PKG_DIR}/lib/systemd/system"
mkdir -p "${PKG_DIR}/usr/share/snmp/mibs"
mkdir -p "${PKG_DIR}/usr/share/doc/${PKG_NAME}"
# Control file
cat > "${PKG_DIR}/DEBIAN/control" <<EOF
Package: ${PKG_NAME}
Version: ${PKG_VERSION}-1
Architecture: amd64
Maintainer: Piotr Olszewski <asmie@asmie.pl>
Depends: adduser
Description: Simple Two-Way Active Measurement Protocol (STAMP)
stamp-suite is a Rust implementation of the Simple Two-Way Active
Measurement Protocol (STAMP) as defined in RFC 8762 and RFC 8972.
Section: net
Priority: optional
EOF
# Trim leading spaces from heredoc
sed -i 's/^ //' "${PKG_DIR}/DEBIAN/control"
# Install files
cp target/release/${PKG_NAME} "${PKG_DIR}/usr/bin/"
cp dist/systemd/${PKG_NAME}.service "${PKG_DIR}/lib/systemd/system/"
cp mibs/STAMP-SUITE-MIB.mib "${PKG_DIR}/usr/share/snmp/mibs/"
cp README.md "${PKG_DIR}/usr/share/doc/${PKG_NAME}/"
# Maintainer scripts
for script in postinst postrm prerm; do
if [ -f "dist/debian/${script}" ]; then
cp "dist/debian/${script}" "${PKG_DIR}/DEBIAN/"
chmod 0755 "${PKG_DIR}/DEBIAN/${script}"
fi
done
chmod 0755 "${PKG_DIR}/usr/bin/${PKG_NAME}"
dpkg-deb --build --root-owner-group "${PKG_DIR}"
- name: Verify DEB package
run: |
echo "=== Package info ==="
dpkg-deb --info stamp-suite_0.5.0-1_amd64.deb
echo "=== Package contents ==="
dpkg-deb --contents stamp-suite_0.5.0-1_amd64.deb
echo "=== Verify expected files ==="
dpkg-deb --contents stamp-suite_0.5.0-1_amd64.deb | grep -q usr/bin/stamp-suite
dpkg-deb --contents stamp-suite_0.5.0-1_amd64.deb | grep -q lib/systemd/system/stamp-suite.service
dpkg-deb --contents stamp-suite_0.5.0-1_amd64.deb | grep -q usr/share/snmp/mibs/STAMP-SUITE-MIB.mib
echo "All expected files present in DEB package."
package-rpm:
name: Package RPM
runs-on: ubuntu-latest
needs: [test]
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
with:
key: package-rpm
- name: Install RPM tools
run: sudo apt-get update && sudo apt-get install -y rpm
- name: Build release binary
run: cargo build --release --all-features
- name: Build RPM package
run: |
# Set up rpmbuild tree
mkdir -p ~/rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS,BUILDROOT}
# Create source tarball layout expected by the spec
PKG_NAME=stamp-suite
PKG_VERSION=0.5.0
TARDIR="${PKG_NAME}-${PKG_VERSION}"
mkdir -p "/tmp/${TARDIR}"
cp -a . "/tmp/${TARDIR}/"
# Pre-build: place the release binary so rpmbuild finds it
mkdir -p "/tmp/${TARDIR}/target/release"
cp target/release/${PKG_NAME} "/tmp/${TARDIR}/target/release/"
tar czf ~/rpmbuild/SOURCES/${PKG_NAME}-${PKG_VERSION}.tar.gz -C /tmp "${TARDIR}"
# Patch spec to skip cargo build (binary already built)
sed 's/^cargo build --release$/# binary pre-built/' dist/rpm/${PKG_NAME}.spec > ~/rpmbuild/SPECS/${PKG_NAME}.spec
rpmbuild -bb --nodeps \
--define "_topdir $HOME/rpmbuild" \
--define "debug_package %{nil}" \
--define "_unitdir /usr/lib/systemd/system" \
~/rpmbuild/SPECS/${PKG_NAME}.spec
- name: Verify RPM package
run: |
RPM_FILE=$(find ~/rpmbuild/RPMS -name '*.rpm' | head -1)
echo "=== Package info ==="
rpm -qip "${RPM_FILE}"
echo "=== Package contents ==="
rpm -qlp "${RPM_FILE}"
echo "=== Verify expected files ==="
rpm -qlp "${RPM_FILE}" | grep -q /usr/bin/stamp-suite
rpm -qlp "${RPM_FILE}" | grep -q stamp-suite.service
rpm -qlp "${RPM_FILE}" | grep -q STAMP-SUITE-MIB.mib
echo "All expected files present in RPM package."
nix-build:
name: Nix Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: cachix/install-nix-action@v31
with:
nix_path: nixpkgs=channel:nixpkgs-unstable
- name: Build with Nix
run: nix build --print-build-logs
security-audit:
name: Security Audit
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: rustsec/audit-check@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}