name: CI Browser Extension

on:
  push:
    branches: [main]
    paths:
      - 'browser/**'
      - '.tool-versions'
      - '.github/workflows/ci-browser.yml'
  pull_request:
    branches: [main]
    paths:
      - 'browser/**'
      - '.tool-versions'
      - '.github/workflows/ci-browser.yml'
  workflow_dispatch:

permissions:
  contents: read

jobs:
  lint-browser:
    name: Lint Browser Extension
    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
      - name: Install browser extension dependencies
        working-directory: browser
        run: npm ci
      - name: Prepare WXT
        working-directory: browser
        run: node --run prepare
      - name: Lint browser extension
        working-directory: browser
        run: node --run lint

  test-browser:
    name: Test Browser Extension
    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
      - name: Install browser extension dependencies
        working-directory: browser
        run: npm ci
      - name: Prepare WXT
        working-directory: browser
        run: node --run prepare
      - name: Test browser extension
        working-directory: browser
        run: node --run test
