From 103fdeb3eb14585ed4e139949ec832a576ee83c2 Mon Sep 17 00:00:00 2001 From: Tom Ross Date: Fri, 22 Oct 2021 10:37:01 +0100 Subject: [PATCH 1/2] Support baseBranch flag --- cli/index.js | 8 +++++++- cli/src/pipeline/config.js | 5 +++++ next-steps.md | 2 +- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/cli/index.js b/cli/index.js index 20c8e2b..46116b9 100644 --- a/cli/index.js +++ b/cli/index.js @@ -13,10 +13,16 @@ const github = require('./src/reporters/github') const build = require('./src/reporters/build') const summarize = require('./src/utils/summarize') +/** + * Default branches to cache against when running through CI. + */ +const defaultBaseBranches = ['main', 'master']; + const run = async () => { const results = analyse(markDuplicates(files)) + const onBaseBranch = branch === flags.baseBranch || defaultBaseBranches.includes(branch) - if (ci && branch === 'master' && !process.env.INTERNAL_SKIP_CACHE) { + if (ci && onBaseBranch && !process.env.INTERNAL_SKIP_CACHE) { await cache.save(results) } const cachedResults = await cache.read() diff --git a/cli/src/pipeline/config.js b/cli/src/pipeline/config.js index 43d836c..1ad13b2 100644 --- a/cli/src/pipeline/config.js +++ b/cli/src/pipeline/config.js @@ -15,6 +15,10 @@ program '--enable-github-checks', 'Enable checks on GitHub (needs installation)' ) + .option( + '--base-branch', + 'Specify which branch to use as a baseline for comparison' + ) .option('-f, --files [files]', '(legacy) files to test against (dist/*.js)') .option('-s, --max-size [maxSize]', '(legacy) maximum size threshold (3Kb)') .option( @@ -86,6 +90,7 @@ debug('selected config', files) const flags = { debug: program.debug, enableGitHubChecks: program.enableGithubChecks, + baseBranch: program.baseBranch, } module.exports = { files, flags } diff --git a/next-steps.md b/next-steps.md index 270a92b..f36bb6e 100644 --- a/next-steps.md +++ b/next-steps.md @@ -1,7 +1,7 @@ - [x] make checks opt in - [x] improve title message if there's only one file - [ ] pass ci build if failed check was added -- [ ] allow customisation of base branch, make main and master default +- [x] allow customisation of base branch, make main and master default - [ ] rewrite readme - [ ] match fuzzy rules from cache - [ ] add cumulative diff with master in title [#22](https://github.com/siddharthkp/bundlesize2/issues/22) From 61be25ae3248bb7649b9a2dccdfc4850e59c9180 Mon Sep 17 00:00:00 2001 From: Tom Ross Date: Fri, 22 Oct 2021 10:58:53 +0100 Subject: [PATCH 2/2] Fix summary --- cli/index.js | 12 ++++-------- cli/src/utils/summarize.js | 2 +- next-steps.md | 2 +- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/cli/index.js b/cli/index.js index 46116b9..5f8925b 100644 --- a/cli/index.js +++ b/cli/index.js @@ -13,26 +13,22 @@ const github = require('./src/reporters/github') const build = require('./src/reporters/build') const summarize = require('./src/utils/summarize') -/** - * Default branches to cache against when running through CI. - */ -const defaultBaseBranches = ['main', 'master']; - const run = async () => { const results = analyse(markDuplicates(files)) - const onBaseBranch = branch === flags.baseBranch || defaultBaseBranches.includes(branch) + const baseBranch = flags.baseBranch || 'main' - if (ci && onBaseBranch && !process.env.INTERNAL_SKIP_CACHE) { + if (ci && branch === baseBranch && !process.env.INTERNAL_SKIP_CACHE) { await cache.save(results) } const cachedResults = await cache.read() - const summary = summarize(results, cachedResults) + const summary = summarize(results, cachedResults, { baseBranch }) cli.report(summary) if (ci && flags.enableGitHubChecks) { const summaryWithoutColors = summarize(results, cachedResults, { colors: false, + baseBranch }) await github.report(summaryWithoutColors) } diff --git a/cli/src/utils/summarize.js b/cli/src/utils/summarize.js index dbf91e6..7be43ca 100644 --- a/cli/src/utils/summarize.js +++ b/cli/src/utils/summarize.js @@ -6,7 +6,7 @@ const { Colors, WithoutColors } = require('./colors') const summarize = (results, cachedResults = [], options = {}) => { const colors = options.colors === false ? WithoutColors : Colors - const baseBranch = options.baseBranch || 'master' + const baseBranch = options.baseBranch const status = results.status diff --git a/next-steps.md b/next-steps.md index f36bb6e..8c394e1 100644 --- a/next-steps.md +++ b/next-steps.md @@ -1,7 +1,7 @@ - [x] make checks opt in - [x] improve title message if there's only one file - [ ] pass ci build if failed check was added -- [x] allow customisation of base branch, make main and master default +- [x] allow customisation of base branch, make main default - [ ] rewrite readme - [ ] match fuzzy rules from cache - [ ] add cumulative diff with master in title [#22](https://github.com/siddharthkp/bundlesize2/issues/22)