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 phpize
36+ check_command pecl
37+
538# Check that we're not on the main branch
639current_branch=$( git branch --show-current)
740if [ " $current_branch " = " main" ]; then
2356changelog=$( cat CHANGELOG.md)
2457
2558regex='
26- ([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})\)
2760-*
2861
2962((.|
3063)*)
3164'
3265
3366if [[ ! $changelog =~ $regex ]]; then
34- echo " Could not find date line in change log!"
35- exit 1
67+ echo " Could not find date line in change log!"
68+ exit 1
3669fi
3770
3871version=" ${BASH_REMATCH[1]} "
39- date=" ${BASH_REMATCH[2 ]} "
40- 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' ) "
4174
42- if [[ " $date " != $( date +" %Y-%m-%d" ) ]]; then
75+ if [[ " $date " != " $( date +" %Y-%m-%d" ) " ]]; then
4376 echo " $date is not today!"
4477 exit 1
4578fi
@@ -87,7 +120,7 @@ pecl package
87120
88121package=" maxminddb-$version .tgz"
89122
90- read -p " Push to origin? (y/n) " should_push
123+ read -r - p " Push to origin? (y/n) " should_push
91124
92125if [ " $should_push " != " y" ]; then
93126 echo " Aborting"
@@ -126,13 +159,13 @@ if [ ! -d "$ext_repo_dir" ]; then
126159fi
127160
128161# Navigate to extension repository
129- pushd " $ext_repo_dir " > /dev/null
162+ pushd " $ext_repo_dir " > /dev/null
130163
131164# Safety check: ensure working directory is clean
132165if [ -n " $( git status --porcelain) " ]; then
133166 echo " ERROR: Extension repository has uncommitted changes"
134167 echo " Please commit or stash changes in: $ext_repo_dir "
135- popd > /dev/null
168+ popd > /dev/null
136169 exit 1
137170fi
138171
@@ -155,7 +188,7 @@ git checkout "$tag"
155188
156189if [ $? -ne 0 ]; then
157190 echo " ERROR: Failed to checkout tag $tag in submodule"
158- popd > /dev/null
191+ popd > /dev/null
159192 exit 1
160193fi
161194
@@ -167,7 +200,7 @@ git add MaxMind-DB-Reader-php
167200# Check if there are actual changes
168201if [ -z " $( git status --porcelain) " ]; then
169202 echo " No changes needed in extension repository (already at $tag )"
170- popd > /dev/null
203+ popd > /dev/null
171204 echo " Extension repository is up to date"
172205else
173206 # Commit submodule update
@@ -185,7 +218,7 @@ $notes"
185218
186219 if [ $? -ne 0 ]; then
187220 echo " ERROR: Failed to push to extension repository"
188- popd > /dev/null
221+ popd > /dev/null
189222 exit 1
190223 fi
191224
@@ -196,13 +229,13 @@ $notes"
196229
197230 # Create tarball with files at root level (PIE requirement)
198231 # Note: naming must be {extension-name}-v{version}.tgz
199- pushd MaxMind-DB-Reader-php/ext > /dev/null
232+ pushd MaxMind-DB-Reader-php/ext > /dev/null
200233 tar -czf " ../../$pie_tarball " *
201- popd > /dev/null
234+ popd > /dev/null
202235
203236 if [ ! -f " $pie_tarball " ]; then
204237 echo " ERROR: Failed to create source tarball"
205- popd > /dev/null
238+ popd > /dev/null
206239 exit 1
207240 fi
208241
@@ -226,7 +259,7 @@ $notes" \
226259 echo " ERROR: Failed to create release in extension repository"
227260 echo " You may need to create it manually at:"
228261 echo " https://github.com/maxmind/MaxMind-DB-Reader-php-ext/releases/new?tag=$tag "
229- popd > /dev/null
262+ popd > /dev/null
230263 exit 1
231264 fi
232265
@@ -239,7 +272,7 @@ $notes" \
239272 echo " ✓ Pre-packaged source uploaded: $pie_tarball "
240273fi
241274
242- popd > /dev/null
275+ popd > /dev/null
243276
244277echo " "
245278echo " ==================================================================="
0 commit comments