Skip to content

Commit

Permalink
chore: fail prepare package for release if tag exists
Browse files Browse the repository at this point in the history
  • Loading branch information
Riccardo Cipolleschi committed Nov 10, 2022
1 parent 1453ef1 commit cc05168
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
8 changes: 8 additions & 0 deletions scripts/prepare-package-for-release.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
const {echo, exec, exit} = require('shelljs');
const yargs = require('yargs');
const {isReleaseBranch, parseVersion} = require('./version-utils');
const {checkIfTagExists} = require('./release-utils');

const argv = yargs
.option('r', {
Expand Down Expand Up @@ -49,6 +50,13 @@ const releaseVersion = argv.toVersion;
const isLatest = argv.latest;
const isDryRun = argv.dryRun;

if (checkIfTagExists(releaseVersion)) {
echo(`Tag v${releaseVersion} already exists.`);
echo('You may want to rollback the last commit');
echo('git reset --hard HEAD~1');
exit(1);
}

if (branch && !isReleaseBranch(branch) && !isDryRun) {
console.error(`This needs to be on a release branch. On branch: ${branch}`);
exit(1);
Expand Down
10 changes: 10 additions & 0 deletions scripts/release-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,18 @@ function generateiOSArtifacts(
return tarballOutputPath;
}

function checkIfTagExists(version) {
const {code, stdout} = exec('git tag -l', {silent: true});
if (code !== 0) {
throw new Error('Failed to retrieve the list of tags');
}
const tags = new Set(stdout.split('\n'));
return tags.has(`v${version}`);
}

module.exports = {
generateAndroidArtifacts,
generateiOSArtifacts,
publishAndroidArtifactsToMaven,
checkIfTagExists,
};

0 comments on commit cc05168

Please sign in to comment.