name: Test commit or pull request

on: [push, pull_request]

jobs:
  eslint:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2

      - name: Read Node.js & NPM versions
        run: |
          echo "##[set-output name=NODE;]$(cat package.json | jq -r '.engines.node')"
          echo "##[set-output name=NPM;]$(cat package.json | jq -r '.engines.npm')"
        id: versions

      - name: Use correct Node.js version
        uses: actions/setup-node@v2
        with:
          node-version: "${{ steps.versions.outputs.NODE }}"

      - name: Use correct NPM version
        run: npm i -g npm@"${{ steps.versions.outputs.NPM }}"

      - name: Install dependencies
        run: npm ci

      - name: Test with eslint
        run: npm run test:eslint

  stylelint:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2

      - name: Read Node.js & NPM versions
        run: |
          echo "##[set-output name=NODE;]$(cat package.json | jq -r '.engines.node')"
          echo "##[set-output name=NPM;]$(cat package.json | jq -r '.engines.npm')"
        id: versions

      - name: Use correct Node.js version
        uses: actions/setup-node@v2
        with:
          node-version: "${{ steps.versions.outputs.NODE }}"

      - name: Use correct NPM version
        run: npm i -g npm@"${{ steps.versions.outputs.NPM }}"

      - name: Install dependencies
        run: npm ci

      - name: Test with stylelint
        run: npm run test:stylelint

  i18n-packs:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2

      - name: Read Node.js & NPM versions
        run: |
          echo "##[set-output name=NODE;]$(cat package.json | jq -r '.engines.node')"
          echo "##[set-output name=NPM;]$(cat package.json | jq -r '.engines.npm')"
        id: versions

      - name: Use correct Node.js version
        uses: actions/setup-node@v2
        with:
          node-version: "${{ steps.versions.outputs.NODE }}"

      - name: Use correct NPM version
        run: npm i -g npm@"${{ steps.versions.outputs.NPM }}"

      - name: Install dependencies
        run: npm ci

      - name: Test i18n packs integrity
        run: npm run test:i18n-packs
