name: CI

on:
  push:
    branches: [main]
    paths-ignore:
      - '**/*.md'
      - 'LICENSE'
      - '.github/releases/**'
      - 'website/**'
      - 'browser/**'
  pull_request:
    branches: [main]
    paths-ignore:
      - '**/*.md'
      - 'LICENSE'
      - '.github/releases/**'
      - 'website/**'
      - 'browser/**'
  workflow_dispatch:

permissions:
  contents: read

jobs:
  lint-biome:
    name: Lint Biome
    runs-on: ubuntu-latest
    timeout-minutes: 10
    steps:
      - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
        with:
          persist-credentials: false
      - uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
        with:
          node-version-file: .tool-versions
          cache: npm
      - run: npm ci
      - run: node --run lint-biome && git diff --exit-code

  lint-oxlint:
    name: Lint oxlint
    runs-on: ubuntu-latest
    timeout-minutes: 10
    steps:
      - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
        with:
          persist-credentials: false
      - uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
        with:
          node-version-file: .tool-versions
          cache: npm
      - run: npm ci
      - run: node --run lint-oxlint && git diff --exit-code

  lint-ts:
    name: Lint TypeScript
    runs-on: ubuntu-latest
    timeout-minutes: 10
    steps:
      - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
        with:
          persist-credentials: false
      - uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
        with:
          node-version-file: .tool-versions
          cache: npm
      - run: npm ci
      - run: node --run lint-ts

  lint-secretlint:
    name: Lint Secretlint
    runs-on: ubuntu-latest
    timeout-minutes: 10
    steps:
      - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
        with:
          persist-credentials: false
      - uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
        with:
          node-version-file: .tool-versions
          cache: npm
      - run: npm ci
      - run: node --run lint-secretlint

  test:
    name: Test
    strategy:
      matrix:
        os: [ubuntu-latest, windows-latest, macos-latest]
        node-version: [22.x, 24.x, 26.x]
    runs-on: ${{ matrix.os }}
    steps:
      - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
        with:
          persist-credentials: false
      - name: Use Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
        with:
          node-version: ${{ matrix.node-version }}
      - run: npm ci
      - run: node --run test -- --reporter=verbose
        env:
          CI_OS: ${{ runner.os }}

  test-bun:
    name: Test with Bun
    strategy:
      matrix:
        os: [ubuntu-latest, windows-latest, macos-latest]
        bun-version: [latest]
    runs-on: ${{ matrix.os }}
    steps:
      - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
        with:
          persist-credentials: false
      - name: Setup Bun ${{ matrix.bun-version }}
        uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2.2.0
        with:
          bun-version: ${{ matrix.bun-version }}
      - run: bun install
      - run: bun run test
        env:
          CI_OS: ${{ runner.os }}

  test-coverage:
    name: Test coverage
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
        with:
          persist-credentials: false
      - uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
        with:
          node-version-file: .tool-versions
          cache: npm
      - run: npm ci
      - run: node --run test-coverage -- --reporter=verbose --reporter=junit --outputFile.junit=./test-report.junit.xml
        env:
          CI_OS: ${{ runner.os }}
      - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
        with:
          name: test-coverage
          path: coverage/
      - uses: codecov/codecov-action@57e3a136b779b570ffcdbf80b3bdc90e7fab3de2 # v6.0.0
        with:
          fail_ci_if_error: true
          directory: ./coverage
        env:
          CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
      - uses: codecov/test-results-action@0fa95f0e1eeaafde2c782583b36b28ad0d8c77d3 # v1.2.1
        if: ${{ !cancelled() }}
        with:
          files: ./test-report.junit.xml
        env:
          CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

  build-and-run:
    name: Build and run
    strategy:
      matrix:
        os: [ubuntu-latest, windows-latest, macos-latest]
        node-version: [22.x, 24.x, 26.x]
    runs-on: ${{ matrix.os }}
    steps:
      - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
        with:
          persist-credentials: false
      - name: Use Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
        with:
          node-version: ${{ matrix.node-version }}
      - run: npm ci
      - run: node --run build -- --sourceMap --declaration
      - name: Remove dev dependencies
        run: npm prune --omit=dev
      - run: node bin/repomix.cjs
      - run: node bin/repomix.cjs --version
      - run: node bin/repomix.cjs --help
      - name: Upload build artifact
        uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
        with:
          name: repomix-output-${{ matrix.os }}-${{ matrix.node-version }}.txt
          path: repomix-output.txt

  build-and-run-bun:
    name: Build and run with Bun
    strategy:
      matrix:
        os: [ubuntu-latest, windows-latest, macos-latest]
        bun-version: [latest]
    runs-on: ${{ matrix.os }}
    steps:
      - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
        with:
          persist-credentials: false
      - name: Setup Bun ${{ matrix.bun-version }}
        uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2.2.0
        with:
          bun-version: ${{ matrix.bun-version }}
      - run: bun install
      - run: bun run build
      - name: Install only production dependencies
        run: bun install --production
      - run: bun bin/repomix.cjs
      - run: bun bin/repomix.cjs --version
      - run: bun bin/repomix.cjs --help
      - name: Upload build artifact
        uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
        with:
          name: repomix-output-bun-${{ matrix.os }}-${{ matrix.bun-version }}.txt
          path: repomix-output.txt
