name: Test and Release

# Run this job on all pushes and pull requests
# as well as tags with a semantic version
on:
  push:
    branches:
      - "*"
    tags:
      # normal versions
      - "v[0-9]+.[0-9]+.[0-9]+"
      # pre-releases
      - "v[0-9]+.[0-9]+.[0-9]+-**"
  pull_request: {}

jobs:
  # Performs quick checks before the expensive test runs
  check-and-lint:
    if: contains(github.event.head_commit.message, '[skip ci]') == false

    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v3

      - name: Install Dependencies
        run: npm ci

      - name: Run Linter
        if: startsWith(runner.OS, 'windows') == false
        run: DEBUG=linter:* npm run lint

    # Runs adapter tests on all supported node versions and OSes
  api-test:
    if: contains(github.event.head_commit.message, '[skip ci]') == false

    needs: [check-and-lint]

    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        node-version: [20, 22]
        os: [ubuntu-latest, windows-latest, macos-latest]

    steps:
      - name: Checkout code
        uses: actions/checkout@v3

      - name: Use Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@v4
        with:
          node-version: ${{ matrix.node-version }}
          cache: "npm"

      - name: Install Dependencies
        run: npm ci

      - name: Run integration tests (unix only)
        if: startsWith(runner.OS, 'windows') == false
        run: DEBUG=testing:* npm run test:integration

      - name: Run integration tests (windows only)
        if: startsWith(runner.OS, 'windows')
        run: set DEBUG=testing:* & npm run test:integration
