# we utilize the images generated by the build-images project, to
# speed up CI runs. We also use ccache and store config.cache
# to speed up compilation. We include a version number in cache
# name to allow expiration of old caches.

cache:
  key: "$CI_JOB_NAME-ver5"
  paths:
    - cache/

before_script:
  # CCache Config
  - mkdir -p cache
  - export CCACHE_BASEDIR=${PWD}
  - export CCACHE_DIR=${PWD}/cache
  - echo $CCACHE_DIR
  - export CC="ccache gcc"

after_script:
  # somehow after_script loses environment
  - export CCACHE_BASEDIR=${PWD}
  - export CCACHE_DIR=${PWD}/cache
  - ccache -s

variables:
  BUILD_IMAGES_PROJECT: gnuwget/build-images
  DEBIAN_BUILD: buildenv-debian-stretch
  FEDORA_BUILD: buildenv-f27
  CENTOS7_BUILD: buildenv-centos7
  MINGW_BUILD: buildenv-mingw
  ALPINE_BUILD: buildenv-alpine
  ARCH_BUILD: buildenv-arch
  BASIC_BUILD: buildenv-basic
  GET_SOURCES_ATTEMPTS: "3"
  GIT_DEPTH: "5"
  CONFIGURE_BASE_FLAGS: --enable-assert --cache-file cache/config.cache
  CFLAGS_DEFAULT: -O0 -g -ggdb3 -Wall -Wextra


VPATH/Debian:
  image: $CI_REGISTRY/$BUILD_IMAGES_PROJECT:$DEBIAN_BUILD
  script:
    - cp -a /builds/common/gnulib .
    - export CFLAGS=$CFLAGS_DEFAULT
    - ./bootstrap --skip-po
    - mkdir vpath && cd vpath
    - ../configure $CONFIGURE_BASE_FLAGS --cache-file ../cache/config.cache
    - make -j$(nproc)
    - make -j$(nproc) distcheck
  tags:
    - shared
    - docker
  artifacts:
    expire_in: 2 weeks
    when: on_failure
    paths:
      - ./*.log
      - fuzz/*.log
      - tests/*.log
      - testenv/*.log

# In this build we combine
#  * syntax-check
#  * abi-check
#  * build/valgrind-check
#  * build/asan-check
#  * build w/Werror and ubsan-check
OpenSSL/Debian:
  image: $CI_REGISTRY/$BUILD_IMAGES_PROJECT:$DEBIAN_BUILD
  script:
  - echo "127.0.0.1 wgettestingserver" >>/etc/hosts
  - cat /etc/hosts
  - alias make="make -j$(nproc)"
  - ./bootstrap --skip-po
  - ./configure $CONFIGURE_BASE_FLAGS --with-ssl=gnutls
  - make syntax-check
  - make check
  - make distcheck
  - make check-valgrind
  tags:
  - shared
  artifacts:
    expire_in: 2 weeks
    when: on_failure
    paths:
      - ./*.log
      - fuzz/*.log
      - tests/*.log
      - testenv/*.log

GnuTLS/Debian:
  image: $CI_REGISTRY/$BUILD_IMAGES_PROJECT:$DEBIAN_BUILD
  script:
  - echo "127.0.0.1 wgettestingserver" >>/etc/hosts
  - cat /etc/hosts
  - alias make="make -j$(nproc)"
  - ./bootstrap --skip-po
  - ./configure $CONFIGURE_BASE_FLAGS --with-ssl=openssl
  - make syntax-check
  - make check
  - make distcheck
  - make check-valgrind
  tags:
  - shared
  artifacts:
    expire_in: 2 weeks
    when: on_failure
    paths:
      - ./*.log
      - fuzz/*.log
      - tests/*.log
      - testenv/*.log

Minimal/Debian:
  image: $CI_REGISTRY/$BUILD_IMAGES_PROJECT:$DEBIAN_BUILD
  script:
    - cp -a /builds/common/gnulib .
    - export CFLAGS=$CFLAGS_DEFAULT
    - ./bootstrap --skip-po
    - ./configure $CONFIGURE_BASE_FLAGS --cache-file ../cache/config.cache
      --disable-nls --without-ssl --enable-ipv6 --without-zlib --without-libiconv-prefix
      --disable-iri --disable-ntlm --disable-pcre --without-libpsl --without-libuuid
      --without-libintl-prefix
    - make -j$(nproc)
    - make -j$(nproc) check
    - make check-valgrind
  tags:
    - shared
    - docker
  artifacts:
    expire_in: 2 weeks
    when: on_failure
    paths:
      - ./*.log
      - fuzz/*.log
      - tests/*.log
      - testenv/*.log


#Centos7 build:
#  image: $CI_REGISTRY/$BUILD_IMAGES_PROJECT:$CENTOS7_BUILD
#  script:
#  - sed -i 's/AM_GNU_GETTEXT_VERSION(0.19.3)/AM_GNU_GETTEXT_VERSION(0.18.2)/g' configure.ac
#  - ./bootstrap && ./configure --enable-gcc-warnings --disable-doc && make -j$(nproc) check
#  tags:
#  - shared
#  artifacts:
#    expire_in: 2 weeks
#    when: on_failure
#    paths:
#      - tests/*.log
#      - compat_reports/

#clang-analyzer/Fedora:
#  image: $CI_REGISTRY/$BUILD_IMAGES_PROJECT:$FEDORA_BUILD
#  script:
#  - ./bootstrap
#  - scan-build ./configure --disable-doc --enable-gcc-warnings
#  - make -j$(nproc) -C gl
#  - scan-build --status-bugs -o scan-build-lib make -j$(nproc) -C lib
#  tags:
#  - shared
#  except:
#  - tags
#  artifacts:
#    expire_in: 2 weeks
#    when: on_failure
#    paths:
#      - scan-build-lib/*

#pages:
#  image: $CI_REGISTRY/$BUILD_IMAGES_PROJECT:$DEBIAN_BUILD
#  script:
#  - ./bootstrap
#  - CFLAGS="-g -O0" ./configure --enable-gtk-doc --enable-code-coverage --disable-gcc-warnings
#  - make -j$(nproc) check
#  - make local-code-coverage-output
#  - mkdir -p public
#  - rm -rf public/coverage
#  - mv libidn2-*-coverage public/coverage
#  - rm -rf public/reference
#  - mv doc/reference/html public/reference
#  - make -C doc manual
#  - rm -rf public/manual
#  - mv doc/manual public/manual
#  tags:
#  - shared
#  artifacts:
#    when: on_success
#    paths:
#      - public
#  only:
#    - master

#MinGW64:
#  image: $CI_REGISTRY/$BUILD_IMAGES_PROJECT:$FEDORA_BUILD
#  before_script:
#  - mount -t binfmt_misc binfmt_misc /proc/sys/fs/binfmt_misc &&
#    echo ':DOSWin:M::MZ::/usr/bin/wine64:' > /proc/sys/fs/binfmt_misc/register
#  script:
#  - ./bootstrap
#  - mingw64-configure --disable-valgrind-tests --disable-doc
#  - mingw64-make -j$(nproc)
#  - mingw64-make -j$(nproc) check
#  tags:
#  - shared
#  - docker
#  except:
#  - tags
#  artifacts:
#    expire_in: 2 weeks
#    when: on_failure
#    paths:
#      - ./*.log
#      - tests/*.log
