-
Notifications
You must be signed in to change notification settings - Fork 6.5k
97 lines (78 loc) · 3.19 KB
/
bundle-compare.yml
File metadata and controls
97 lines (78 loc) · 3.19 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
name: Compare Bundle Size
on:
# For testing
pull_request:
permissions:
contents: read
actions: read
jobs:
compare:
name: Compare Bundle Stats
runs-on: ubuntu-latest
steps:
- name: Harden Runner
uses: step-security/harden-runner@f4a75cfd619ee5ce8d5b864b0d183aff3c69b55a # v2.13.1
with:
egress-policy: audit
- name: Download PR artifact (head)
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
with:
script: |
const fs = require('fs');
const path = require('path');
const artifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: 18635880384 || context.payload.workflow_run.id,
});
const artifact = artifacts.data.artifacts.find(a => a.name === 'webpack-stats');
if (!artifact) {
throw new Error('No artifact found!');
}
const download = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: artifact.id,
archive_format: 'zip',
});
fs.mkdirSync('head-stats', { recursive: true });
fs.writeFileSync('head-stats/stats.zip', Buffer.from(download.data));
- name: Download main branch artifact (base)
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
with:
script: |
const fs = require('fs');
const runs = await github.rest.actions.listWorkflowRuns({
owner: context.repo.owner,
repo: context.repo.repo,
workflow_id: 199178247 || context.payload.workflow_run.workflow_id,
branch: 'main',
status: 'completed',
per_page: 1,
});
const artifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: runs.data.workflow_runs[0].id,
});
const artifact = artifacts.data.artifacts.find(a => a.name === 'webpack-stats');
if (!artifact) {
throw new Error('No artifact found!');
}
const download = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: artifact.id,
archive_format: 'zip',
});
fs.mkdirSync('base-stats', { recursive: true });
fs.writeFileSync('base-stats/stats.zip', Buffer.from(download.data));
- name: Unzip artifacts
run: |
unzip -o head-stats/stats.zip -d head-stats
unzip -o base-stats/stats.zip -d base-stats
- uses: github/webpack-bundlesize-compare-action@89161bb25577f08577ce053c3264c0e3b7d7558f # v2.1.0
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
current-stats-json-path: ./head-stats/webpack-stats.json
base-stats-json-path: ./base-stats/webpack-stats.json