From 59c3946123cadfa1adb27eef7721fe19049409b1 Mon Sep 17 00:00:00 2001 From: Gregory Oschwald Date: Wed, 3 Dec 2025 10:12:17 -0800 Subject: [PATCH 1/2] Add pre-flight checks to release script --- dev-bin/release.sh | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/dev-bin/release.sh b/dev-bin/release.sh index 6c40791b..29a16bb4 100755 --- a/dev-bin/release.sh +++ b/dev-bin/release.sh @@ -2,6 +2,38 @@ set -eu -o pipefail +# Pre-flight checks - verify all required tools are available and configured +# before making any changes to the repository + +check_command() { + if ! command -v "$1" &> /dev/null; then + echo "Error: $1 is not installed or not in PATH" + exit 1 + fi +} + +# Verify gh CLI is authenticated +if ! gh auth status &> /dev/null; then + echo "Error: gh CLI is not authenticated. Run 'gh auth login' first." + exit 1 +fi + +# Verify we can access this repository via gh +if ! gh repo view --json name &> /dev/null; then + echo "Error: Cannot access repository via gh. Check your authentication and repository access." + exit 1 +fi + +# Verify git can connect to the remote (catches SSH key issues, etc.) +if ! git ls-remote origin &> /dev/null; then + echo "Error: Cannot connect to git remote. Check your git credentials/SSH keys." + exit 1 +fi + +check_command perl +check_command php +check_command wget + # Check that we're not on the main branch current_branch=$(git branch --show-current) if [ "$current_branch" = "main" ]; then From d81cb2ece713541bda30a726e9ac5631ba404f6f Mon Sep 17 00:00:00 2001 From: Gregory Oschwald Date: Wed, 3 Dec 2025 13:33:18 -0800 Subject: [PATCH 2/2] Fix release script consistency issues - Remove redundant git push --tags (gh release create handles tags) - 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 --- dev-bin/release.sh | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/dev-bin/release.sh b/dev-bin/release.sh index 29a16bb4..e033be17 100755 --- a/dev-bin/release.sh +++ b/dev-bin/release.sh @@ -6,26 +6,26 @@ set -eu -o pipefail # before making any changes to the repository check_command() { - if ! command -v "$1" &> /dev/null; then + if ! command -v "$1" &>/dev/null; then echo "Error: $1 is not installed or not in PATH" exit 1 fi } # Verify gh CLI is authenticated -if ! gh auth status &> /dev/null; then +if ! gh auth status &>/dev/null; then echo "Error: gh CLI is not authenticated. Run 'gh auth login' first." exit 1 fi # Verify we can access this repository via gh -if ! gh repo view --json name &> /dev/null; then +if ! gh repo view --json name &>/dev/null; then echo "Error: Cannot access repository via gh. Check your authentication and repository access." exit 1 fi # Verify git can connect to the remote (catches SSH key issues, etc.) -if ! git ls-remote origin &> /dev/null; then +if ! git ls-remote origin &>/dev/null; then echo "Error: Cannot connect to git remote. Check your git credentials/SSH keys." exit 1 fi @@ -57,7 +57,7 @@ phar='geoip2.phar' changelog=$(cat CHANGELOG.md) regex=' -([0-9]+\.[0-9]+\.[0-9]+) \(([0-9]{4}-[0-9]{2}-[0-9]{2})\) +([0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9.]+)?) \(([0-9]{4}-[0-9]{2}-[0-9]{2})\) -* ((.| @@ -65,15 +65,15 @@ regex=' ' if [[ ! $changelog =~ $regex ]]; then - echo "Could not find date line in change log!" - exit 1 + echo "Could not find date line in change log!" + exit 1 fi version="${BASH_REMATCH[1]}" -date="${BASH_REMATCH[2]}" -notes="$(echo "${BASH_REMATCH[3]}" | sed -n -e '/^[0-9]\+\.[0-9]\+\.[0-9]\+/,$!p')" +date="${BASH_REMATCH[3]}" +notes="$(echo "${BASH_REMATCH[4]}" | sed -n -E '/^[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9.]+)?/,$!p')" -if [[ "$date" != $(date +"%Y-%m-%d") ]]; then +if [[ "$date" != "$(date +"%Y-%m-%d")" ]]; then echo "$date is not today!" exit 1 fi @@ -95,7 +95,6 @@ php composer.phar update --no-dev perl -pi -e "s/(?<=const VERSION = ').+?(?=';)/$tag/g" src/WebService/Client.php perl -pi -e "s{(?<=php composer\.phar require geoip2/geoip2:).+}{^$version}g" README.md - box_phar_hash='f98cf885a7c07c84df66e33888f1d93f063298598e0a5f41ca322aeb9683179b box.phar' if ! echo "$box_phar_hash" | sha256sum -c; then @@ -137,7 +136,6 @@ else popd fi - if [ -n "$(git status --porcelain)" ]; then echo ".gh-pages is not clean" >&2 exit 1 @@ -171,7 +169,7 @@ php phpDocumentor.phar \ rm -rf "$cachedir" page=index.md -cat < $page +cat <$page --- layout: default title: MaxMind GeoIP2 PHP API @@ -181,14 +179,14 @@ version: $tag EOF -cat ../README.md >> $page +cat ../README.md >>$page git add doc/ echo "Release notes for $tag:" echo "$notes" -read -e -p "Commit changes and push to origin? " should_push +read -r -e -p "Commit changes and push to origin? " should_push if [ "$should_push" != "y" ]; then echo "Aborting" @@ -205,5 +203,3 @@ git commit -m "Update for $tag" -a git push gh release create --target "$(git branch --show-current)" -t "$version" -n "$notes" "$tag" "$phar" - -git push --tags