Skip to content

Commit d81cb2e

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 d81cb2e

File tree

1 file changed

+13
-17
lines changed

1 file changed

+13
-17
lines changed

dev-bin/release.sh

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

88
check_command() {
9-
if ! command -v "$1" &> /dev/null; then
9+
if ! command -v "$1" &>/dev/null; then
1010
echo "Error: $1 is not installed or not in PATH"
1111
exit 1
1212
fi
1313
}
1414

1515
# Verify gh CLI is authenticated
16-
if ! gh auth status &> /dev/null; then
16+
if ! gh auth status &>/dev/null; then
1717
echo "Error: gh CLI is not authenticated. Run 'gh auth login' first."
1818
exit 1
1919
fi
2020

2121
# Verify we can access this repository via gh
22-
if ! gh repo view --json name &> /dev/null; then
22+
if ! gh repo view --json name &>/dev/null; then
2323
echo "Error: Cannot access repository via gh. Check your authentication and repository access."
2424
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
28+
if ! git ls-remote origin &>/dev/null; then
2929
echo "Error: Cannot connect to git remote. Check your git credentials/SSH keys."
3030
exit 1
3131
fi
@@ -57,23 +57,23 @@ phar='geoip2.phar'
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
76+
if [[ "$date" != "$(date +"%Y-%m-%d")" ]]; then
7777
echo "$date is not today!"
7878
exit 1
7979
fi
@@ -95,7 +95,6 @@ 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
@@ -137,7 +136,6 @@ else
137136
popd
138137
fi
139138

140-
141139
if [ -n "$(git status --porcelain)" ]; then
142140
echo ".gh-pages is not clean" >&2
143141
exit 1
@@ -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,14 +179,14 @@ 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
194192
echo "Aborting"
@@ -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)