Skip to content

Commit e4fe556

Browse files
authored
Merge pull request #285 from maxmind/greg/eng-1733
Improve release script reliability (ENG-1733)
2 parents 2f8fe66 + d81cb2e commit e4fe556

File tree

1 file changed

+41
-13
lines changed

1 file changed

+41
-13
lines changed

dev-bin/release.sh

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,38 @@
22

33
set -eu -o pipefail
44

5+
# Pre-flight checks - verify all required tools are available and configured
6+
# before making any changes to the repository
7+
8+
check_command() {
9+
if ! command -v "$1" &>/dev/null; then
10+
echo "Error: $1 is not installed or not in PATH"
11+
exit 1
12+
fi
13+
}
14+
15+
# Verify gh CLI is authenticated
16+
if ! gh auth status &>/dev/null; then
17+
echo "Error: gh CLI is not authenticated. Run 'gh auth login' first."
18+
exit 1
19+
fi
20+
21+
# Verify we can access this repository via gh
22+
if ! gh repo view --json name &>/dev/null; then
23+
echo "Error: Cannot access repository via gh. Check your authentication and repository access."
24+
exit 1
25+
fi
26+
27+
# Verify git can connect to the remote (catches SSH key issues, etc.)
28+
if ! git ls-remote origin &>/dev/null; then
29+
echo "Error: Cannot connect to git remote. Check your git credentials/SSH keys."
30+
exit 1
31+
fi
32+
33+
check_command perl
34+
check_command php
35+
check_command wget
36+
537
# Check that we're not on the main branch
638
current_branch=$(git branch --show-current)
739
if [ "$current_branch" = "main" ]; then
@@ -25,23 +57,23 @@ phar='geoip2.phar'
2557
changelog=$(cat CHANGELOG.md)
2658

2759
regex='
28-
([0-9]+\.[0-9]+\.[0-9]+) \(([0-9]{4}-[0-9]{2}-[0-9]{2})\)
60+
([0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9.]+)?) \(([0-9]{4}-[0-9]{2}-[0-9]{2})\)
2961
-*
3062
3163
((.|
3264
)*)
3365
'
3466

3567
if [[ ! $changelog =~ $regex ]]; then
36-
echo "Could not find date line in change log!"
37-
exit 1
68+
echo "Could not find date line in change log!"
69+
exit 1
3870
fi
3971

4072
version="${BASH_REMATCH[1]}"
41-
date="${BASH_REMATCH[2]}"
42-
notes="$(echo "${BASH_REMATCH[3]}" | sed -n -e '/^[0-9]\+\.[0-9]\+\.[0-9]\+/,$!p')"
73+
date="${BASH_REMATCH[3]}"
74+
notes="$(echo "${BASH_REMATCH[4]}" | sed -n -E '/^[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9.]+)?/,$!p')"
4375

44-
if [[ "$date" != $(date +"%Y-%m-%d") ]]; then
76+
if [[ "$date" != "$(date +"%Y-%m-%d")" ]]; then
4577
echo "$date is not today!"
4678
exit 1
4779
fi
@@ -63,7 +95,6 @@ php composer.phar update --no-dev
6395
perl -pi -e "s/(?<=const VERSION = ').+?(?=';)/$tag/g" src/WebService/Client.php
6496
perl -pi -e "s{(?<=php composer\.phar require geoip2/geoip2:).+}{^$version}g" README.md
6597

66-
6798
box_phar_hash='f98cf885a7c07c84df66e33888f1d93f063298598e0a5f41ca322aeb9683179b box.phar'
6899

69100
if ! echo "$box_phar_hash" | sha256sum -c; then
@@ -105,7 +136,6 @@ else
105136
popd
106137
fi
107138

108-
109139
if [ -n "$(git status --porcelain)" ]; then
110140
echo ".gh-pages is not clean" >&2
111141
exit 1
@@ -139,7 +169,7 @@ php phpDocumentor.phar \
139169
rm -rf "$cachedir"
140170

141171
page=index.md
142-
cat <<EOF > $page
172+
cat <<EOF >$page
143173
---
144174
layout: default
145175
title: MaxMind GeoIP2 PHP API
@@ -149,14 +179,14 @@ version: $tag
149179
150180
EOF
151181

152-
cat ../README.md >> $page
182+
cat ../README.md >>$page
153183

154184
git add doc/
155185

156186
echo "Release notes for $tag:"
157187
echo "$notes"
158188

159-
read -e -p "Commit changes and push to origin? " should_push
189+
read -r -e -p "Commit changes and push to origin? " should_push
160190

161191
if [ "$should_push" != "y" ]; then
162192
echo "Aborting"
@@ -173,5 +203,3 @@ git commit -m "Update for $tag" -a
173203
git push
174204

175205
gh release create --target "$(git branch --show-current)" -t "$version" -n "$notes" "$tag" "$phar"
176-
177-
git push --tags

0 commit comments

Comments
 (0)