name: Test

on:
  push:

jobs:
  test:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout repository
        uses: actions/checkout@v6
        with:
          fetch-depth: 0

      - uses: actions/setup-node@v6
        with:
          node-version: 22
      - name: Install dependencies
        run: npm ci

      - name: Build
        run: npm run build

      - name: Run unit tests
        run: npx jest --testPathIgnorePatterns='PuppeteerGithubRepository'

      - name: Run integration tests
        if: ${{ github.actor != 'dependabot[bot]' }}
        run: npx jest PuppeteerGithubRepository
        env:
          USERNAME: ${{ secrets.USERNAME }}
          PASSWORD: ${{ secrets.PASSWORD }}
          AUTHENTICATOR_KEY: ${{ secrets.AUTHENTICATOR_KEY }}

      - name: Upload test results
        uses: actions/upload-artifact@v7
        with:
          name: jest-junit-report
          path: reports/jest-junit

      - name: Upload artifacts
        uses: actions/upload-artifact@v7
        with:
          name: reports
          path: reports
