Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 40 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This block runs with set -xe
Therefore it exits anyway for a non-zero exit code.
Could be rewritten as:
./phpswitch.sh ${{ matrix.php-version }} -s || { echo "switch failed"; exit 1; }
Also, the code fails (exit 1) Why use exit 0 here?


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
6 changes: 4 additions & 2 deletions phpswitch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Loading