-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrelease.sh
More file actions
executable file
·315 lines (279 loc) · 10.4 KB
/
release.sh
File metadata and controls
executable file
·315 lines (279 loc) · 10.4 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
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
#!/usr/bin/env bash
#
# Release script for GuiInteraction
#
# Prerequisites:
# - SDKMAN installed with JDK 21
# - Signing credentials in gradle.properties (signing.keyId, signing.password, signing.secretKeyRingFile)
# - Sonatype credentials in gradle.properties (sonatypeUsername, sonatypePassword)
# - GitHub CLI (gh) installed and authenticated for creating releases
#
# Usage:
# ./release.sh - Release current version (strips -SNAPSHOT if present)
# ./release.sh --bump minor - Bump version and release (major, minor, patch)
# ./release.sh --dry-run - Show what would be released without publishing
#
# If the version has a -SNAPSHOT suffix, it will be removed to create the release version.
# The README.md will be updated automatically with the release version.
#
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Initialize SDKMAN and use JDK 21
if [ -f ~/.sdkman/bin/sdkman-init.sh ]; then
source ~/.sdkman/bin/sdkman-init.sh
sdk use java 21.0.9.fx-librca 2>/dev/null || sdk use java 21-librca 2>/dev/null || echo "Using default Java"
fi
PROJECT=$(basename "$PWD")
DRY_RUN=false
BUMP_TYPE=""
# Parse arguments
while [[ $# -gt 0 ]]; do
case $1 in
--dry-run)
DRY_RUN=true
shift
;;
--bump)
BUMP_TYPE="$2"
shift 2
;;
*)
echo -e "${RED}Unknown option: $1${NC}"
exit 1
;;
esac
done
# Get current version from build.gradle
get_version() {
grep -E '^\s*version\s*=\s*["'\'']' build.gradle | sed -E 's/^\s*version\s*=\s*["'\'']([^"'\''"]+)["'\''].*/\1/'
}
# Bump version based on type (major, minor, patch)
bump_version() {
local version=$1
local type=$2
local major minor patch
IFS='.' read -r major minor patch <<< "${version%-SNAPSHOT}"
case $type in
major)
major=$((major + 1))
minor=0
patch=0
;;
minor)
minor=$((minor + 1))
patch=0
;;
patch)
patch=$((patch + 1))
;;
*)
echo -e "${RED}Invalid bump type: $type. Use major, minor, or patch${NC}"
exit 1
;;
esac
echo "${major}.${minor}.${patch}"
}
# Update version in build.gradle
update_version() {
local new_version=$1
sed -i.bak "s/^version = '.*'/version = '${new_version}'/" build.gradle
rm build.gradle.bak
echo -e "${GREEN}Updated build.gradle version to ${new_version}${NC}"
}
# Update version in README.md
update_readme_version() {
local new_version=$1
# Update all version references in README.md (Gradle, Maven, Grape examples)
sed -i.bak -E "s/(gi-(swing|fx|console):)[0-9]+\.[0-9]+\.[0-9]+(-SNAPSHOT)?/\1${new_version}/g" README.md
sed -i.bak -E "s/(<version>)[0-9]+\.[0-9]+\.[0-9]+(-SNAPSHOT)?(<\/version>)/\1${new_version}\3/g" README.md
rm -f README.md.bak
echo -e "${GREEN}Updated README.md version to ${new_version}${NC}"
}
# Check if README.md has the correct version
check_readme_version() {
local expected_version=$1
local readme_versions=$(grep -oE '(gi-(swing|fx|console):)[0-9]+\.[0-9]+\.[0-9]+(-SNAPSHOT)?' README.md | head -1 | sed -E 's/gi-(swing|fx|console)://')
if [ "$readme_versions" != "$expected_version" ]; then
echo -e "${RED}Warning: README.md contains version '${readme_versions}' but releasing '${expected_version}'${NC}"
return 1
fi
return 0
}
# Generate changelog entry
generate_changelog() {
local version=$1
local date=$(date +%Y-%m-%d)
local changelog_file="CHANGELOG.md"
if [ ! -f "$changelog_file" ]; then
echo "# Changelog" > "$changelog_file"
echo "" >> "$changelog_file"
fi
# Get commits since last tag
local last_tag=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
local commits=""
if [ -n "$last_tag" ]; then
commits=$(git log --oneline "${last_tag}..HEAD" 2>/dev/null || echo "")
else
commits=$(git log --oneline -20 2>/dev/null || echo "")
fi
# Create changelog entry
local entry="## [${version}] - ${date}\n\n"
if [ -n "$commits" ]; then
entry+="### Changes\n\n"
while IFS= read -r line; do
if [ -n "$line" ]; then
entry+="- ${line#* }\n"
fi
done <<< "$commits"
fi
entry+="\n"
# Insert after first line (# Changelog)
if [ -f "$changelog_file" ]; then
local temp_file=$(mktemp)
head -2 "$changelog_file" > "$temp_file"
echo -e "$entry" >> "$temp_file"
tail -n +3 "$changelog_file" >> "$temp_file"
mv "$temp_file" "$changelog_file"
echo -e "${GREEN}Updated ${changelog_file}${NC}"
fi
}
# Publish a subproject
publish() {
local sub=$1
echo -e "${YELLOW}Publishing $sub to Maven Central...${NC}"
if [ "$DRY_RUN" = true ]; then
echo -e "${YELLOW}[DRY RUN] Would execute: ./gradlew :${sub}:clean :${sub}:build :${sub}:release${NC}"
else
./gradlew ":${sub}:clean" ":${sub}:build" ":${sub}:release" --no-configuration-cache
fi
}
# Main script
echo -e "${GREEN}========================================${NC}"
echo -e "${GREEN} GuiInteraction Release Script${NC}"
echo -e "${GREEN}========================================${NC}"
echo ""
CURRENT_VERSION=$(get_version)
echo -e "Current version: ${YELLOW}${CURRENT_VERSION}${NC}"
# Handle SNAPSHOT version - strip -SNAPSHOT suffix for release
if echo "$CURRENT_VERSION" | grep -q '\-SNAPSHOT'; then
RELEASE_VERSION="${CURRENT_VERSION%-SNAPSHOT}"
echo -e "Stripping SNAPSHOT suffix: ${YELLOW}${CURRENT_VERSION}${NC} -> ${GREEN}${RELEASE_VERSION}${NC}"
if [ "$DRY_RUN" = false ]; then
update_version "$RELEASE_VERSION"
update_readme_version "$RELEASE_VERSION"
generate_changelog "$RELEASE_VERSION"
# Commit version changes
if ! git add build.gradle README.md CHANGELOG.md; then
echo -e "${RED}Error: Failed to add files to git. Please resolve the issue and try again.${NC}" >&2
exit 1
fi
if ! git commit -m "Release version ${RELEASE_VERSION}"; then
echo -e "${RED}Error: Failed to commit version change. Please resolve the issue and try again.${NC}" >&2
exit 1
fi
else
echo -e "${YELLOW}[DRY RUN] Would update build.gradle and README.md to ${RELEASE_VERSION}${NC}"
fi
CURRENT_VERSION=$RELEASE_VERSION
else
# No SNAPSHOT - verify README.md has the correct version
if ! check_readme_version "$CURRENT_VERSION"; then
if [ "$DRY_RUN" = true ]; then
echo -e "${YELLOW}[DRY RUN] Would update README.md to match version ${CURRENT_VERSION}${NC}"
else
read -p "Update README.md to version ${CURRENT_VERSION}? [Y/n]: " update_readme
if [[ ! "$update_readme" =~ ^[Nn]$ ]]; then
update_readme_version "$CURRENT_VERSION"
fi
fi
fi
fi
# Check if version has already been released (git tag exists)
TAG="v${CURRENT_VERSION}"
if git rev-parse "$TAG" >/dev/null 2>&1 || git ls-remote --tags origin | grep -q "refs/tags/$TAG$"; then
if [ "$DRY_RUN" = true ]; then
echo -e "${YELLOW}Warning: Tag $TAG already exists. This version may have already been released.${NC}"
else
echo -e "${RED}Warning: Version ${CURRENT_VERSION} appears to have already been released (tag $TAG exists).${NC}"
read -p "Continue anyway? [y/N]: " confirm
if [[ ! "$confirm" =~ ^[Yy]$ ]]; then
echo -e "${RED}Aborting release.${NC}"
exit 1
fi
fi
fi
# Handle version bump
if [ -n "$BUMP_TYPE" ]; then
NEW_VERSION=$(bump_version "$CURRENT_VERSION" "$BUMP_TYPE")
echo -e "Bumping version to: ${GREEN}${NEW_VERSION}${NC}"
if [ "$DRY_RUN" = false ]; then
update_version "$NEW_VERSION"
update_readme_version "$NEW_VERSION"
generate_changelog "$NEW_VERSION"
# Commit version change
if ! git add build.gradle README.md CHANGELOG.md; then
echo -e "${RED}Error: Failed to add files to git. Please resolve the issue and try again.${NC}" >&2
exit 1
fi
if ! git commit -m "Release version ${NEW_VERSION}"; then
echo -e "${RED}Error: Failed to commit version change. Please resolve the issue and try again.${NC}" >&2
exit 1
fi
else
echo -e "${YELLOW}[DRY RUN] Would update version to ${NEW_VERSION}${NC}"
fi
CURRENT_VERSION=$NEW_VERSION
fi
echo ""
echo -e "Releasing version: ${GREEN}${CURRENT_VERSION}${NC}"
echo ""
# Run tests first
echo -e "${YELLOW}Running tests...${NC}"
if [ "$DRY_RUN" = true ]; then
echo -e "${YELLOW}[DRY RUN] Would run: ./gradlew test${NC}"
else
./gradlew test
fi
# Publish each module
publish 'gi-common'
publish 'gi-console'
publish 'gi-fx'
publish 'gi-swing'
echo ""
# Create GitHub release
TAG="v${CURRENT_VERSION}"
RELEASE_TITLE="Ver ${CURRENT_VERSION}"
if [ "$DRY_RUN" = true ]; then
echo -e "${YELLOW}[DRY RUN] Would push commits to origin${NC}"
echo -e "${YELLOW}[DRY RUN] Would create GitHub release:${NC}"
echo -e "${YELLOW} Tag: ${TAG}${NC}"
echo -e "${YELLOW} Title: ${RELEASE_TITLE}${NC}"
echo -e "${YELLOW} Command: gh release create ${TAG} --title \"${RELEASE_TITLE}\" --generate-notes${NC}"
else
echo -e "${YELLOW}Pushing commits to origin...${NC}"
if ! git push origin; then
echo -e "${RED}Error: Failed to push commits. Please resolve the issue and try again.${NC}" >&2
exit 1
fi
echo -e "${YELLOW}Creating GitHub release...${NC}"
if ! gh release create "${TAG}" --title "${RELEASE_TITLE}" --generate-notes; then
echo -e "${RED}Error: Failed to create GitHub release. Please create it manually.${NC}" >&2
echo -e "${YELLOW}You can create it at: https://github.com/Alipsa/GuiInteraction/releases/new${NC}"
else
echo -e "${GREEN}GitHub release created successfully!${NC}"
fi
fi
echo ""
echo -e "${GREEN}========================================${NC}"
if [ "$DRY_RUN" = true ]; then
echo -e "${YELLOW}[DRY RUN] Release simulation complete${NC}"
else
echo -e "${GREEN}$PROJECT v${CURRENT_VERSION} released to Maven Central and GitHub!${NC}"
echo ""
echo "See https://central.sonatype.org/publish/release/ for more info"
fi
echo -e "${GREEN}========================================${NC}"