From 1dbc89b83f7eb81f510a7ad9631ae4dd13fb831f Mon Sep 17 00:00:00 2001 From: Andrew Miller Date: Tue, 25 Nov 2025 09:33:55 +0900 Subject: [PATCH 1/7] Update ci.yml --- .github/workflows/ci.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f637d35..35cfe1f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,6 +21,11 @@ jobs: - '7.3' - '7.4' - '8.0' + - '8.1' + - '8.2' + - '8.3' + - '8.4' + - '8.5' steps: - name: "Checkout code" From e8905a763e296effa8fca1a95c417c5198707a43 Mon Sep 17 00:00:00 2001 From: Andrew Miller Date: Tue, 25 Nov 2025 09:40:59 +0900 Subject: [PATCH 2/7] Update hombrew before running --- .github/workflows/ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 35cfe1f..abd55f1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -34,6 +34,8 @@ jobs: - run: | set -xe + brew update + brew upgrade --greedy --force brew --version brew tap shivammathur/php brew install shivammathur/php/php@${{ matrix.php-version }} From 91991974cbf5fc8292db3da872d210c1c49970bb Mon Sep 17 00:00:00 2001 From: Andrew Miller Date: Tue, 25 Nov 2025 10:00:27 +0900 Subject: [PATCH 3/7] Improve CI check --- .github/workflows/ci.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index abd55f1..5532c97 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -40,8 +40,12 @@ jobs: brew tap shivammathur/php brew install shivammathur/php/php@${{ matrix.php-version }} ./phpswitch.sh ${{ matrix.php-version }} -s + if [ $@ != 0 ]; then + echo "Expected PHP version ${{ matrix.php-version}} failed to switch." + exit 0 + fi switched=$(php -v | grep -e '^PHP' | cut -d' ' -f2 | cut -d. -f1,2) if [ "${{ matrix.php-version }}" != "$switched" ]; then - echo "Expected ${{ matrix.php-version }} got $switched" + echo "Expected PHP version ${{ matrix.php-version }} successfully switched." exit 1 fi From 3fc8528193e5b03a0b26c9b0c6feecee4786c6d2 Mon Sep 17 00:00:00 2001 From: Andrew Miller Date: Tue, 25 Nov 2025 10:00:52 +0900 Subject: [PATCH 4/7] Use non-zero exit codes for error situations --- phpswitch.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/phpswitch.sh b/phpswitch.sh index f0237f7..de7242f 100755 --- a/phpswitch.sh +++ b/phpswitch.sh @@ -40,7 +40,7 @@ if [[ -z "$1" ]]; then echo " -s=* skip change of mod_php on apache or valet restart i.e (apache|valet,apache|valet)" echo " -c=* switch a specific config (apache|valet,apache|valet" echo - exit + exit 1 fi if [[ $(echo "$php_version" | sed 's/^php@//' | sed 's/\.//') -ge 80 ]]; then @@ -101,7 +101,7 @@ done # Check if php version support via valet if [[ (" ${valet_support_php_version_array[*]} " != *"$php_version"*) && ($valet_restart -eq 1) ]]; then echo "Sorry, but $php_version is not support via valet" - exit + exit 1 fi # Check that the requested version is supported @@ -166,7 +166,9 @@ $comment_apache_module_string\\ echo "All done!" else echo "Sorry, but $php_version is not installed via brew. Install by running: brew install $php_version" + exit 1 fi else echo "Unknown version of PHP. PHP Switcher can only handle arguments of:" ${brew_array[@]} + exit 1 fi From bd9f1aa869bbf164bfda1671c5afe686a054ae88 Mon Sep 17 00:00:00 2001 From: Andrew Miller Date: Tue, 25 Nov 2025 13:54:17 +0900 Subject: [PATCH 5/7] Fix result variable --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5532c97..e1f1d86 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -40,7 +40,7 @@ jobs: brew tap shivammathur/php brew install shivammathur/php/php@${{ matrix.php-version }} ./phpswitch.sh ${{ matrix.php-version }} -s - if [ $@ != 0 ]; then + if [ "$?" != 0 ]; then echo "Expected PHP version ${{ matrix.php-version}} failed to switch." exit 0 fi From 4ad41cccb4b178bb7bc1d94bdb86be72dd2c9756 Mon Sep 17 00:00:00 2001 From: Andrew Miller Date: Tue, 25 Nov 2025 14:04:05 +0900 Subject: [PATCH 6/7] Try adding caching to homebrew updates --- .github/workflows/ci.yml | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e1f1d86..faa3b82 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -28,23 +28,47 @@ jobs: - '8.5' steps: - - name: "Checkout code" - uses: actions/checkout@v2.3.3 + - name: Checkout code + uses: actions/checkout@v4 - - run: | - set -xe + - name: Cache Homebrew + uses: actions/cache@v4 # Use the latest version of actions/cache + id: brew-cache + with: + path: | + ~/Library/Caches/Homebrew + /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core + /usr/local/Homebrew/Library/Taps/shivammathur/php + key: ${{ runner.os }}-brew-${{ hashFiles('**/Brewfile') }} # Or use a different key strategy + restore-keys: | + ${{ runner.os }}-brew- - brew update - brew upgrade --greedy --force + - name: Update Homebrew + # The cache is restored automatically if a match is found + run: | + brew update # Update Homebrew's understanding of available packages + brew upgrade # Upgrade all installed packages + brew cleanup # Remove old versions and a growing cache + + - name: Install PHP + run: | brew --version brew tap shivammathur/php brew install shivammathur/php/php@${{ matrix.php-version }} + + - name: Confirm PHP version switch + run: | + set -xe + ./phpswitch.sh ${{ matrix.php-version }} -s + if [ "$?" != 0 ]; then echo "Expected PHP version ${{ matrix.php-version}} failed to switch." exit 0 fi + switched=$(php -v | grep -e '^PHP' | cut -d' ' -f2 | cut -d. -f1,2) + if [ "${{ matrix.php-version }}" != "$switched" ]; then echo "Expected PHP version ${{ matrix.php-version }} successfully switched." exit 1 From 8d56fe76f8910a49e7c07831e5adab325993d2fa Mon Sep 17 00:00:00 2001 From: Andrew Miller Date: Tue, 25 Nov 2025 14:09:40 +0900 Subject: [PATCH 7/7] Cache based on PHP version --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index faa3b82..0353d4c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -39,7 +39,7 @@ jobs: ~/Library/Caches/Homebrew /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core /usr/local/Homebrew/Library/Taps/shivammathur/php - key: ${{ runner.os }}-brew-${{ hashFiles('**/Brewfile') }} # Or use a different key strategy + key: ${{ runner.os }}-brew-${{ matrix.php-version }} # Or use a different key strategy restore-keys: | ${{ runner.os }}-brew-