name: CI

permissions:
  contents: read

on:
  push:
    branches: [master]
  pull_request:
  merge_group:

jobs:
  static-analysis:
    name: Static Analysis
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Setup node
        uses: actions/setup-node@v4
        with:
          node-version-file: "package.json"

      - name: Install dependencies
        run: npm ci

      - name: Build third-party libraries
        run: npm run build:libs

      - name: Run static analysis tests
        run: npm run test:static-analysis

  static-analysis-json:
    name: Static Analysis (JSON)
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Setup node
        uses: actions/setup-node@v4
        with:
          node-version-file: "package.json"

      - name: Install dependencies
        run: npm ci

      - name: Build third-party libraries
        run: npm run build:libs

      - name: Run static analysis tests
        run: npm run test:json

  unit-tests:
    name: Unit Tests
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Setup node
        uses: actions/setup-node@v4
        with:
          node-version-file: "package.json"

      - name: Install dependencies
        run: npm ci

      - name: Build third-party libraries
        run: npm run build:libs

      - name: Run unit tests
        run: npm run test:unit

      - name: Run unit tests (options)
        run: npm run test:unit:options

  test-build:
    name: Test Build
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Setup node
        uses: actions/setup-node@v4
        with:
          node-version-file: "package.json"

      - name: Install dependencies
        run: npm ci

      - name: Build Libs
        run: npm run build:libs

      - name: Build Legal
        run: npm run license-report:html

      - name: Build
        run: npm run build

      - name: Validate manifest.json of the extension
        uses: cardinalby/schema-validator-action@2166123eb256fa40baef7e22ab1379708425efc7 # v3.1.1
        with:
          file: ext/manifest.json
          schema: "https://json.schemastore.org/chrome-manifest.json"
          fixSchemas: true