Skip to content

Commit

Permalink
chore: fix candidate bump invocation (#11318)
Browse files Browse the repository at this point in the history
Allow versions with pre-release tags in stable branches to allow BUMP_CANDIDATE to work. Otherwise, after the bump, any call to `resolve-version` will fail because there is a mismatch between the actual version and `release.json`.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
iliapolo committed Nov 5, 2020
1 parent 246404d commit f77dbde
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 16 deletions.
2 changes: 1 addition & 1 deletion bump.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
set -euo pipefail
scriptdir=$(cd $(dirname $0) && pwd)
cd ${scriptdir}
yarn
yarn --frozen-lockfile
${scriptdir}/scripts/bump.js ${1:-minor}
2 changes: 1 addition & 1 deletion scripts/bump.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ async function main() {

if (forTesting) {
opts.skip.commit = true;
opts.changelog = 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
Expand Down
9 changes: 4 additions & 5 deletions scripts/resolve-version-lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,10 @@ function resolveVersion(rootdir) {
if (!currentVersion.startsWith(`${majorVersion}.`)) {
throw new Error(`current version "${currentVersion}" does not use the expected major version ${majorVersion}`);
}
if (releaseType === 'stable') {
if (currentVersion.includes('-')) {
throw new Error(`found pre-release tag in version specified in ${versionFile} is ${currentVersion} but "releaseType"" is set to "stable"`);
}
} else {
// if this is a pre-release, make sure current version includes the
// pre-release tag (e.g. "1.0.0-alpha.0"). we allow stable branches to bump to
// a pre-release for testing purposes when BUMP_CANDIDATE=true (see bump.js)
if (releaseType !== 'stable') {
if (!currentVersion.includes(`-${releaseType}.`)) {
throw new Error(`could not find pre-release tag "${releaseType}" in current version "${currentVersion}" defined in ${versionFile}`);
}
Expand Down
24 changes: 15 additions & 9 deletions scripts/script-tests/resolve-version.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,21 @@ happy({
}
});

happy({
name: 'to support BUMP_CANDIDATE stable branches can be bumped towards a pre-release',
inputs: {
'release.json': { majorVersion: 2, releaseType: 'stable' },
'version.v2.json': { version: '2.0.0-rc.0' }
},
expected: {
changelogFile: 'CHANGELOG.v2.md',
marker: '0.0.0',
prerelease: undefined,
version: '2.0.0-rc.0',
versionFile: 'version.v2.json'
}
});

failure({
name: 'invalid release type',
inputs: { 'release.json': { majorVersion: 2, releaseType: 'build' } },
Expand Down Expand Up @@ -113,15 +128,6 @@ failure({
expected: 'could not find pre-release tag "alpha" in current version "2.0.0-rc.0" defined in version.v2.json'
});

failure({
name: 'actual version not the right pre-release (stable)',
inputs: {
'release.json': { majorVersion: 2, releaseType: 'stable' },
'version.v2.json': { version: '2.0.0-alpha.0' }
},
expected: 'found pre-release tag in version specified in version.v2.json is 2.0.0-alpha.0 but "releaseType"" is set to "stable"'
});

function happy({ name, inputs, expected } = opts) {
test(name, () => {
const tmpdir = stage(inputs);
Expand Down

0 comments on commit f77dbde

Please sign in to comment.