image: fedora${CI_PCS_FC_IMG_TAG}

variables:
  PYTHON_DEPENDENCIES: "
    python3-cryptography
    python3-devel
    python3-lxml
    python3-pycurl
    python3-pyparsing
    python3-setuptools
    python3-setuptools_scm
    python3-wheel
  "
  RUBY_GEMS: "
    rubygem-backports
    rubygem-ethon
    rubygem-ffi
    rubygem-io-console
    rubygem-json
    rubygem-open4
    rubygem-rack
    rubygem-rack-protection
    rubygem-rack-test
    rubygem-rexml
    rubygem-sinatra
    rubygem-test-unit
    rubygem-thin
    rubygem-tilt
    rubygem-webrick
  "
  COMMON_DEPENDENCIES: "
    autoconf
    automake
    coreutils
    curl
    findutils
    git
    make
    sed
    systemd
    tar
    time
    wget
    python3-pip
    pkgconf-pkg-config
    ruby
    ruby-devel
    rubygem-bundler
  "
  COMMON_BUILD_DEPENDENCIES: "
    fontconfig
    gcc
    gcc-c++
    psmisc
    redhat-rpm-config
    ${COMMON_DEPENDENCIES}
    ${PYTHON_DEPENDENCIES}
  "
  APP_VERSION: "0.0.1.ci"
  DIST_VERSION: "${APP_VERSION}.${CI_PROJECT_NAMESPACE}-${CI_COMMIT_SHORT_SHA}"
  RPM_VERSION: "${APP_VERSION}-1.${CI_PROJECT_NAMESPACE}.$CI_COMMIT_SHORT_SHA"

default:
  before_script:
    - "echo ${DIST_VERSION} > .tarball-version"
    - cat .tarball-version

stages:
  - stage1
  - stage2

rpm_build:
  stage: stage1
  script:
    - "dnf install -y
        ${COMMON_BUILD_DEPENDENCIES}
        dnf-plugins-core
        rpm-build
        rpmdevtools
      "
    - ./autogen.sh
    - ./configure --enable-local-build
    - make rpm/pcs.spec
    - dnf builddep -y rpm/pcs.spec
    - make rpm
    - mkdir -p rpms && cp -v $(find rpm  -type f -name '*.rpm' -not -name '*.src.rpm') rpms
  artifacts:
    expire_in: 1 week
    paths:
      - rpms

distcheck:
  stage: stage1
  script:
    - "dnf install -y
        ${COMMON_BUILD_DEPENDENCIES}
        ${RUBY_GEMS}
        bzip2
        xz
      "
    - "pip3 install
        dacite
        tornado
        pyagentx
      "
    - ./autogen.sh
    - ./configure --enable-local-build
    - make distcheck DISTCHECK_CONFIGURE_FLAGS='--enable-local-build'
    - mkdir -p dist && cp -v pcs*.tar.* dist/
  artifacts:
    expire_in: 1 week
    paths:
      - dist


black:
  stage: stage1
  script:
    - dnf install -y ${COMMON_DEPENDENCIES}
    - python3 -m pip install --upgrade -r dev_requirements.txt
    - ./autogen.sh
    - ./configure --enable-local-build --enable-dev-tests --enable-tests-only
    - make black_check

pylint:
  stage: stage1
  script:
    - dnf install -y ${COMMON_BUILD_DEPENDENCIES}
    - python3 -m pip install --upgrade -r dev_requirements.txt
    - ./autogen.sh
    - ./configure --enable-local-build --enable-dev-tests
    - make
    - make pylint

mypy:
  stage: stage1
  script:
    - dnf install -y ${COMMON_BUILD_DEPENDENCIES}
    - python3 -m pip install --upgrade -r dev_requirements.txt
    - ./autogen.sh
    - ./configure --enable-local-build --enable-dev-tests
    - make
    - make mypy

ruby_tests:
  stage: stage1
  script:
    - dnf install -y ${COMMON_BUILD_DEPENDENCIES}
    - ./autogen.sh
    - ./configure --enable-local-build
    - make
    - make pcsd-tests

python_tier0_tests:
  stage: stage1
  script:
    - dnf install -y ${COMMON_BUILD_DEPENDENCIES}
    - python3 -m pip install concurrencytest
    - ./autogen.sh
    - ./configure --enable-local-build
    - make
    - make tests_tier0

python_tier1_tests:
  stage: stage2
  needs:
    - rpm_build
  script:
    - "dnf install -y
        ${COMMON_DEPENDENCIES}
        python3-mock
        fence-agents-scsi
        fence-agents-apc
        fence-agents-ipmilan
        fence-virt
        booth-site
        rpms/pcs-*.rpm
      "
    - python3 -m pip install concurrencytest
    - ./autogen.sh
    - ./configure --enable-local-build --enable-destructive-tests --enable-tests-only
    - rm -rf pcs pcsd pcs_bundled # make sure we are testing installed package
    - pcs_test/suite -v --installed --tier1

python_smoke_tests:
  stage: stage2
  needs:
    - rpm_build
  script:
    - "dnf install -y
        ${COMMON_DEPENDENCIES}
        cracklib-dicts
        passwd
        procps-ng
        rpms/pcs-*.rpm
      "
    - export GEM_HOME=/usr/lib64/pcsd/vendor/bundle/
    - /usr/lib64/pcsd/pcsd & # start pcsd (ruby - thin)
    - sleep 10 # wait for pcsd (ruby - thin) to start up properly
    - /usr/sbin/pcsd & # start pcsd (python - tornado)
    - sleep 10 # wait for pcsd (python - tornado) to start up properly
    - ./autogen.sh
    - ./configure --enable-local-build --enable-tests-only
    - pcs_test/smoke.sh
  artifacts:
    paths:
      - /var/log/pcsd/
    when: on_failure
