name: ci

on:
  pull_request:
  push:
    branches: [main]

permissions:
  contents: read

jobs:
  contracts:
    strategy:
      fail-fast: false
      matrix:
        include:
          - os: ubuntu-latest
            node: 20
          - os: ubuntu-latest
            node: 22
          - os: windows-latest
            node: 22
          - os: macos-latest
            node: 22
    runs-on: ${{ matrix.os }}
    steps:
      - uses: actions/checkout@v7
        with:
          fetch-depth: 0
      - uses: actions/setup-node@v6
        with:
          node-version: ${{ matrix.node }}
          cache: npm
      - run: npm ci
      - run: npm run verify:ci

  remote-cdp:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7
        with:
          fetch-depth: 0
      - uses: actions/setup-node@v6
        with:
          node-version: 22
          cache: npm
      - run: npm ci
      - name: Resolve Chrome
        shell: bash
        run: |
          chrome_bin="$(command -v google-chrome-stable || command -v google-chrome || command -v chromium || command -v chromium-browser)"
          test -n "$chrome_bin"
          echo "CHROME_BIN=$chrome_bin" >> "$GITHUB_ENV"
      - run: npm run check:remote-cdp

  coverage:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7
        with:
          fetch-depth: 0
      - uses: actions/setup-node@v6
        with:
          node-version: 22
          cache: npm
      - run: npm ci
      - run: npm run coverage:contracts
      - uses: actions/upload-artifact@v7
        with:
          name: browser67-coverage-summary
          path: runtime/coverage/coverage-summary.json
          if-no-files-found: error
