name: AVM ISA Cross-Port CI

on:
  push:
    paths:
      - 'python/**'
      - 'go/**'
      - 'rust/src/**'
      - 'c/**'
      - 'cpp/**'
      - 'julia/**'
      - 'r/**'
      - 'fortran/**'
      - 'octave/**'
      - 'scala/**'
      - 'coq/**'
      - 'tests/**'
      - 'scripts/wolfram_verify.py'
  workflow_dispatch:

jobs:
  python:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-python@v5
        with: { python-version: '3.12' }
      - name: Python AVM tests
        run: PYTHONPATH=python python3 tests/test_avm_python.py

  go:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-go@v5
        with: { go-version: '1.26' }
      - name: Go AVM tests
        run: go test -v ./go/

  rust:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions-rust-lang/setup-rust-toolchain@v1
      - name: Rust AVM tests
        run: cd rust && cargo test

  c:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: C AVM tests
        run: gcc -o /tmp/c_avm c/test_avm.c -lm && /tmp/c_avm

  cpp:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: C++ AVM tests
        run: g++ -std=c++17 -o /tmp/cpp_avm cpp/test_avm.cpp && /tmp/cpp_avm

  julia:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: julia-actions/setup-julia@v2
      - name: Julia AVM tests
        run: julia julia/AVMIsa/test_avm.jl

  r:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: r-lib/actions/setup-r@v2
      - name: R AVM tests
        run: Rscript r/AVMIsa/test_avm.r

  wolfram-verify:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-python@v5
        with: { python-version: '3.12' }
      - name: Wolfram Alpha verification
        run: python3 scripts/wolfram_verify.py
        env:
          WOLFRAM_APP_ID: ${{ secrets.WOLFRAM_APP_ID }}

  cross-verify:
    runs-on: ubuntu-latest
    needs: [python, go, rust, c, cpp, julia, r]
    steps:
      - uses: actions/checkout@v4
      - name: All AVM ports passed
        run: echo "✅ All AVM ISA port tests passed (Python, Go, Rust, C, C++, Julia, R)"
