-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfinalize-release.sh
More file actions
executable file
·108 lines (91 loc) · 2.92 KB
/
finalize-release.sh
File metadata and controls
executable file
·108 lines (91 loc) · 2.92 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
#!/usr/bin/env bash
set -e
# Finalize release after PR merge
# Usage: ./scripts/finalize-release.sh [version]
# Example: ./scripts/finalize-release.sh v1.0.2
VERSION="${1}"
MAIN_BRANCH="${MAIN_BRANCH:-main}"
if [[ -z "$VERSION" ]]; then
# Try to read from saved state
if [[ -f .release-temp/pending-version ]]; then
VERSION=$(cat .release-temp/pending-version)
IS_PRERELEASE=$(cat .release-temp/is-prerelease)
echo "📦 Finalizing release: $VERSION"
else
echo "❌ Usage: ./scripts/finalize-release.sh [version]"
echo " Example: ./scripts/finalize-release.sh v1.0.2"
exit 1
fi
else
# Add 'v' prefix if not present
if [[ ! "$VERSION" =~ ^v ]]; then
VERSION="v$VERSION"
fi
IS_PRERELEASE=false
fi
# Check if gh CLI is installed
if ! command -v gh &> /dev/null; then
echo "❌ GitHub CLI (gh) is not installed."
exit 1
fi
# Ensure we're on main branch
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
if [[ "$CURRENT_BRANCH" != "$MAIN_BRANCH" ]]; then
echo "⚠️ Not on $MAIN_BRANCH branch. Switching..."
git checkout "$MAIN_BRANCH"
fi
# Pull latest changes
echo "📥 Pulling latest merged changes..."
git pull
# Verify the version in package.json matches
PACKAGE_VERSION="v$(node -p "require('./package.json').version")"
if [[ "$PACKAGE_VERSION" != "$VERSION" ]]; then
echo "❌ Version mismatch!"
echo " Expected: $VERSION"
echo " package.json: $PACKAGE_VERSION"
echo ""
echo " Make sure the release PR has been merged."
exit 1
fi
# Get current commit
CURRENT_COMMIT=$(git rev-parse HEAD)
echo "📌 Tagging commit: $CURRENT_COMMIT"
# Create and push tag
echo "🏷️ Creating tag $VERSION..."
git tag -a "$VERSION" -m "Release $VERSION"
git push origin "$VERSION"
# Generate release notes
echo ""
echo "📝 Generating release notes..."
# Try to get previous tag
PREVIOUS_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "")
if [[ -n "$PREVIOUS_TAG" ]]; then
COMPARE_LINK="https://github.com/waynebrantley/port-manager/compare/${PREVIOUS_TAG}...${VERSION}"
AUTO_NOTES="## What's Changed
Full changelog: $COMPARE_LINK"
else
AUTO_NOTES="Release $VERSION"
fi
# Create GitHub Release
echo "🎉 Creating GitHub Release..."
if [[ "$IS_PRERELEASE" == "true" ]]; then
gh release create "$VERSION" \
--title "$VERSION" \
--notes "$AUTO_NOTES" \
--prerelease
else
gh release create "$VERSION" \
--title "$VERSION" \
--notes "$AUTO_NOTES"
fi
# Clean up temp files
rm -rf .release-temp
echo ""
echo "✅ Release $VERSION finalized successfully!"
echo " 🏷️ Tag: $VERSION"
echo " 📦 npm package will be published automatically via GitHub Actions"
echo " 🔗 View release: https://github.com/waynebrantley/port-manager/releases/tag/$VERSION"
echo ""
echo "🔍 Monitor publish workflow:"
echo " https://github.com/waynebrantley/port-manager/actions"
echo ""