Skip to content

Commit c06191d

Browse files
committed
[wip] bundle stats
1 parent 2ee10e9 commit c06191d

File tree

1 file changed

+62
-22
lines changed

1 file changed

+62
-22
lines changed
Lines changed: 62 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,9 @@
1-
# Security Notes
2-
# Only selected Actions are allowed within this repository. Please refer to (https://github.com/nodejs/nodejs.org/settings/actions)
3-
# for the full list of available actions. If you want to add a new one, please reach out a maintainer with Admin permissions.
4-
# REVIEWERS, please always double-check security practices before merging a PR that contains Workflow changes!!
5-
# AUTHORS, please only use actions with explicit SHA references, and avoid using `@master` or `@main` references or `@version` tags.
6-
71
name: Compare Bundle Size
82

93
on:
10-
# TMP, for testing
11-
pull_request:
12-
13-
defaults:
14-
run:
15-
# This ensures that the working directory is the root of the repository
16-
working-directory: ./
4+
workflow_run:
5+
workflows: ["Build"]
6+
types: [completed]
177

188
permissions:
199
contents: read
@@ -30,19 +20,69 @@ jobs:
3020
with:
3121
egress-policy: audit
3222

33-
- uses: dawidd6/action-download-artifact@ac66b43f0e6a346234dd65d4d0c8fbb31cb316e5 # v11
23+
- name: Download PR artifact (head)
24+
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
3425
with:
35-
name: webpack-stats
36-
path: head-stats
26+
script: |
27+
const fs = require('fs');
28+
const path = require('path');
29+
30+
const artifacts = await github.rest.actions.listWorkflowRunArtifacts({
31+
owner: context.repo.owner,
32+
repo: context.repo.repo,
33+
run_id: context.payload.workflow_run.id,
34+
});
35+
36+
const artifact = artifacts.data.artifacts.find(a => a.name === 'webpack-stats');
37+
const download = await github.rest.actions.downloadArtifact({
38+
owner: context.repo.owner,
39+
repo: context.repo.repo,
40+
artifact_id: artifact.id,
41+
archive_format: 'zip',
42+
});
43+
44+
fs.mkdirSync('head-stats', { recursive: true });
45+
fs.writeFileSync('head-stats/stats.zip', Buffer.from(download.data));
3746
38-
- uses: dawidd6/action-download-artifact@ac66b43f0e6a346234dd65d4d0c8fbb31cb316e5 # v11
47+
- name: Download main branch artifact (base)
48+
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
3949
with:
40-
name: webpack-stats
41-
commit: ${{ github.sha }}
42-
path: base-stats
50+
script: |
51+
const fs = require('fs');
52+
53+
const runs = await github.rest.actions.listWorkflowRuns({
54+
owner: context.repo.owner,
55+
repo: context.repo.repo,
56+
workflow_id: context.payload.workflow_run.workflow_id,
57+
branch: 'main',
58+
status: 'completed',
59+
per_page: 1,
60+
});
61+
62+
const artifacts = await github.rest.actions.listWorkflowRunArtifacts({
63+
owner: context.repo.owner,
64+
repo: context.repo.repo,
65+
run_id: runs.data.workflow_runs[0].id,
66+
});
67+
68+
const artifact = artifacts.data.artifacts.find(a => a.name === 'webpack-stats');
69+
const download = await github.rest.actions.downloadArtifact({
70+
owner: context.repo.owner,
71+
repo: context.repo.repo,
72+
artifact_id: artifact.id,
73+
archive_format: 'zip',
74+
});
75+
76+
fs.mkdirSync('base-stats', { recursive: true });
77+
fs.writeFileSync('base-stats/stats.zip', Buffer.from(download.data));
78+
79+
- name: Unzip artifacts
80+
run: |
81+
unzip -o head-stats/stats.zip -d head-stats
82+
unzip -o base-stats/stats.zip -d base-stats
4383
4484
- uses: github/webpack-bundlesize-compare-action@89161bb25577f08577ce053c3264c0e3b7d7558f # v2.1.0
4585
with:
4686
github-token: ${{ secrets.GITHUB_TOKEN }}
47-
current-stats-json-path: ./head-stats/stats.json
48-
base-stats-json-path: ./base-stats/stats.json
87+
current-stats-json-path: ./head-stats/webpack-stats.json
88+
base-stats-json-path: ./base-stats/webpack-stats.json

0 commit comments

Comments
 (0)