# Verify the complete public test suite across supported Node.js releases and operating systems.
name: Cross-platform tests

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

# Tests need read access to the project and its public workspace-data source.
permissions:
  contents: read

jobs:
  test:
    name: ${{ matrix.os }} / Node.js ${{ matrix.node }}
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-latest, windows-latest, macos-latest]
        node: [24, 26]

    steps:
      # Check out the exact project revision selected by the workflow event.
      - name: Check out repository
        uses: actions/checkout@v7

      # Install each supported Node.js runtime independently on every operating system.
      - name: Set up Node.js
        uses: actions/setup-node@v7
        with:
          node-version: ${{ matrix.node }}

      # Install development dependencies without requiring a generated package lock.
      - name: Install dependencies
        run: npm install --no-audit --no-fund

      # Check out only this project's test concern from the public workspace-data source.
      - name: Check out public tests
        uses: actions/checkout@v7
        with:
          repository: SorinGFS/public-data
          ref: master
          path: workspace-data
          sparse-checkout: tests/github.com/SorinGFS/identifier-js

      # Check out the extension-owned runtime helper required by materialized dispatchers.
      - name: Check out workspace runtime
        uses: actions/checkout@v7
        with:
          repository: SorinGFS/gh-workspace-data
          ref: v0.7.4
          path: workspace-runtime
          sparse-checkout: src/version-layers.js
          sparse-checkout-cone-mode: false

      # Reproduce the ordinary workspace layout generated by gh-workspace-data.
      - name: Materialize public tests and runtime
        run: >-
          node -e "const fs = require('node:fs'); fs.cpSync('workspace-data/tests/github.com/SorinGFS/identifier-js', '#/public/tests', { recursive: true }); fs.copyFileSync('workspace-runtime/src/version-layers.js', '#/version-layers.js')"

      # Execute the materialized Node.js suite and propagate any failed result.
      - name: Run tests
        run: npm test
