Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 682
TheWebs Avatar asked Dec 22 '20 03:12

TheWebs


1 Answers

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');"
    [...]
like image 184
riQQ Avatar answered Sep 18 '22 18:09

riQQ