Skip to content

Commit b2e0652

Browse files
authored
Merge pull request #407 from maxmind/greg/eng-1733
Improve release script reliability (ENG-1733)
2 parents 7439567 + dc3754a commit b2e0652

File tree

1 file changed

+46
-13
lines changed

1 file changed

+46
-13
lines changed

dev-bin/release.sh

Lines changed: 46 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 make
35+
check_command autoconf
36+
537
# Check that we're not on the main branch
638
current_branch=$(git branch --show-current)
739
if [ "$current_branch" = "main" ]; then
@@ -22,24 +54,24 @@ fi
2254

2355
changelog=$(cat Changes.md)
2456

25-
regex='## ([0-9]+\.[0-9]+\.[0-9]+) - ([0-9]{4}-[0-9]{2}-[0-9]{2})
57+
regex='## ([0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9.]+)?) - ([0-9]{4}-[0-9]{2}-[0-9]{2})
2658
2759
((.|
2860
)*)
2961
'
3062

3163
if [[ ! $changelog =~ $regex ]]; then
32-
echo "Could not find date line in change log!"
33-
exit 1
64+
echo "Could not find date line in change log!"
65+
exit 1
3466
fi
3567

3668
version="${BASH_REMATCH[1]}"
37-
date="${BASH_REMATCH[2]}"
38-
notes="$(echo "${BASH_REMATCH[3]}" | sed -n -e '/^## [0-9]\+\.[0-9]\+\.[0-9]\+/,$!p')"
69+
date="${BASH_REMATCH[3]}"
70+
notes="$(echo "${BASH_REMATCH[4]}" | sed -n -E '/^## [0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9.]+)?/,$!p')"
3971

4072
dist="libmaxminddb-$version.tar.gz"
4173

42-
if [[ "$date" != $(date +"%Y-%m-%d") ]]; then
74+
if [[ "$date" != "$(date +"%Y-%m-%d")" ]]; then
4375
echo "$date is not today!"
4476
exit 1
4577
fi
@@ -49,7 +81,8 @@ if [ -n "$(git status --porcelain)" ]; then
4981
exit 1
5082
fi
5183

52-
old_version=$(perl -MFile::Slurp=read_file <<EOF
84+
old_version=$(
85+
perl -MFile::Slurp=read_file <<EOF
5386
use v5.16;
5487
my \$conf = read_file(q{configure.ac});
5588
\$conf =~ /AC_INIT.+\[(\d+\.\d+\.\d+)\]/;
@@ -63,7 +96,7 @@ perl -MFile::Slurp=edit_file -e \
6396
if [ -n "$(git status --porcelain)" ]; then
6497
git diff
6598

66-
read -e -p "Commit changes? " should_commit
99+
read -r -e -p "Commit changes? (y/n) " should_commit
67100

68101
if [ "$should_commit" != "y" ]; then
69102
echo "Aborting"
@@ -97,30 +130,30 @@ if [ -n "$(git status --porcelain)" ]; then
97130
fi
98131

99132
index=index.md
100-
cat <<EOF > $index
133+
cat <<EOF >$index
101134
---
102135
layout: default
103136
title: libmaxminddb - a library for working with MaxMind DB files
104137
version: $version
105138
---
106139
EOF
107140

108-
cat ../doc/libmaxminddb.md >> $index
141+
cat ../doc/libmaxminddb.md >>$index
109142

110143
mmdblookup=mmdblookup.md
111-
cat <<EOF > $mmdblookup
144+
cat <<EOF >$mmdblookup
112145
---
113146
layout: default
114147
title: mmdblookup - a utility to look up an IP address in a MaxMind DB file
115148
version: $version
116149
---
117150
EOF
118151

119-
cat ../doc/mmdblookup.md >> $mmdblookup
152+
cat ../doc/mmdblookup.md >>$mmdblookup
120153

121154
git commit -m "Updated for $version" -a
122155

123-
read -p "Push to origin? (y/n) " should_push
156+
read -r -e -p "Push to origin? (y/n) " should_push
124157

125158
if [ "$should_push" != "y" ]; then
126159
echo "Aborting"

0 commit comments

Comments
 (0)