# ---------------------------
# RHEL packaging workflow
# ---------------------------

include:
  # https://computing.docs.ligo.org/gitlab-ci-templates/
  - project: computing/gitlab-ci-templates
    # https://computing.docs.ligo.org/gitlab-ci-templates/rhel/
    file: rhel.yml
  # local test template
  - local: /.gitlab/ci/test.yml

# -- macros

.el:
  variables:
    EPEL: "true"

.el7:
  extends: .el
  image: igwn/base:el7-testing

.el7-builder:
  extends: .el7
  image: igwn/builder:el7-testing

.el8:
  extends: .el
  image: igwn/base:el8-testing

.el8-builder:
  extends: .el8
  image: igwn/builder:el8-testing

.el9:
  extends: .el
  image: igwn/base:el9-testing

.el9-builder:
  extends: .el9
  image: igwn/builder:el9-testing

# -- source packages --------
#
# These jobs make src RPMs
#

.srpm:
  extends:
    # https://computing.docs.ligo.org/gitlab-ci-templates/rhel/#.rhel:srpm
    - .rhel:srpm
  stage: source packages
  needs:
    - dist
  variables:
    TARBALL: "framel-*.tar.*"

srpm:el7:
  extends:
    - .srpm
    - .el7-builder

srpm:el8:
  extends:
    - .srpm
    - .el8-builder

srpm:el9:
  extends:
    - .srpm
    - .el9-builder

# -- binary packages --------
#
# These jobs generate binary RPMs
# from the src RPMs
#

.rpm:
  extends:
    # https://computing.docs.ligo.org/gitlab-ci-templates/rhel/#.rhel:rpm
    - .rhel:rpm
  stage: binary packages
  variables:
    RPMBUILD_OPTIONS: "--without mex"
    SRPM: "framel-*.src.rpm"

rpm:el7:
  extends:
    - .rpm
    - .el7-builder
  needs:
    - srpm:el7

rpm:el8:
  extends:
    - .rpm
    - .el8-builder
  needs:
    - srpm:el8

rpm:el9:
  extends:
    - .rpm
    - .el9-builder
  needs:
    - srpm:el9

# -- test -------------------

.test:el:
  extends:
    # see /.gitlab/ci/test.yml
    - .test
  before_script:
    # set up yum caching
    - !reference [".rhel:base", before_script]
    # configure EPEL
    - yum -y -q install epel-release && yum -y -q install epel-rpm-macros
    # install testing dependencies
    - PY3=$(rpm --eval '%{?python3_pkgversion:%{python3_pkgversion}}%{!?python3_pkgversion:3}')
    - yum -y -q install
          findutils
          python${PY3}-pytest
    # install our package(s)
    - yum -y -q install *.rpm

test:el7:
  extends:
    - .test:el
    - .el7
  needs:
    - rpm:el7
  script:
    # only test executables, not python
    - !reference [".test-exe", script]

test:el8:
  extends:
    - .test:el
    - .el8
  needs:
    - rpm:el8
  before_script:
    - !reference [".test:el", before_script]
    # install a newer version of pytest that supports tmp_path
    - dnf -y -q install python3-pip
    - python3 -m pip install "pytest >= 3.9.0"

test:el9:
  extends:
    - .test:el
    - .el9
  needs:
    - rpm:el9

# -- lint -------------------
#
# These jobs check the code
# for quality issues
#

.rpmlint:
  extends:
    # https://computing.docs.ligo.org/gitlab-ci-templates/rhel/#.rhel:lint
    - .rhel:lint
  stage: code quality
  variables:
    GIT_STRATEGY: fetch
    INSTALLED_RPMS: "*framel*"
    RPMLINT_OPTIONS: "--info"

rpmlint:el7:
  extends:
    - .rpmlint
    - .el7
  needs:
    - rpm:el7

rpmlint:el8:
  extends:
    - .rpmlint
    - .el8
  needs:
    - rpm:el8

rpmlint:el9:
  extends:
    - .rpmlint
    - .el9
  needs:
    - rpm:el9
