name: CI

permissions:
  contents: read
  pull-requests: write
  issues: write

on:
  workflow_dispatch:
  push:
    branches:
      - master
    paths:
      - 'index.js'
      - '__test__/**'
      - 'Makefile'
      - '*.json'
      - '.github/workflows/**'
      - '!**.md'
  pull_request:
    types: [opened, synchronize, reopened]
    paths:
      - 'index.js'
      - '__test__/**'
      - 'Makefile'
      - '*.json'
      - '.github/workflows/**'
      - '!**.md'

jobs:
  test:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout code
        uses: actions/checkout@v6

      - name: Set up Node.js
        uses: actions/setup-node@v6
        with:
          node-version: '22'

      - name: Install dependencies
        run: npm ci

      - name: Build
        run: make

      - name: Lint
        run: make lint

      - name: Check for skipped tests
        run: make skipped_tests

      - name: Test
        run: make test

      - name: Upload coverage to Coveralls
        if: github.event.pull_request.head.repo.full_name == github.repository || github.event_name == 'push' || github.event_name == 'workflow_dispatch'
        uses: coverallsapp/github-action@v2
        with:
          github-token: ${{ secrets.GITHUB_TOKEN }}
          path-to-lcov: ./coverage/lcov.info

      - name: Purge README images
        if: github.event.pull_request.head.repo.full_name == github.repository || github.event_name == 'push' || github.event_name == 'workflow_dispatch'
        uses: kevincobain2000/action-camo-purge@v1
