-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathrelease.sh
More file actions
executable file
·184 lines (137 loc) · 4.07 KB
/
release.sh
File metadata and controls
executable file
·184 lines (137 loc) · 4.07 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
#!/bin/bash
set -eu -o pipefail
# Pre-flight checks - verify all required tools are available and configured
# before making any changes to the repository
check_command() {
if ! command -v "$1" &>/dev/null; then
echo "Error: $1 is not installed or not in PATH"
exit 1
fi
}
# Verify gh CLI is authenticated
if ! gh auth status &>/dev/null; then
echo "Error: gh CLI is not authenticated. Run 'gh auth login' first."
exit 1
fi
# Verify we can access this repository via gh
if ! gh repo view --json name &>/dev/null; then
echo "Error: Cannot access repository via gh. Check your authentication and repository access."
exit 1
fi
# Verify git can connect to the remote (catches SSH key issues, etc.)
if ! git ls-remote origin &>/dev/null; then
echo "Error: Cannot connect to git remote. Check your git credentials/SSH keys."
exit 1
fi
check_command perl
check_command mvn
# Check that we're not on the main branch
current_branch=$(git branch --show-current)
if [ "$current_branch" = "main" ]; then
echo "Error: Releases should not be done directly on the main branch."
echo "Please create a release branch and run this script from there."
exit 1
fi
# Fetch latest changes and check that we're not behind origin/main
echo "Fetching from origin..."
git fetch origin
if ! git merge-base --is-ancestor origin/main HEAD; then
echo "Error: Current branch is behind origin/main."
echo "Please merge or rebase with origin/main before releasing."
exit 1
fi
changelog=$(cat CHANGELOG.md)
regex='
([0-9]+\.[0-9]+\.[0-9]+[a-zA-Z0-9\-]*) \(([0-9]{4}-[0-9]{2}-[0-9]{2})\)
-*
((.|
)*)
'
if [[ ! $changelog =~ $regex ]]; then
echo "Could not find date line in change log!"
exit 1
fi
version="${BASH_REMATCH[1]}"
date="${BASH_REMATCH[2]}"
notes="$(echo "${BASH_REMATCH[3]}" | sed -n -e '/^[0-9]\+\.[0-9]\+\.[0-9]\+/,$!p')"
if [[ "$date" != "$(date +"%Y-%m-%d")" ]]; then
echo "$date is not today!"
exit 1
fi
tag="v$version"
if [ -n "$(git status --porcelain)" ]; then
echo ". is not clean." >&2
exit 1
fi
if [ ! -d .gh-pages ]; then
echo "Checking out gh-pages in .gh-pages"
git clone -b gh-pages git@github.com:maxmind/minfraud-api-java.git .gh-pages
pushd .gh-pages
else
echo "Updating .gh-pages"
pushd .gh-pages
git pull
fi
if [ -n "$(git status --porcelain)" ]; then
echo ".gh-pages is not clean" >&2
exit 1
fi
popd
mvn versions:display-plugin-updates
mvn versions:display-dependency-updates
read -r -n 1 -p "Continue given above dependencies? (y/n) " should_continue
if [ "$should_continue" != "y" ]; then
echo "Aborting"
exit 1
fi
mvn test
read -r -n 1 -p "Continue given above tests? (y/n) " should_continue
if [ "$should_continue" != "y" ]; then
echo "Aborting"
exit 1
fi
page=.gh-pages/index.md
cat <<EOF >$page
---
layout: default
title: MaxMind minFraud Java API
language: java
version: $tag
---
EOF
mvn versions:set -DnewVersion="$version"
perl -pi -e "s/(?<=<version>)[^<]*/$version/" README.md
perl -pi -e "s/(?<=com\.maxmind\.minfraud\:minfraud\:)\d+\.\d+\.\d+([\w\-]+)?/$version/" README.md
# Update japicmp.baselineVersion for API compatibility checking
perl -pi -e "s/(<japicmp\.baselineVersion>)[^<]*(<\/japicmp\.baselineVersion>)/\${1}$version\${2}/" pom.xml
cat README.md >>$page
git diff
read -r -n 1 -p "Commit changes? " should_commit
if [ "$should_commit" != "y" ]; then
echo "Aborting"
exit 1
fi
git add README.md pom.xml
git commit -m "Preparing for $version"
mvn clean deploy
rm -fr ".gh-pages/doc/$tag"
cp -r target/reports/apidocs ".gh-pages/doc/$tag"
rm -f .gh-pages/doc/latest
ln -fs "$tag" .gh-pages/doc/latest
pushd .gh-pages
git add doc/
git commit -m "Updated for $tag" -a
echo "Release notes for $version:
$notes
"
read -r -n 1 -p "Push to origin? " should_push
if [ "$should_push" != "y" ]; then
echo "Aborting"
exit 1
fi
git push
popd
git push
gh release create --target "$(git branch --show-current)" -t "$version" -n "$notes" "$tag" \
"target/minfraud-$version-with-dependencies.zip" \
"target/minfraud-$version-with-dependencies.zip.asc"