-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathrelease.sh
More file actions
executable file
·159 lines (138 loc) · 5.25 KB
/
Copy pathrelease.sh
File metadata and controls
executable file
·159 lines (138 loc) · 5.25 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
#!/usr/bin/env bash
set -x
set -e
TYPE=$1
DRYRUN=$2
BRANCH=$(git branch --show-current)
RELEASE_BRANCH=
SKIP_RELEASE_CREATION=false
BASE=$(./gradlew printVersion -Psnapshot=false | grep 'Version:' | cut -f2 -d' ')
# BASE == 0.0.1
create_annotated_tag() {
local version=$1
local type=$2
local branch=$3
local tag_name="v_${version}"
local tag_message="Release v_${version} (${type,,}) from ${branch}"
# Check if tag exists
if git rev-parse "$tag_name" >/dev/null 2>&1; then
if [ -z "$DRYRUN" ]; then
echo "::error::Tag $tag_name already exists"
exit 1
else
echo "[DRY-RUN] Tag $tag_name exists (would fail)"
return
fi
fi
if [ -z "$DRYRUN" ]; then
git tag -a "$tag_name" -m "$tag_message"
echo "✓ Created annotated tag: $tag_name"
else
echo "[DRY-RUN] Would create tag: $tag_name"
echo "[DRY-RUN] Message: $tag_message"
fi
}
if [ "$TYPE" == "MINOR" ] || [ "$TYPE" == "MAJOR" ]; then
if [ "$BRANCH" != "main" ] && [ -z "$DRYRUN" ]; then
echo "Major or minor release can be performed only from 'main' branch."
exit 1
fi
if [ "$TYPE" == "MAJOR" ]; then
# 0.1.0 -> 1.0.0
./gradlew incrementVersion --versionIncrementType=MAJOR
BASE=$(./gradlew printVersion -Psnapshot=false | grep 'Version:' | cut -f2 -d' ')
# BASE == 1.0.0
fi
RELEASE_BRANCH="release/${BASE%.*}._"
if [ -z "$DRYRUN" ] && git rev-parse "v_${BASE}" >/dev/null 2>&1; then
echo "Tag v_${BASE} already exists; skipping tag and release branch creation — will only produce a version-bump PR"
SKIP_RELEASE_CREATION=true
else
create_annotated_tag "$BASE" "$TYPE" "$BRANCH"
fi
fi
if [ "$TYPE" == "PATCH" ]; then
if [[ ! $BRANCH =~ ^release\/[0-9]+\.[0-9]+\._$ ]] && [ -z "$DRYRUN" ]; then
echo "Patch release can be created only for 'release/*' branch."
exit 1
fi
RELEASE_BRANCH="release/${BASE%.*}._"
create_annotated_tag "$BASE" "$TYPE" "$BRANCH"
fi
# RETAG: re-point an existing tag at the current HEAD of a release branch.
# Use when a partial release (tag + branch created, but no Maven artifacts and
# no final GitHub release yet) needs additional commits (e.g. a cherry-picked fix).
if [ "$TYPE" == "RETAG" ]; then
if [[ ! $BRANCH =~ ^release\/[0-9]+\.[0-9]+\._$ ]] && [ -z "$DRYRUN" ]; then
echo "Retag can only be performed from a 'release/*' branch."
exit 1
fi
TAG_NAME="v_${BASE}"
if ! git rev-parse "$TAG_NAME" >/dev/null 2>&1; then
echo "::error::Tag $TAG_NAME does not exist. Use a normal release to create a new tag."
exit 1
fi
# Refuse to retag if the GitHub release is already public
if command -v gh >/dev/null 2>&1; then
IS_DRAFT=$(gh release view "$TAG_NAME" --json isDraft --jq '.isDraft' 2>/dev/null || echo "not-found")
if [ "$IS_DRAFT" == "false" ]; then
echo "::error::GitHub release $TAG_NAME is already public. Retagging is not allowed."
exit 1
fi
fi
if [ -z "$DRYRUN" ]; then
git tag -f -a "$TAG_NAME" -m "Release v_${BASE} (retag) from ${BRANCH}"
git push --force-with-lease origin "$BRANCH"
git push origin :"$TAG_NAME"
git push origin "$TAG_NAME"
else
echo "[DRY-RUN] Would force-move tag $TAG_NAME to $(git rev-parse HEAD)"
echo "[DRY-RUN] Would push $BRANCH with --force-with-lease"
echo "[DRY-RUN] Would delete and re-push remote tag $TAG_NAME"
fi
echo "==================== RETAG SUMMARY ===================="
echo "Release Branch: $BRANCH"
echo "Retagged Version: $BASE"
echo "Tag: $TAG_NAME -> $(git rev-parse HEAD)"
echo "========================================================"
exit 0
fi
if [ "$SKIP_RELEASE_CREATION" == "false" ] && [ "$BRANCH" != "$RELEASE_BRANCH" ]; then
git checkout -b $RELEASE_BRANCH
if ! git diff --quiet; then
git add build.gradle.kts
git commit -m "[Automated] Release ${BASE}"
fi
git push $DRYRUN --atomic --set-upstream origin $RELEASE_BRANCH
git checkout $BRANCH
fi
if [ "$TYPE" == "MAJOR" ] || [ "$TYPE" == "MINOR" ]; then
./gradlew incrementVersion --versionIncrementType=MINOR
else
./gradlew incrementVersion --versionIncrementType=PATCH
fi
CANDIDATE=$(./gradlew printVersion -Psnapshot=false | grep 'Version:' | cut -f2 -d' ')
git add build.gradle.kts
git commit -m "[Automated] Bump dev version to ${CANDIDATE}"
if [ -z "$DRYRUN" ]; then
BUMP_BRANCH="automated/bump-${CANDIDATE//./-}"
git checkout -b "$BUMP_BRANCH"
git push --force-with-lease --set-upstream origin "$BUMP_BRANCH"
REPO="${GITHUB_REPOSITORY:-$(git remote get-url origin | sed 's|.*github.com[:/]\(.*\)\.git|\1|')}"
BUMP_PR_URL="https://github.com/${REPO}/compare/${BRANCH}...${BUMP_BRANCH}?quick_pull=1&title=%5BAutomated%5D+Bump+dev+version+to+${CANDIDATE}"
echo "BUMP_PR_URL=$BUMP_PR_URL" >> "${GITHUB_OUTPUT:-/dev/null}"
echo "⚠ Open this URL to create the version bump PR: $BUMP_PR_URL"
else
git push $DRYRUN --atomic --set-upstream origin $BRANCH
fi
git push $DRYRUN --atomic --tags
echo "==================== RELEASE SUMMARY ===================="
echo "Release Type: $TYPE"
echo "Released Version: $BASE"
echo "Next Dev Version: $CANDIDATE"
echo "Release Branch: $RELEASE_BRANCH"
echo "Tag: v_$BASE"
if [ -z "$DRYRUN" ]; then
echo "Tag Message: $(git tag -l v_$BASE -n1 --format='%(contents:subject)')"
fi
echo "=========================================================="