-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathpublish.sh
More file actions
executable file
·109 lines (92 loc) · 3.36 KB
/
publish.sh
File metadata and controls
executable file
·109 lines (92 loc) · 3.36 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
#!/bin/bash
set -euo pipefail
if [ -z "${1:-}" ]; then
echo "Usage: $0 \"commit message\""
exit 1
fi
COMMIT_MSG="$1"
# Ensure we're on main branch
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
if [ "$CURRENT_BRANCH" != "main" ]; then
echo "❌ Error: Not on main branch (currently on: $CURRENT_BRANCH)"
echo "Run: git checkout main"
exit 1
fi
# Get version from package.json
VERSION=$(node -p "require('./package.json').version")
TAG="v${VERSION}"
echo "📦 Publishing version ${VERSION}..."
# Check if version tag already exists locally
if git rev-parse "$TAG" >/dev/null 2>&1; then
echo "❌ Error: Tag $TAG already exists locally."
echo "Did you forget to bump the version in package.json?"
exit 1
fi
# Check if version tag already exists on remote
if git ls-remote --tags origin | grep -q "refs/tags/$TAG"; then
echo "❌ Error: Tag $TAG already exists on remote."
echo "Did you forget to bump the version in package.json?"
exit 1
fi
# Compile
echo "🔨 Compiling..."
npm run compile || exit 1
# Package
echo "📦 Packaging..."
vsce package || exit 1
# Git commit/push
echo "💾 Committing and pushing..."
git add .
git commit -m "$COMMIT_MSG" || echo "Nothing to commit"
# Create tag
echo "🏷️ Creating tag ${TAG}..."
git tag "$TAG"
# Push to GitHub
echo "⬆️ Pushing to GitHub..."
git push origin main || exit 1
git push origin "$TAG" || exit 1
# Publish to Microsoft Marketplace
echo "📤 Publishing to VS Code Marketplace..."
if [ -z "${VSCE_PAT:-}" ]; then
echo "❌ Error: VSCE_PAT environment variable is not set."
echo "Run: export VSCE_PAT=<your-personal-access-token>"
exit 1
fi
vsce publish -p "$VSCE_PAT" || {
echo "❌ Marketplace publish failed. Rolling back tag..."
git tag -d "$TAG"
git push --delete origin "$TAG"
exit 1
}
# Publish to Open VSX
echo "📤 Publishing to Open VSX..."
npx ovsx publish -p "${OVSX_PAT:-$VSCE_PAT}" || {
echo "⚠️ Open VSX publish failed (VS Code Marketplace publish succeeded)"
}
# Create GitHub Release (auto-extracts changelog)
echo "📝 Creating GitHub Release..."
if command -v gh &> /dev/null; then
# Extract changelog entry for this version
CHANGELOG_ENTRY=$(awk "/## \[${VERSION}\]/,/## \[/" CHANGELOG.md | sed '$d')
# Create release with .vsix file attached
gh release create "$TAG" \
--title "$TAG" \
--notes "$CHANGELOG_ENTRY" \
./clprompter-${VERSION}.vsix || {
echo "⚠️ GitHub release creation failed (marketplace publish succeeded)"
echo "📝 Create release manually at: https://github.com/bobcozzi/clPrompter/releases/new?tag=${TAG}"
}
else
echo "⚠️ GitHub CLI (gh) not installed. Opening browser for manual release creation..."
echo "📝 Copy this changelog entry:"
echo "----------------------------------------"
awk "/## \[${VERSION}\]/,/## \[/" CHANGELOG.md | sed '$d'
echo "----------------------------------------"
open "https://github.com/bobcozzi/clPrompter/releases/new?tag=${TAG}" 2>/dev/null || {
echo "📝 Create release manually at: https://github.com/bobcozzi/clPrompter/releases/new?tag=${TAG}"
}
fi
echo "✅ Successfully published ${TAG}!"
echo "📦 VS Code Marketplace: https://marketplace.visualstudio.com/items?itemName=CozziResearch.clprompter"
echo "📦 Open VSX: https://open-vsx.org/extension/CozziResearch/clprompter"
echo "📝 GitHub Release: https://github.com/bobcozzi/clPrompter/releases/tag/${TAG}"