name: Reusable OmniOS amd64

on:
  workflow_call:

permissions:
  contents: read

jobs:
  build:
    runs-on: ubuntu-latest
    defaults:
      run:
        shell: cpa.sh {0}

    steps:
      - name: checkout repository
        uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1

      - name: Start VM
        uses: cross-platform-actions/action@5ea7e8e4677bd726033a10b094ba1c5762b15dee # v1.3.0
        with:
          operating_system: omnios
          version: 'r151058'
          shell: bash
          cpu_count: 4

      - name: Show system info
        run: |
          uname -a

      - name: Update and install dependencies
        run: |
          sudo pkg update --accept || true
          sudo pkg install gcc14 cmake git pkg-config glib2 dbus sqlite-3 imagemagick ninja

      - name: CMake configuration
        run: cmake -DSET_TWEAK=Off -DBUILD_TESTS=On -GNinja -DENABLE_EMBEDDED_PCIIDS=On -DENABLE_EMBEDDED_AMDGPUIDS=On -DCMAKE_BUILD_TYPE=${{ vars.CMAKE_BUILD_TYPE || 'RelWithDebInfo' }} .

      - name: CMake build
        run: cmake --build . --verbose -j4

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

      - name: Run normal
        run: time ./fastfetch -c presets/ci.jsonc --stat false

      - name: Run json
        run: time ./fastfetch -c presets/ci.jsonc --format json

      - name: Run flashfetch
        run: time ./flashfetch

      - name: Run ldd
        run: ldd fastfetch

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

      - name: Package
        run: |
          echo 'set(CPACK_PACKAGE_FILE_NAME "fastfetch-omnios-amd64")' >> CPackConfig.cmake
          cpack -V

      - name: upload artifacts
        uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
        with:
          name: fastfetch-omnios-amd64
          path: ./fastfetch-*.*
