diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f637d35..0353d4c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,20 +21,55 @@ jobs: - '7.3' - '7.4' - '8.0' + - '8.1' + - '8.2' + - '8.3' + - '8.4' + - '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-${{ matrix.php-version }} # Or use a different key strategy + restore-keys: | + ${{ runner.os }}-brew- + - 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 ${{ matrix.php-version }} got $switched" + echo "Expected PHP version ${{ matrix.php-version }} successfully switched." exit 1 fi 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