# This file uses the freedesktop ci-templates to build shared-mime-info and
# run our tests in CI.
#
# ci-templates uses a multi-stage build process. First, the base container
# image is built which contains the core distribution, the toolchain, and
# all our build dependencies. This container is aggressively cached; if a
# container image matching $FDO_DISTRIBUTION_TAG is found in either the
# upstream repo (wayland/weston) or the user's downstream repo, it is
# reused for the build. This gives us predictability of build and far
# quicker runtimes, however it means that any changes to the base container
# must also change $FDO_DISTRIBUTION_TAG. When changing this, please use
# the current date as well as a unique build identifier.
#
# After the container is either rebuilt (tag mismatch) or reused (tag
# previously used), the build stage executes within this container.
#
# Apart from the 'variables', 'include', and 'stages' top-level anchors,
# everything not beginning with a dot ('.') is the name of a job which will
# be executed as part of CI, unless the rules specify that it should not be
# run.
#
# Variables prefixed with CI_ are generally provided by GitLab itself;
# variables prefixed with FDO_ and templates prefixed by .fdo are provided
# by the ci-templates.
#
# For more information on GitLab CI, including the YAML syntax, see:
#   https://docs.gitlab.com/ee/ci/yaml/README.html
#
# Note that freedesktop.org uses the 'Community Edition' of GitLab, so features
# marked as 'premium' or 'ultimate' are not available to us.
#
# For more information on ci-templates, see:
#   - documentation at https://freedesktop.pages.freedesktop.org/ci-templates/
#   - repo at https://gitlab.freedesktop.org/freedesktop/ci-templates/

# These are used to make sure that we execute 'detached pipelines' on merge
# requests.
workflow:
  rules:
    - if: $CI_PIPELINE_SOURCE == 'merge_request_event'
    - if: $CI_PIPELINE_SOURCE == 'push'

stages:
  - "Base container"
  - "Build and test"

# Here we use a fixed ref in order to isolate ourselves from ci-templates
# API changes. If you need new features from ci-templates you must bump
# this to the current SHA you require from the ci-templates repo, however
# be aware that you may need to account for API changes when doing so.
.templates_sha: &template_sha b791bd48996e3ced9ca13f1c5ee82be8540b8adb # see https://docs.gitlab.com/ee/ci/yaml/#includefile

include:
  - project: 'freedesktop/ci-templates'
    ref: *template_sha
    file:
      - '/templates/fedora.yml'

variables:
  FDO_UPSTREAM_REPO: "xdg/shared-mime-info"
  FDO_REPO_SUFFIX: "$BUILD_OS/$BUILD_ARCH"
  GIT_SUBMODULE_STRATEGY: normal


# Per-OS environment definitions
.os-fedora:
  variables:
    # bump this tag every time you change something which requires rebuilding
    # the base image (e.g. changing dependencies)
    FDO_DISTRIBUTION_TAG: "2022-08-15.0"
    BUILD_OS: fedora
    FDO_DISTRIBUTION_VERSION: 38
    FDO_DISTRIBUTION_PACKAGES: "gcc gcc-c++ glibc-devel make libxml2-devel glib2-devel gettext git xmlto findutils gettext-devel meson"
  
.fedora-x86_64:
  extends:
    - .os-fedora
  variables:
    BUILD_ARCH: "x86-64"

.build-env-fedora-x86_64:
  extends:
    - .fdo.suffixed-image@fedora
    - .fedora-x86_64
  needs:
    - job: fedora-x86_64-container_prep
      artifacts: false

# Real container build job (mostly a no-op)
fedora-x86_64-container_prep:
  extends:
    - .fedora-x86_64
    - .fdo.container-build@fedora
  stage: "Base container"
  variables:
    GIT_STRATEGY: none


# Build job template
.do-build:
  stage: "Build and test"
  script:
    # Compile xdgmime
    - make -C xdgmime

    # Compile and test shared-mime-info
    - meson _build
    - ninja -C _build
    - ninja -C _build test
    - ninja -C _build dist
  artifacts:
    when: always
    paths:
      - _build/meson-logs/*.txt
      - _build/meson-dist/*.*

# Real build job
fedora-x86_64-build:
  extends:
    - .build-env-fedora-x86_64
    - .do-build
