# vim: set expandtab shiftwidth=2 tabstop=8:

piper_references:
  build_dependencies: &build_dependencies
    FEDORA_RPMS: meson gettext python3 pygobject3-devel python3-lxml libratbag-ratbagd python3-cairo python3-evdev python3-flake8 gtk-update-icon-cache
    UBUNTU_DEBS: meson pkg-config gettext python3 python-gi-dev python3-lxml python3-evdev gir1.2-rsvg-2.0 python3-gi-cairo python3-flake8 ratbagd gtk-update-icon-cache

  default_settings: &default_settings
    working_directory: ~/piper
    environment:
      LANG: C.UTF-8

  build_default: &build_default
    name: Build
    command: |
      rm -rf build
      meson build ${MESON_PARAMS}
      meson configure build
      ninja -v -C build ${NINJA_ARGS}
    environment:
      MESON_PARAMS: --prefix=/usr
  build_buildtype_plain: &build_buildtype_plain
    run:
      <<: *build_default
      name: Build with buildtype plain
      environment:
        MESON_PARAMS: --prefix=/usr -Dbuildtype=plain
  build_buildtype_release: &build_buildtype_release
    run:
      <<: *build_default
      name: Build with buildtype release
      environment:
        MESON_PARAMS: --prefix=/usr -Dbuildtype=release
  build_and_test: &build_and_test
    run:
      <<: *build_default
      name: Build and test
      environment:
        NINJA_ARGS: test
  install: &install
    run:
      name: Installing
      command: ninja -C build install
  export_logs: &export_logs
    store_artifacts:
      path: ~/piper/build/meson-logs

fedora_settings: &fedora_settings
  <<: *default_settings
  steps:
    - run:
        name: Install prerequisites
        command: |
          dnf install -y tree git diffutils ${FEDORA_RPMS}
    - checkout
    - *build_and_test
    - *install
    - *build_buildtype_plain
    - *build_buildtype_release
    - *export_logs
  environment:
    *build_dependencies

ubuntu_settings: &ubuntu_settings
  <<: *default_settings
  steps:
    - run:
        name: Install prerequisites
        command: |
          apt-get update
          apt-get install -y software-properties-common
          add-apt-repository universe
          apt-get update
          apt-get install -y tree git ${UBUNTU_DEBS}
    - checkout
    - *build_and_test
    - *install
    - *build_buildtype_plain
    - *build_buildtype_release
    - *export_logs
  environment:
    *build_dependencies

version: 2
jobs:
  fedora_31:
    <<: *fedora_settings
    docker:
      - image: fedora:31
  ubuntu_19_04:
    <<: *ubuntu_settings
    docker:
      - image: ubuntu:19.04

workflows:
  version: 2
  compile_and_test:
    jobs:
      - ubuntu_19_04
      - fedora_31
