name: fast-smoke

on:
  push:
    branches: [ "**" ]
  workflow_dispatch:

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

jobs:
  fast:
    runs-on: ubuntu-latest
    timeout-minutes: 20
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Setup Rust (stable)
        uses: dtolnay/rust-toolchain@stable

      - name: Cache cargo
        uses: Swatinem/rust-cache@v2

      - name: Install LLVM 18 and Python deps
        run: |
          sudo apt-get update
          sudo apt-get install -y curl ca-certificates lsb-release wget gnupg python3-pip
          curl -fsSL https://apt.llvm.org/llvm.sh -o llvm.sh
          chmod +x llvm.sh
          sudo ./llvm.sh 18
          llvm-config-18 --version
          python3 -m pip install --upgrade pip
          python3 -m pip install llvmlite jsonschema

      - name: Build (release)
        run: |
          cargo build --release -j 2
          cargo build --release -p nyash-llvm-compiler -j 2
          cargo build --release -p nyrt -j 2

      - name: EXE smoke (ternary_basic -> 10)
        run: |
          mkdir -p tmp
          ./target/release/nyash --emit-mir-json tmp/tb.json --backend mir apps/tests/ternary_basic.hako
          ./target/release/ny-llvmc --in tmp/tb.json --emit exe --nyrt target/release --out tmp/tb
          set +e; ./tmp/tb >/dev/null 2>&1; CODE=$?; set -e
          echo "exit=$CODE"; test "$CODE" -eq 10

      - name: EXE smoke (ternary_nested -> 50)
        run: |
          ./target/release/nyash --emit-mir-json tmp/tn.json --backend mir apps/tests/ternary_nested.hako
          ./target/release/ny-llvmc --in tmp/tn.json --emit exe --nyrt target/release --out tmp/tn
          set +e; ./tmp/tn >/dev/null 2>&1; CODE=$?; set -e
          echo "exit=$CODE"; test "$CODE" -eq 50

      - name: EXE smoke (peek_expr_block -> 1)
        run: |
          ./target/release/nyash --emit-mir-json tmp/pb.json --backend mir apps/tests/peek_expr_block.hako
          ./target/release/ny-llvmc --in tmp/pb.json --emit exe --nyrt target/release --out tmp/pb
          set +e; ./tmp/pb >/dev/null 2>&1; CODE=$?; set -e
          echo "exit=$CODE"; test "$CODE" -eq 1

