Skip to content

Commit

Permalink
[CHORE] AssetSize check for both modern and IE11 builds (#6826)
Browse files Browse the repository at this point in the history
* build both IE11 and modern

* cleanup

* fix

* fix path

* more cleanup

* fix comment formatting

* add no-rollup check too

* fix display

* sweet lines

* 🤦
  • Loading branch information
runspired authored Dec 1, 2019
1 parent 692c4ca commit 26331d8
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 49 deletions.
76 changes: 49 additions & 27 deletions .github/workflows/asset-size-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,52 +28,74 @@ jobs:
run: git checkout master
- name: Install dependencies for master
run: yarn install
- name: Build Production master (IE11)
run: |
mkdir -p packages/-ember-data/dists
TARGET_IE11=true yarn workspace ember-data ember build -e production --output-path dists/control-ie11
- name: Build Production master
# This will leave the assets in a dist that is maintained when
# We switch back to the primary branch
run: yarn workspace ember-data ember build -e production
run: yarn workspace ember-data ember build -e production --output-path dists/control
- name: Build Production master (no rollup)
run: EMBER_DATA_ROLLUP_PRIVATE=false yarn workspace ember-data ember build -e production --output-path dists/control-no-rollup
- name: Checkout ${{github.ref}}
# We checkout the PR Branch before parsing the master vendor file
# So that we are always using the current analysis tooling
run: |
sha=$(cat tmp/sha-for-check.txt)
git checkout --progress --force $sha
- name: Install dependencies for ${{github.ref}}
run: yarn install
- name: Parse Master Assets
run: |
node ./bin/asset-size-tracking/generate-analysis.js
mkdir -p tmp
mkdir -p tmp/asset-sizes
node ./bin/asset-size-tracking/print-analysis.js -show > tmp/asset-sizes/master-analysis.txt
- name: Upload Master Dist Artifacts
uses: actions/upload-artifact@v1
with:
name: master-dist
path: packages/-ember-data/dist/assets
- name: Build Production ${{github.ref}} (IE11)
run: TARGET_IE11=true yarn workspace ember-data ember build -e production --output-path dists/experiment-ie11
- name: Build Production ${{github.ref}}
run: yarn workspace ember-data ember build -e production
- name: Test Asset Sizes
run: yarn workspace ember-data ember build -e production --output-path dists/experiment
- name: Build Production ${{github.ref}} (no rollup)
run: EMBER_DATA_ROLLUP_PRIVATE=false yarn workspace ember-data ember build -e production --output-path dists/experiment-no-rollup
- name: Analyze Master Assets (IE11)
run: |
node ./bin/asset-size-tracking/generate-analysis.js packages/-ember-data/dists/control-ie11 ./control-ie11-data.json
mkdir -p tmp
mkdir -p tmp/asset-sizes
node ./bin/asset-size-tracking/print-analysis.js ./control-ie11-data.json -show > tmp/asset-sizes/master-analysis-ie11.txt
- name: Analyze Master Assets
run: |
node ./bin/asset-size-tracking/generate-analysis.js packages/-ember-data/dists/control ./control-data.json
node ./bin/asset-size-tracking/print-analysis.js ./control-data.json -show > tmp/asset-sizes/master-analysis.txt
- name: Analyze Master Assets (no rollup)
run: |
node ./bin/asset-size-tracking/generate-analysis.js packages/-ember-data/dists/control-no-rollup ./control-data-no-rollup.json
node ./bin/asset-size-tracking/print-analysis.js ./control-data-no-rollup.json -show > tmp/asset-sizes/master-analysis-no-rollup.txt
- name: Analyze ${{github.ref}} Assets (IE11)
run: |
node ./bin/asset-size-tracking/generate-analysis.js packages/-ember-data/dists/experiment-ie11 ./experiment-ie11-data.json
node ./bin/asset-size-tracking/print-analysis.js ./experiment-ie11-data.json > tmp/asset-sizes/experiment-analysis-ie11.txt
- name: Analyze ${{github.ref}} Assets
run: |
node ./bin/asset-size-tracking/generate-analysis.js packages/-ember-data/dists/experiment ./experiment-data.json
node ./bin/asset-size-tracking/print-analysis.js ./experiment-data.json > tmp/asset-sizes/experiment-analysis.txt
- name: Analyze ${{github.ref}} Assets
run: |
node ./bin/asset-size-tracking/generate-analysis.js packages/-ember-data/dists/experiment-no-rollup ./experiment-data-no-rollup.json
node ./bin/asset-size-tracking/print-analysis.js ./experiment-data-no-rollup.json > tmp/asset-sizes/experiment-analysis-no-rollup.txt
- name: Test Asset Sizes (IE11)
run: |
set -o pipefail
node ./bin/asset-size-tracking/generate-diff.js | tee tmp/asset-sizes/diff.txt
- name: Prepare Data For Report
node ./bin/asset-size-tracking/generate-diff.js ./control-ie11-data.json ./experiment-ie11-data.json | tee tmp/asset-sizes/diff-ie11.txt
- name: Test Asset Sizes
if: failure() || success()
run: |
node ./bin/asset-size-tracking/generate-analysis.js
- name: Print Asset Size Report
set -o pipefail
node ./bin/asset-size-tracking/generate-diff.js ./control-data.json ./experiment-data.json | tee tmp/asset-sizes/diff.txt
- name: Test Asset Sizes
if: failure() || success()
run: |
set -o pipefail
node ./bin/asset-size-tracking/print-analysis.js | tee tmp/asset-sizes/commit-analysis.txt
- name: Upload ${{github.ref}} Dist Artifacts
# we don't set -o pipefail as this should always pass, we just want the diff
node ./bin/asset-size-tracking/generate-diff.js ./control-data-no-rollup.json ./experiment-data-no-rollup.json | tee tmp/asset-sizes/diff-no-rollup.txt
- name: Upload Dist Artifacts
if: failure() || success()
uses: actions/upload-artifact@v1
with:
name: commit-dist
path: packages/-ember-data/dist/assets
name: dists
path: packages/-ember-data/dists
- name: Upload Report Artifacts
if: failure() || success()
uses: actions/upload-artifact@v1
with:
name: reports
Expand Down
7 changes: 4 additions & 3 deletions bin/asset-size-tracking/generate-analysis.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@
*/
const fs = require('fs');
const path = require('path');
let INPUT_FILE = process.argv[2] || false;
let INPUT_DIST = process.argv[2] || false;
let OUTPUT_FILE = process.argv[3] || './current-data.json';
const parseModules = require('./src/parse-modules');
const getBuiltDist = require('./src/get-built-dist');

const builtAsset = getBuiltDist(INPUT_FILE);
const builtAsset = getBuiltDist(path.join(INPUT_DIST, 'assets/vendor.js'));
const library = parseModules(builtAsset);
const outputPath = path.resolve(__dirname, './current-data.json');
const outputPath = path.resolve(__dirname, OUTPUT_FILE);

fs.writeFileSync(outputPath, JSON.stringify(library, null, 2));
18 changes: 12 additions & 6 deletions bin/asset-size-tracking/generate-diff.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,23 @@ const library_failure_threshold = 15;
const package_warn_threshold = 0;

let BASE_DATA_FILE = process.argv[2] || false;
let NEW_VENDOR_FILE = process.argv[3] || false;
let NEW_DATA_FILE = process.argv[3] || false;

if (!BASE_DATA_FILE) {
BASE_DATA_FILE = path.resolve(__dirname, './current-data.json');
BASE_DATA_FILE = './current-data.json';
}

const data = fs.readFileSync(BASE_DATA_FILE, 'utf-8');
const current_library = Library.fromData(JSON.parse(data));
const baseData = fs.readFileSync(path.resolve(__dirname, BASE_DATA_FILE), 'utf-8');
const current_library = Library.fromData(JSON.parse(baseData));

const builtAsset = getBuiltDist(NEW_VENDOR_FILE);
const new_library = parseModules(builtAsset);
let new_library;
if (!NEW_DATA_FILE) {
const builtAsset = getBuiltDist();
new_library = parseModules(builtAsset);
} else {
const newData = fs.readFileSync(path.resolve(__dirname, NEW_DATA_FILE), 'utf-8');
new_library = Library.fromData(JSON.parse(newData));
}

function getDiff(oldLibrary, newLibrary) {
const compressionDelta = newLibrary.compressedSize - oldLibrary.compressedSize;
Expand Down
2 changes: 1 addition & 1 deletion bin/asset-size-tracking/print-analysis.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ if (!INPUT_FILE) {
INPUT_FILE = path.resolve(__dirname, './current-data.json');
}

const data = fs.readFileSync(INPUT_FILE, 'utf-8');
const data = fs.readFileSync(path.resolve(__dirname, INPUT_FILE), 'utf-8');

const library = Library.fromData(JSON.parse(data));
library.print(SHOW_MODULES);
24 changes: 19 additions & 5 deletions bin/asset-size-tracking/src/create-comment-text.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,26 @@ const fs = require('fs');
const path = require('path');
const GITHUB_SHA = process.argv[2];

const diffPath = path.resolve(__dirname, '../../../tmp/asset-sizes/diff.txt');
const analysisPath = path.resolve(__dirname, '../../../tmp/asset-sizes/commit-analysis.txt');
const diffText = fs.readFileSync(diffPath);
const analysisText = fs.readFileSync(analysisPath);
const IE11DiffPath = path.resolve(__dirname, '../../../tmp/asset-sizes/diff-ie11.txt');
const IE11AnalysisPath = path.resolve(__dirname, '../../../tmp/asset-sizes/experiment-analysis-ie11.txt');
const ModernDiffPath = path.resolve(__dirname, '../../../tmp/asset-sizes/diff.txt');
const ModernAnalysisPath = path.resolve(__dirname, '../../../tmp/asset-sizes/experiment-analysis.txt');
const ModernDiffPathNoRollup = path.resolve(__dirname, '../../../tmp/asset-sizes/diff-no-rollup.txt');
const ModernAnalysisPathNoRollup = path.resolve(
__dirname,
'../../../tmp/asset-sizes/experiment-analysis-no-rollup.txt'
);

const commentText = `Asset Size Report for ${GITHUB_SHA}\n${diffText}\n<details>\n <summary>Full Asset Analysis</summary>\n\n\`\`\`${analysisText}\n\`\`\`\n</details>`;
const IE11DiffText = fs.readFileSync(IE11DiffPath);
const IE11AnalysisText = fs.readFileSync(IE11AnalysisPath);
const ModernDiffText = fs.readFileSync(ModernDiffPath);
const ModernAnalysisText = fs.readFileSync(ModernAnalysisPath);
const ModernDiffTextNoRollup = fs.readFileSync(ModernDiffPathNoRollup);
const ModernAnalysisTextNoRollup = fs.readFileSync(ModernAnalysisPathNoRollup);

const commentText = `Asset Size Report for ${GITHUB_SHA}\n\n**IE11 Builds**\n${IE11DiffText}\n<details>\n <summary>Full Asset Analysis (IE11)</summary>\n\n\`\`\`${IE11AnalysisText}\n\`\`\`\n</details>
\n**Modern Builds**\n${ModernDiffText}\n<details>\n <summary>Full Asset Analysis (Modern)</summary>\n\n\`\`\`${ModernAnalysisText}\n\`\`\`\n</details>
\n**Modern Builds (No Rollup)**\n${ModernDiffTextNoRollup}\n<details>\n <summary>Full Asset Analysis (Modern)</summary>\n\n\`\`\`${ModernAnalysisTextNoRollup}\n\`\`\`\n</details>`;
const commentJSON = {
body: commentText,
};
Expand Down
23 changes: 16 additions & 7 deletions bin/asset-size-tracking/src/library.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,17 +133,26 @@ class Package {
compressed: formatBytes(this.compressedSize),
'% Of Library': this.percentOfLibrary,
});
const longest = this.modules.reduce((longest, m) => {
return m.name.length > longest ? m.name.length : longest;
}, TablePads.name);
console.log(
`\t${rightPad('Module', TablePads.name)} | ` +
`\t${rightPad('Module', longest + 4)} | ` +
`${rightPad('Bytes', TablePads.bytes)} | ` +
`${rightPad('Compressed', TablePads.compressedBytes)} | ` +
`${rightPad('% of Package', TablePads.percentOfPackage)} | ` +
`% Of Library`
);
console.log(
'\t-----------------------------------------------------------------------------------------------------'
);
this.modules.forEach(s => s.print());
let line =
'\t-----------------------------------------------------------------------------------------------------';
if (longest > TablePads.name) {
let toAdd = longest - TablePads.name;
for (let i = 0; i < toAdd; i++) {
line += '-';
}
}
console.log(line);
this.modules.forEach(s => s.print(longest + 4));
}
toJSON() {
return {
Expand Down Expand Up @@ -180,10 +189,10 @@ class Module {
get percentOfLibrary() {
return getRelativeSizeOf(this.package.library, this);
}
print() {
print(namePadding) {
console.log(
'\t' +
rightPad(this.name, TablePads.name) +
rightPad(this.name, namePadding) +
' | ' +
rightPad(this.bytes, TablePads.bytes) +
' | ' +
Expand Down

0 comments on commit 26331d8

Please sign in to comment.