name: Reusable macOS Hosts

on:
  workflow_call:
    inputs:
      arch:
        required: true
        type: string
      runs-on:
        required: true
        type: string

permissions:
  contents: read

env:
  CMAKE_BUILD_TYPE: ${{ vars.CMAKE_BUILD_TYPE || 'RelWithDebInfo' }}

jobs:
  build:
    runs-on: ${{ inputs.runs-on }}
    steps:
      - name: checkout repository
        uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1

      - name: uname -a
        run: uname -a

      - name: install required packages
        run: |
          HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK=1 brew update
          HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK=1 brew install --overwrite vulkan-loader vulkan-headers molten-vk imagemagick chafa lua quickjs-ng

      - name: configure project
        run: cmake -DSET_TWEAK=Off -DBUILD_TESTS=On .

      - name: build project
        run: cmake --build . --target package --verbose -j4

      - name: list features
        run: ./fastfetch --list-features

      - name: run fastfetch
        run: time ./fastfetch -c presets/ci.jsonc --structure-disabled vulkan --stat false

      - name: run fastfetch --format json
        run: time ./fastfetch -c presets/ci.jsonc --structure-disabled vulkan --format json

      - name: run flashfetch
        run: time ./flashfetch

      - name: print dependencies
        run: otool -L fastfetch

      - name: run tests
        run: ctest --output-on-failure

      - name: upload artifacts
        uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
        with:
          name: fastfetch-macos-${{ inputs.arch }}
          path: ./fastfetch-*.*
