include:
  - project: sysadmin/ci-utilities
    file:
      - /gitlab-templates/linux.yml
      - /gitlab-templates/linux-qt6.yml
      - /gitlab-templates/freebsd.yml
      - /gitlab-templates/freebsd-qt6.yml
      - /gitlab-templates/android.yml
      - /gitlab-templates/android-qt6.yml

build_ubuntu_20_10:
  stage: build
  image: ubuntu:groovy
  tags:
    - Linux
  only:
    - merge_requests
  before_script:
    - sed -i -e 's/# deb-src/deb-src/g' /etc/apt/sources.list
    - sed -i -e 's/archive/old-releases/g' /etc/apt/sources.list
    - sed -i -e 's/security.ubuntu/old-releases.ubuntu/g' /etc/apt/sources.list
    - echo "91.189.91.124 old-releases.ubuntu.com" >> /etc/hosts
    - apt update
    - apt install --yes eatmydata
    - eatmydata apt build-dep --yes --no-install-recommends qca2
    - eatmydata apt install --yes --no-install-recommends ninja-build libbotan-2-dev libnss3-dev libgcrypt20-dev libpkcs11-helper1-dev gnupg
  script:
    - mkdir -p build && cd build
    - cmake -G Ninja .. -DBUILD_PLUGINS=all
    - ninja
    - QT_PLUGIN_PATH=`pwd`/lib/qca-qt5/ ctest -V

build_fedora_34:
  stage: build
  image: fedora:34
  tags:
    - Linux
  only:
    - merge_requests
  before_script:
    - dnf -y --setopt=install_weak_deps=False install git gcc-c++ make cmake ninja-build qt6-qtbase-devel qt6-qt5compat-devel botan2-devel cyrus-sasl-devel nss-devel libgcrypt-devel pkcs11-helper-devel gnupg
  script:
    - mkdir -p build && cd build
    - cmake -G Ninja -DBUILD_WITH_QT6=ON .. -DBUILD_PLUGINS=all
    - ninja
    - QT_PLUGIN_PATH=`pwd`/lib/qca-qt6/ ctest -V

build_clazy_clang_tidy:
  stage: build
  image: debian:unstable
  tags:
    - Linux
  only:
    - merge_requests
  before_script:
    - echo 'deb-src http://deb.debian.org/debian unstable main' >> /etc/apt/sources.list
    - apt-get update
    - apt-get install --yes eatmydata
    - eatmydata apt-get build-dep --yes --no-install-recommends qca2
    - eatmydata apt-get install --yes --no-install-recommends ninja-build libbotan-2-dev libnss3-dev libgcrypt20-dev libpkcs11-helper1-dev clazy clang clang-tidy-14 jq gnupg
  script:
    - srcdir=`pwd` && mkdir -p /tmp/qca_build && cd /tmp/qca_build && CC=clang CXX=clazy CXXFLAGS="-Werror -Wno-deprecated-declarations" cmake -DBUILD_PLUGINS=all -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -G Ninja $srcdir && cat compile_commands.json | jq  '[.[] | select(.file | contains("'"$srcdir"'"))]' > compile_commands.aux.json && mv compile_commands.aux.json compile_commands.json
    - CLAZY_CHECKS="level0,level1,level2,no-copyable-polymorphic,no-ctor-missing-parent-argument,isempty-vs-count,qhash-with-char-pointer-key,qproperty-type-mismatch,qrequiredresult-candidates,signal-with-return-value,thread-with-slots,tr-non-literal,unneeded-cast" ninja
    - "run-clang-tidy-14 -header-filter='.*/qca/.*' -checks='-*,performance-*,modernize-deprecated-headers,modernize-make-unique,modernize-make-shared,modernize-use-override,modernize-use-equals-delete,modernize-use-emplace,modernize-use-bool-literals,modernize-redundant-void-arg,modernize-loop-convert,modernize-use-nullptr,-performance-no-automatic-move,-performance-no-int-to-ptr' -config=\"{WarningsAsErrors: '*'}\""
    - QT_PLUGIN_PATH=`pwd`/lib/qca-qt5/ ctest -V

build_openssl3_botan3:
  stage: build
  image: debian:unstable
  tags:
    - Linux
  only:
    - merge_requests
  before_script:
    - echo 'deb-src http://deb.debian.org/debian unstable main' >> /etc/apt/sources.list
    - apt-get update
    - apt-get install --yes eatmydata
    - eatmydata apt-get build-dep --yes --no-install-recommends qca2
    - eatmydata apt-get install --yes --no-install-recommends ninja-build libnss3-dev libgcrypt20-dev libpkcs11-helper1-dev gnupg wget libz-dev
  script:
    - wget https://github.com/randombit/botan/archive/refs/tags/3.0.0.tar.gz
    - tar xvfh 3.0.0.tar.gz
    - cd botan-3.0.0
    - ./configure.py --prefix="/usr" --with-zlib
    - time make -j `nproc` install
    - cd ..
    - mkdir -p build && cd build
    - cmake -G Ninja .. -DBUILD_PLUGINS=all
    - ninja
    - QT_PLUGIN_PATH=`pwd`/lib/qca-qt5/ bin/qcatool* --debug plugins > features-with-legacy
    - QT_PLUGIN_PATH=`pwd`/lib/qca-qt5/ ctest -V
    - echo "Now test without the legacy provider"
    - ls /usr/lib/x86_64-linux-gnu/ossl-modules/legacy.so
    - rm /usr/lib/x86_64-linux-gnu/ossl-modules/legacy.so
    - QT_PLUGIN_PATH=`pwd`/lib/qca-qt5/ bin/qcatool* --debug plugins > features-without-legacy
    - QT_PLUGIN_PATH=`pwd`/lib/qca-qt5/ ctest -V
    - echo "Make sure there is a difference without the legacy provider"
    - "! diff -u features-with-legacy features-without-legacy"

clang_format:
  stage: build
  image: debian:testing
  tags:
    - Linux
  only:
    - merge_requests
  before_script:
    - apt-get update
    - apt-get install --yes --no-install-recommends git clang-format-16
  script:
    - find . \( -name "*.cpp" -or -name "*.h"  -or -name "*.c"  -or -name "*.cc" \) -exec clang-format-16 -i {} \;
    - git diff --exit-code
