name: 'Test'

on:
  pull_request:
    types: [opened, synchronize]
    paths-ignore:
    - '**.md'
  push:
    paths-ignore:
    - '**.md'
    branches:
    - master

jobs:
  test:
    runs-on: ubuntu-18.04

    steps:
    - uses: actions/checkout@v1
      with:
        fetch-depth: 1

    - name: Read .nvmrc
      run: echo ::set-output name=NVMRC::$(cat .nvmrc)
      id: nvm

    - name: Setup Node
      uses: actions/setup-node@v1
      with:
        node-version: '${{ steps.nvm.outputs.NVMRC }}'

    - name: Cache
      uses: actions/cache@v1.0.1
      with:
        path: ~/.npm
        key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
        restore-keys: |
          ${{ runner.os }}-node-

    - run: npm ci

    - run: npm run format:check

    - run: npm run lint

    - run: npm test

    - name: Upload test coverage
      uses: actions/upload-artifact@master
      with:
        name: coverage
        path: coverage


  test-prod:
    runs-on: ${{ matrix.os }}
    needs: test
    strategy:
      matrix:
        os: ['ubuntu-18.04', 'macos-latest', 'windows-latest']
        hugo-version: ['latest', '0.57.2']
        extended: [true, false]

    steps:
    - uses: actions/checkout@v1
      with:
        fetch-depth: 1

    - name: Test action
      uses: ./
      with:
        hugo-version: ${{ matrix.hugo-version }}
        extended: ${{ matrix.extended }}