Skip to content

Commit 868685d

Browse files
committed
Fix release script consistency issues
- Remove redundant git push --tags (gh release create handles tags) - Support pre-release versions in changelog parsing - Quote date command substitution for defensive programming - Fix shellcheck SC2162: add -r flag to read command - Apply shfmt formatting
1 parent 59c3946 commit 868685d

File tree

1 file changed

+58
-62
lines changed

1 file changed

+58
-62
lines changed

dev-bin/release.sh

Lines changed: 58 additions & 62 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,54 +37,54 @@ check_command wget
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
phar='geoip2.phar'
5656

5757
changelog=$(cat CHANGELOG.md)
5858

5959
regex='
60-
([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})\)
6161
-*
6262
6363
((.|
6464
)*)
6565
'
6666

6767
if [[ ! $changelog =~ $regex ]]; then
68-
echo "Could not find date line in change log!"
69-
exit 1
68+
echo "Could not find date line in change log!"
69+
exit 1
7070
fi
7171

7272
version="${BASH_REMATCH[1]}"
73-
date="${BASH_REMATCH[2]}"
74-
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')"
7575

76-
if [[ "$date" != $(date +"%Y-%m-%d") ]]; then
77-
echo "$date is not today!"
78-
exit 1
76+
if [[ "$date" != "$(date +"%Y-%m-%d")" ]]; then
77+
echo "$date is not today!"
78+
exit 1
7979
fi
8080

8181
tag="v$version"
8282

8383
rm -f "$phar"
8484

8585
if [ -n "$(git status --porcelain)" ]; then
86-
echo ". is not clean." >&2
87-
exit 1
86+
echo ". is not clean." >&2
87+
exit 1
8888
fi
8989

9090
rm -fr vendor
@@ -95,11 +95,10 @@ php composer.phar update --no-dev
9595
perl -pi -e "s/(?<=const VERSION = ').+?(?=';)/$tag/g" src/WebService/Client.php
9696
perl -pi -e "s{(?<=php composer\.phar require geoip2/geoip2:).+}{^$version}g" README.md
9797

98-
9998
box_phar_hash='f98cf885a7c07c84df66e33888f1d93f063298598e0a5f41ca322aeb9683179b box.phar'
10099

101100
if ! echo "$box_phar_hash" | sha256sum -c; then
102-
wget -O box.phar "https://github.com/box-project/box/releases/download/4.6.10/box.phar"
101+
wget -O box.phar "https://github.com/box-project/box/releases/download/4.6.10/box.phar"
103102
fi
104103

105104
echo "$box_phar_hash" | sha256sum -c
@@ -108,8 +107,8 @@ php box.phar compile
108107

109108
phar_test=$(./dev-bin/phar-test.php)
110109
if [[ -n $phar_test ]]; then
111-
echo "Phar test outputed non-empty string: $phar_test"
112-
exit 1
110+
echo "Phar test outputed non-empty string: $phar_test"
111+
exit 1
113112
fi
114113

115114
# Download test deps
@@ -118,36 +117,35 @@ php composer.phar update
118117
./vendor/bin/phpunit
119118

120119
if [ ! -d .gh-pages ]; then
121-
echo "Checking out gh-pages in .gh-pages"
122-
git clone -b gh-pages [email protected]:maxmind/GeoIP2-php.git .gh-pages
123-
pushd .gh-pages
120+
echo "Checking out gh-pages in .gh-pages"
121+
git clone -b gh-pages [email protected]:maxmind/GeoIP2-php.git .gh-pages
122+
pushd .gh-pages
124123
else
125-
echo "Updating .gh-pages"
126-
pushd .gh-pages
127-
git pull
124+
echo "Updating .gh-pages"
125+
pushd .gh-pages
126+
git pull
128127
fi
129128

130129
if [ ! -d .maxminddb ]; then
131-
echo "Cloning MaxMind-DB for docs"
132-
git clone [email protected]:maxmind/MaxMind-DB-Reader-php.git .maxminddb
130+
echo "Cloning MaxMind-DB for docs"
131+
git clone [email protected]:maxmind/MaxMind-DB-Reader-php.git .maxminddb
133132
else
134-
echo "Updating MaxMind-DB for docs"
135-
pushd .maxminddb
136-
git pull
137-
popd
133+
echo "Updating MaxMind-DB for docs"
134+
pushd .maxminddb
135+
git pull
136+
popd
138137
fi
139138

140-
141139
if [ -n "$(git status --porcelain)" ]; then
142-
echo ".gh-pages is not clean" >&2
143-
exit 1
140+
echo ".gh-pages is not clean" >&2
141+
exit 1
144142
fi
145143

146144
# Using Composer is possible, but they don't recommend it.
147145
phpdocumentor_phar_hash='aa00973d88b278fe59fd8dce826d8d5419df589cb7563ac379856ec305d6b938 phpDocumentor.phar'
148146

149147
if ! echo "$phpdocumentor_phar_hash" | sha256sum -c; then
150-
wget -O phpDocumentor.phar https://github.com/phpDocumentor/phpDocumentor/releases/download/v3.8.1/phpDocumentor.phar
148+
wget -O phpDocumentor.phar https://github.com/phpDocumentor/phpDocumentor/releases/download/v3.8.1/phpDocumentor.phar
151149
fi
152150

153151
echo "$phpdocumentor_phar_hash" | sha256sum -c
@@ -157,12 +155,12 @@ cachedir="/tmp/phpdoc-$$-$RANDOM"
157155
rm -rf "$cachedir"
158156

159157
php phpDocumentor.phar \
160-
--visibility=public \
161-
--cache-folder="$cachedir" \
162-
--title="GeoIP2 PHP API $tag" \
163-
run \
164-
-d "$PWD/../src" \
165-
-t "doc/$tag"
158+
--visibility=public \
159+
--cache-folder="$cachedir" \
160+
--title="GeoIP2 PHP API $tag" \
161+
run \
162+
-d "$PWD/../src" \
163+
-t "doc/$tag"
166164
# This used to work but doesn't as of 4.5.1. They say that they are working
167165
# on fixing it. Neither the config file nor the relative path fix work as
168166
# suggested either.
@@ -171,7 +169,7 @@ php phpDocumentor.phar \
171169
rm -rf "$cachedir"
172170

173171
page=index.md
174-
cat <<EOF > $page
172+
cat <<EOF >$page
175173
---
176174
layout: default
177175
title: MaxMind GeoIP2 PHP API
@@ -181,18 +179,18 @@ version: $tag
181179
182180
EOF
183181

184-
cat ../README.md >> $page
182+
cat ../README.md >>$page
185183

186184
git add doc/
187185

188186
echo "Release notes for $tag:"
189187
echo "$notes"
190188

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

193191
if [ "$should_push" != "y" ]; then
194-
echo "Aborting"
195-
exit 1
192+
echo "Aborting"
193+
exit 1
196194
fi
197195

198196
git commit -m "Updated for $tag" -a
@@ -205,5 +203,3 @@ git commit -m "Update for $tag" -a
205203
git push
206204

207205
gh release create --target "$(git branch --show-current)" -t "$version" -n "$notes" "$tag" "$phar"
208-
209-
git push --tags

0 commit comments

Comments
 (0)