name: Main

on: [pull_request, push]

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      # https://github.com/actions/checkout
      - name: Checkout
        uses: actions/checkout@master
        with:
          fetch-depth: 1
      - name: Install
        run: npm ci
      - name: Build
        run: npm run build
      - name: Test
        run: npm run test
      - name: "check for uncommitted changes"
        # Ensure no changes, but ignore node_modules dir since dev/fresh ci deps installed.
        run: |
          git diff --exit-code --stat -- . ':!node_modules' \
          || (echo "##[error] found changed files after build. please 'npm run build && npm run format'" \
                  "and check in all changes" \
              && exit 1)