# Please read the TESTING file before modifying this file

# Specific workflow for MacPorts, as we need to disable Brew for this to work
# so it's difficult to use the other standard workflows.

name: Build Crate (MacPorts)
# Build the crate with a native toolchain from Alire

env:
  CHECKS_ORG: alire-project
  CHECKS_REPO: alire-index-checks
  ALR_VERSION: 2.1.0

on:
  pull_request:
    paths:
      - 'index/**.toml'

jobs:

  build:
    name: ${{ matrix.os }}
    env:
      JOB_NAME: ${{ matrix.os }}

    runs-on: ${{ matrix.os }}

    strategy:
      fail-fast: false
      matrix:
        os:
          - macos-13     # amd64
          - macos-14     # arm64
          # macos-latest breaks the action that sets up MacPorts. See
          # https://github.com/melusina-org/setup-macports/issues/2

    steps:
    - name: Check out alire-index
      uses: actions/checkout@v4
      with:
        fetch-depth: 0
        # Needed to be able to diff and obtain changed files. Furthermore, we
        # need the full history or else grafted partial branches confuse the
        # changed files detectors (in both scripts/gh-build-crate.sh and
        # check-author action).

    - name: Check out alire-index-checks
      uses: actions/checkout@v4
      with:
        repository: ${{env.CHECKS_ORG}}/${{env.CHECKS_REPO}}
        ref: ${{github.base_ref}}
        path: ${{env.CHECKS_REPO}}

    - name: Set up stable `alr`
      uses: alire-project/setup-alire@v5
      with:
        version: ${{env.ALR_VERSION}}

    - name: Disable Homebrew
      run: rm -f $(which brew)
      shell: bash

    - name: Install Ports
      uses: melusina-org/setup-macports@v1

    - name: Prefer Quartz to X11 for MacPorts
      shell: bash
      run: echo '-x11 +no_x11 +quartz' >> /opt/local/etc/macports/variants.conf

    - name: Test crate
      run: ${{env.CHECKS_REPO}}/scripts/gh-build-crate.sh
      shell: bash
      env:
        GITHUB_EVENT_PATH: ${{ github.event_path }}
        GITHUB_REPOSITORY: ${{ github.repository }}
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to apply labels/comment
