name: CI
on: [push, pull_request]
jobs:
  bsd:
    runs-on: ${{ matrix.os.host }}
    strategy:
      matrix:
        os:
          - name: freebsd
            architecture: x86-64
            version: '14.1'
            host: ubuntu-latest
          - name: netbsd
            architecture: x86-64
            version: '10.0'
            host: ubuntu-latest
          - name: openbsd
            architecture: x86-64
            version: '7.5'
            host: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4
      - name: Run CI script on ${{ matrix.os.name }}
        uses: cross-platform-actions/action@v0.25.0
        with:
          operating_system: ${{ matrix.os.name }}
          architecture: ${{ matrix.os.architecture }}
          version: ${{ matrix.os.version }}
          shell: bash
          run: |
            # doas(1) isn't configured on OpenBSD.
            # See https://github.com/cross-platform-actions/action/issues/75
            sudo ci/install-deps.sh
            TCLLIBPATH=/usr/local/lib/tcllib2.0 make test

  linux:
    runs-on: ubuntu-latest
    steps:
    - name: Checkout
      uses: actions/checkout@v4
    - name: Install dependencies
      run: |
        sudo ci/install-deps.sh
        echo TCLLIBPATH=/usr/local/lib/tcllib2.0 >> "$GITHUB_ENV"
    - name: Test
      run: |
        make test
    - name: Build artifacts
      run: |
        ci/build-artifacts.tcl
    - name: Upload artifacts
      uses: actions/upload-artifact@v4
      with:
        name: artifacts
        path: |
          artifacts/

  macos:
    runs-on: macos-latest
    steps:
    - name: Checkout
      uses: actions/checkout@v4
    - name: Install dependencies
      run: |
        brew install cmark tcl-tk
    - name: Test
      run: |
        make test

  windows:
    runs-on: windows-latest
    steps:
    - name: 'Disable `autocrlf` in Git'
      run: git config --global core.autocrlf false
    - name: Checkout
      uses: actions/checkout@v4
    - name: Install dependencies
      run: |
        choco install magicsplat-tcl-tk
    - name: Test
      run: |
        Import-Module $env:ChocolateyInstall\helpers\chocolateyProfile.psm1
        refreshenv

        tclsh86t tests.tcl
