name: Lint Test Deploy

on: [push]

jobs:
  lint:
    name: Lint

    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2

      - name: Use Node.js 12.x
        uses: actions/setup-node@v1
        with:
          node-version: 12.x

      - name: Install dependencies
        run: |
          npm ci
          composer install

      - name: Run linter
        run: npm run lint

      - name: Run PHP linter
        run: npm run lint:php

  tests:
    name: Tests

    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2

      - name: Use Node.js 12.x
        uses: actions/setup-node@v1
        with:
          node-version: 12.x

      - name: Install dependencies
        run: |
          npm ci
          composer install

      - name: Install WordPress
        run: |
          chmod -R 767 ./ # TODO: Possibly integrate in wp-env
          npm run wp-env start

      - name: Running JavaScript E2E tests
        run: npm run test:e2e

      - name: Running PHP unit tests
        run: npm run test:unit:php:ci

  deploy:
    name: Deploy

    # only run on tags
    if: startsWith(github.ref, 'refs/tags/')

    needs: [ lint, tests ]

    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2

      - shell: bash
        env:
          SVN_PASSWORD: ${{ secrets.SVN_PASSWORD }}
        run: |
          scripts/deploy-wp-plugin.sh
