name: Reusable Linux VMs

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

permissions:
  contents: read

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

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: checkout repository
        uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1

      - name: run VM
        uses: uraimo/run-on-arch-action@f9b26e3a1a408d5fd530d20c17b9f3f4428ff8d9 # v3.1.0
        id: runcmd
        with:
          arch: ${{ inputs.arch }}
          distro: ubuntu22.04
          githubToken: ${{ github.token }}
          run: |
            uname -a
            apt-get update && apt-get install -y software-properties-common
            add-apt-repository -y ppa:ubuntu-toolchain-r/test
            apt-get update && apt-get install -y cmake make gcc-13 libvulkan-dev libwayland-dev libxrandr-dev libxcb-randr0-dev libdconf-dev libdbus-1-dev libmagickcore-dev libsqlite3-dev librpm-dev libegl-dev libglx-dev ocl-icd-opencl-dev libpulse-dev libdrm-dev libchafa-dev libelf-dev libefl-all-dev liblua5.4-dev libvdpau-dev libva-dev rpm
            CC=gcc-13 cmake -DSET_TWEAK=Off -DBUILD_TESTS=On -DCMAKE_INSTALL_PREFIX=/usr .
            cmake --build . --target package --verbose -j4
            ./fastfetch --list-features
            time ./fastfetch -c presets/ci.jsonc --stat false
            time ./fastfetch -c presets/ci.jsonc --format json
            time ./flashfetch
            ldd fastfetch
            ctest --output-on-failure

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