# vim: set ts=2 sts=2 sw=2 expandtab :
dist: xenial
sudo: required
language: bash
services:
  - docker

branches:
  except:
  - gh-pages

before_install:
  - curl -Ls -o docker-build https://github.com/mate-desktop/mate-dev-scripts/raw/master/travis/docker-build
  - curl -Ls -o gen-index https://github.com/mate-desktop/mate-dev-scripts/raw/master/travis/gen-index.sh
  - chmod +x docker-build gen-index

install:
  - sudo apt-get install -y python3-pip python3-setuptools
  - sudo pip3 install --upgrade pip
  - sudo pip install PyGithub
  - ./docker-build --name ${DISTRO} --config .travis.yml --install

script:
  - ./docker-build --name ${DISTRO} --verbose --config .travis.yml --build scripts

deploy:
  - provider: pages
    github-token: $GITHUB_TOKEN
    #keep-history: true
    skip_cleanup: true
    committer-from-gh: true
    target-branch: gh-pages
    local-dir: html-report
    on:
      all_branches: true
      condition: ${DISTRO} =~ ^fedora.*$
  - provider: script
    script: ./docker-build --verbose --config .travis.yml --release github
    skip_cleanup: true
    on:
      tags: true
      condition: "${TRAVIS_TAG} =~ ^v.*$ && ${DISTRO} =~ ^fedora.*$"

