-
-
Notifications
You must be signed in to change notification settings - Fork 114
Expand file tree
/
Copy pathrelease.sh
More file actions
executable file
·264 lines (218 loc) · 7.95 KB
/
Copy pathrelease.sh
File metadata and controls
executable file
·264 lines (218 loc) · 7.95 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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
#!/bin/bash
################################################################################
# ReplicaDB Release Script
#
# Automates the release process:
# 1. Validates version format (semantic versioning)
# 2. Updates pom.xml with new version
# 3. Commits version bump
# 4. Creates git tag
# 5. Pushes to origin (CI/CD builds release automatically)
#
# Usage: ./release.sh <version>
# Example: ./release.sh 0.16.0
################################################################################
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
# Configuration
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
POM_FILE="${REPO_ROOT}/pom.xml"
README_FILE="${REPO_ROOT}/README.md"
################################################################################
# Functions
################################################################################
print_header() {
echo -e "${BLUE}╔════════════════════════════════════════════════════════╗${NC}"
echo -e "${BLUE}║${NC} $1"
echo -e "${BLUE}╚════════════════════════════════════════════════════════╝${NC}"
}
print_success() {
echo -e "${GREEN}✓${NC} $1"
}
print_error() {
echo -e "${RED}✗${NC} $1"
}
print_warning() {
echo -e "${YELLOW}⚠${NC} $1"
}
print_info() {
echo -e "${BLUE}ℹ${NC} $1"
}
validate_version() {
local version=$1
# Validate semantic versioning (X.Y.Z)
if [[ ! $version =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
print_error "Invalid version format: $version"
print_info "Use semantic versioning format: X.Y.Z"
exit 1
fi
print_success "Version format valid: $version"
}
get_current_version() {
grep '<version>' "$POM_FILE" | head -1 | sed 's/.*<version>\(.*\)<\/version>.*/\1/'
}
check_git_clean() {
if ! git diff-index --quiet HEAD --; then
print_error "Git working directory is not clean"
print_info "Commit or stash your changes before releasing"
exit 1
fi
print_success "Git working directory is clean"
}
check_git_branch() {
local branch=$(git rev-parse --abbrev-ref HEAD)
if [[ "$branch" != "master" && "$branch" != "main" ]]; then
print_warning "Current branch is '$branch', not master/main"
read -p "Continue anyway? (y/n) " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
print_info "Release cancelled"
exit 1
fi
fi
print_success "On branch: $branch"
}
update_pom_version() {
local old_version=$1
local new_version=$2
print_info "Updating pom.xml: $old_version -> $new_version"
# Update version in pom.xml
sed -i.bak "s/<version>${old_version}<\/version>/<version>${new_version}<\/version>/" "$POM_FILE"
rm -f "${POM_FILE}.bak"
print_success "pom.xml updated"
}
update_readme_version() {
local old_version=$1
local new_version=$2
print_info "Updating README.md installation version: ${old_version} → ${new_version}"
if [ ! -f "$README_FILE" ]; then
print_warning "README.md not found, skipping README update"
return
fi
# Update version in README.md installation section
# Replaces all occurrences of vX.Y.Z with the new version
sed -i.bak "s/ReplicaDB-${old_version}/ReplicaDB-${new_version}/g" "$README_FILE"
sed -i.bak "s/v${old_version}/v${new_version}/g" "$README_FILE"
rm -f "${README_FILE}.bak"
print_success "README.md updated"
}
create_release_commit() {
local version=$1
print_info "Creating release commit..."
git add "$POM_FILE" "$README_FILE"
git commit -m "Release v${version}" || print_warning "Commit may have failed or nothing to commit"
print_success "Release commit created"
}
create_git_tag() {
local version=$1
local tag="v${version}"
print_info "Creating git tag: $tag"
if git rev-parse "$tag" >/dev/null 2>&1; then
print_error "Tag $tag already exists"
exit 1
fi
git tag -a "$tag" -m "Release $tag" || print_warning "Tag creation completed (may already exist)"
print_success "Git tag created: $tag"
}
push_to_origin() {
local version=$1
local tag="v${version}"
print_info "Pushing to origin..."
print_info " - Branch: master/main"
print_info " - Tag: $tag"
git push origin HEAD:master || git push origin HEAD:main
git push origin "$tag"
print_success "Pushed to origin"
}
show_release_summary() {
local old_version=$1
local new_version=$2
echo
print_header "RELEASE SUMMARY"
echo -e "${BLUE}Previous Version:${NC} ${old_version}"
echo -e "${BLUE}Release Version:${NC} v${new_version}"
echo -e "${BLUE}Release Tag:${NC} v${new_version}"
echo -e "${BLUE}Git Branch:${NC} $(git rev-parse --abbrev-ref HEAD)"
echo -e "${BLUE}Commit Hash:${NC} $(git rev-parse --short HEAD)"
echo
echo -e "${GREEN}CI/CD Pipeline:${NC} Automatically triggered on tag push"
echo -e "${GREEN}Release Assets:${NC}"
echo " - ReplicaDB-${new_version}.tar.gz"
echo " - ReplicaDB-${new_version}.zip"
echo " - ReplicaDB-${new_version}-no-oracle.tar.gz"
echo " - ReplicaDB-${new_version}-no-oracle.zip"
echo
echo -e "${GREEN}Docker Images:${NC}"
echo " - osalvador/replicadb:${new_version}"
echo " - osalvador/replicadb:latest"
echo " - osalvador/replicadb:ubi9-${new_version}"
echo " - osalvador/replicadb:ubi9-latest"
echo
echo -e "${BLUE}Release URL:${NC} https://github.com/osalvador/ReplicaDB/releases/tag/v${new_version}"
echo
}
################################################################################
# Main Script
################################################################################
main() {
# Check arguments
if [[ $# -ne 1 ]]; then
print_error "Missing version argument"
echo
echo "Usage: ./release.sh <version>"
echo "Example: ./release.sh 0.16.0"
echo
echo "Steps performed:"
echo " 1. Validate version format (semantic versioning)"
echo " 2. Verify git working directory is clean"
echo " 3. Update pom.xml with new version"
echo " 4. Create release commit"
echo " 5. Create git tag (v\${version})"
echo " 6. Push commits and tags to origin"
echo " 7. CI/CD builds and publishes release automatically"
exit 1
fi
local new_version=$1
local old_version=$(get_current_version)
print_header "ReplicaDB Release Process"
echo "Current Version: ${old_version}"
echo "Release Version: ${new_version}"
echo
# Validations
validate_version "$new_version"
check_git_clean
check_git_branch
# Ask for confirmation
echo
read -p "Ready to release v${new_version}? (y/n) " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
print_info "Release cancelled"
exit 0
fi
# Execute release steps
print_header "Executing Release Steps"
update_pom_version "$old_version" "$new_version"
update_readme_version "$old_version" "$new_version"
create_release_commit "$new_version"
create_git_tag "$new_version"
push_to_origin "$new_version"
# Show summary
show_release_summary "$old_version" "$new_version"
print_header "RELEASE SUCCESSFUL"
echo -e "${GREEN}Release v${new_version} has been created and pushed!${NC}"
echo
echo "CI/CD Pipeline Status:"
echo " → Visit: https://github.com/osalvador/ReplicaDB/actions"
echo
echo "To view release progress:"
echo " → Visit: https://github.com/osalvador/ReplicaDB/releases/tag/v${new_version}"
echo
}
# Run main function
main "$@"