1+ #! /bin/bash
2+ set -e
3+
4+ # GitHub Release Creation Script
5+ # This script handles only the GitHub release creation.
6+ # Building and NPM publishing are handled by GitHub workflows.
7+ #
8+ # Usage: ./scripts/release.sh <version> [--dry-run]
9+ VERSION=$1
10+ DRY_RUN=false
11+
12+ # Validate version format
13+ if ! [[ " $VERSION " =~ ^[0-9]+\. [0-9]+\. [0-9]+ (-[a-zA-Z0-9]+\. [0-9]+)? $ ]]; then
14+ echo " ❌ Invalid version format: $VERSION "
15+ echo " Version must be in format: x.y.z or x.y.z-tag.n (e.g., 1.4.0 or 1.4.0-beta.3)"
16+ exit 1
17+ fi
18+
19+ # Check for arguments and set flags
20+ for arg in " $@ " ; do
21+ if [[ " $arg " == " --dry-run" ]]; then
22+ DRY_RUN=true
23+ fi
24+ done
25+
26+ if [ -z " $VERSION " ]; then
27+ echo " Usage: $0 <version> [--dry-run]"
28+ echo " "
29+ echo " This script creates a GitHub release and tag. The GitHub workflow will handle:"
30+ echo " - Building the project"
31+ echo " - Bundling AXe artifacts"
32+ echo " - Publishing to NPM"
33+ exit 1
34+ fi
35+
36+ # Detect current branch
37+ BRANCH=$( git rev-parse --abbrev-ref HEAD)
38+
39+ # Enforce branch policy - only allow releases from main
40+ if [[ " $BRANCH " != " main" ]]; then
41+ echo " ❌ Error: Releases must be created from the main branch."
42+ echo " Current branch: $BRANCH "
43+ echo " Please switch to main and try again."
44+ exit 1
45+ fi
46+
47+ run () {
48+ if $DRY_RUN ; then
49+ echo " [dry-run] $* "
50+ else
51+ eval " $@ "
52+ fi
53+ }
54+
55+ # Ensure we're in the project root (parent of scripts directory)
56+ cd " $( dirname " $0 " ) /.."
57+
58+ # Check if working directory is clean
59+ if ! git diff-index --quiet HEAD --; then
60+ echo " ❌ Error: Working directory is not clean."
61+ echo " Please commit or stash your changes before creating a release."
62+ exit 1
63+ fi
64+
65+ # Version update
66+ echo " "
67+ echo " 🔧 Setting version to $VERSION ..."
68+ run " npm version \" $VERSION \" --no-git-tag-version"
69+
70+ # README update
71+ echo " "
72+ echo " 📝 Updating version in README.md..."
73+ # Update version references in code examples using extended regex for precise semver matching
74+ run " sed -i '' -E 's/@[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9]+\.[0-9]+)?(-[a-zA-Z0-9]+\.[0-9]+)*(-[a-zA-Z0-9]+)?/@'" $VERSION " '/g' README.md"
75+
76+ # Update URL-encoded version references in shield links
77+ echo " 📝 Updating version in README.md shield links..."
78+ run " sed -i '' -E 's/npm%3Axcodebuildmcp%40[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9]+\.[0-9]+)?(-[a-zA-Z0-9]+\.[0-9]+)*(-[a-zA-Z0-9]+)?/npm%3Axcodebuildmcp%40'" $VERSION " '/g' README.md"
79+
80+ echo " "
81+ echo " 📝 Updating version in TOOL_OPTIONS.md..."
82+ run " sed -i '' -E 's/@[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9]+\.[0-9]+)?(-[a-zA-Z0-9]+\.[0-9]+)*(-[a-zA-Z0-9]+)?/@'" $VERSION " '/g' TOOL_OPTIONS.md"
83+
84+ # Git operations
85+ echo " "
86+ echo " 📦 Committing version changes..."
87+ run " git add package.json README.md TOOL_OPTIONS.md"
88+ run " git commit -m \" Release v$VERSION \" "
89+ run " git tag \" v$VERSION \" "
90+
91+ echo " "
92+ echo " 🚀 Pushing to origin..."
93+ run " git push origin $BRANCH --tags"
94+
95+ echo " "
96+ echo " 🎯 Tag pushed! GitHub will automatically:"
97+ echo " - Detect the new tag and start the release workflow"
98+ echo " - Bundle AXe artifacts"
99+ echo " - Build the project"
100+ echo " - Publish to NPM"
101+ echo " - Create the GitHub release"
102+ echo " "
103+ echo " ✅ Release v$VERSION initiated!"
104+ echo " 📝 Monitor the GitHub Actions workflow for completion"
105+ echo " 📦 View workflow: https://github.com/cameroncooke/XcodeBuildMCP/actions"
0 commit comments