image: debian:stable-slim

stages:
  - build
  - test
  # Do not run Linux and Windows tests at the same time. Test rigs share some scanners
  # and both systems cannot access a scanner at the same time.
  - test_hw_linux
  - test_hw_windows
  - deploy

.apt: &apt
  before_script:
    - apt-get update
    # WORKAROUND: manpages is required to install some of the openjdk-jre
    # and openjdk-jre is required for plantuml, which is required to generate
    # documentation
    - mkdir -p /usr/share/man/man1
    - apt-get install -y -qq make meson build-essential
    - apt-get install -y -qq libsane-dev
    - apt-get install -y -qq libgirepository1.0-dev gobject-introspection
    - apt-get install -y -qq libcunit1-ncurses-dev
    - apt-get install -y -qq valgrind valac
    - apt-get install --no-install-recommends -y -qq gtk-doc-tools doxygen plantuml graphviz

.msys: &msys
  before_script:
    - c:\msys64\usr\bin\pacman --needed --noconfirm -S make
    - c:\msys64\usr\bin\pacman --needed --noconfirm -S mingw-w64-i686-cunit
    - c:\msys64\usr\bin\pacman --needed --noconfirm -S mingw-w64-i686-doxygen
    - c:\msys64\usr\bin\pacman --needed --noconfirm -S mingw-w64-i686-gcc
    - c:\msys64\usr\bin\pacman --needed --noconfirm -S mingw-w64-i686-gobject-introspection
    - c:\msys64\usr\bin\pacman --needed --noconfirm -S mingw-w64-i686-meson
    - c:\msys64\usr\bin\pacman --needed --noconfirm -S mingw-w64-i686-python3-gobject
    - c:\msys64\usr\bin\pacman --needed --noconfirm -S mingw-w64-i686-python3-pillow
    - c:\msys64\usr\bin\pacman --needed --noconfirm -S mingw-w64-i686-vala

.msys64: &msys64
  before_script:
    - c:\msys64\usr\bin\pacman --needed --noconfirm -S make
    - c:\msys64\usr\bin\pacman --needed --noconfirm -S mingw-w64-x86_64-cunit
    - c:\msys64\usr\bin\pacman --needed --noconfirm -S mingw-w64-x86_64-doxygen
    - c:\msys64\usr\bin\pacman --needed --noconfirm -S mingw-w64-x86_64-gcc
    - c:\msys64\usr\bin\pacman --needed --noconfirm -S mingw-w64-x86_64-gobject-introspection
    - c:\msys64\usr\bin\pacman --needed --noconfirm -S mingw-w64-x86_64-meson
    - c:\msys64\usr\bin\pacman --needed --noconfirm -S mingw-w64-x86_64-python3-gobject
    - c:\msys64\usr\bin\pacman --needed --noconfirm -S mingw-w64-x86_64-python3-pillow
    - c:\msys64\usr\bin\pacman --needed --noconfirm -S mingw-w64-x86_64-vala

check:
  stage: test
  only:
    - branches@World/OpenPaperwork/libinsane
    - tags@World/OpenPaperwork/libinsane
  # We use buster so we have clang-tidy-7 available
  image: debian:buster-slim
  tags:
    - linux
    - volatile
  <<: *apt
  script:
    - apt-get install -y -qq sparse clang-tidy-7
    - make check

test:
  stage: test
  only:
    - branches@World/OpenPaperwork/libinsane
    - tags@World/OpenPaperwork/libinsane
  # WORKAROUND: valgrind from Debian stable doesn't work on armhf.
  image: debian:buster-slim
  tags:
    - linux
    - volatile
  <<: *apt
  script:
    - make test


doc:
  stage: deploy
  only:
    - branches@World/OpenPaperwork/libinsane
    - tags@World/OpenPaperwork/libinsane
  image: debian:buster-slim
  tags:
    - linux
    - volatile
  <<: *apt
  script:
    - apt-get install -y -qq rclone
    - make doc
    - ./deliver_doc.sh
  artifacts:
    paths:
      - doc/build
    expire_in: 2 days


test_hw_linux:
  stage: test_hw_linux
  only:
    - branches@World/OpenPaperwork/libinsane
    - tags@World/OpenPaperwork/libinsane
  tags:
    - linux
    - testhw
  script:
    # Keep in mind this one is a real system --> you're not root on it
    # --> no APT commands here
    - . ./activate_test_env.sh && make test_hw
  artifacts:
    paths:
      - test_hw_out
    expire_in: 2 days


test_hw_windows:
  stage: test_hw_windows
  only:
    - branches@World/OpenPaperwork/libinsane
    - tags@World/OpenPaperwork/libinsane
  variables:
    MSYSTEM: "MINGW32"
    CHERE_INVOKING: "yes"
  tags:
    - windows
    - testhw
  # This one is a real system too, but it's a Windows, so nobody cares.
  # Dependencies should already be installed, but still it's simpler and safer
  # to ask pacman to install them anyway.
  <<: *msys
  script:
    - c:\msys64\usr\bin\bash -lc "make install PREFIX=/mingw32"
    - c:\msys64\usr\bin\bash -lc "make test_hw"
  artifacts:
    paths:
      - test_hw_out
    expire_in: 2 days


test_hw_windows64:
  stage: test_hw_windows
  only:
    - branches@World/OpenPaperwork/libinsane
    - tags@World/OpenPaperwork/libinsane
  variables:
    MSYSTEM: "MINGW64"
    CHERE_INVOKING: "yes"
  tags:
    - windows
    - testhw
  # This one is a real system too, but it's a Windows, so nobody cares.
  # Dependencies should already be installed, but still it's simpler and safer
  # to ask pacman to install them anyway.
  <<: *msys64
  script:
    - c:\msys64\usr\bin\bash -lc "make install PREFIX=/mingw64"
    - c:\msys64\usr\bin\bash -lc "make test_hw"
  artifacts:
    paths:
      - test_hw_out
    expire_in: 2 days
