name: Windows (xmake)

on:
  pull_request:
  push:
    paths-ignore:
      - '.gitignore'
      - 'LICENSE'
      - 'README.md'

jobs:
  build:
    strategy:
      fail-fast: false
      matrix:
        os: [windows-latest]
        arch: [x64]
        mode: [release]

    runs-on: ${{ matrix.os }}
    if: "!contains(github.event.head_commit.message, 'ci skip')"

    steps:
    - name: Get current date as package key
      id: cache_key
      run: echo "key=$(date +'%W')" >> $GITHUB_OUTPUT

    - name: Checkout repository
      uses: actions/checkout@v4

    # Force xmake to a specific folder (for cache)
    - name: Set xmake env
      run: echo "XMAKE_GLOBALDIR=${{ runner.workspace }}/xmake-global" >> $GITHUB_ENV

    # Install xmake
    - name: Setup xmake
      uses: xmake-io/github-action-setup-xmake@v1
      with:
        xmake-version: branch@master
        actions-cache-folder: .xmake-cache-W${{ steps.cache_key.outputs.key }}

    # Update xmake repository (in order to have the file that will be cached)
    - name: Update xmake repository
      run: xmake repo --update

    # Setup compilation mode and install project dependencies
    - name: Configure xmake and install dependencies
      run: xmake config --arch=${{ matrix.arch }} --mode=${{ matrix.mode }} --yes

    # Build the mlx
    - name: Build MacroLibX
      run: xmake --yes
