include:
 - remote: 'https://source.puri.sm/Librem5/librem5-ci/raw/master/librem5-pipeline-definitions.yml'
 - remote: 'https://gitlab.freedesktop.org/freedesktop/ci-templates/-/raw/34039cd573a2df832d465bc9e4c5f543571f5241/templates/ci-fairy.yml'

stages:
 - build

default:
  # Protect CI infra from rogue jobs
  timeout: 15 minutes
  # Allow jobs to be caneled on new commits
  interruptible: true
  # Retry on infra hickups automatically
  retry:
    max: 1
    when:
      - 'api_failure'
      - 'runner_system_failure'
      - 'scheduler_failure'
      - 'stuck_or_timeout_failure'

variables:
  # For ci-fairy
  FDO_UPSTREAM_REPO: guidog/phosh-mobile-settings
  DEBIAN_IMAGE: $CI_REGISTRY/guidog/phosh-osk-stub/debian:v0.0.20220824
  COMMON_BUILD_OPTS: --werror

.bookworm_vars: &bookworm_vars
  variables:
    DIST: bookworm
    BUILD_OPTS:  ${COMMON_BUILD_OPTS}

.build_step: &build_step
  script:
    - 'echo "Build opts: ${BUILD_OPTS}"'
    - meson ${BUILD_OPTS} . _build
    - meson compile -C _build

# Sanity checks of MR settings and commit logs
sanity:
  extends:
    - .fdo.ci-fairy
  stage: build
  script: |
    if [ -n "$CI_OPEN_MERGE_REQUESTS" ]; then
      ci-fairy check-commits --junit-xml=commit-message-junit-report.xml cifairy/main..HEAD ;
    else
      echo "Not a merge request" ;
    fi
  artifacts:
    reports:
      junit: commit-message-junit-report.xml
  only:
    variables:
      - $CI_OPEN_MERGE_REQUESTS && $PKG_ONLY != "1"

build:native-debian-bookworm:
  stage: build
  image: ${DEBIAN_IMAGE}
  before_script:
    - apt-get -y update
    - apt-get -y build-dep .
  <<: *bookworm_vars
  <<: *build_step
  artifacts:
    paths:
      - _build
