name: CI

on:
  push:
    tags-ignore:
      - "v*"
  pull_request:
  workflow_dispatch:

env:
  FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true

jobs:
  conventional-commits:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - uses: actions/setup-python@v5
        with:
          python-version: '3.12'

      - name: Validate pull request title
        if: github.event_name == 'pull_request'
        run: python execution/conventional_commits.py check-subject "${{ github.event.pull_request.title }}"

      - name: Validate pushed commit subjects
        if: github.event_name == 'push'
        run: python execution/conventional_commits.py check-push-range "${{ github.event.before }}" "$GITHUB_SHA"

      - name: Validate manual run HEAD commit subject
        if: github.event_name == 'workflow_dispatch'
        run: python execution/conventional_commits.py check-range "HEAD^!"

  release-version:
    needs: conventional-commits
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - uses: actions/setup-python@v5
        with:
          python-version: '3.12'

      - name: Run version sync tests
        run: python -m unittest discover -s execution -p 'test_*.py'

      - name: Verify release metadata stays aligned
        run: python execution/version_sync.py check

  rust:
    needs: release-version
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Install Rust toolchain
        uses: dtolnay/rust-toolchain@master
        with:
          toolchain: "1.94.0"

      - name: Run cargo check
        run: cargo check

      - name: Run Rust tests
        run: cargo test --all-targets -- --test-threads=1

  npm:
    needs: release-version
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - uses: actions/setup-node@v4
        with:
          node-version: 20

      - name: Test npm package
        working-directory: npm
        run: npm test
