name: jscpd CI

on: [push, pull_request]

env:
  FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: "true"

permissions:
  contents: read
  checks: write

jobs:
  build:

    runs-on: ubuntu-latest

    strategy:
      matrix:
        node-version: [22.x, 24.x, 26.x]

    steps:
    - uses: actions/checkout@v5
    - name: Install pnpm
      uses: pnpm/action-setup@v4
    - name: Use Node.js ${{ matrix.node-version }}
      uses: actions/setup-node@v5
      with:
        node-version: ${{ matrix.node-version }}
        package-manager-cache: false

    - name: Install dependencies
      run: pnpm install

    - name: Build
      run: pnpm build

    - name: Lint
      run: pnpm lint

    - name: Test
      run: pnpm test -- --reporter=default --reporter=junit --outputFile=test-results/junit.xml

    - name: Upload test results
      if: always()
      uses: actions/upload-artifact@v4
      with:
        name: test-results-node-${{ matrix.node-version }}
        path: '**/test-results/junit.xml'
        if-no-files-found: warn

    - name: Test Report
      if: always()
      continue-on-error: true
      uses: dorny/test-reporter@v1
      with:
        name: Node.js Tests (${{ matrix.node-version }})
        path: '**/test-results/junit.xml'
        reporter: java-junit
        fail-on-error: false

    - name: jscpd
      run: ./apps/jscpd/bin/jscpd ./fixtures
