Skip to content

Commit 134a96a

Browse files
basetenAlex Prokop
and
Alex Prokop
authored
add check for master branch prerelease script (#400)
Co-authored-by: Alex Prokop <[email protected]>
1 parent 70959ad commit 134a96a

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"clean": "rimraf packages/*/dist packages/*/build",
1212
"lint": "eslint .",
1313
"prepare": "husky install",
14-
"prerelease": "npm run lint && npm run test:force && npm run build:force",
14+
"prerelease": "./scripts/checkReleaseBranch.mjs && npm run lint && npm run test:force && npm run build:force",
1515
"release": "lerna publish --no-private",
1616
"test": "nx run-many --target=test --all --parallel",
1717
"test:force": "nx run-many --target=test --all --parallel --skip-nx-cache",

scripts/checkReleaseBranch.mjs

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env node
2+
import process from 'node:process';
3+
import { execSync } from 'child_process';
4+
5+
const RELEASE_BRANCH = 'master';
6+
const CONSOLE_COLOR_RED = '\x1b[31m';
7+
const CONSOLE_COLOR_RESET = '\x1b[0m';
8+
9+
const status = execSync('git status', { encoding: 'utf-8' });
10+
11+
const res = status.match(/on branch (.+)\n/i);
12+
const currentBranch = res?.[1];
13+
14+
if (currentBranch !== RELEASE_BRANCH)
15+
{
16+
const messageParts = [
17+
CONSOLE_COLOR_RED,
18+
`You are on the "${currentBranch}" branch and not the release branch: "${RELEASE_BRANCH}"!`,
19+
CONSOLE_COLOR_RESET,
20+
];
21+
22+
console.error(messageParts.join(''));
23+
process.exit(1);
24+
}
25+
26+
process.exit(0);

0 commit comments

Comments
 (0)