Skip to content

An AI-powered task-management system you can drop into Cursor, Lovable, Windsurf, Roo, and others.

chore: improve release check for release-check and release flow (#1095)

Ralph Khreishfcf14e09be8a
diff --git a/.github/scripts/check-pre-release-mode.mjs b/.github/scripts/check-pre-release-mode.mjs
new file mode 100755
index 00000000..32ac0f54
--- /dev/null
+++ b/.github/scripts/check-pre-release-mode.mjs
@@ -0,0 +1,102 @@
+#!/usr/bin/env node
+import { readFileSync, existsSync } from 'node:fs';
+import { join, dirname, resolve } from 'node:path';
+import { fileURLToPath } from 'node:url';
+
+const __filename = fileURLToPath(import.meta.url);
+const __dirname = dirname(__filename);
+
+// Get context from command line argument or environment
+const context = process.argv[2] || process.env.GITHUB_WORKFLOW || 'manual';
+
+function findRootDir(startDir) {
+ let currentDir = resolve(startDir);
+ while (currentDir !== '/') {
+ if (existsSync(join(currentDir, 'package.json'))) {
+ try {
+ const pkg = JSON.parse(
+ readFileSync(join(currentDir, 'package.json'), 'utf8')
+ );
+ if (pkg.name === 'task-master-ai' || pkg.repository) {
+ return currentDir;
+ }
+ } catch {}
+ }
+ currentDir = dirname(currentDir);
+ }
+ throw new Error('Could not find root directory');
+}
+
+function checkPreReleaseMode() {
+ console.log('πŸ” Checking if branch is in pre-release mode...');
+
+ const rootDir = findRootDir(__dirname);
+ const preJsonPath = join(rootDir, '.changeset', 'pre.json');
+
+ // Check if pre.json exists
+ if (!existsSync(preJsonPath)) {
+ console.log('βœ… Not in active pre-release mode - safe to proceed');
+ process.exit(0);
+ }
+
+ try {
+ // Read and parse pre.json
+ const preJsonContent = readFileSync(preJsonPath, 'utf8');
+ const preJson = JSON.parse(preJsonContent);
+
+ // Check if we're in active pre-release mode
+ if (preJson.mode === 'pre') {
+ console.error('❌ ERROR: This branch is in active pre-release mode!');
+ console.error('');
+
+ // Provide context-specific error messages
+ if (context === 'Release Check' || context === 'pull_request') {
+ console.error(
+ 'Pre-release mode must be exited before merging to main.'
+ );
+ console.error('');
+ console.error(
+ 'To fix this, run the following commands in your branch:'
+ );
+ console.error(' npx changeset pre exit');
+ console.error(' git add -u');
+ console.error(' git commit -m "chore: exit pre-release mode"');
+ console.error(' git push');
+ console.error('');
+ console.error('Then update this pull request.');
+ } else if (context === 'Release' || context === 'main') {
+ console.error(
+ 'Pre-release mode should only be used on feature branches, not main.'
+ );
+ console.error('');
+ console.error('To fix this, run the following commands locally:');
+ console.error(' npx changeset pre exit');
+ console.error(' git add -u');
+ console.error(' git commit -m "chore: exit pre-release mode"');
+ console.error(' git push origin main');
+ console.error('');
+ console.error('Then re-run this workflow.');
+ } else {
+ console.error('Pre-release mode must be exited before proceeding.');
+ console.error('');
+ console.error('To fix this, run the following commands:');
+ console.error(' npx changeset pre exit');
+ console.error(' git add -u');
+ console.error(' git commit -m "chore: exit pre-release mode"');
+ console.error(' git push');
+ }
+
+ process.exit(1);
+ }
+
+ console.log('βœ… Not in active pre-release mode - safe to proceed');
+ process.exit(0);
+ } catch (error) {
+ console.error(`❌ ERROR: Unable to parse .changeset/pre.json – aborting.`);
+ console.error(`Error details: ${error.message}`);
+ process.exit(1);
+ }
+}
+
+// Run the check
+checkPreReleaseMode();
diff --git a/.github/workflows/release-check.yml b/.github/workflows/release-check.yml
index 245ad4ad..4febf099 100644
--- a/.github/workflows/release-check.yml
+++ b/.github/workflows/release-check.yml
@@ -18,29 +18,4 @@ jobs:
fetch-depth: 0
- name: Check release mode
- run: |
- set -euo pipefail
- echo "πŸ” Checking if branch is in pre-release mode..."
-
- if [[ -f .changeset/pre.json ]]; then
- if ! PRE_MODE=$(jq -r '.mode' .changeset/pre.json 2>/dev/null); then
- echo "❌ ERROR: Unable to parse .changeset/pre.json – aborting merge."
- exit 1
- fi
- if [[ "$PRE_MODE" == "pre" ]]; then
- echo "❌ ERROR: This branch is in active pre-release mode!"
- echo ""
- echo "Pre-release mode must be exited before merging to main."
- echo ""
- echo "To fix this, run the following commands in your branch:"
- echo " npx changeset pre exit"
- echo " git add -u"
- echo " git commit -m 'chore: exit pre-release mode'"
- echo " git push"
- echo ""
- echo "Then update this pull request."
- exit 1
- fi
- fi
-
- echo "βœ… Not in active pre-release mode - PR can be merged"
+ run: node ./.github/scripts/check-pre-release-mode.mjs "pull_request"
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index 16b90248..3c439f4d 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -39,25 +39,7 @@ jobs:
timeout-minutes: 2
- name: Check pre-release mode
- run: |
- set -euo pipefail
- echo "πŸ” Checking pre-release mode status..."
- if [[ -f .changeset/pre.json ]]; then
- echo "❌ ERROR: Main branch is in pre-release mode!"
- echo ""
- echo "Pre-release mode should only be used on feature branches, not main."
- echo ""
- echo "To fix this, run the following commands locally:"
- echo " npx changeset pre exit"
- echo " git add -u"
- echo " git commit -m 'chore: exit pre-release mode'"
- echo " git push origin main"
- echo ""
- echo "Then re-run this workflow."
- exit 1
- fi
-
- echo "βœ… Not in pre-release mode - proceeding with release"
+ run: node ./.github/scripts/check-pre-release-mode.mjs "main"
- name: Create Release Pull Request or Publish to npm
uses: changesets/action@v1