on: 
  pull_request:
    paths:
      - .github/actions/extism/**
      - .github/workflows/ci-haskell.yml
      - manifest/**
      - runtime/**
      - libextism/**
      - haskell/**
  workflow_dispatch:

name: Haskell CI

jobs:
  haskell:
    name: Haskell
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: [ubuntu-latest, macos-latest]
        rust:
          - stable
    steps:
      - name: Checkout sources
        uses: actions/checkout@v3
      - uses: ./.github/actions/extism
      - name: Setup Haskell env
        uses: haskell/actions/setup@v2
        with:
          enable-stack: false
      - name: Cache Haskell
        id: cache-haskell
        uses: actions/cache@v3
        with:
          path: ./haskell/dist-newstyle
          key: ${{ runner.os }}-haskell-${{ hashFiles('haskell/**') }}
      - name: Build Haskell Host SDK
        if: steps.cache-haskell.outputs.cache-hit != 'true'
        run: |
          cd haskell
          cabal update
          LD_LIBRARY_PATH=/usr/local/lib cabal build
      - name: Test Haskell SDK
        run: |
          cd haskell
          cabal update
          LD_LIBRARY_PATH=/usr/local/lib cabal test
