Fix: add check for current branch to ensure it's "release"

This commit is contained in:
Louis Lam
2025-09-05 12:46:07 +08:00
parent a133d1269d
commit b478141416
3 changed files with 21 additions and 2 deletions

View File

@@ -8,7 +8,7 @@ import {
checkVersionFormat,
getRepoNames,
pressAnyKey,
execSync, uploadArtifacts,
execSync, uploadArtifacts, checkReleaseBranch,
} from "./lib.mjs";
import semver from "semver";
@@ -23,6 +23,9 @@ if (!githubToken) {
process.exit(1);
}
// Check if the current branch is "release"
checkReleaseBranch();
// Check if the version is a valid semver
checkVersionFormat(version);

View File

@@ -7,7 +7,7 @@ import {
checkTagExists,
checkVersionFormat,
getRepoNames,
pressAnyKey, execSync, uploadArtifacts
pressAnyKey, execSync, uploadArtifacts, checkReleaseBranch
} from "./lib.mjs";
const repoNames = getRepoNames();
@@ -21,6 +21,9 @@ if (!githubToken) {
process.exit(1);
}
// Check if the current branch is "release"
checkReleaseBranch();
// Check if the version is a valid semver
checkVersionFormat(version);

View File

@@ -249,3 +249,16 @@ export function execSync(cmd) {
console.info(`[DRY RUN] ${cmd}`);
}
}
/**
* Check if the current branch is "release"
* @returns {void}
*/
export function checkReleaseBranch() {
const res = childProcess.spawnSync("git", [ "rev-parse", "--abbrev-ref", "HEAD" ]);
const branch = res.stdout.toString().trim();
if (branch !== "release") {
console.error(`Current branch is ${branch}, please switch to "release" branch`);
process.exit(1);
}
}