Skip to content

Commit 4a55bdb

Browse files
committed
Fix release script consistency issues
1 parent e6f327e commit 4a55bdb

File tree

1 file changed

+55
-54
lines changed

1 file changed

+55
-54
lines changed

dev-bin/release.sh

Lines changed: 55 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,28 @@ set -eu -o pipefail
66
# before making any changes to the repository
77

88
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
9+
if ! command -v "$1" &>/dev/null; then
10+
echo "Error: $1 is not installed or not in PATH"
11+
exit 1
12+
fi
1313
}
1414

1515
# 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
16+
if ! gh auth status &>/dev/null; then
17+
echo "Error: gh CLI is not authenticated. Run 'gh auth login' first."
18+
exit 1
1919
fi
2020

2121
# 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
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
2525
fi
2626

2727
# 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
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
3131
fi
3232

3333
check_command perl
@@ -37,51 +37,52 @@ check_command autoconf
3737
# Check that we're not on the main branch
3838
current_branch=$(git branch --show-current)
3939
if [ "$current_branch" = "main" ]; then
40-
echo "Error: Releases should not be done directly on the main branch."
41-
echo "Please create a release branch and run this script from there."
42-
exit 1
40+
echo "Error: Releases should not be done directly on the main branch."
41+
echo "Please create a release branch and run this script from there."
42+
exit 1
4343
fi
4444

4545
# Fetch latest changes and check that we're not behind origin/main
4646
echo "Fetching from origin..."
4747
git fetch origin
4848

4949
if ! git merge-base --is-ancestor origin/main HEAD; then
50-
echo "Error: Current branch is behind origin/main."
51-
echo "Please merge or rebase with origin/main before releasing."
52-
exit 1
50+
echo "Error: Current branch is behind origin/main."
51+
echo "Please merge or rebase with origin/main before releasing."
52+
exit 1
5353
fi
5454

5555
changelog=$(cat Changes.md)
5656

57-
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})
5858
5959
((.|
6060
)*)
6161
'
6262

6363
if [[ ! $changelog =~ $regex ]]; then
64-
echo "Could not find date line in change log!"
65-
exit 1
64+
echo "Could not find date line in change log!"
65+
exit 1
6666
fi
6767

6868
version="${BASH_REMATCH[1]}"
69-
date="${BASH_REMATCH[2]}"
70-
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')"
7171

7272
dist="libmaxminddb-$version.tar.gz"
7373

74-
if [[ "$date" != $(date +"%Y-%m-%d") ]]; then
75-
echo "$date is not today!"
76-
exit 1
74+
if [[ "$date" != "$(date +"%Y-%m-%d")" ]]; then
75+
echo "$date is not today!"
76+
exit 1
7777
fi
7878

7979
if [ -n "$(git status --porcelain)" ]; then
80-
echo ". is not clean." >&2
81-
exit 1
80+
echo ". is not clean." >&2
81+
exit 1
8282
fi
8383

84-
old_version=$(perl -MFile::Slurp=read_file <<EOF
84+
old_version=$(
85+
perl -MFile::Slurp=read_file <<EOF
8586
use v5.16;
8687
my \$conf = read_file(q{configure.ac});
8788
\$conf =~ /AC_INIT.+\[(\d+\.\d+\.\d+)\]/;
@@ -90,20 +91,20 @@ EOF
9091
)
9192

9293
perl -MFile::Slurp=edit_file -e \
93-
"edit_file { s/\Q$old_version/$version/g } \$_ for qw( configure.ac include/maxminddb.h CMakeLists.txt )"
94+
"edit_file { s/\Q$old_version/$version/g } \$_ for qw( configure.ac include/maxminddb.h CMakeLists.txt )"
9495

9596
if [ -n "$(git status --porcelain)" ]; then
96-
git diff
97+
git diff
9798

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

100-
if [ "$should_commit" != "y" ]; then
101-
echo "Aborting"
102-
exit 1
103-
fi
101+
if [ "$should_commit" != "y" ]; then
102+
echo "Aborting"
103+
exit 1
104+
fi
104105

105-
git add configure.ac include/maxminddb.h CMakeLists.txt
106-
git commit -m "Bumped version to $version"
106+
git add configure.ac include/maxminddb.h CMakeLists.txt
107+
git commit -m "Bumped version to $version"
107108
fi
108109

109110
./bootstrap
@@ -114,49 +115,49 @@ make clean
114115
make safedist
115116

116117
if [ ! -d .gh-pages ]; then
117-
echo "Checking out gh-pages in .gh-pages"
118-
git clone -b gh-pages [email protected]:maxmind/libmaxminddb.git .gh-pages
119-
pushd .gh-pages
118+
echo "Checking out gh-pages in .gh-pages"
119+
git clone -b gh-pages [email protected]:maxmind/libmaxminddb.git .gh-pages
120+
pushd .gh-pages
120121
else
121-
echo "Updating .gh-pages"
122-
pushd .gh-pages
123-
git pull
122+
echo "Updating .gh-pages"
123+
pushd .gh-pages
124+
git pull
124125
fi
125126

126127
if [ -n "$(git status --porcelain)" ]; then
127-
echo ".gh-pages is not clean" >&2
128-
exit 1
128+
echo ".gh-pages is not clean" >&2
129+
exit 1
129130
fi
130131

131132
index=index.md
132-
cat <<EOF > $index
133+
cat <<EOF >$index
133134
---
134135
layout: default
135136
title: libmaxminddb - a library for working with MaxMind DB files
136137
version: $version
137138
---
138139
EOF
139140

140-
cat ../doc/libmaxminddb.md >> $index
141+
cat ../doc/libmaxminddb.md >>$index
141142

142143
mmdblookup=mmdblookup.md
143-
cat <<EOF > $mmdblookup
144+
cat <<EOF >$mmdblookup
144145
---
145146
layout: default
146147
title: mmdblookup - a utility to look up an IP address in a MaxMind DB file
147148
version: $version
148149
---
149150
EOF
150151

151-
cat ../doc/mmdblookup.md >> $mmdblookup
152+
cat ../doc/mmdblookup.md >>$mmdblookup
152153

153154
git commit -m "Updated for $version" -a
154155

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

157158
if [ "$should_push" != "y" ]; then
158-
echo "Aborting"
159-
exit 1
159+
echo "Aborting"
160+
exit 1
160161
fi
161162

162163
git push

0 commit comments

Comments
 (0)