-
Notifications
You must be signed in to change notification settings - Fork 10
269 lines (249 loc) · 7.99 KB
/
Copy pathrust.yml
File metadata and controls
269 lines (249 loc) · 7.99 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
name: Rust
on:
push:
branches: [main]
tags:
- 'v*'
- 'cli-v*'
- 'wasm-v*'
pull_request:
branches: [main]
workflow_dispatch:
jobs:
build-library:
runs-on: ubuntu-latest
if: github.event_name == 'push' || github.event_name == 'pull_request'
steps:
- uses: actions/checkout@v4
- name: Set up Rust
uses: dtolnay/rust-toolchain@stable
with:
components: clippy, rustfmt
- name: Check Formatting
run: cargo fmt -- --check
- name: Security audit
run: |
cargo install cargo-audit
cargo audit
- name: Build Library
run: cargo build --verbose
- name: Run Library Tests
run: |
cargo test --verbose
cargo test --verbose -F std
- name: Run Library Tests with plaintext before with enabled
run: cargo test --verbose -F plaintext-before-extension
- name: Lint with Clippy
run: |
rustup component add clippy
cargo clippy -- -D warnings
build-cli:
runs-on: ubuntu-latest
if: github.event_name == 'push' || github.event_name == 'pull_request'
needs: build-library
steps:
- uses: actions/checkout@v4
- name: Set up Rust
uses: dtolnay/rust-toolchain@stable
with:
components: clippy, rustfmt
- name: Check CLI Formatting
run: |
cd cli
cargo fmt -- --check
- name: Build CLI
run: |
cd cli
cargo build --verbose
- name: Run CLI Tests
run: |
cd cli
cargo test --verbose
- name: Lint CLI with Clippy
run: |
rustup component add clippy
cd cli
cargo clippy -- -D warnings
build-wasm:
runs-on: ubuntu-latest
if: github.event_name == 'push' || github.event_name == 'pull_request'
needs: build-library
steps:
- uses: actions/checkout@v4
- name: Set up Rust
uses: dtolnay/rust-toolchain@stable
with:
components: clippy, rustfmt
- name: Check WASM Formatting
run: |
cd wasm
cargo fmt -- --check
- name: Build WASM
run: |
cd wasm
cargo build --verbose
- name: Run WASM Tests
run: |
cd wasm
cargo test --verbose
- name: Install wasm-pack
run: cargo install wasm-pack --locked
- name: Run WASM browser tests
run: |
cd wasm
wasm-pack test --headless --firefox
- name: Lint WASM with Clippy
run: |
rustup component add clippy
cd wasm
cargo clippy -- -D warnings
publish-library:
needs: build-library
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
if: startsWith(github.ref, 'refs/tags/v')
steps:
- uses: actions/checkout@v4
- name: Set up Rust
uses: dtolnay/rust-toolchain@stable
with:
components: clippy, rustfmt
- uses: rust-lang/crates-io-auth-action@v1
id: auth
- name: Publish Library to crates.io
env:
CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}
run: |
set -euo pipefail
CRATES_USER_AGENT="m-bus-parser-release-workflow (https://github.com/maebli/m-bus-parser)"
crate_exists() {
curl -fsS -A "$CRATES_USER_AGENT" "https://crates.io/api/v1/crates/$1/$2" >/dev/null
}
wait_for_crate() {
crate="$1"
version="$2"
for _ in {1..40}; do
if crate_exists "$crate" "$version"; then
return 0
fi
sleep 15
done
echo "$crate $version did not appear on crates.io"
return 1
}
publish_crate() {
crate="$1"
manifest="$2"
manifest_path="$(realpath "$manifest")"
version="$(
cargo metadata --manifest-path "$manifest" --no-deps --format-version 1 |
jq -r --arg manifest_path "$manifest_path" \
'.packages[] | select(.manifest_path == $manifest_path) | .version'
)"
if crate_exists "$crate" "$version"; then
echo "$crate $version is already published"
return 0
fi
cargo publish --manifest-path "$manifest"
wait_for_crate "$crate" "$version"
}
publish_crate m-bus-core crates/m-bus-core/Cargo.toml
publish_crate wired-mbus-link-layer crates/wired-mbus-link-layer/Cargo.toml
publish_crate wireless-mbus-link-layer crates/wireless-mbus-link-layer/Cargo.toml
publish_crate m-bus-application-layer crates/m-bus-application-layer/Cargo.toml
publish_crate m-bus-parser Cargo.toml
publish-cli:
needs: build-cli
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
if: startsWith(github.ref, 'refs/tags/cli-v')
steps:
- uses: actions/checkout@v4
- name: Set up Rust
uses: dtolnay/rust-toolchain@stable
with:
components: clippy, rustfmt
- uses: rust-lang/crates-io-auth-action@v1
id: auth
- name: Publish CLI to crates.io
env:
CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}
RELEASE_REF_NAME: ${{ github.ref_name }}
run: |
set -euo pipefail
VERSION="${RELEASE_REF_NAME#cli-v}"
CRATES_USER_AGENT="m-bus-parser-release-workflow (https://github.com/maebli/m-bus-parser)"
crate_exists() {
curl -fsS -A "$CRATES_USER_AGENT" "https://crates.io/api/v1/crates/$1/$VERSION" >/dev/null
}
wait_for_crate() {
crate="$1"
for _ in {1..40}; do
if crate_exists "$crate"; then
return 0
fi
sleep 15
done
echo "$crate $VERSION did not appear on crates.io"
return 1
}
wait_for_crate m-bus-parser
if crate_exists m-bus-parser-cli; then
echo "m-bus-parser-cli $VERSION is already published"
exit 0
fi
cd cli
cargo publish
publish-wasm:
needs: build-wasm
runs-on: ubuntu-latest
permissions:
id-token: write
contents: write
if: startsWith(github.ref, 'refs/tags/wasm-v')
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Rust
uses: dtolnay/rust-toolchain@stable
with:
components: clippy, rustfmt
- name: Install wasm-pack
run: cargo install wasm-pack
- name: Build wasm package
run: |
cd wasm
wasm-pack build --target bundler
- uses: actions/setup-node@v6
with:
node-version: '24'
registry-url: 'https://registry.npmjs.org'
package-manager-cache: false
- name: Publish WASM package
run: wasm-pack publish --access public wasm
- name: Create new artifacts for website
run: |
cd wasm
wasm-pack build --target web --out-dir pkg-web
- name: Copy wasm artifacts to docs
run: |
cp wasm/pkg-web/m_bus_parser_wasm_pack.js docs/
cp wasm/pkg-web/m_bus_parser_wasm_pack_bg.wasm docs/
if [ -f wasm/pkg-web/m_bus_parser_wasm_pack_bg.js ]; then
cp wasm/pkg-web/m_bus_parser_wasm_pack_bg.js docs/
fi
- name: Commit updated wasm artifacts
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git config user.name "github-actions"
git config user.email "github-actions@github.com"
git add docs/m_bus_parser_wasm_pack.js docs/m_bus_parser_wasm_pack_bg.js docs/m_bus_parser_wasm_pack_bg.wasm docs/meter.png
git commit -m "Update docs wasm artifacts" || echo "No changes to commit"
git push origin HEAD:main