name: Build
on:
  - pull_request
  - push

concurrency:
  group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
  cancel-in-progress: ${{ github.ref != 'refs/heads/master' }}

jobs:
  Lint:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0
      - uses: actions/setup-node@v4
        with:
          node-version: '22.x'
      - name: Install dependencies
        run: npm ci
      - name: Lint
        run: npm run lint
  Test:
    needs: Lint
    name: ${{ matrix.os }} Node.js ${{ matrix.nodeVersion }} Ti SDK ${{ matrix.tiSDK }} Tests
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        nodeVersion: [ '22.x' ]
        os: [ macos-latest ]
        tiSDK: [ 'latest' ]
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0
      - uses: actions/setup-node@v4
        with:
          node-version: ${{ matrix.nodeVersion }}
      - name: Install dependencies
        run: |
          npm ci
          npm i titanium -g
          ti sdk install ${{ matrix.tiSDK }}
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      - name: Run tests
        run: npm test
