name: 'Tests: ls-engines'

on: [pull_request, push]

jobs:
  engines-matrix:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: ljharb/actions/node/install@main
        name: 'nvm install lts/* && npm install'
        with:
          node-version: 'lts/*'
      - id: set-matrix
        run: |
          echo "matrix=$(npm query --no-workspaces .workspace | npx json -a location | { cat; echo; } | sort | node -pe 'JSON.stringify(fs.readFileSync(0, "utf-8").split("\n").slice(0,-1).map(x => "./"+x))')" >> $GITHUB_OUTPUT
    outputs:
      matrix: ${{ steps.set-matrix.outputs.matrix }}

  engines-job:
    name: 'ls-engines: package'
    needs: [engines-matrix]
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        package: ${{ fromJson(needs.engines-matrix.outputs.matrix) }}
    steps:
      - uses: actions/checkout@v4
      - uses: ljharb/actions/node/install@main
        name: 'nvm install lts/* && npm install'
        with:
          node-version: 'lts/*'
      - run: npx ls-engines
        working-directory: ${{ matrix.package }}

  engines:
    name: 'ls-engines'
    needs: [engines-job]
    runs-on: ubuntu-latest
    steps:
      - run: 'echo tests completed'
