-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrelease.sh
More file actions
executable file
·196 lines (163 loc) · 5.55 KB
/
release.sh
File metadata and controls
executable file
·196 lines (163 loc) · 5.55 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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#!/bin/bash
set -e
# Check if version is provided
if [ -z "$1" ]; then
echo "❌ Error: Version number required"
echo ""
echo "Usage: ./release.sh <version>"
echo "Example: ./release.sh v0.2.0"
exit 1
fi
VERSION=$1
BINARY_NAME="mem"
RELEASE_DIR="releases/$VERSION"
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m'
echo -e "${GREEN}🚀 Creating release $VERSION...${NC}"
echo ""
# Validate version format (should start with v)
if [[ ! $VERSION =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo -e "${RED}❌ Error: Version must be in format vX.Y.Z (e.g., v0.2.0)${NC}"
exit 1
fi
# Check if we're on main branch
BRANCH=$(git branch --show-current)
if [ "$BRANCH" != "main" ] && [ "$BRANCH" != "master" ]; then
echo -e "${YELLOW}⚠️ You are on branch '$BRANCH', not 'main' or 'master'${NC}"
read -p "Continue anyway? (y/n) " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
exit 1
fi
fi
# Check for uncommitted changes
if ! git diff-index --quiet HEAD --; then
echo -e "${YELLOW}⚠️ You have uncommitted changes.${NC}"
read -p "Commit them now? (y/n) " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
git add .
git commit -m "Pre-release cleanup for $VERSION"
else
echo "Please commit or stash changes first."
exit 1
fi
fi
# Build binaries with version embedded
echo "📦 Building binaries with version $VERSION..."
mkdir -p "$RELEASE_DIR"
LDFLAGS="-X main.Version=$VERSION"
echo " Building for Linux (amd64)..."
GOOS=linux GOARCH=amd64 go build -ldflags="$LDFLAGS" -o "$RELEASE_DIR/${BINARY_NAME}-linux-amd64" main.go
echo " Building for Linux (arm64)..."
GOOS=linux GOARCH=arm64 go build -ldflags="$LDFLAGS" -o "$RELEASE_DIR/${BINARY_NAME}-linux-arm64" main.go
echo " Building for macOS (amd64)..."
GOOS=darwin GOARCH=amd64 go build -ldflags="$LDFLAGS" -o "$RELEASE_DIR/${BINARY_NAME}-darwin-amd64" main.go
echo " Building for macOS (arm64)..."
GOOS=darwin GOARCH=arm64 go build -ldflags="$LDFLAGS" -o "$RELEASE_DIR/${BINARY_NAME}-darwin-arm64" main.go
echo " Building for Windows (amd64)..."
GOOS=windows GOARCH=amd64 go build -ldflags="$LDFLAGS" -o "$RELEASE_DIR/${BINARY_NAME}-windows-amd64.exe" main.go
echo " Building for Windows (arm64)..."
GOOS=windows GOARCH=arm64 go build -ldflags="$LDFLAGS" -o "$RELEASE_DIR/${BINARY_NAME}-windows-arm64.exe" main.go
# Create checksums
echo "🔐 Creating checksums..."
cd "$RELEASE_DIR"
sha256sum * > checksums.txt
cd ../..
echo -e "\n✅ Binaries built in $RELEASE_DIR/"
ls -lh "$RELEASE_DIR/"
echo ""
# Handle git tag
if git rev-parse "$VERSION" >/dev/null 2>&1; then
echo -e "${YELLOW}⚠️ Tag $VERSION already exists${NC}"
read -p "Delete existing tag and create new one? (y/n) " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
echo "Deleting existing tag..."
git tag -d "$VERSION"
git push origin ":refs/tags/$VERSION" 2>/dev/null || true
echo "Creating new tag..."
git tag -a "$VERSION" -m "Release $VERSION"
git push origin "$VERSION"
else
echo "Keeping existing tag."
fi
else
echo "🏷️ Creating and pushing git tag $VERSION..."
git tag -a "$VERSION" -m "Release $VERSION"
git push origin "$VERSION"
fi
# Push any committed changes
git push origin "$BRANCH" 2>/dev/null || true
# Check if gh CLI is installed
if command -v gh &> /dev/null; then
echo "📝 Creating GitHub release..."
# Check if release already exists
if gh release view "$VERSION" &>/dev/null; then
echo -e "${YELLOW}⚠️ Release $VERSION already exists on GitHub${NC}"
read -p "Delete existing release and create new one? (y/n) " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
echo "Deleting existing release..."
gh release delete "$VERSION" -y
else
echo "Skipping release creation."
exit 0
fi
fi
# Generate release notes
RELEASE_NOTES=$(cat <<-END
## What's New in $VERSION
### Added
- Version flag (\`--version\`) to display current version
- Version embedded in binaries at build time
- Comprehensive unit tests with 81%+ coverage
- Integration tests against real Rails API
- Uninstall command (\`mem uninstall\`)
- Mock server for testing
- Test documentation
### Improved
- Better error handling in API client
- Binary path detection in tests
- Makefile with coverage target
- Test isolation with temporary config directories
### Fixed
- Integration test binary path issues
- Config file handling in tests
- Revoke token error handling
## Installation
\`\`\`bash
curl -sSL https://raw.githubusercontent.com/bitcoiners/ai-memoria-cli/main/get.sh | bash
\`\`\`
## Verify Version
\`\`\`bash
mem --version
\`\`\`
## Checksums
\`\`\`
$(cat releases/$VERSION/checksums.txt)
\`\`\`
END
)
# Create release
gh release create "$VERSION" \
--title "AI Memoria CLI $VERSION" \
--notes "$RELEASE_NOTES" \
releases/"$VERSION"/*
echo -e "\n${GREEN}✅ Release created: https://github.com/bitcoiners/ai-memoria-cli/releases/tag/$VERSION${NC}"
else
echo -e "${YELLOW}⚠️ GitHub CLI (gh) not installed${NC}"
echo ""
echo "Manual steps:"
echo "1. Push changes: git push origin $BRANCH"
echo "2. Push tags: git push --tags"
echo "3. Go to: https://github.com/bitcoiners/ai-memoria-cli/releases"
echo "4. Click 'Create a new release'"
echo "5. Use tag: $VERSION"
echo "6. Upload files from releases/$VERSION/"
echo "7. Publish release"
fi
echo ""
echo -e "${GREEN}🎉 Release $VERSION complete!${NC}"