# Run the jobs below on every push to master branch and pull request.
on:
  push:
    branches:
      - master
      - 'ci/**'  # Allow automatic CI testing on ci/* branches
  pull_request:
    branches:
      - master
  workflow_dispatch:  # Allow manual triggering on any branch

# Runs basic configure, make and make check.
jobs:
  # ubuntu:
  #   name: Ubuntu
  #   runs-on: ubuntu-${{ matrix.release }}
  #   continue-on-error: true
  #   strategy:
  #     fail-fast: false
  #     matrix:
  #       release:
  #         - 24.04

  #   steps:
  #     - name: Identify the system
  #       run: |
  #         cat /etc/os-release

  #     - name: Enable source repositories
  #       run: |
  #         sudo sed -i 's/Types: deb$/Types: deb deb-src/g' \
  #                  /etc/apt/sources.list.d/ubuntu.sources

  #     - name: Install build dependencies
  #       run: |
  #         sudo apt-get update
  #         sudo apt-get -y build-dep virt-v2v

  #     - name: Install extra dependencies
  #       run: |
  #         # Git is needed to run git submodule command.
  #         sudo apt-get -y install git

  #     - name: Fix broken Ubuntu kernel permissions
  #       run: |
  #         # https://bugs.launchpad.net/ubuntu/+source/linux/+bug/759725
  #         sudo chmod 0644 /boot/vmlinuz*

  #     - name: Enable KVM
  #       run: |
  #         sudo chmod 0666 /dev/kvm

  #     - name: Checkout sources
  #       uses: actions/checkout@v5

  #     - name: Checkout submodule
  #       run: |
  #         git submodule update --init

  #     - name: Compile the code
  #       run: |
  #         autoreconf -fiv
  #         ./configure --enable-werror
  #         make -j

  #     - name: Run the full tests
  #       run: |
  #         if ! make check; then
  #             find -name test-suite.log -exec cat {} \;
  #             exit 1
  #         fi

  fedora:
    name: Fedora
    runs-on: ubuntu-latest  # VM where the container runs
    strategy:
      fail-fast: false
      matrix:
        release:
         - 43

    container:
      image: quay.io/fedora/fedora:${{ matrix.release }}
      options: --privileged

    steps:
      - name: Identify the system
        run: |
          cat /etc/os-release

      - name: Install build dependencies
        run: |
          dnf builddep -y virt-v2v libguestfs
          # Install a bunch of bits to enable more tests
          dnf install -y \
            git kernel sqlite perl-hivex \
            mingw-srvany-redistributable nbdkit-\* virt-v2v \
            guestfs-tools\*

          # Hides 'multiple definition' warnings
          dnf remove -y ocaml-libguestfs\*

      - name: Checkout sources
        uses: actions/checkout@v5

      - name: Checkout and build libguestfs
        run: |
            git clone --depth=1 https://github.com/libguestfs/libguestfs
            cd libguestfs
            git submodule update --init
            autoreconf -fiv
            ./configure CFLAGS="-fPIC -g -O2" --enable-werror
            make -j
            cd ..

      - name: Compile the code
        run: |
            git config --global --add safe.directory $PWD
            git submodule update --init
            autoreconf -fiv
            ./libguestfs/run ./configure CFLAGS="-fPIC -g -O2" --enable-werror
            ./libguestfs/run make -j

      # feb2026: tests mostly run but random bits fail with
      #   part_to_partnum_stub: /dev/sda2: No such file or directory
      # Possibly this is systemd udev issue which is fixed in v260.
      # Let's try enabling again when fedora-44 is out
      # Some discussion: https://github.com/libguestfs/virt-v2v/pull/135
      #
      # - name: Run the full tests
      #   run: |
      #       ./libguestfs/run libguestfs-test-tool
      #
      #       # Busted on root:
      #       # virt-v2v: changeuid: test-o-ovirt.d/12345678-1234-1234-1234-123456789abc/x8gdeog2: Sys_error("test-o-ovirt.d/12345678-1234-1234-1234-123456789abc/x8gdeog2: Permission denied")
      #       export SKIP_TEST_O_OVIRT_SH=1
      #
      #       if ! ./libguestfs/run make check; then
      #           find -name test-suite.log -exec cat {} \;
      #           exit 1
      #       fi
