name: main
on:
  push:
    branches:
      - main
  pull_request:

jobs:
  install:
    name: Install Dependencies
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v2
      - name: Setup
        uses: ./.github/actions/setup
  #<% if (checkFormat) { %>
  check-format:
    name: Check Format
    runs-on: ubuntu-latest
    needs: install
    steps:
      - name: Checkout
        uses: actions/checkout@v2
      - name: Setup
        uses: ./.github/actions/setup
      - name: Check Format
        run: <% if (yarn) { %>yarn<% } else { %>npm run<% } %> format:check
  #<% } %>
  #<% if (lint) { %>
  lint:
    name: Lint
    runs-on: ubuntu-latest
    needs: install
    steps:
      - name: Checkout
        uses: actions/checkout@v2
      - name: Setup
        uses: ./.github/actions/setup
      - name: Lint
        run: <% if (yarn) { %>yarn<% } else { %>npm run<% } %> lint --format junit -o reports/lint-results.xml
      - name: Upload Report
        uses: actions/upload-artifact@v2
        if: always()
        with:
          name: lint-results
          path: reports/lint-results.xml
  #<% } %>
  #<% if (checkTypes) { %>
  check-types:
    name: Check Typescript Types
    runs-on: ubuntu-latest
    needs: install
    steps:
      - name: Checkout
        uses: actions/checkout@v2
      - name: Setup
        uses: ./.github/actions/setup
      - name: Check Typescript Types
        run: <% if (yarn) { %>yarn<% } else { %>npm run<% } %> check-types
  #<% } %>
  #<% if (unitTests) { %>
  unit-test:
    name: Unit Tests
    runs-on: ubuntu-latest
    needs: install
    steps:
      - name: Checkout
        uses: actions/checkout@v2
      - name: Setup
        uses: ./.github/actions/setup
      - name: Unit Tests
        run: <% if (yarn) { %>yarn<% } else { %>npm run<% } %> test:coverage --ci --reporters=default --reporters=jest-junit
        env:
          JEST_JUNIT_OUTPUT_FILE: 'reports/unit-test-results.xml'
      - name: Upload Report to Codecov
        uses: codecov/codecov-action@v2
        if: always()
      - name: Upload Report
        uses: actions/upload-artifact@v2
        if: always()
        with:
          name: unit-test-results
          path: reports/unit-test-results.xml
  #<% } %>
  #<% if (e2eTests) { %>
  e2e-test:
    name: E2E Tests
    runs-on: ubuntu-latest
    needs: install
    steps:
      - name: Checkout
        uses: actions/checkout@v2
      - name: Setup
        uses: ./.github/actions/setup
      - name: E2E Tests
        run: <% if (yarn) { %>yarn<% } else { %>npm run<% } %> test:e2e --ci --reporters=default --reporters=jest-junit
        env:
          JEST_JUNIT_OUTPUT_FILE: 'reports/e2e-test-results.xml'
      - name: Upload Report
        uses: actions/upload-artifact@v2
        if: always()
        with:
          name: e2e-test-results
          path: reports/e2e-test-results.xml
  #<% } %>
  #<% if (build) { %>
  build:
    name: Build
    runs-on: ubuntu-latest
    needs:
      #<% if (checkFormat) { %>
      - check-format
      #<% } %>
      #<% if (lint) { %>
      - lint
      #<% } %>
      #<% if (checkTypes) { %>
      - check-types
      #<% } %>
      #<% if (unitTests) { %>
      - unit-test
      #<% } %>
      #<% if (e2eTests) { %>
      - e2e-test
      #<% } %>
    steps:
      - name: Checkout
        uses: actions/checkout@v2
      - name: Setup
        uses: ./.github/actions/setup
      - name: Build
        run: <% if (yarn) { %>yarn<% } else { %>npm run<% } %> build
      #<% } %>
      #<% if (checkSize) { %>
      - name: Upload Build Artifact
        uses: actions/upload-artifact@v2
        with:
          name: bundle
          path: hello-web-components.min.*
  size:
    name: Check Size
    runs-on: ubuntu-latest
    needs: build
    steps:
      - name: Checkout
        uses: actions/checkout@v2
      - name: Setup
        uses: ./.github/actions/setup
      - name: Download Build Artifact
        uses: actions/download-artifact@v2
        with:
          name: bundle
      - name: Check Size
        run: <% if (yarn) { %>yarn<% } else { %>npm run<% } %> size
  #<% } %>
