forked from aws/aws-cdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbump.js
executable file
·62 lines (52 loc) · 2.4 KB
/
bump.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env node
const fs = require('fs');
const path = require('path');
const semver = require('semver');
const ver = require('./resolve-version');
const { exec } = require('child_process');
const repoRoot = path.join(__dirname, '..');
const releaseAs = process.argv[2] || 'minor';
const forTesting = process.env.BUMP_CANDIDATE || false;
async function main() {
if (releaseAs !== 'minor' && releaseAs !== 'patch') {
throw new Error(`invalid bump type "${releaseAs}". only "minor" (the default) and "patch" are allowed. major version bumps require *slightly* more intention`);
}
console.error(`Starting ${releaseAs} version bump`);
console.error('Current version information:', JSON.stringify(ver, undefined, 2));
const changelogPath = path.join(repoRoot, ver.changelogFile);
const opts = {
releaseAs: releaseAs,
skip: { tag: true },
packageFiles: [ { filename: ver.versionFile, type: 'json' } ],
bumpFiles: [ { filename: ver.versionFile, type: 'json' } ],
infile: ver.changelogFile,
prerelease: ver.prerelease,
scripts: {
postchangelog: `${path.join(__dirname, 'changelog-experimental-fix.sh')} ${changelogPath}`
}
};
if (forTesting) {
opts.skip.commit = true;
opts.skip.changelog = true;
// if we are on a "stable" branch, add a pre-release tag ("rc") to the
// version number as a safety in case this version will accidentally be
// published.
opts.prerelease = ver.prerelease || 'rc'
console.error(`BUMP_CANDIDATE is set, so bumping version for testing (with the "${opts.prerelease}" prerelease tag)`);
}
// `standard-release` will -- among other things -- create the changelog.
// However, on the v2 branch, `conventional-changelog` (which `standard-release` uses) gets confused
// and creates really muddled changelogs with both v1 and v2 releases intermingled, and lots of missing data.
// A super HACK here is to locally remove all version tags that don't match this major version prior
// to doing the bump, and then later fetching to restore those tags.
const majorVersion = semver.major(ver.version);
await exec(`git tag -d $(git tag -l | grep -v '^v${majorVersion}.')`);
// Delay loading standard-version until the git tags have been pruned.
const standardVersion = require('standard-version');
await standardVersion(opts);
await exec('git fetch -t');
}
main().catch(err => {
console.error(err.stack);
process.exit(1);
});