name: PR Coverage Report

on:
  pull_request: # This will trigger the action on any pull request

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout repository
        uses: actions/checkout@v4

      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: '24'

      - name: Install dependencies
        run: npm ci

      - name: Run Build
        run: npm run build

      - name: Run Coverage Script
        run: npm run coverage

      - name: Coveralls
        uses: coverallsapp/github-action@v2

      - name: Markdownize Istanbul report
        run: |
          sed -i -e '1{/^----/d}; ${/^----/d}' ./coverage/report.txt

      - name: Comment Coverage on PR
        if: ${{ ! github.event.pull_request.head.repo.fork }}
        uses: marocchino/sticky-pull-request-comment@v2
        with:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          path: ./coverage/report.txt