-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathrelease.sh
More file actions
executable file
·204 lines (163 loc) · 5.69 KB
/
release.sh
File metadata and controls
executable file
·204 lines (163 loc) · 5.69 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
197
198
199
200
201
202
203
204
#!/bin/bash
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Function to print colored output
print_info() {
echo -e "${BLUE}[INFO]${NC} $1"
}
print_success() {
echo -e "${GREEN}[SUCCESS]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
# Check if version is provided
if [ -z "$1" ]; then
print_error "Usage: $0 <version>"
print_info "Example: $0 1.5.0"
print_info ""
print_info "This script can be run:"
print_info " • Locally: ./release.sh 1.5.0"
print_info " • Via GitHub Actions: Go to Actions → Release → Run workflow"
exit 1
fi
VERSION="$1"
RELEASE_BRANCH="release/v${VERSION}"
CURRENT_DATE=$(date +%Y-%m-%d)
# Validate version format (semantic versioning)
if ! [[ $VERSION =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
print_error "Version must follow semantic versioning format (e.g., 1.2.3)"
exit 1
fi
# Detect if running in GitHub Actions
if [ -n "$GITHUB_ACTIONS" ]; then
print_info "Running in GitHub Actions environment"
else
print_info "Running locally"
fi
print_info "Starting release process for version ${VERSION}"
# Check if we're on develop branch
CURRENT_BRANCH=$(git branch --show-current)
if [ "$CURRENT_BRANCH" != "develop" ]; then
print_error "You must be on the 'develop' branch to create a release"
print_info "Current branch: $CURRENT_BRANCH"
exit 1
fi
# Check if working directory is clean
if [ -n "$(git status --porcelain)" ]; then
print_error "Working directory is not clean. Please commit or stash your changes."
git status --short
exit 1
fi
# Check if develop is up to date
print_info "Checking if develop branch is up to date..."
git fetch origin
LOCAL=$(git rev-parse develop)
REMOTE=$(git rev-parse origin/develop)
if [ "$LOCAL" != "$REMOTE" ]; then
print_error "Your develop branch is not up to date with origin/develop"
print_info "Please run: git pull origin develop"
exit 1
fi
# Check if release branch already exists
if git show-ref --verify --quiet "refs/heads/$RELEASE_BRANCH"; then
print_error "Release branch $RELEASE_BRANCH already exists"
exit 1
fi
# Check if tag already exists
if git show-ref --verify --quiet "refs/tags/$VERSION"; then
print_error "Tag $VERSION already exists"
exit 1
fi
# Check if CHANGELOG has [Next] section
if ! grep -q "\[Next\]" CHANGELOG.md; then
print_warning "No [Next] section found in CHANGELOG.md"
print_info "Please add a [Next] section with your changes before creating a release"
exit 1
fi
print_info "All pre-checks passed"
# Create release branch
print_info "Creating release branch: $RELEASE_BRANCH"
git checkout -b "$RELEASE_BRANCH"
# Update version in package.json
print_info "Updating version in package.json"
sed -i.bak "s/\"version\": \"[^\"]*\"/\"version\": \"$VERSION\"/" package.json
rm package.json.bak
# Update version in config.yaml
print_info "Updating version in ha_addon/config.yaml"
sed -i.bak "s/version: \"[^\"]*\"/version: \"$VERSION\"/" ha_addon/config.yaml
rm ha_addon/config.yaml.bak
# Update CHANGELOG.md
print_info "Updating CHANGELOG.md"
# Replace [Next] with [VERSION] - DATE
sed -i.bak "s/\[Next\]/[$VERSION] - $CURRENT_DATE/" CHANGELOG.md
rm CHANGELOG.md.bak
# Run npm install to update package-lock.json
print_info "Updating package-lock.json"
npm install
# Show the changes
print_info "Changes to be committed:"
git diff --cached package.json ha_addon/config.yaml CHANGELOG.md package-lock.json || git diff package.json ha_addon/config.yaml CHANGELOG.md package-lock.json
# Stage and commit changes
git add package.json ha_addon/config.yaml CHANGELOG.md package-lock.json
git commit -m "Release v${VERSION}
- Update version in package.json to ${VERSION}
- Update version in config.yaml to ${VERSION}
- Update CHANGELOG.md with release date
- Update package-lock.json"
print_success "Created release commit"
# Push release branch
print_info "Pushing release branch to origin"
git push origin "$RELEASE_BRANCH"
# Switch to main and merge
print_info "Switching to main branch"
git checkout main
git pull origin main
print_info "Merging release branch into main"
git merge "$RELEASE_BRANCH" --no-ff -m "Merge release v${VERSION}"
# Create and push tag
print_info "Creating tag ${VERSION}"
git tag "${VERSION}"
print_info "Pushing main branch and tag"
git push origin main
git push origin "${VERSION}"
# Switch back to develop and sync with main
print_info "Switching back to develop branch"
git checkout develop
print_info "Syncing develop with main to include release changes"
git merge main --no-ff -m "Sync develop with main after release v${VERSION}"
# Add new [Next] section to CHANGELOG if it doesn't exist
if ! grep -q "\[Next\]" CHANGELOG.md; then
print_info "Adding new [Next] section to CHANGELOG.md"
# Insert new [Next] section after the first line
sed -i.bak '1a\
## [Next]\
\
' CHANGELOG.md
rm CHANGELOG.md.bak
git add CHANGELOG.md
git commit -m "Add new [Next] section to CHANGELOG.md"
fi
print_info "Pushing updated develop branch"
git push origin develop
print_success "Release v${VERSION} completed successfully!"
print_info ""
print_info "Summary:"
print_info "- Release branch: $RELEASE_BRANCH (kept for potential hotfixes)"
print_info "- Main branch: Updated to v${VERSION}"
print_info "- Tag: ${VERSION} created"
print_info "- Develop branch: Ready for next development cycle"
print_info ""
print_info "Next steps:"
print_info "1. Verify the release on the main branch"
print_info "2. Check that CI/CD pipelines are triggered correctly"
print_info "3. Monitor for any issues with the release"
print_info "4. Continue development on the develop branch"