forked from cortexkit/magic-context
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrelease.sh
More file actions
executable file
·137 lines (113 loc) · 3.77 KB
/
Copy pathrelease.sh
File metadata and controls
executable file
·137 lines (113 loc) · 3.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#!/usr/bin/env bash
set -euo pipefail
# release.sh — Tag and push a new magic-context release
#
# Usage:
# ./scripts/release.sh 0.1.0 # release v0.1.0
# ./scripts/release.sh 0.1.0 --dry # preview without committing/pushing
#
# What it does:
# 1. Validates the version is semver
# 2. Checks for clean working tree (no uncommitted changes)
# 3. Syncs version in package.json
# 4. Runs pre-release checks (lint, typecheck, build)
# 5. Commits the version bump
# 6. Creates a git tag (v0.1.0)
# 7. Pushes commit + tag to origin
# 8. CI takes over: test → build → publish npm + GitHub release
VERSION="${1:-}"
DRY="${2:-}"
if [[ -z "$VERSION" ]]; then
echo "Usage: ./scripts/release.sh <version> [--dry]"
echo " e.g. ./scripts/release.sh 0.1.0"
exit 1
fi
if ! [[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9.]+)?(\+[a-zA-Z0-9.]+)?$ ]]; then
echo "Error: '$VERSION' is not valid semver (expected X.Y.Z)"
exit 1
fi
TAG="v$VERSION"
# Check if tag already exists
if git rev-parse "$TAG" >/dev/null 2>&1; then
echo "Error: tag '$TAG' already exists"
exit 1
fi
# Check for clean working tree
if [[ -n "$(git status --porcelain)" ]]; then
echo "Error: working tree is not clean — commit or stash changes first"
git status --short
exit 1
fi
# Check we're on main/master
BRANCH=$(git branch --show-current)
if [[ "$BRANCH" != "main" && "$BRANCH" != "master" ]]; then
echo "Warning: releasing from '$BRANCH' (not main/master)"
read -rp "Continue? [y/N] " confirm
if [[ "$confirm" != "y" && "$confirm" != "Y" ]]; then
echo "Aborted."
exit 1
fi
fi
echo ""
echo " Releasing magic-context $TAG"
echo " ─────────────────────────────"
echo ""
# Step 1: Dry run preview
if [[ "$DRY" == "--dry" ]]; then
echo "→ Version sync (dry run):"
bun scripts/version-sync.mjs "$VERSION" --dry-run
echo ""
echo "[DRY RUN] Would commit, tag $TAG, and push to origin."
exit 0
fi
# Step 2: Pre-release checks
echo "→ Running pre-release checks..."
echo ""
PLUGIN_DIR="packages/plugin"
echo " bun lint..."
bun run --cwd "$PLUGIN_DIR" lint 2>&1 || { echo "Error: Lint failed"; exit 1; }
echo " bun typecheck..."
bun run --cwd "$PLUGIN_DIR" typecheck 2>&1 || { echo "Error: Typecheck failed"; exit 1; }
echo " bun test..."
# Bun has a known panic crash after tests complete (https://github.com/oven-sh/bun/issues/XXXXX).
# All tests pass but the process exits non-zero. Check output for failures instead of exit code.
TEST_OUTPUT=$(bun test --cwd "$PLUGIN_DIR" 2>&1 || true)
echo "$TEST_OUTPUT"
if echo "$TEST_OUTPUT" | grep -q "[1-9][0-9]* fail"; then
echo "Error: Tests failed"
exit 1
fi
echo " bun build..."
bun run --cwd "$PLUGIN_DIR" build 2>&1 || { echo "Error: Build failed"; exit 1; }
# Copy root README into plugin package for npm publishing
cp README.md "$PLUGIN_DIR/README.md"
echo " ✓ All checks passed"
echo ""
# Step 3: Generate JSON Schema
echo "→ Generating JSON Schema..."
bun packages/plugin/scripts/build-schema.ts || { echo "Error: Schema generation failed"; exit 1; }
echo ""
# Step 4: Sync version
echo "→ Syncing version to $VERSION..."
bun scripts/version-sync.mjs "$VERSION"
echo ""
# Step 4: Commit (skip if versions were already at target)
echo "→ Committing version bump..."
git add -A
if git diff --cached --quiet; then
echo " (no changes — version already at $VERSION)"
else
git commit -m "release: $TAG"
fi
# Step 5: Tag
echo "→ Creating tag $TAG..."
git tag -a "$TAG" -m "Release $TAG"
echo ""
# Step 6: Push
echo "→ Pushing to origin..."
git push origin "$BRANCH"
git push origin "$TAG"
echo ""
echo " ✓ Released $TAG"
echo " → GitHub Actions will now: test → build → publish"
echo " → Watch: https://github.com/cortexkit/opencode-magic-context/actions"