stages:
  - approve
  - test

approve1:
  stage: approve
  script:
    - echo "Approved..."
  rules:
    # TODO: Filter only safe repositories, or user in developers
    - if: $CI_PROJECT_PATH != "csonto/lvm2" && $CI_PROJECT_PATH != "lvmteam/lvm2"
      when: manual
    # TODO: for other branches than main/rhel: run pipeline only when requested:
    - if: $CI_COMMIT_BRANCH != "main" && $CI_COMMIT_BRANCH !~ "^rhel.*"
      when: manual
    - when: on_success
  allow_failure: false


pages:
  image: elecnix/ikiwiki
  stage: test
  script:
    - ikiwiki --setup ikiwiki.setup --libdir themes/ikistrap/lib
  artifacts:
    paths:
      - public
  only:
    refs:
      - main
    changes:
      - doc/**/*
      - ikiwiki.setup


# TODO:
# - check results of autoreconf and make generate - may need additional commit
#     - we need a particular setup (rawhide OR latest supported fedora?)
# - do make rpm and publish results as artifacts - we will use packit/COPR for this eventually

# Run on any commits to main (master), rhel8, rhel9 branches
test-job:
  stage: test
  parallel:
    matrix:
      - TAG: rhel8
        CONFIGURE: >
          --with-cluster=internal
          --enable-cmirrord
      - TAG: rhel9
        CONFIGURE: >
          --with-default-use-devices-file=1
          --enable-app-machineid
          --enable-editline
          --disable-readline
  artifacts:
    paths:
      - test/results/
    expire_in: 1 week
  tags:
      - ${TAG}
  timeout: 2h
  script:
    # Common options go here, diffs to the above matrix
    - >
      ./configure ${CONFIGURE}
      --enable-fsadm
      --enable-write_install
      --enable-pkgconfig
      --enable-cmdlib
      --enable-dmeventd
      --enable-blkid_wiping
      --enable-udev_sync
      --with-thin=internal
      --with-cache=internal
      --enable-lvmpolld
      --enable-lvmlockd-dlm --enable-lvmlockd-dlmcontrol
      --enable-lvmlockd-sanlock
      --enable-dbus-service --enable-notify-dbus
      --enable-dmfilemapd
      --with-writecache=internal
      --with-vdo=internal --with-vdo-format=/usr/bin/vdoformat
      --with-integrity=internal
      --disable-silent-rules
    - make
    - rm -rf test/results
    - mkdir -p /dev/shm/lvm2-test
    - mount -o remount,dev /dev/shm
    # TODO: Need to distinguish failed test from failed harness
    # TODO: Also need a way to find if run is incomplete, e.g. full disk resulting in many skipped tests
    - VERBOSE=0 BATCH=1 LVM_TEST_DIR=/dev/shm/lvm2-test make check || true
    - rm -rf /dev/shm/lvm2-test
    - cut -d' ' -f2 test/results/list | sort | uniq -c
    # Filter artifacts - keep only logs from tests which are not pass
    - cd test/results && rm $(grep 'passed$' list | cut -d' ' -f1 | sed -e 's|/|_|g' -e 's|.*|\0.txt|')
    # TODO: Keep a list of known failures, and translate into regexp - or simply use python...
    - if grep failed test/results/list | grep -v '\\\(dbustest\|lvconvert-mirror\)\.sh' | sort; then false; else true; fi
  rules:
    # Filter only safe repositories, or user in developers:
    # NOTE: Already done in approve stage, may be more caution than necessary
    - if: $CI_PROJECT_PATH != "csonto/lvm2" && $CI_PROJECT_PATH != "lvmteam/lvm2"
      when: manual
    - when: on_success