Skip to content

Commit

Permalink
chore: don't bump empty releases (aws#18151)
Browse files Browse the repository at this point in the history
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*
  • Loading branch information
rix0rrr authored and TikiTDO committed Feb 21, 2022
1 parent c22c1a5 commit a912632
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions scripts/bump.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const fs = require('fs');
const path = require('path');
const semver = require('semver');
const ver = require('./resolve-version');
const { exec } = require('child_process');
const { execSync } = require('child_process');

async function main() {
const releaseAs = process.argv[2] || 'minor';
Expand Down Expand Up @@ -39,6 +39,23 @@ async function main() {
// published.
opts.prerelease = ver.prerelease || 'rc';
console.error(`BUMP_CANDIDATE is set, so bumping version for testing (with the "${opts.prerelease}" prerelease tag)`);
} else {
// We're not running the bump in a regular pipeline, we're running it "for real" to do an actual release.
//
// In that case -- check if there have been changes since the last release. If not, there's no point in
// doing the release at all. Our customers won't appreciate a new version with 0 changes.
const prevVersion = ver.version;
const topLevelFileChanges = execSync(`git diff-tree --name-only v${prevVersion} HEAD`, { encoding: 'utf-8' }).split('\n').filter(x => x);

// We only release if there have been changes to files other than metadata files
// (for an empty release, the difference since the previous release is updates to json files and the changelog, through
// mergeback)
const anyInteresting = topLevelFileChanges.some(name => !name.includes('CHANGELOG') && !name.startsWith('version.'));

if (!anyInteresting) {
console.error(`No changes detected since last release -- we're done here.`);
return;
}
}

const majorVersion = semver.major(ver.version);
Expand All @@ -52,14 +69,14 @@ async function main() {
// 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.
await exec(`git tag -d $(git tag -l | grep -v '^v${majorVersion}.')`);
execSync(`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);

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

0 comments on commit a912632

Please sign in to comment.