stages:
  - test
  - test-long
  - ci-status
variables:
  GIT_STRATEGY: fetch
  GIT_CLEAN_FLAGS: -ffdxq

.test:
  stage: test
  image: jedbrown/mpich
  variables:
    GIT_DEPTH: 1
  before_script:
    - echo nproc=$(nproc)
    - cat /proc/cpuinfo
  script:
    - ${PYTHON} ./configure --with-debugging=0 COPTFLAGS='-O -march=native' CXXOPTFLAGS='-O -march=native' FOPTFLAGS='-O -march=native' ${CONFIG_OPTS}
    - make -j$(nproc) -l$(nproc)
    - make -j$(nproc) -l$(nproc) -f gmakefile test search="${TEST_SEARCH}"

mpich-cxx-py3:
  extends: .test
  variables:
    PYTHON: python3
    CONFIG_OPTS: --with-mpi-dir=/usr/local --with-clanguage=cxx --with-fc=0
    TEST_SEARCH: snes_tutorials-ex48%

uni-complex-float-int64:
  extends: .test
  variables:
    PYTHON: python3
    CONFIG_OPTS: <
      --with-mpi=0
      --with-scalar-type=complex --with-precision=single --with-64-bit-indices
    TEST_SEARCH: ts_tutorials-ex11_adv_2d_quad_%

c89-mlib-static-py2:
  extends: .test
  variables:
    PYTHON: python3
    CONFIG_OPTS: <
      --with-mpi-dir=/usr/local
      --with-single-library=0 --with-shared-libraries=0 'CFLAGS=-std=c89 -pedantic -Wno-long-long -Wno-overlength-strings'
    TEST_SEARCH: snes_tutorials-ex48%


.mcs_test:
  stage: test-long
  script:
    - git config user.email "petsc@gitlab.none"
    - git config user.name "petsc gitlab-ci"
    - git fetch origin master
    - git merge -m "test" FETCH_HEAD
    - ./config/examples/${TEST_ARCH}.py
    - make
    - make check
    - make cleantest allgtests-tap TIMEOUT=300

.linux_mcs_test:
  extends: .mcs_test
  tags:
    - mcs
    - linux
  before_script:
    - hostname
    - grep PRETTY_NAME /etc/os-release
    - echo $(nproc)

.freebsd_mcs_test:
  extends: .mcs_test
  tags:
    - mcs
    - freebsd
  before_script:
    - hostname
    - freebsd-version
    - echo $(sysctl -n hw.ncpu)

.osx_mcs_test:
  extends: .mcs_test
  tags:
    - mcs
    - osx
  before_script:
    - hostname
    - sw_vers -productVersion
    - echo $(sysctl -n hw.ncpu)

.opensolaris_mcs_test:
  extends: .mcs_test
  tags:
    - mcs
    - opensolaris
  before_script:
    - hostname
    - uname -a
    - echo $(nproc)

linux-gcc-complex-opt:
  extends: .linux_mcs_test
  variables:
    TEST_ARCH: arch-jenkins-linux-gcc-complex-opt

linux-gcc-pkgs-opt:
  extends: .linux_mcs_test
  variables:
    TEST_ARCH: arch-jenkins-linux-gcc-pkgs-opt

linux-gcc-quad-64idx-dbg:
  extends: .linux_mcs_test
  variables:
    TEST_ARCH: arch-jenkins-linux-gcc-quad-64idx-dbg

freebsd-c-single-opt:
  extends: .freebsd_mcs_test
  variables:
    TEST_ARCH: arch-jenkins-freebsd-c-single-opt

freebsd-cxx-cmplx-64idx-dbg:
  extends: .freebsd_mcs_test
  variables:
    TEST_ARCH: arch-jenkins-freebsd-cxx-cmplx-64idx-dbg

osx-cxx-pkgs-opt:
  extends: .osx_mcs_test
  variables:
    TEST_ARCH: arch-jenkins-osx-cxx-pkgs-opt

opensolaris-cmplx-pkgs-dbg:
  extends: .opensolaris_mcs_test
  variables:
    TEST_ARCH: arch-jenkins-opensolaris-cmplx-pkgs-dbg

.status:
  stage: ci-status
  image: jedbrown/alpine-curl
  script:
    - BUILD_KEY=push BITBUCKET_NAMESPACE=petsc ./.gitlab-build-status.sh

success:
  extends: .status
  variables:
    BUILD_STATUS: passed
  when: on_success

failure:
  extends: .status
  variables:
    BUILD_STATUS: failed
  when: on_failure
