diff --git a/scripts/bump-oss-version.js b/scripts/bump-oss-version.js index ed14b1015270a0..b76f161ad874cd 100755 --- a/scripts/bump-oss-version.js +++ b/scripts/bump-oss-version.js @@ -21,6 +21,7 @@ const request = require('request'); const {getBranchName, exitIfNotOnGit} = require('./scm-utils'); const {parseVersion, isReleaseBranch} = require('./version-utils'); +const {failIfTagExists} = require('./release-utils'); let argv = yargs .option('r', { @@ -75,6 +76,7 @@ async function main() { ); const token = argv.token; const releaseVersion = argv.toVersion; + failIfTagExists(releaseVersion); const {pushed} = await inquirer.prompt({ type: 'confirm', diff --git a/scripts/prepare-package-for-release.js b/scripts/prepare-package-for-release.js index 4f89743c618827..2191e8eb026acb 100755 --- a/scripts/prepare-package-for-release.js +++ b/scripts/prepare-package-for-release.js @@ -21,6 +21,7 @@ const {echo, exec, exit} = require('shelljs'); const yargs = require('yargs'); const {isReleaseBranch, parseVersion} = require('./version-utils'); +const {failIfTagExists} = require('./release-utils'); const argv = yargs .option('r', { @@ -49,6 +50,8 @@ const releaseVersion = argv.toVersion; const isLatest = argv.latest; const isDryRun = argv.dryRun; +failIfTagExists(releaseVersion); + if (branch && !isReleaseBranch(branch) && !isDryRun) { console.error(`This needs to be on a release branch. On branch: ${branch}`); exit(1); diff --git a/scripts/release-utils.js b/scripts/release-utils.js index f2e8cbb6032cd4..e5bab0347ea97d 100644 --- a/scripts/release-utils.js +++ b/scripts/release-utils.js @@ -111,8 +111,27 @@ function generateiOSArtifacts( return tarballOutputPath; } +function failIfTagExists(version) { + 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); + } +} + +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, + failIfTagExists, };