variables:
  FDO_UPSTREAM_REPO: mesa/waffle
  FDO_DISTRIBUTION_TAG: '2021-01-26_2'
  FDO_DISTRIBUTION_VERSION: 'buster-slim'

include:
  - project: 'freedesktop/ci-templates'
    ref: &ci-templates-sha 52dd4a94044449c8481d18dcdc221a3c636366d2
    file: '/templates/debian.yml'

stages:
  - container
  - build
  - www

# When to automatically run the CI
.ci-run-policy:
  retry:
    max: 2
    when:
      - runner_system_failure
  # Cancel CI run if a newer commit is pushed to the same branch
  interruptible: true

container:
  stage: container
  extends:
    - .fdo.container-build@debian
    - .ci-run-policy
  variables:
    # no need to pull the whole repo to build the container image
    GIT_STRATEGY: none
   
    FDO_DISTRIBUTION_PACKAGES: >
      bash-completion
      ca-certificates
      cmake
      docbook-xsl
      docbook-xml
      g++
      gcc
      libcmocka-dev
      libegl1-mesa-dev
      libgbm-dev
      libgl1-mesa-dev
      libudev-dev
      libwayland-dev
      libx11-dev
      libxcb1-dev
      make
      meson
      pkg-config
      wayland-protocols
      xauth
      xsltproc
      xvfb

# BUILD
.build:
  extends: 
    - .ci-run-policy
    - .fdo.container-build@debian
  stage: build
  variables:
    GIT_DEPTH: 100
  image: "$CI_REGISTRY_IMAGE/debian/$FDO_DISTRIBUTION_VERSION:$FDO_DISTRIBUTION_TAG"
  needs:
    - container
    

meson:
  extends:
    - .build
  script:
    - bash .gitlab-ci/build-meson.sh x11
    - bash .gitlab-ci/build-meson.sh wayland
    - bash .gitlab-ci/build-meson.sh gbm
    - bash .gitlab-ci/build-meson.sh surfaceless
  artifacts:
    when: on_failure
    paths:
      - _build/meson-logs/*.txt

cmake:
  extends:
    - .build
  script:
    - cmake
        -S . -B _build
        -DCMAKE_INSTALL_PREFIX=`pwd`/install
        -DCMAKE_BUILD_TYPE=Debug
        -Dwaffle_has_gbm=1
        -Dwaffle_has_glx=1
        -Dwaffle_has_x11_egl=1
        -Dwaffle_has_wayland=1
        -Dwaffle_has_surfaceless=1
        -Dwaffle_build_manpages=1
        -Dwaffle_build_htmldocs=1
        -Dwaffle_build_examples=1
    - make -C _build -j4
    - make -C _build check
    - make -C _build install


pages:
  stage: www
  image: alpine
  script:
  - apk add --no-cache git git-lfs
  - git lfs install
  - mkdir public
  - git checkout origin/website
  - git log --oneline -1
  - cp -r files man public
  - git checkout origin/master
  - git log --oneline -1
  - cd www
  - cp -r *.jpg *.html *.css ../public
  artifacts:
    paths:
    - public
  only:
    refs:
      - master
# TODO: Trigger pages only when the `www` directory changes. But, with this
# `changes` code, it never triggers the job.
#    changes:
#      - www/**

