name: CI

on:
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]

jobs:
  build:
    name: Build (${{ matrix.os }})
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: [ubuntu-latest, windows-latest, macos-latest]
        # os: [ubuntu-latest, macos-latest]
    
    steps:
    - name: Checkout code
      uses: actions/checkout@v4
      
    - name: Setup Zig
      uses: mlugg/setup-zig@v2
      with:
        version: 0.15.2
          
    - name: Build project
      run: zig build
      
    - name: Verify executable
      run: |
        ./zig-out/bin/zx --help || echo "Executable built successfully"
      shell: bash

    - name: Upload build artifacts
      uses: actions/upload-artifact@v4
      with:
        name: temporalz-${{ matrix.os }}
        path: zig-out/
        retention-days: 1

  test:
    name: Test (${{ matrix.os }})
    runs-on: ${{ matrix.os }}
    needs: build
    strategy:
      matrix:
        os: [ubuntu-latest, windows-latest, macos-latest]
        # os: [ubuntu-latest, macos-latest]
    
    steps:
    - name: Checkout code
      uses: actions/checkout@v4
      
    - name: Setup Zig
      uses: mlugg/setup-zig@v2
      with:
        version: 0.15.2

    - name: Download build artifacts
      uses: actions/download-artifact@v4
      with:
        name: temporalz-${{ matrix.os }}
        path: zig-out/

    - name: Make executable (Unix)
      if: runner.os != 'Windows'
      run: chmod +x zig-out/bin/temporalz

    - name: Run tests
      run: zig build test