# ---------------------------
# Debian packaging workflow
# ---------------------------

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

# -- macros

.bullseye:
  image: igwn/builder:bullseye

.bookworm:
  image: igwn/builder:bookworm

# -- source packages --------
#
# These jobs make DSC packages
#

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

dsc:bullseye:
  extends:
    - .dsc
    - .bullseye

dsc:bookworm:
  extends:
    - .dsc
    - .bookworm

# -- binary packages --------
#
# These jobs generate DEB
# binary packages from the
# DSC sources packages
#

.deb:
  extends:
    # https://computing.docs.ligo.org/gitlab-ci-templates/debian/#.debian:deb
    - .debian:deb
  stage: binary packages
  variables:
    DSC: "framel_*.dsc"

deb:bullseye:
  extends:
    - .deb
    - .bullseye
  needs:
    - dsc:bullseye

deb:bookworm:
  extends:
    - .deb
    - .bookworm
  needs:
    - dsc:bookworm

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

.test:debian:
  extends:
    # see /.gitlab/ci/test.yml
    - .test
    # https://computing.docs.ligo.org/gitlab-ci-templates/debian/#.debian:base
    - .debian:base
  before_script:
    # set up apt
    - !reference [".debian:base", before_script]
    # setup local apt repository
    - apt-get -y -q -q install local-apt-repository
    - mkdir -pv /srv/local-apt-repository
    - |
      cat > /etc/apt/preferences.d/99local-apt-repository << EOF
      Package: *
      Pin: origin ""
      Pin-Priority: 1001
      EOF
    # fill our local apt repo and rebuild it
    - mv -v *.deb /srv/local-apt-repository
    - /usr/lib/local-apt-repository/rebuild
    - apt-get -y -q update
    # install testing dependencies
    - apt-get -y -q install
          findutils
          python3-pytest
    # install our package(s)
    - apt-cache policy framel
    - apt-cache show framel
    - apt-get -y install framel python3-framel

test:bullseye:
  extends:
    - .test:debian
    - .bullseye
  needs:
    - deb:bullseye

test:bookworm:
  extends:
    - .test:debian
    - .bookworm
  needs:
    - deb:bookworm

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

.lintian:
  extends:
    # https://computing.docs.ligo.org/gitlab-ci-templates/debian/#.debian:lint
    - .debian:lint
  stage: code quality
  variables:
    LINTIAN_OPTIONS: "--color always --suppress-tags new-package-should-close-itp-bug,groff-message,embedded-library --fail-on error --allow-root --pedantic"

lintian:bullseye:
  extends:
    - .lintian
    - .bullseye
  needs:
    - deb:bullseye
  variables:

lintian:bookworm:
  extends:
    - .lintian
    - .bookworm
  needs:
    - deb:bookworm
