Skip to content

Commit ee46421

Browse files
author
Riccardo Cipolleschi
committed
chore: fail prepare package for release if tag exists
1 parent 1453ef1 commit ee46421

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

scripts/bump-oss-version.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const request = require('request');
2121
const {getBranchName, exitIfNotOnGit} = require('./scm-utils');
2222

2323
const {parseVersion, isReleaseBranch} = require('./version-utils');
24+
const {failIfTagExists} = require('./release-utils');
2425

2526
let argv = yargs
2627
.option('r', {
@@ -75,6 +76,7 @@ async function main() {
7576
);
7677
const token = argv.token;
7778
const releaseVersion = argv.toVersion;
79+
failIfTagExists(releaseVersion);
7880

7981
const {pushed} = await inquirer.prompt({
8082
type: 'confirm',

scripts/prepare-package-for-release.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
const {echo, exec, exit} = require('shelljs');
2222
const yargs = require('yargs');
2323
const {isReleaseBranch, parseVersion} = require('./version-utils');
24+
const {failIfTagExists} = require('./release-utils');
2425

2526
const argv = yargs
2627
.option('r', {
@@ -49,6 +50,8 @@ const releaseVersion = argv.toVersion;
4950
const isLatest = argv.latest;
5051
const isDryRun = argv.dryRun;
5152

53+
failIfTagExists(releaseVersion);
54+
5255
if (branch && !isReleaseBranch(branch) && !isDryRun) {
5356
console.error(`This needs to be on a release branch. On branch: ${branch}`);
5457
exit(1);

scripts/release-utils.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,27 @@ function generateiOSArtifacts(
111111
return tarballOutputPath;
112112
}
113113

114+
function failIfTagExists(version) {
115+
if (checkIfTagExists(releaseVersion)) {
116+
echo(`Tag v${releaseVersion} already exists.`);
117+
echo('You may want to rollback the last commit');
118+
echo('git reset --hard HEAD~1');
119+
exit(1);
120+
}
121+
}
122+
123+
function checkIfTagExists(version) {
124+
const {code, stdout} = exec('git tag -l', {silent: true});
125+
if (code !== 0) {
126+
throw new Error('Failed to retrieve the list of tags');
127+
}
128+
const tags = new Set(stdout.split('\n'));
129+
return tags.has(`v${version}`);
130+
}
131+
114132
module.exports = {
115133
generateAndroidArtifacts,
116134
generateiOSArtifacts,
117135
publishAndroidArtifactsToMaven,
136+
failIfTagExists,
118137
};

0 commit comments

Comments
 (0)