Skip to content

Commit ee76aac

Browse files
committed
Fix release script consistency issues
- 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 29cb614 commit ee76aac

File tree

1 file changed

+111
-111
lines changed

1 file changed

+111
-111
lines changed

dev-bin/release.sh

Lines changed: 111 additions & 111 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
@@ -38,50 +38,50 @@ check_command pecl
3838
# Check that we're not on the main branch
3939
current_branch=$(git branch --show-current)
4040
if [ "$current_branch" = "main" ]; then
41-
echo "Error: Releases should not be done directly on the main branch."
42-
echo "Please create a release branch and run this script from there."
43-
exit 1
41+
echo "Error: Releases should not be done directly on the main branch."
42+
echo "Please create a release branch and run this script from there."
43+
exit 1
4444
fi
4545

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

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

5656
changelog=$(cat CHANGELOG.md)
5757

5858
regex='
59-
([0-9]+\.[0-9]+\.[0-9]+) \(([0-9]{4}-[0-9]{2}-[0-9]{2})\)
59+
([0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9.]+)?) \(([0-9]{4}-[0-9]{2}-[0-9]{2})\)
6060
-*
6161
6262
((.|
6363
)*)
6464
'
6565

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

7171
version="${BASH_REMATCH[1]}"
72-
date="${BASH_REMATCH[2]}"
73-
notes="$(echo "${BASH_REMATCH[3]}" | sed -n -e '/^[0-9]\+\.[0-9]\+\.[0-9]\+/,$!p')"
72+
date="${BASH_REMATCH[3]}"
73+
notes="$(echo "${BASH_REMATCH[4]}" | sed -n -E '/^[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9.]+)?/,$!p')"
7474

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

8080
tag="v$version"
8181

8282
if [ -n "$(git status --porcelain)" ]; then
83-
echo ". is not clean." >&2
84-
exit 1
83+
echo ". is not clean." >&2
84+
exit 1
8585
fi
8686

8787
rm -fr vendor
@@ -110,7 +110,7 @@ echo $'\nDiff:'
110110
git diff
111111

112112
if [ -n "$(git status --porcelain)" ]; then
113-
git commit -m "Bumped version to $version" -a
113+
git commit -m "Bumped version to $version" -a
114114
fi
115115

116116
echo $'\nRelease notes:'
@@ -120,11 +120,11 @@ pecl package
120120

121121
package="maxminddb-$version.tgz"
122122

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

125125
if [ "$should_push" != "y" ]; then
126-
echo "Aborting"
127-
exit 1
126+
echo "Aborting"
127+
exit 1
128128
fi
129129

130130
echo "Creating tag $tag"
@@ -147,33 +147,33 @@ echo "==================================================================="
147147

148148
# Check if extension repository exists locally
149149
if [ ! -d "$ext_repo_dir" ]; then
150-
echo "Extension repository not found at: $ext_repo_dir"
151-
echo "Cloning extension repository..."
152-
git clone --recurse-submodules "$ext_repo_url" "$ext_repo_dir"
153-
154-
if [ $? -ne 0 ]; then
155-
echo "ERROR: Failed to clone extension repository"
156-
echo "Please clone manually: git clone --recurse-submodules $ext_repo_url $ext_repo_dir"
157-
exit 1
158-
fi
150+
echo "Extension repository not found at: $ext_repo_dir"
151+
echo "Cloning extension repository..."
152+
git clone --recurse-submodules "$ext_repo_url" "$ext_repo_dir"
153+
154+
if [ $? -ne 0 ]; then
155+
echo "ERROR: Failed to clone extension repository"
156+
echo "Please clone manually: git clone --recurse-submodules $ext_repo_url $ext_repo_dir"
157+
exit 1
158+
fi
159159
fi
160160

161161
# Navigate to extension repository
162-
pushd "$ext_repo_dir" > /dev/null
162+
pushd "$ext_repo_dir" >/dev/null
163163

164164
# Safety check: ensure working directory is clean
165165
if [ -n "$(git status --porcelain)" ]; then
166-
echo "ERROR: Extension repository has uncommitted changes"
167-
echo "Please commit or stash changes in: $ext_repo_dir"
168-
popd > /dev/null
169-
exit 1
166+
echo "ERROR: Extension repository has uncommitted changes"
167+
echo "Please commit or stash changes in: $ext_repo_dir"
168+
popd >/dev/null
169+
exit 1
170170
fi
171171

172172
# Ensure we're on main branch
173173
current_branch=$(git rev-parse --abbrev-ref HEAD)
174174
if [ "$current_branch" != "main" ]; then
175-
echo "Switching to main branch..."
176-
git checkout main
175+
echo "Switching to main branch..."
176+
git checkout main
177177
fi
178178

179179
# Pull latest changes
@@ -187,9 +187,9 @@ git fetch --tags origin
187187
git checkout "$tag"
188188

189189
if [ $? -ne 0 ]; then
190-
echo "ERROR: Failed to checkout tag $tag in submodule"
191-
popd > /dev/null
192-
exit 1
190+
echo "ERROR: Failed to checkout tag $tag in submodule"
191+
popd >/dev/null
192+
exit 1
193193
fi
194194

195195
cd ..
@@ -199,80 +199,80 @@ git add MaxMind-DB-Reader-php
199199

