name: Mac OS build

on:
  workflow_dispatch:
  push:
    branches:
      - master
      - fixes
      - develop
      - release/*
    tags:
      - 'v[0-9]+.*'
  pull_request:
    branches:
      - master
      - fixes
      - develop
      - release/*

env:
  # Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
  BUILD_TYPE: Release

jobs:
  mosquitto:
    runs-on: macos-latest

    steps:
      - uses: actions/checkout@v6

      - name: pin cmake to 3.x series
        uses: jwlawson/actions-setup-cmake@09fd9b0fb3b239b4b68d9256cd65adf8d6b91da0
        with:
          cmake-version: '3.31.6'

      - name: Python test dependencies
        uses: actions/setup-python@v6
        with:
          cache: 'pip'

      - name: Install Homebrew dependencies
        run: |
          brew update
          brew list cmake || brew install cmake
          brew install \
            argon2 \
            cjson \
            cunit \
            docbook-xsl \
            gcc \
            googletest \
            libedit \
            libmicrohttpd \
            make \
            openssl \
            uthash

      - name: Configure CMake
        run: |
          EDITLINE_DIR=$(brew --prefix libedit)
          HOMEBREW_PREFIX=$(brew --prefix)
          cmake -B ${{github.workspace}}/build64 \
            -G Ninja \
            -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} \
            -DCMAKE_PREFIX_PATH="$HOMEBREW_PREFIX" \
            -DWITH_DOCS=OFF \
            -DOPENSSL_ROOT_DIR=$(brew --prefix openssl@3)
      - name: Build
        run: |
          cmake --build ${{github.workspace}}/build64 \
            --config ${{env.BUILD_TYPE}}

      - name: Test
        working-directory: build64/
        run: |
          python3 -m venv venv
          source venv/bin/activate
          python3 -m pip install --upgrade pip
          python3 -m pip install psutil
          ctest --output-on-failure --repeat until-pass:5
