22
33set -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
638current_branch=$( git branch --show-current)
739if [ " $current_branch " = " main" ]; then
@@ -25,23 +57,23 @@ phar='geoip2.phar'
2557changelog=$( cat CHANGELOG.md)
2658
2759regex='
28- ([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})\)
2961-*
3062
3163((.|
3264)*)
3365'
3466
3567if [[ ! $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
3870fi
3971
4072version=" ${BASH_REMATCH[1]} "
41- date=" ${BASH_REMATCH[2 ]} "
42- 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' ) "
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
4779fi
@@ -63,7 +95,6 @@ php composer.phar update --no-dev
6395perl -pi -e " s/(?<=const VERSION = ').+?(?=';)/$tag /g" src/WebService/Client.php
6496perl -pi -e " s{(?<=php composer\.phar require geoip2/geoip2:).+}{^$version }g" README.md
6597
66-
6798box_phar_hash=' f98cf885a7c07c84df66e33888f1d93f063298598e0a5f41ca322aeb9683179b box.phar'
6899
69100if ! echo " $box_phar_hash " | sha256sum -c; then
105136 popd
106137fi
107138
108-
109139if [ -n " $( git status --porcelain) " ]; then
110140 echo " .gh-pages is not clean" >&2
111141 exit 1
@@ -139,7 +169,7 @@ php phpDocumentor.phar \
139169rm -rf " $cachedir "
140170
141171page=index.md
142- cat << EOF > $page
172+ cat << EOF >$page
143173---
144174layout: default
145175title: MaxMind GeoIP2 PHP API
@@ -149,14 +179,14 @@ version: $tag
149179
150180EOF
151181
152- cat ../README.md >> $page
182+ cat ../README.md >> $page
153183
154184git add doc/
155185
156186echo " Release notes for $tag :"
157187echo " $notes "
158188
159- read -e -p " Commit changes and push to origin? " should_push
189+ read -r - e -p " Commit changes and push to origin? " should_push
160190
161191if [ " $should_push " != " y" ]; then
162192 echo " Aborting"
@@ -173,5 +203,3 @@ git commit -m "Update for $tag" -a
173203git push
174204
175205gh release create --target " $( git branch --show-current) " -t " $version " -n " $notes " " $tag " " $phar "
176-
177- git push --tags
0 commit comments