name: Pantheon WP EI Build
on:
  pull_request:
    branches:
      - build
jobs:
  test:
    runs-on: ubuntu-latest
    name: Lint and Test
    steps:
    - uses: actions/checkout@v3
    - uses: shogo82148/actions-setup-mysql@v1
      with:
        mysql-version: 'mariadb-10.9'
        root-password: ''
    - name: Start MariaDB
      run: mysql -uroot -h127.0.0.1 -e 'SELECT version()'
    - name: Install dependencies
      run: composer install
    - name: Run lint
      run: composer lint
    - name: Run unit tests
      run: composer test
  build:
    needs: test
    runs-on: ubuntu-latest
    name: Build
    steps:
    - uses: actions/checkout@v2
      with:
        fetch-depth: 0
    - name: Run release
      run: |
        git config --local user.email "bot@getpantheon.com"
        git config --local user.name "Pantheon Automation"
        npm -v && npm install --legacy-peer-deps
        npm run release
        git status
        git commit -m "Built assets"
    - name: Push changes
      uses: ad-m/github-push-action@master
      with:
        github_token: ${{ secrets.GITHUB_TOKEN }}
        branch: ${{ github.head_ref }}
        force: true
