name: Install php
description: Setup PHP, with composer and extensions
inputs:
  shell:
    description: 'Shell to use'
    required: false
    default: bash
  php_version:
    description: 'PHP version'
    default: '8.1'
    required: true
runs:
  using: "composite"
  steps:
    - name: apt update
      run: sudo apt-get update -y
      shell: bash
    - name: Setup Chrome Action
      uses: browser-actions/setup-chrome@v1
      with:
        chrome-version: 122
    - name: Setup PHP, with composer and extensions
      uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php
      env:
        APP_ENV: "testing"
      with:
        php-version: ${{ inputs.php_version }}
        extensions: mbstring, dom, fileinfo, mysql, gd, curl, zip, sqlite, xml, bcmath, intl, sodium
        ini-values: post_max_size=2560M, max_execution_time=1800, memory_limit=2560M,
        tools: phpunit:10.1.3, composer
    - name: Get composer cache directory
      id: composer-cache
      run: echo "::set-output name=dir::$(composer config cache-files-dir)"
      shell: bash
    - name: Cache composer dependencies
      uses: actions/cache@v2
      with:
        path: ${{ steps.composer-cache.outputs.dir }}
        # Use composer.json for key, if composer.lock is not committed.
        # key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
        key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
        restore-keys: ${{ runner.os }}-composer-
    - name: Install Composer dependencies
      run: composer install --no-progress --prefer-dist --optimize-autoloader
      shell: bash
#    - name: Install Chrome Driver
#      run: php artisan dusk:install
#      shell: bash
#    - name: Dusk update
#      run: php artisan dusk:chrome-driver 117
#      shell: bash
    - name: Install Dusk
      run: |
        composer update "laravel/dusk" --prefer-dist --no-interaction --no-progress -W
        php artisan dusk:install
        php artisan dusk:chrome-driver 122
      shell: bash
    - name: Update Chrome Driver
      run: |
        composer require --dev staudenmeir/dusk-updater
        php artisan package:discover --ansi
        php artisan dusk:update --detect
      shell: bash
    - name: Copy env
      run: |
        cp --force /home/runner/work/microweber/microweber/.env.testing /home/runner/work/microweber/microweber/.env
        chmod 777 /home/runner/work/microweber/microweber/.env
        chmod 777 /home/runner/work/microweber/microweber/storage/
        sudo php artisan config:clear
        sudo php artisan optimize:clear
      shell: bash
    - name: Start Chrome Driver
      run: |
        vendor/laravel/dusk/bin/chromedriver-linux --version
        vendor/laravel/dusk/bin/chromedriver-linux > /dev/null 2>&1 &
      shell: bash
