variables:
  DEBIAN_FRONTEND: noninteractive

before_script:  
  - bash ci/docker_install.sh 

stages:
  - test
  - build
  - deploy

check_changelog:
  stage: test
  tags:
    - docker
  image: ubuntu
  script:
    - bash ci/check_changelog.sh
  rules:
    # Run the pipeline when the MR is created and required files are changed
    - if: $CI_PIPELINE_SOURCE == 'merge_request_event'
      changes:
        - debian/*
        - purgekernels

build_deb_package:
  tags:
    - docker

  image: ubuntu:$UBUNTU_VERSION

  stage: build

  script:
    - dpkg-buildpackage -us -uc
    - mkdir -p build/$UBUNTU_VERSION
    - mv ../bit-purgekernels_* build/$UBUNTU_VERSION
    - dpkg -i build/$UBUNTU_VERSION/bit-purgekernels*.deb
  
  rules:
    # Run the pipeline when the MR is created and required files are changed
    - if: $CI_PIPELINE_SOURCE == 'merge_request_event'
      changes:
        - debian/*
        - purgekernels
    # Or run the pipeline when the MR is merged and required files are changed
    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
      changes:
        - debian/*
        - purgekernels

  artifacts:
    paths:
      - build/*
    expire_in: 1 week
  parallel:
    matrix:
      - UBUNTU_VERSION: ["focal", "jammy", "noble"]

deploy_deb_pkgs:
  stage: deploy
  dependencies:
    - build_deb_package
  tags:
    - obit
  script:
    - bash ci/pkg_deploy.sh
  rules:
    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
      changes:
        - debian/*
        - purgekernels
