name: watcher
description: Install e-dant/watcher
runs:
  using: composite
  steps:
    -
      name: Determine e-dant/watcher version
      id: determine-watcher-version
      run: echo version="$(gh release view --repo e-dant/watcher --json tagName --template '{{ .tagName }}')" >> "${GITHUB_OUTPUT}"
      shell: bash
      env:
        GH_TOKEN: ${{ github.token }}
    -
      name: Cache e-dant/watcher
      id: cache-watcher
      uses: actions/cache@v4
      with:
        path: watcher/target
        key: watcher-${{ runner.os }}-${{ runner.arch }}-${{ steps.determine-watcher-version.outputs.version }}-${{ env.CC && env.CC || 'gcc' }}
    -
      if: steps.cache-watcher.outputs.cache-hit != 'true'
      name: Compile e-dant/watcher
      run: |
        mkdir watcher
        gh release download --repo e-dant/watcher -A tar.gz -O - | tar -xz -C watcher --strip-components 1
        cd watcher
        cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
        cmake --build build
        sudo cmake --install build --prefix target
      shell: bash
      env:
        GH_TOKEN: ${{ github.token }}
    -
      name: Update LD_LIBRARY_PATH
      run: |
        sudo sh -c "echo ${PWD}/watcher/target/lib > /etc/ld.so.conf.d/watcher.conf"
        sudo ldconfig
      shell: bash
