-
Notifications
You must be signed in to change notification settings - Fork 19
252 lines (218 loc) · 8.9 KB
/
test.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
250
251
252
name: Build and Test
on:
push:
branches:
- main
pull_request:
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
- name: Install
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
- uses: Swatinem/rust-cache@v2
- run: wasm-pack build --dev --target nodejs
- run: wasm-pack test --node
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: wasm32-unknown-unknown
- uses: Swatinem/rust-cache@v2
- run: cargo install cargo-all-features
- name: Check all combinations of features can build
run: cargo check-all-features --target wasm32-unknown-unknown
node-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
- name: Install
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
- uses: Swatinem/rust-cache@v2
- uses: actions/setup-node@v4
with:
node-version: "20"
- name: Build bundle
run: yarn build:test
- name: Install dev dependencies
run: yarn
- name: Run Node tests
run: yarn test
fmt:
name: fmt
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt
- uses: Swatinem/rust-cache@v2
- name: Run
run: cargo fmt --all -- --check
clippy:
name: Clippy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
components: clippy
- uses: Swatinem/rust-cache@v2
- name: "clippy --all"
run: cargo clippy --all --features=full --tests -- -D warnings
node-build-report:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: wasm32-unknown-unknown
- name: Install
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
- uses: Swatinem/rust-cache@v2
- uses: actions/setup-node@v4
with:
node-version: "20"
- uses: awalsh128/cache-apt-pkgs-action@latest
with:
packages: brotli pv parallel jq
version: 1.0
- name: Build bundle
run: ./scripts/report_build.sh
- name: Size Reporting
run: |
ls report_pkg/*/*.wasm | parallel brotli -f -Z {}
mkdir -p ./pr
echo "| Asset | Size | Compressed Size |" >> ./pr/step_summary.md
echo "| ------ | ---- | --------------- |" >> ./pr/step_summary.md
for asset in $(ls report_pkg/*/*.wasm); do
export SIZE=$(stat --format '%s' $asset)
export COMPRESSED_SIZE=$(stat --format '%s' "${asset}.br")
export asset
echo "| ${asset} | $(echo $SIZE | numfmt --to=si --suffix="B") | $(echo $COMPRESSED_SIZE | numfmt --to=si --suffix="B") |" >> ./pr/step_summary.md
echo $(jq -n '{"asset": $ENV.asset, "size": $ENV.SIZE | tonumber, "compressed_size": $ENV.COMPRESSED_SIZE | tonumber}')
done | jq -s 'map({ (.asset|tostring): .}) | add' > ./pr/asset_manifest.json
echo ${{ github.event.number }} > ./pr/NR
if [[ "${{ github.event_type }}" != "pull_request" ]]; then
cat ./pr/step_summary.md > $GITHUB_STEP_SUMMARY
fi;
- uses: actions/upload-artifact@v3
with:
name: pr
path: pr/
delta_generation:
runs-on: ubuntu-latest
if: >
github.event_name == 'pull_request'
needs: node-build-report
steps:
- uses: actions/download-artifact@v3
with:
name: pr
path: pr/
- name: 'Generate size deltas'
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const { execSync } = require('child_process');
const baseContext = {
repo: {
repo: '${{ github.event.pull_request.base.repo.name }}',
owner: '${{ github.event.pull_request.base.repo.owner.login }}'
}
};
const baseWorkflows = await github.rest.actions.listWorkflowRuns({
...baseContext.repo,
branch: '${{ github.event.pull_request.base.ref }}',
status: 'success',
workflow_id: 'test.yml',
});
const matchWorkflow = baseWorkflows.data?.workflow_runs?.[0];
const artifacts = await github.rest.actions.listWorkflowRunArtifacts({
...baseContext.repo,
run_id: matchWorkflow?.id,
});
const matchArtifact = artifacts.data.artifacts.filter((artifact) => {
return artifact.name == "pr"
})[0];
if(matchArtifact) {
const download = await github.rest.actions.downloadArtifact({
...baseContext.repo,
artifact_id: matchArtifact.id,
archive_format: 'zip',
});
fs.writeFileSync('${{github.workspace}}/base.zip', Buffer.from(download.data));
execSync(`unzip -p base.zip asset_manifest.json >base_asset_manifest.json || true`);
}
// now, read in the asset manifests, for the head and base
let baseAssets = {};
try {
baseAssets = JSON.parse(fs.readFileSync('./base_asset_manifest.json')) ?? {};
} catch (error) {
console.log('No base asset manifest found');
}
const assets = JSON.parse(fs.readFileSync('./pr/asset_manifest.json'));
const unitOptions = {
style: 'unit', unit: 'byte', unitDisplay: 'narrow', notation: 'compact',
maximumSignificantDigits: 3
};
const formatter = new Intl.NumberFormat('en-US', unitOptions);
const signedFormatter = new Intl.NumberFormat('en-US', { ...unitOptions, signDisplay: 'always' });
const percentFormatter = Intl.NumberFormat('en-US', { style: 'percent', signDisplay: 'always' });
const colorMap = {
'-1': 'green',
1: 'red',
0: 'black',
NaN: 'black'
};
// compute deltas and output markdown fragments
const lineFragments = Object.entries(assets).map(([k, v]) => {
const baseAsset = baseAssets[k] ?? {};
const { asset, size, compressed_size, size_delta, compressed_size_delta } = {
...v,
...Object.fromEntries(['size', 'compressed_size'].map(subK => {
// compute the percentage change, NaN if the asset wasn't available
const proportionalDelta = v?.[subK] / baseAsset?.[subK] - 1;
const absoluteDelta = v?.[subK] - baseAsset?.[subK]
const sign = Math.sign(proportionalDelta);
// conditionally color the output via an inline latex block
let fragment = '';
if(Number.isFinite(proportionalDelta)) {
fragment = `${signedFormatter.format(absoluteDelta)} ${percentFormatter.format(proportionalDelta)}`;
} else {
fragment = 'N/A';
}
if(!Number.isFinite(proportionalDelta) || sign === 0) {
return [`${subK}_delta`, fragment]
} else {
const formattedFragment = `$\\color{${colorMap[sign]}}\\textbf{${fragment.replace('%', '\\%')}}$`;
return [`${subK}_delta`, formattedFragment]
}
}))
};
// output a markdown fragment
const sizeFragment = `${formatter.format(size)} ${size_delta}`
const compressedFragment = `${formatter.format(compressed_size)} ${compressed_size_delta}`
return [asset.replace('report_pkg/', ''), sizeFragment, compressedFragment]
});
await core.summary.addHeading('Asset Sizes').addTable([
[{data: 'Asset', header: true}, {data: 'Uncompressed Size', header: true}, {data: 'Compressed Size', header: true}],
...lineFragments
]).write();
fs.cpSync(process.env.GITHUB_STEP_SUMMARY, './pr/step_summary.md')
- uses: actions/upload-artifact@v3
with:
name: pr
path: pr/