name: CI

on:
  push:
    branches:
      - dev
      - master
  pull_request:
    branches:
      - dev
      - master

env:
  NODE_VERSION: 16
  NODE_OPTIONS: --max_old_space_size=6144
  GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

jobs:
  lint:
    runs-on: ubuntu-latest
    steps:
      - name: Check out files from GitHub
        uses: actions/checkout@v3.3.0
      - name: Set up Node ${{ env.NODE_VERSION }}
        uses: actions/setup-node@v3.6.0
        with:
          node-version: ${{ env.NODE_VERSION }}
          cache: yarn
      - name: Install dependencies
        run: yarn install
        env:
          CI: true
      - name: Build resources
        run: ./node_modules/.bin/gulp gen-icons-json build-translations build-locale-data gather-gallery-pages
      - name: Run eslint
        run: yarn run lint:eslint
      - name: Run tsc
        run: yarn run lint:types
      - name: Run prettier
        run: yarn run lint:prettier
      - name: Check for duplicate dependencies
        run: yarn dedupe --check
  test:
    runs-on: ubuntu-latest
    steps:
      - name: Check out files from GitHub
        uses: actions/checkout@v3.3.0
      - name: Set up Node ${{ env.NODE_VERSION }}
        uses: actions/setup-node@v3.6.0
        with:
          node-version: ${{ env.NODE_VERSION }}
          cache: yarn
      - name: Install dependencies
        run: yarn install
        env:
          CI: true
      - name: Build resources
        run: ./node_modules/.bin/gulp build-translations build-locale-data
      - name: Run Tests
        run: yarn run test
  build:
    runs-on: ubuntu-latest
    needs: [lint, test]
    steps:
      - name: Check out files from GitHub
        uses: actions/checkout@v3.3.0
      - name: Set up Node ${{ env.NODE_VERSION }}
        uses: actions/setup-node@v3.6.0
        with:
          node-version: ${{ env.NODE_VERSION }}
          cache: yarn
      - name: Install dependencies
        run: yarn install
        env:
          CI: true
      - name: Build Application
        run: ./node_modules/.bin/gulp build-app
        env:
          IS_TEST: "true"
  supervisor:
    runs-on: ubuntu-latest
    needs: [lint, test]
    steps:
      - name: Check out files from GitHub
        uses: actions/checkout@v3.3.0
      - name: Set up Node ${{ env.NODE_VERSION }}
        uses: actions/setup-node@v3.6.0
        with:
          node-version: ${{ env.NODE_VERSION }}
          cache: yarn
      - name: Install dependencies
        run: yarn install
        env:
          CI: true
      - name: Build Application
        run: ./node_modules/.bin/gulp build-hassio
        env:
          IS_TEST: "true"
