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 make
35+ check_command autoconf
36+
537# Check that we're not on the main branch
638current_branch=$( git branch --show-current)
739if [ " $current_branch " = " main" ]; then
2254
2355changelog=$( cat Changes.md)
2456
25- regex=' ## ([0-9]+\.[0-9]+\.[0-9]+) - ([0-9]{4}-[0-9]{2}-[0-9]{2})
57+ regex=' ## ([0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9.]+)? ) - ([0-9]{4}-[0-9]{2}-[0-9]{2})
2658
2759((.|
2860)*)
2961'
3062
3163if [[ ! $changelog =~ $regex ]]; then
32- echo " Could not find date line in change log!"
33- exit 1
64+ echo " Could not find date line in change log!"
65+ exit 1
3466fi
3567
3668version=" ${BASH_REMATCH[1]} "
37- date=" ${BASH_REMATCH[2 ]} "
38- notes=" $( echo " ${BASH_REMATCH[3 ]} " | sed -n -e ' /^## [0-9]\ +\.[0-9]\ +\.[0-9]\+ /,$!p' ) "
69+ date=" ${BASH_REMATCH[3 ]} "
70+ notes=" $( echo " ${BASH_REMATCH[4 ]} " | sed -n -E ' /^## [0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9.]+)? /,$!p' ) "
3971
4072dist=" libmaxminddb-$version .tar.gz"
4173
42- if [[ " $date " != $( date +" %Y-%m-%d" ) ]]; then
74+ if [[ " $date " != " $( date +" %Y-%m-%d" ) " ]]; then
4375 echo " $date is not today!"
4476 exit 1
4577fi
@@ -49,7 +81,8 @@ if [ -n "$(git status --porcelain)" ]; then
4981 exit 1
5082fi
5183
52- old_version=$( perl -MFile::Slurp=read_file << EOF
84+ old_version=$(
85+ perl -MFile::Slurp=read_file << EOF
5386use v5.16;
5487my \$ conf = read_file(q{configure.ac});
5588\$ conf =~ /AC_INIT.+\[(\d+\.\d+\.\d+)\]/;
@@ -63,7 +96,7 @@ perl -MFile::Slurp=edit_file -e \
6396if [ -n " $( git status --porcelain) " ]; then
6497 git diff
6598
66- read -e -p " Commit changes? " should_commit
99+ read -r - e -p " Commit changes? (y/n) " should_commit
67100
68101 if [ " $should_commit " != " y" ]; then
69102 echo " Aborting"
@@ -97,30 +130,30 @@ if [ -n "$(git status --porcelain)" ]; then
97130fi
98131
99132index=index.md
100- cat << EOF > $index
133+ cat << EOF >$index
101134---
102135layout: default
103136title: libmaxminddb - a library for working with MaxMind DB files
104137version: $version
105138---
106139EOF
107140
108- cat ../doc/libmaxminddb.md >> $index
141+ cat ../doc/libmaxminddb.md >> $index
109142
110143mmdblookup=mmdblookup.md
111- cat << EOF > $mmdblookup
144+ cat << EOF >$mmdblookup
112145---
113146layout: default
114147title: mmdblookup - a utility to look up an IP address in a MaxMind DB file
115148version: $version
116149---
117150EOF
118151
119- cat ../doc/mmdblookup.md >> $mmdblookup
152+ cat ../doc/mmdblookup.md >> $mmdblookup
120153
121154git commit -m " Updated for $version " -a
122155
123- read -p " Push to origin? (y/n) " should_push
156+ read -r -e - p " Push to origin? (y/n) " should_push
124157
125158if [ " $should_push " != " y" ]; then
126159 echo " Aborting"
0 commit comments