200200
# Check if there are actual changes
201201
if [ -z "$(git status --porcelain)" ]; then
202-
echo "No changes needed in extension repository (already at $tag)"
203-
popd > /dev/null
204-
echo "Extension repository is up to date"
202+
echo "No changes needed in extension repository (already at $tag)"
203+
popd >/dev/null
204+
echo "Extension repository is up to date"
205205
else
206-
# Commit submodule update
207-
echo "Committing submodule update..."
208-
git commit -m "Update to MaxMind-DB-Reader-php $version
206+
# Commit submodule update
207+
echo "Committing submodule update..."
208+
git commit -m "Update to MaxMind-DB-Reader-php $version
209209
210210
This updates the submodule reference to track the $tag release.
211211
212212
Release notes from main repository:
213213
$notes"
214214

215-
# Push changes
216-
echo "Pushing to origin..."
217-
git push origin main
218-
219-
if [ $? -ne 0 ]; then
220-
echo "ERROR: Failed to push to extension repository"
221-
popd > /dev/null
222-
exit 1
223-
fi
224-
225-
# Create pre-packaged source tarball for PIE
226-
# PIE needs this because it doesn't handle git submodules automatically
227-
echo "Creating pre-packaged source tarball for PIE..."
228-
pie_tarball="maxminddb-${tag}.tgz"
229-
230-
# Create tarball with files at root level (PIE requirement)
231-
# Note: naming must be {extension-name}-v{version}.tgz
232-
pushd MaxMind-DB-Reader-php/ext > /dev/null
233-
tar -czf "../../$pie_tarball" *
234-
popd > /dev/null
235-
236-
if [ ! -f "$pie_tarball" ]; then
237-
echo "ERROR: Failed to create source tarball"
238-
popd > /dev/null
239-
exit 1
240-
fi
241-
242-
echo "Created $pie_tarball"
243-
244-
# Create corresponding release in extension repo with same tag
245-
echo "Creating release $tag in extension repository..."
246-
gh release create "$tag" \
247-
--repo maxmind/MaxMind-DB-Reader-php-ext \
248-
--title "$version" \
249-
--notes "Extension release for MaxMind-DB-Reader-php $version
215+
# Push changes
216+
echo "Pushing to origin..."
217+
git push origin main
218+
219+
if [ $? -ne 0 ]; then
220+
echo "ERROR: Failed to push to extension repository"
221+
popd >/dev/null
222+
exit 1
223+
fi
224+
225+
# Create pre-packaged source tarball for PIE
226+
# PIE needs this because it doesn't handle git submodules automatically
227+
echo "Creating pre-packaged source tarball for PIE..."
228+
pie_tarball="maxminddb-${tag}.tgz"
229+
230+
# Create tarball with files at root level (PIE requirement)
231+
# Note: naming must be {extension-name}-v{version}.tgz
232+
pushd MaxMind-DB-Reader-php/ext >/dev/null
233+
tar -czf "../../$pie_tarball" *
234+
popd >/dev/null
235+
236+
if [ ! -f "$pie_tarball" ]; then
237+
echo "ERROR: Failed to create source tarball"
238+
popd >/dev/null
239+
exit 1
240+
fi
241+
242+
echo "Created $pie_tarball"
243+
244+
# Create corresponding release in extension repo with same tag
245+
echo "Creating release $tag in extension repository..."
246+
gh release create "$tag" \
247+
--repo maxmind/MaxMind-DB-Reader-php-ext \
248+
--title "$version" \
249+
--notes "Extension release for MaxMind-DB-Reader-php $version
250250
251251
This release tracks the $tag tag of the main repository.
252252
253253
## Release notes from main repository
254254
255255
$notes" \
256-
"$pie_tarball"
257-
258-
if [ $? -ne 0 ]; then
259-
echo "ERROR: Failed to create release in extension repository"
260-
echo "You may need to create it manually at:"
261-
echo "https://github.com/maxmind/MaxMind-DB-Reader-php-ext/releases/new?tag=$tag"
262-
popd > /dev/null
263-
exit 1
264-
fi
265-
266-
# Clean up tarball
267-
rm -f "$pie_tarball"
268-
269-
echo ""
270-
echo "✓ Extension repository updated successfully!"
271-
echo "✓ Release created: https://github.com/maxmind/MaxMind-DB-Reader-php-ext/releases/tag/$tag"
272-
echo "✓ Pre-packaged source uploaded: $pie_tarball"
256+
"$pie_tarball"
257+
258+
if [ $? -ne 0 ]; then
259+
echo "ERROR: Failed to create release in extension repository"
260+
echo "You may need to create it manually at:"
261+
echo "https://github.com/maxmind/MaxMind-DB-Reader-php-ext/releases/new?tag=$tag"
262+
popd >/dev/null
263+
exit 1
264+
fi
265+
266+
# Clean up tarball
267+
rm -f "$pie_tarball"
268+
269+
echo ""
270+
echo "✓ Extension repository updated successfully!"
271+
echo "✓ Release created: https://github.com/maxmind/MaxMind-DB-Reader-php-ext/releases/tag/$tag"
272+
echo "✓ Pre-packaged source uploaded: $pie_tarball"
273273
fi
274274

275-
popd > /dev/null
275+
popd >/dev/null
276276

277277
echo ""
278278
echo "==================================================================="

0 commit comments

Comments
 (0)