Skip to content

Commit 5337cbb

Browse files
committed
Fix release script consistency issues
- Quote date command substitution for defensive programming - Apply shfmt formatting
1 parent d5a578d commit 5337cbb

File tree

1 file changed

+44
-44
lines changed

1 file changed

+44
-44
lines changed

dev-bin/release.sh

Lines changed: 44 additions & 44 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
@@ -36,19 +36,19 @@ check_command mvn
3636
# Check that we're not on the main branch
3737
current_branch=$(git branch --show-current)
3838
if [ "$current_branch" = "main" ]; then
39-
echo "Error: Releases should not be done directly on the main branch."
40-
echo "Please create a release branch and run this script from there."
41-
exit 1
39+
echo "Error: Releases should not be done directly on the main branch."
40+
echo "Please create a release branch and run this script from there."
41+
exit 1
4242
fi
4343

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

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

5454
changelog=$(cat CHANGELOG.md)
@@ -62,39 +62,39 @@ regex='
6262
'
6363

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

6969
version="${BASH_REMATCH[1]}"
7070
date="${BASH_REMATCH[2]}"
7171
notes="$(echo "${BASH_REMATCH[3]}" | sed -n -e '/^[0-9]\+\.[0-9]\+\.[0-9]\+/,$!p')"
7272

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

7878
tag="v$version"
7979

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

8585
if [ ! -d .gh-pages ]; then
86-
echo "Checking out gh-pages in .gh-pages"
87-
git clone -b gh-pages [email protected]:maxmind/MaxMind-DB-Reader-java.git .gh-pages
88-
pushd .gh-pages
86+
echo "Checking out gh-pages in .gh-pages"
87+
git clone -b gh-pages [email protected]:maxmind/MaxMind-DB-Reader-java.git .gh-pages
88+
pushd .gh-pages
8989
else
90-
echo "Updating .gh-pages"
91-
pushd .gh-pages
92-
git pull
90+
echo "Updating .gh-pages"
91+
pushd .gh-pages
92+
git pull
9393
fi
9494

9595
if [ -n "$(git status --porcelain)" ]; then
96-
echo ".gh-pages is not clean" >&2
97-
exit 1
96+
echo ".gh-pages is not clean" >&2
97+
exit 1
9898
fi
9999

100100
popd
@@ -105,21 +105,21 @@ mvn versions:display-dependency-updates
105105
read -r -n 1 -p "Continue given above dependencies? (y/n) " should_continue
106106

107107
if [ "$should_continue" != "y" ]; then
108-
echo "Aborting"
109-
exit 1
108+
echo "Aborting"
109+
exit 1
110110
fi
111111

112112
mvn test
113113

114114
read -r -n 1 -p "Continue given above tests? (y/n) " should_continue
115115

116116
if [ "$should_continue" != "y" ]; then
117-
echo "Aborting"
118-
exit 1
117+
echo "Aborting"
118+
exit 1
119119
fi
120120

121121
page=.gh-pages/index.md
122-
cat <<EOF > $page
122+
cat <<EOF >$page
123123
---
124124
layout: default
125125
title: MaxMind DB Java API
@@ -134,14 +134,14 @@ mvn versions:set -DnewVersion="$version"
134134
perl -pi -e "s/(?<=<version>)[^<]*/$version/" README.md
135135
perl -pi -e "s/(?<=com\.maxmind\.db\:maxmind-db\:)\d+\.\d+\.\d+([\w\-]+)?/$version/" README.md
136136

137-
cat README.md >> $page
137+
cat README.md >>$page
138138

139139
git diff
140140

141141
read -r -n 1 -p "Commit changes? " should_commit
142142
if [ "$should_commit" != "y" ]; then
143-
echo "Aborting"
144-
exit 1
143+
echo "Aborting"
144+
exit 1
145145
fi
146146
git add README.md pom.xml
147147
git commit -m "Preparing for $version"
@@ -166,8 +166,8 @@ $notes
166166
read -r -n 1 -p "Push to origin? " should_push
167167

168168
if [ "$should_push" != "y" ]; then
169-
echo "Aborting"
170-
exit 1
169+
echo "Aborting"
170+
exit 1
171171
fi
172172

173173
git push

0 commit comments

Comments
 (0)