Skip to content

Commit fa5b2bb

Browse files
authored
chore: don't bump empty releases (#18151)
v2.3.0 was an empty release compared to v2.2.0, because the forward merge had been failing. It's pointless to release an empty release, so have the bump script check for this situation, and not do anything. Slightly complicated from the obvious logic which would only check commit history: in practice the merge-back commit gets added on top. So we check the actual file changes since the previous release. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent eca1e74 commit fa5b2bb

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

scripts/bump.js

+20-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const fs = require('fs');
44
const path = require('path');
55
const semver = require('semver');
66
const ver = require('./resolve-version');
7-
const { exec } = require('child_process');
7+
const { execSync } = require('child_process');
88

99
async function main() {
1010
const releaseAs = process.argv[2] || 'minor';
@@ -39,6 +39,23 @@ async function main() {
3939
// published.
4040
opts.prerelease = ver.prerelease || 'rc';
4141
console.error(`BUMP_CANDIDATE is set, so bumping version for testing (with the "${opts.prerelease}" prerelease tag)`);
42+
} else {
43+
// We're not running the bump in a regular pipeline, we're running it "for real" to do an actual release.
44+
//
45+
// In that case -- check if there have been changes since the last release. If not, there's no point in
46+
// doing the release at all. Our customers won't appreciate a new version with 0 changes.
47+
const prevVersion = ver.version;
48+
const topLevelFileChanges = execSync(`git diff-tree --name-only v${prevVersion} HEAD`, { encoding: 'utf-8' }).split('\n').filter(x => x);
49+
50+
// We only release if there have been changes to files other than metadata files
51+
// (for an empty release, the difference since the previous release is updates to json files and the changelog, through
52+
// mergeback)
53+
const anyInteresting = topLevelFileChanges.some(name => !name.includes('CHANGELOG') && !name.startsWith('version.'));
54+
55+
if (!anyInteresting) {
56+
console.error(`No changes detected since last release -- we're done here.`);
57+
return;
58+
}
4259
}
4360

4461
const majorVersion = semver.major(ver.version);
@@ -52,14 +69,14 @@ async function main() {
5269
// and creates really muddled changelogs with both v1 and v2 releases intermingled, and lots of missing data.
5370
// A super HACK here is to locally remove all version tags that don't match this major version prior
5471
// to doing the bump, and then later fetching to restore those tags.
55-
await exec(`git tag -d $(git tag -l | grep -v '^v${majorVersion}.')`);
72+
execSync(`git tag -d $(git tag -l | grep -v '^v${majorVersion}.')`);
5673

5774
// Delay loading standard-version until the git tags have been pruned.
5875
const standardVersion = require('standard-version');
5976
await standardVersion(opts);
6077

6178
// fetch back the tags, and only the tags, removed locally above
62-
await exec('git fetch origin "refs/tags/*:refs/tags/*"');
79+
execSync('git fetch origin "refs/tags/*:refs/tags/*"');
6380
} else {
6481
// this is incredible, but passing this option to standard-version actually makes it crash!
6582
// good thing we're getting rid of it...

0 commit comments

Comments
 (0)