diff --git a/cli/index.js b/cli/index.js index 20c8e2b..5f8925b 100644 --- a/cli/index.js +++ b/cli/index.js @@ -15,18 +15,20 @@ const summarize = require('./src/utils/summarize') const run = async () => { const results = analyse(markDuplicates(files)) + const baseBranch = flags.baseBranch || 'main' - if (ci && branch === 'master' && !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/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/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 270a92b..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 -- [ ] 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)