after_success:
  - 'if [[ "$TRAVIS_SECURE_ENV_VARS" == "true" && "$TRAVIS_PULL_REQUEST" != "false" && ${DISTRO} =~ ^fedora.*$ ]]; then
        REPO_SLUG_ARRAY=(${TRAVIS_REPO_SLUG//\// });
        REPO_NAME=${REPO_SLUG_ARRAY[1]};
        URL="https://${REPO_NAME}.mate-desktop.dev";
        COMMENT="Code analysis completed";
        curl -H "Authorization: token $GITHUB_TOKEN" -X POST
           -d "{\"state\": \"success\", \"description\": \"$COMMENT\", \"context\":\"scan-build\", \"target_url\": \"$URL\"}"
           https://api.github.com/repos/${TRAVIS_REPO_SLUG}/statuses/${TRAVIS_PULL_REQUEST_SHA};
     fi'

env:
  - DISTRO="archlinux/base"
  - DISTRO="debian:sid"
  - DISTRO="fedora:30"
  - DISTRO="ubuntu:19.10"

##########################################################
# THE FOLLOWING LINES IS USED BY docker-build
##########################################################
requires:
  archlinux:
    # Useful URL: https://git.archlinux.org/svntogit/community.git/tree/mate-panel
    - autoconf-archive
    - clang
    - gcc
    - git
    - gobject-introspection
    - intltool
    - itstool
    - libcanberra
    - libmateweather
    - libsm
    - libwnck3
    - make
    - mate-common
    - mate-desktop
    - mate-menus
    - meson
    - which
    - yelp-tools

  debian:
    # Useful URL: https://github.com/mate-desktop/debian-packages
    # Useful URL: https://salsa.debian.org/debian-mate-team/mate-panel
    - autoconf-archive
    - clang
    - clang-tools
    - cppcheck
    - gir1.2-freedesktop
    - git
    - gobject-introspection
    - gtk-doc-tools
    - intltool
    - libatk1.0-dev
    - libcairo2-dev
    - libdconf-dev
    - libgirepository1.0-dev
    - libglib2.0-dev
    - libgtk-3-dev
    - libice-dev
    - libmate-desktop-dev
    - libmate-menu-dev
    - libmateweather-dev
    - libpango1.0-dev
    - librsvg2-dev
    - libsm-dev
    - libsoup2.4-dev
    - libwnck-3-dev
    - libx11-dev
    - libxau-dev
    - libxrandr-dev
    - lsb-release
    - make
    - mate-common
    - meson
    - yelp-tools

  fedora:
    # Useful URL: https://src.fedoraproject.org/cgit/rpms/mate-panel.git
    - autoconf-archive
    - clang-analyzer
    - clang
    - cppcheck-htmlreport
    - desktop-file-utils
    - gcc
    - git
    - gobject-introspection-devel
    - gtk3-devel
    - libSM-devel
    - libcanberra-devel
    - libmateweather-devel
    - librsvg2-devel
    - libwnck3-devel
    - make
    - mate-common
    - mate-desktop-devel
    - mate-menus-devel
    - meson
    - redhat-rpm-config
    - yelp-tools

  ubuntu:
    - autoconf-archive
    - clang
    - clang-tools
    - gir1.2-freedesktop
    - git
    - gobject-introspection
    - gtk-doc-tools
    - intltool
    - libatk1.0-dev
    - libcairo2-dev
    - libdconf-dev
    - libgirepository1.0-dev
    - libglib2.0-dev
    - libgtk-3-dev
    - libice-dev
    - libmate-desktop-dev
    - libmate-menu-dev
    - libmateweather-dev
    - libpango1.0-dev
    - librsvg2-dev
    - libsm-dev
    - libsoup2.4-dev
    - libwnck-3-dev
    - libx11-dev
    - libxau-dev
    - libxrandr-dev
    - lsb-release
    - make
    - mate-common
    - meson
    - yelp-tools

variables:
  - CFLAGS="-Wall -Werror=format-security"
  - 'CHECKERS="
    -enable-checker deadcode.DeadStores
    -enable-checker alpha.deadcode.UnreachableCode
    -enable-checker alpha.core.CastSize
    -enable-checker alpha.core.CastToStruct
    -enable-checker alpha.core.IdenticalExpr
    -enable-checker alpha.core.SizeofPtr
    -enable-checker alpha.security.ArrayBoundV2
    -enable-checker alpha.security.MallocOverflow
    -enable-checker alpha.security.ReturnPtrRange
    -enable-checker alpha.unix.SimpleStream
    -enable-checker alpha.unix.cstring.BufferOverlap
    -enable-checker alpha.unix.cstring.NotNullTerminated
    -enable-checker alpha.unix.cstring.OutOfBounds
    -enable-checker alpha.core.FixedAddr
    -enable-checker security.insecureAPI.strcpy"'

build_scripts:
# build failed with f30 und using clang patch, fixed in f30?
#  - if [ ${DISTRO_NAME} == "fedora" ];then
#  -     curl -Ls -o fedora.sh https://github.com/mate-desktop/mate-dev-scripts/raw/master/travis/fedora.sh
#  -     bash ./fedora.sh
#  - fi
  - ./autogen.sh
  - scan-build $CHECKERS ./configure
  - if [ $CPU_COUNT -gt 1 ]; then
  -     scan-build $CHECKERS --keep-cc -o html-report make -j $CPU_COUNT
  - else
  -     scan-build $CHECKERS --keep-cc -o html-report make
  - fi
  - if [ ${DISTRO_NAME} == "debian" ];then
  -     cppcheck --enable=warning,style,performance,portability,information,missingInclude -i'mate-menus-build' -i'gtk-layer-shell-build' .
  - fi

before_scripts:
  - cd ${START_DIR}
  - if [ ! -d mate-menus-build ]; then
  -     git clone --depth 1  https://github.com/mate-desktop/mate-menus.git mate-menus-build
  - fi
  - cd mate-menus-build
  - if [ ${DISTRO_NAME} == "debian" -o ${DISTRO_NAME} == "ubuntu" ];then
  -     ./autogen.sh --prefix=/usr --libdir=/usr/lib/x86_64-linux-gnu --libexecdir=/usr/lib/x86_64-linux-gnu
  - else
  -     ./autogen.sh --prefix=/usr
  - fi
  - if [ ${TRAVIS} == "false" ]; then
  -     make clean
  - fi
  - make
  - make install

  - cd ${START_DIR}
  - if [ ! -d gtk-layer-shell-build ]; then
  -     git clone --depth 1  https://github.com/wmww/gtk-layer-shell.git gtk-layer-shell-build
  - fi
  - cd gtk-layer-shell-build
  - meson _build --prefix /usr
  - ninja -C _build
  - ninja -C _build install

after_scripts:
  - if [ ${DISTRO_NAME} == "fedora" ];then
  -   cppcheck --xml --output-file=cppcheck.xml --enable=warning,style,performance,portability,information,missingInclude -i'mate-menus-build' -i'gtk-layer-shell-build' .
  -   cppcheck-htmlreport --title=${REPO_NAME} --file=cppcheck.xml --report-dir=cppcheck-htmlreport
  -   ./gen-index -l 20 -i https://raw.githubusercontent.com/${OWNER_NAME}/${REPO_NAME}/master/icons/16x16/${REPO_NAME}.png
  - fi
  - make distcheck

releases:
  draft: false
  prerelease: false
  checksum: true
  file_glob: true
  files: mate-panel-*.tar.xz
  github_release:
    tags: true
    overwrite: true
    base_version: 1.20.0