name: "CI Pipeline"
on:
  push:
    branches:
      - '*'
    paths-ignore:
      - '*.md'
      - 'LICENSE'
    tags-ignore:
      - '*'
  pull_request:
    branches:
      - master
    paths-ignore:
      - '*.md'
      - 'LICENSE'
jobs:
  lint:
    runs-on: ubuntu-latest
    steps:
      - name: "Check out Git repository"
        uses: actions/checkout@v2
      - name: "Use Node.js 22"
        uses: actions/setup-node@v4
        with:
          node-version: 22
          cache: npm
      - name: "Install application"
        run: npm install --ignore-scripts
      - name: "Lint code"
        run: npm run lint
  test:
    runs-on: ubuntu-latest
    steps:
      - name: "Check out Git repository"
        uses: actions/checkout@v2
      - name: "Use Node.js 22"
        uses: actions/setup-node@v4
        with:
          node-version: 22
          cache: npm
      - name: "Cache Node.js modules"
        uses: actions/cache@v4
        with:
          path: ~/.npm
          key: ${{ runner.OS }}-node-${{ hashFiles('**/package.json') }}
          restore-keys: |
            ${{ runner.OS }}-node-
            ${{ runner.OS }}-
      - name: "Install application"
        run: npm install
      - name: "Execute unit tests"
        run: npm test
        env:
          AWS_API_KEY: ${{ secrets.AWS_API_KEY }}
      - name: "Publish coverage to Coveralls"
        if: github.event_name == 'push'
        uses: coverallsapp/github-action@master
        with:
          github-token: ${{ secrets.GITHUB_TOKEN }}
          path-to-lcov: ./build/reports/coverage/lcov.info
  notify-slack:
    if: github.event_name == 'push' && (success() || failure())
    needs:
      - lint
      - test
    runs-on: ubuntu-latest
    steps:
      - name: "Slack workflow notification"
        uses: Gamesight/slack-workflow-status@master
        with:
          repo_token: ${{ secrets.GITHUB_TOKEN }}
          slack_webhook_url: ${{ secrets.SLACK_WEBHOOK_URL }}
