Skip to content

Commit

Permalink
chore: refine make tag script (#1720)
Browse files Browse the repository at this point in the history
  • Loading branch information
baurine authored Aug 23, 2024
1 parent 0db7bc6 commit 383cf60
Showing 1 changed file with 57 additions and 10 deletions.
67 changes: 57 additions & 10 deletions scripts/create_release_tag.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@

const { execSync } = require('child_process');

const readline = require('readline');

const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});

// rl.on('close', () => {
// console.log('exit')
// process.exit(0);
// });

function getGitBranch() {
// master, release-7.6
return execSync('git rev-parse --abbrev-ref HEAD').toString().trim();
Expand All @@ -20,20 +32,27 @@ function getGitLatestTag() {
return execSync('git describe --tags --dirty --always').toString().trim();
}

function question(nextTag) {
rl.question(`Do you want to create tag ${nextTag}? (y or enter continue, others exit): `, (answer) => {
if (answer.toLowerCase() === 'y' || answer.toLowerCase() === '') {
execSync(`git tag ${nextTag}`);
console.log(`Created tag ${nextTag}`)
process.exit(0);
} else {
console.log('Cancel create tag')
process.exit(0);
}
})
}

function createReleaseTag() {
const branch = getGitBranch();

if (!branch.match(/release-\d.\d$/)) {
console.error('Err: this is not a valid release branch');
return
}

const branchVer = branch.replace('release-', '');
const latestTag = getGitLatestTag().replace('-fips', '');

if (!latestTag.startsWith(`v${branchVer}.`)) {
console.error(`Err: latest tag ${latestTag} doesn't match the branch ${branch}, you need to add the new tag manually`);
return
process.exit(1)
}

const shortSha = getGitShortSha();
Expand All @@ -50,8 +69,36 @@ function createReleaseTag() {
const prefix = latestTag.substring(0, splitPos);
nextTag = `${prefix}-${shortSha}`;
}
execSync(`git tag ${nextTag}`);
console.log(`Created tag ${nextTag}`)

question(nextTag)
}

function createMasterTag() {
const latestTag = getGitLatestTag();
// the latest tag must like vX.Y.0-alpha, likes `v8.4.0-alpha`
if (!latestTag.match(/^v\d+\.\d+.0-alpha$/)) {
console.error(`Err: latest tag ${latestTag} is not a valid alpha tag`)
process.exit(1)
}
const splitPos = latestTag.indexOf('-');
const prefix = latestTag.substring(0, splitPos);
const shortSha = getGitShortSha();
const nextTag = `${prefix}-${shortSha}`

question(nextTag)
}

function createTag() {
const branch = getGitBranch();

if (branch.match(/^release-\d+\.\d+$/)) {
createReleaseTag()
} else if (branch === 'master') {
createMasterTag()
} else {
console.error('Err: this is not a valid branch that can be tagged');
process.exit(1)
}
}

createReleaseTag()
createTag()

0 comments on commit 383cf60

Please sign in to comment.