Skip to content

Commit 868c48a

Browse files
authored
Merge pull request #239 from maxmind/greg/eng-1733
Improve release script reliability (ENG-1733)
2 parents 8791645 + c60ef94 commit 868c48a

1 file changed

Lines changed: 39 additions & 10 deletions

File tree

dev-bin/release.sh

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,38 @@
22

33
set -eu -o pipefail
44

5+
# Pre-flight checks - verify all required tools are available and configured
6+
# before making any changes to the repository
7+
8+
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
13+
}
14+
15+
# 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
19+
fi
20+
21+
# 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
25+
fi
26+
27+
# 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
31+
fi
32+
33+
check_command perl
34+
check_command php
35+
check_command wget
36+
537
# Check that we're not on the main branch
638
current_branch=$(git branch --show-current)
739
if [ "$current_branch" = "main" ]; then
@@ -33,15 +65,15 @@ regex='
3365
'
3466

3567
if [[ ! $changelog =~ $regex ]]; then
36-
echo "Could not find date line in change log!"
37-
exit 1
68+
echo "Could not find date line in change log!"
69+
exit 1
3870
fi
3971

4072
version="${BASH_REMATCH[1]}"
4173
date="${BASH_REMATCH[3]}"
42-
notes="$(echo "${BASH_REMATCH[4]}" | sed -n -E '/^[0-9]+\.[0-9]+\.[0-9]+/,$!p')"
74+
notes="$(echo "${BASH_REMATCH[4]}" | sed -n -E '/^[0-9]+\.[0-9]+\.[0-9]+(-[^ ]+)?/,$!p')"
4375

44-
if [[ "$date" != $(date +"%Y-%m-%d") ]]; then
76+
if [[ "$date" != "$(date +"%Y-%m-%d")" ]]; then
4577
echo "$date is not today!"
4678
exit 1
4779
fi
@@ -106,7 +138,6 @@ else
106138
popd
107139
fi
108140

109-
110141
if [ -n "$(git status --porcelain)" ]; then
111142
echo ".gh-pages is not clean" >&2
112143
exit 1
@@ -140,7 +171,7 @@ php phpDocumentor.phar \
140171
rm -rf "$cachedir"
141172

142173
page=index.md
143-
cat <<EOF > $page
174+
cat <<EOF >$page
144175
---
145176
layout: default
146177
title: minFraud PHP API
@@ -150,14 +181,14 @@ version: $tag
150181
151182
EOF
152183

153-
cat ../README.md >> $page
184+
cat ../README.md >>$page
154185

155186
git add doc/
156187

157188
echo "Release notes for $tag:"
158189
echo "$notes"
159190

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

162193
if [ "$should_push" != "y" ]; then
163194
echo "Aborting"
@@ -174,5 +205,3 @@ git commit -m "Update for $tag" -a
174205
git push
175206

176207
gh release create --target "$(git branch --show-current)" -t "$version" -n "$notes" "$tag" "$phar"
177-
178-
git push --tags

0 commit comments

Comments
 (0)