From 26331d86ca7810e98cd7afed356d053f781599b3 Mon Sep 17 00:00:00 2001 From: Chris Thoburn Date: Sat, 30 Nov 2019 17:59:04 -0800 Subject: [PATCH] [CHORE] AssetSize check for both modern and IE11 builds (#6826) * build both IE11 and modern * cleanup * fix * fix path * more cleanup * fix comment formatting * add no-rollup check too * fix display * sweet lines * :facepalm: --- .github/workflows/asset-size-check.yml | 76 ++++++++++++------- bin/asset-size-tracking/generate-analysis.js | 7 +- bin/asset-size-tracking/generate-diff.js | 18 +++-- bin/asset-size-tracking/print-analysis.js | 2 +- .../src/create-comment-text.js | 24 ++++-- bin/asset-size-tracking/src/library.js | 23 ++++-- 6 files changed, 101 insertions(+), 49 deletions(-) diff --git a/.github/workflows/asset-size-check.yml b/.github/workflows/asset-size-check.yml index 6f3d19c1787..0b10b55188d 100644 --- a/.github/workflows/asset-size-check.yml +++ b/.github/workflows/asset-size-check.yml @@ -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 diff --git a/bin/asset-size-tracking/generate-analysis.js b/bin/asset-size-tracking/generate-analysis.js index f0855a33ec4..6df5d2c2055 100644 --- a/bin/asset-size-tracking/generate-analysis.js +++ b/bin/asset-size-tracking/generate-analysis.js @@ -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)); diff --git a/bin/asset-size-tracking/generate-diff.js b/bin/asset-size-tracking/generate-diff.js index 0c9751d27df..22f81842f63 100644 --- a/bin/asset-size-tracking/generate-diff.js +++ b/bin/asset-size-tracking/generate-diff.js @@ -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; diff --git a/bin/asset-size-tracking/print-analysis.js b/bin/asset-size-tracking/print-analysis.js index 4a533007598..877a954e4a2 100644 --- a/bin/asset-size-tracking/print-analysis.js +++ b/bin/asset-size-tracking/print-analysis.js @@ -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); diff --git a/bin/asset-size-tracking/src/create-comment-text.js b/bin/asset-size-tracking/src/create-comment-text.js index 9d706f3e82e..84b673d767b 100644 --- a/bin/asset-size-tracking/src/create-comment-text.js +++ b/bin/asset-size-tracking/src/create-comment-text.js @@ -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
\n Full Asset Analysis\n\n\`\`\`${analysisText}\n\`\`\`\n
`; +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
\n Full Asset Analysis (IE11)\n\n\`\`\`${IE11AnalysisText}\n\`\`\`\n
+\n**Modern Builds**\n${ModernDiffText}\n
\n Full Asset Analysis (Modern)\n\n\`\`\`${ModernAnalysisText}\n\`\`\`\n
+\n**Modern Builds (No Rollup)**\n${ModernDiffTextNoRollup}\n
\n Full Asset Analysis (Modern)\n\n\`\`\`${ModernAnalysisTextNoRollup}\n\`\`\`\n
`; const commentJSON = { body: commentText, }; diff --git a/bin/asset-size-tracking/src/library.js b/bin/asset-size-tracking/src/library.js index 32117b57bc8..94f05786fcf 100644 --- a/bin/asset-size-tracking/src/library.js +++ b/bin/asset-size-tracking/src/library.js @@ -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 { @@ -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) + ' | ' +