TheWebs
TheWebs

Reputation: 12913

How do you set the PHP version with this GitHub Actions workflow?

I have been using a GitHub Actions workflow for a while now:

name: Laravel

on: [push]

jobs:
  laravel-tests:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v1
    - name: Copy .env
      run: php -r "file_exists('.env') || copy('.env.example', '.env');"
    - name: Install Dependencies
      run: |
        rm -rf vendor
        composer install
    - name: Generate key
      run: php artisan key:generate
    - name: Link Storage
      run: php artisan storage:link
    - name: Create Database
      run: |
        mkdir -p database
        touch database/database.sqlite
    - name: Execute tests (Unit and Feature tests) via PHPUnit
      env:
        DB_CONNECTION: sqlite
        DB_DATABASE: database/database.sqlite
      run: vendor/bin/phpunit --stop-on-failure

It worked until 8.0 came out, then composer exploded with a bunch of errors that this and that package, which I update regularly, are not compatible with 8.0.

Anywho, I need to set this to use 7.4 for now.

I understand the:

with:
  php-version: '7.4'

and I know I can use a matrix, but where am I calling the whole "use this php version" with in this script to make the tests run against 7.4?

Upvotes: 12

Views: 5889

Answers (1)

riQQ
riQQ

Reputation: 12843

Use the setup-php action:

name: Laravel

on: [push]

jobs:
  laravel-tests:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v1    
    - name: Setup PHP
      uses: shivammathur/setup-php@v2
      with:
        php-version: 7.4
    - name: Copy .env
      run: php -r "file_exists('.env') || copy('.env.example', '.env');"
    [...]

Upvotes: 20

Related Questions