Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add webpack-bundle-diff CI #47

Merged
merged 5 commits into from
Feb 27, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 82 additions & 0 deletions .github/workflows/check-bundle-diff.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
name: Check Bundle Diff

on: [ push ]

jobs:
master-bundle:
runs-on: ubuntu-latest
defaults:
run:
working-directory: frontend
steps:
- uses: actions/checkout@v2
with:
ref: master
- name: Use Node.js v16.x
uses: actions/setup-node@v2
with:
node-version: 16.x
- run: |
yarn
yarn build
- run: mv artifacts/webpack-stats.json artifacts/webpack-stats-base.json
- uses: actions/upload-artifact@v2
with:
name: stats
path: frontend/artifacts/webpack-stats-base.json

current-branch-bundle:
runs-on: ubuntu-latest
defaults:
run:
working-directory: frontend
steps:
- uses: actions/checkout@v2
- name: Use Node.js v16.x
uses: actions/setup-node@v2
with:
node-version: 16.x
- run: |
yarn
yarn build
- uses: actions/upload-artifact@v2
with:
name: stats
path: frontend/artifacts/webpack-stats.json

check-diff:
runs-on: ubuntu-latest
needs: [master-bundle, current-branch-bundle]
steps:
- name: Use Node.js v16.x
uses: actions/setup-node@v2
with:
node-version: 16.x
- run: npm install -g webpack-bundle-diff
- uses: actions/download-artifact@v2
with:
name: stats
- run: wbd diff webpack-stats.json webpack-stats-base.json -o output.json
- name: Check bundle diff
run: |
const fs = require('fs');

fs.readFile('output.json', (err, data) => {
if (err) {
throw err
}

const stats = JSON.parse(data)
for (let key in stats) {
let stat = stats[key]
if (!Array.isArray(stat['added']) || !Array.isArray(stat['removed']) || !Array.isArray(stat['changed'])) {
throw new Error(`Why stats of this key is not Array? added: ${stat['added']}, removed: ${stat['removed']}, changed: ${stat['changed']}`)
}

if (stat['delta'] || stat['added'].length > 0 || stat['removed'].length > 0 || stat['changed'].length > 0) {
throw new Error('this artifact is different from HEAD')
}
}
})
shell: node {0}