#
# stage-1 take only a few minutes; they do not run the full test suite or external packages.
#
# stage-2 runs on MCS systems and may take 10 to 15 minutes. They run the full test suite but with limited mixture of external packages
#
# stage-3 runs on MCS systems and may take an hour or more. They run the full test suite and heavily test external packages, utilize valgrind etc
#
# The stage-(n) tests are only started if all of the stage-(n-1) tests run without error
#   You can limit the testing by using the variable STAGE with value 1 or 2
#

stages:
  - stage-1
  - stage-2
  - stage-3
variables:
  GIT_STRATEGY: fetch
  GIT_CLEAN_FLAGS: -ffdxq
  PETSC_OPTIONS: -check_pointer_intensity 0 -error_output_stdout -nox -nox_warning -malloc_dump -checkstack
  TIMEOUT: 450

#
# The most basic template that most tests will expand upon
#

.test-basic:
  interruptible: true
  only:
    refs:
#     Set with CI/CD Shedules - New Schedule
      - schedules
      - api
#     Set with CI/CD Pipelines - Run Pipeline
      - web
      - merge_requests
  dependencies: []

.test:
  extends: .test-basic
  except:
    variables:
      # Skip if the docs-only label is attached to a merge request
      - $CI_MERGE_REQUEST_LABELS =~ /(^|,)docs-only($|,)/
      - $PETSC_CI_SCHEDULED =~ /yes/

check-ci-settings:
  extends: .test-basic
  stage: .pre
  tags:
    - check-ci-settings
  script:
    - lib/petsc/bin/maint/check-ci-settings.sh
#
#  This provides the basic order of operations and options template for cloud based stage 1 tests.
#  Not all test-short need to follow this template but most will.
#

.stage-1:
  extends: .test
  stage: stage-1
  tags:
    - stage1
  before_script:
    - date
    - hostname
    - grep PRETTY_NAME /etc/os-release
    - nproc
    - lscpu
    - ccache --zero-stats
    - echo ${CONFIG_OPTS}
  script:
    - printf "PATH:$PATH\n"
    - printf "PYTHONPATH:$PYTHONPATH\n"
    - printf "PETSC_OPTIONS:$PETSC_OPTIONS\n"
    - if [ ! -z ${CI_MERGE_REQUEST_SOURCE_BRANCH_NAME+x} ]; then printf "CI_MERGE_REQUEST_SOURCE_BRANCH_NAME:$CI_MERGE_REQUEST_SOURCE_BRANCH_NAME\n" ;fi
    - ${PYTHON} ./configure --with-debugging=0 COPTFLAGS='-O3 -march=native' CXXOPTFLAGS='-O3 -march=native' FOPTFLAGS='-O3 -march=native' ${CONFIG_OPTS}
    - make CFLAGS="${MAKE_CFLAGS}" CXXFLAGS="${MAKE_CXXFLAGS}" FFLAGS="${MAKE_FFLAGS}"
    - make CFLAGS="${MAKE_TEST_CFLAGS}" CXXFLAGS="${MAKE_TEST_CXXFLAGS}" FFLAGS="${MAKE_TEST_FFLAGS}" allgtests-tap gmakesearch="${TEST_SEARCH}" TIMEOUT=${TIMEOUT}
  variables:
    MAKE_CFLAGS: -Werror
    MAKE_CXXFLAGS: -Werror -Wzero-as-null-pointer-constant
    MAKE_FFLAGS: -Werror
    MAKE_TEST_CFLAGS: -Werror
    MAKE_TEST_CXXFLAGS: -Werror
    MAKE_TEST_FFLAGS: -Werror
  after_script:
    - date
    - ccache --show-stats
  artifacts:
    reports:
      junit: arch-*/tests/testresults.xml
    name: "$CI_JOB_NAME"
    when: always
    paths:
    - arch-*/lib/petsc/conf/*.log
    - arch-*/lib/pkgconfig/petsc.pc
    - arch-*/tests/testresults.xml
    - arch-*/tests/test_*_tap.log
    - arch-*/tests/test_*_err.log
    expire_in: 4 days

#
# The following tests run on the cloud as part of stage-1.
#

ompi-cuda:
  extends: .stage-1
  tags:
  - stage1, name:p1
  variables:
    PYTHON: python3
    CONFIG_OPTS: --with-mpi-dir=/home/petsc/soft/openmpi-4.0.2-cuda --with-cuda=1 --with-fc=0
    TEST_SEARCH: snes_tutorials-ex19_cuda%
    MAKE_CXXFLAGS: -Werror

mpich-cxx-py3:
  extends: .stage-1
  tags:
  - stage1, fedora
  variables:
    PYTHON: python3
    CONFIG_OPTS: --with-mpi-dir=/home/glci/soft/mpich-3.3.2 --with-clanguage=cxx --with-fc=0
    TEST_SEARCH: snes_tutorials-ex48%

uni-complex-float-int64:
  extends: .stage-1
  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_%

c99-mlib-static-py2:
  extends: .stage-1
  variables:
    PYTHON: python2
    CONFIG_OPTS: --with-mpi-dir=/home/glci/soft/mpich-3.3.2 --with-single-library=0 --with-shared-libraries=0 CFLAGS=-std=c99
    TEST_SEARCH: snes_tutorials-ex19% snes_tutorials-ex5f90t%
    MAKE_TEST_FFLAGS: -Werror -std=f2008

petsc4py-install:
  extends: .stage-2
  tags:
    - linux-stage2
  variables:
    PYTHON: python3
    T_PREFIX: petsc-install
    T_DESTDIR: petsc-destdir
    T_PETSC4PY: src/binding/petsc4py
    T_VALIDATE_CMD: lib/petsc/bin/maint/validate-petsc4py.sh
  script:
    - printf "PATH:$PATH\n"
    - mkdir hide
    - if [ ! -z ${CI_MERGE_REQUEST_SOURCE_BRANCH_NAME+x} ]; then printf "CI_MERGE_REQUEST_SOURCE_BRANCH_NAME:$CI_MERGE_REQUEST_SOURCE_BRANCH_NAME\n" ;fi
    - ${PYTHON} ./configure --prefix="${PWD}/${T_PREFIX}" --with-petsc4py=1 --with-debugging=0 --with-mpi-dir=/home/glci/soft/mpich-3.3.2
    - make CFLAGS=-Werror CXXFLAGS="-Werror -Wzero-as-null-pointer-constant" FFLAGS=-Werror
    - printf "====== Test A. Install into staging directory then into prefix directory (mimics distro package recipe) =====\n"
    - make install DESTDIR="${PWD}/${T_DESTDIR}"
    - test "$(find ${PWD}/${T_PREFIX} -mindepth 1 | wc -l)" -eq 0
    - test "$(find ${PWD}/${T_DESTDIR} -mindepth 1 | wc -l)" -gt 0
    - (cd "${PWD}/${T_DESTDIR}" && find * -exec install -v -D "{}" "/{}" \; )
    - mv arch-* hide/ && PETSC_DIR="${PWD}/${T_PREFIX}" ${T_VALIDATE_CMD} && mv hide/arch-* ./
    - rm -r "${PWD}/${T_PREFIX}" "${PWD}/${T_DESTDIR}" && mkdir "${PWD}/${T_PREFIX}"
    - printf "====== Test B. Install directly into prefix directory =====\n"
    - make install
    - test "$(find ${PWD}/${T_PREFIX} -mindepth 1 | wc -l)" -gt 0
    - mv arch-* hide/ && PETSC_DIR="${PWD}/${T_PREFIX}" ${T_VALIDATE_CMD} && mv hide/arch-* ./
    - rm -r "${PWD}/${T_PREFIX}"/*/petsc4py*
    - printf "====== Test C. Install manually with setuptools =====\n"
    - export PETSC_DIR="${PWD}/${T_PREFIX}" && (cd "${T_PETSC4PY}" && ${PYTHON} setup.py build)
    - export PETSC_DIR="${PWD}/${T_PREFIX}" P="${PWD}" && (cd "${T_PETSC4PY}" && ${PYTHON} setup.py install --install-lib="${P}/${T_PREFIX}/lib")
    - mv arch-* hide/ && PETSC_DIR="${PWD}/${T_PREFIX}" ${T_VALIDATE_CMD} && mv hide/arch-* ./
    - rm -r "${PWD}/${T_PREFIX}"/*/petsc4py*
    - printf "====== Test D. Install manually with setuptools with staging =====\n"
    - export PETSC_DIR="${PWD}/${T_PREFIX}" P="${PWD}" && (cd "${T_PETSC4PY}" && ${PYTHON} setup.py install --root="${P}/${T_DESTDIR}" --install-lib="${P}/${T_PREFIX}/lib")
    - (cd "${PWD}/${T_DESTDIR}" && find * -exec install -v -D "{}" "/{}" \; )
    - mv arch-* hide/ && PETSC_DIR="${PWD}/${T_PREFIX}" ${T_VALIDATE_CMD} && mv hide/arch-* ./

checksource:
  extends: .test-basic
  stage: .pre
  tags:
    - stage1
  script:
    - python3 ./configure --with-mpi=0 --with-fc=0 --with-cxx=0
    - vermin --version
    - make vermin
    - make checkbadSource SHELL=bash
    - make -f gmakefile check_output SHELL=bash
    - make check_petsc4py_rst

pause-for-approval:
  extends: .test
  stage: .pre
  tags:
    - stage1
  only:
    refs:
      - merge_requests
    variables:
      - $CI_MERGE_REQUEST_EVENT_TYPE == "merged_result"
      - $CI_MERGE_REQUEST_EVENT_TYPE == "detached"
  script:
    - echo "pause-for-approval has no script to run"
  variables:
    GIT_STRATEGY: none
  when: manual
  allow_failure: false

#
# This provides the basic order of operations and options template for stage-2,3 tests.
# Not all stage-2,3 need to follow this template, but most will.
#
.stage-23:
  extends: .test
  script:
    - printf "PATH:$PATH\n"
    - printf "PYTHONPATH:$PYTHONPATH\n"
    - printf "PETSC_OPTIONS:$PETSC_OPTIONS\n"
    - if [ ! -z ${CI_MERGE_REQUEST_SOURCE_BRANCH_NAME+x} ]; then printf "CI_MERGE_REQUEST_SOURCE_BRANCH_NAME:$CI_MERGE_REQUEST_SOURCE_BRANCH_NAME\n" ;fi
    - printf "./config/examples/${TEST_ARCH}.py\n"
    - cat ./config/examples/${TEST_ARCH}.py
    - ./config/examples/${TEST_ARCH}.py
    - make CFLAGS="${MAKE_CFLAGS}" CXXFLAGS="${MAKE_CXXFLAGS}" FFLAGS="${MAKE_FFLAGS}"
    - make CFLAGS="${MAKE_CFLAGS}" CXXFLAGS="${MAKE_CXXFLAGS}" FFLAGS="${MAKE_FFLAGS}" check
    - make updatedatafiles
    - if [ -z ${DISABLE_PETSC4PY_TESTS+x} ]; then if [ -z ${ENABLE_PETSC4PY_LDPRELOAD+x} ]; then echo "NOT using LD_PRELOAD"; make petsc4pytest; else echo "using LD_PRELOAD"; LD_PRELOAD=${PWD}/${TEST_ARCH}/lib/libpetsc.so make petsc4pytest; fi; fi
    - if [ -z ${DISABLE_TESTS+x} ]; then make CFLAGS="${MAKE_CFLAGS}" CXXFLAGS="${MAKE_CXXFLAGS}" FFLAGS="${MAKE_FFLAGS}" cleantest allgtests-tap TIMEOUT=${TIMEOUT}  ${TEST_OPTS}; fi
    - if [ ! -z ${RUN_GCOV+x} ]; then make gcov; fi
  artifacts:
    reports:
      junit: ${TEST_ARCH}/tests/testresults.xml
    name: "$CI_JOB_NAME"
    when: always
    paths:
    - ${TEST_ARCH}/lib/petsc/conf/*.log
    - ${TEST_ARCH}/lib/pkgconfig/petsc.pc
    - ${TEST_ARCH}/tests/testresults.xml
    - ${TEST_ARCH}/tests/test_${TEST_ARCH}_tap.log
    - ${TEST_ARCH}/tests/test_${TEST_ARCH}_err.log
    - ${TEST_ARCH}/gcov.tar.gz
    expire_in: 4 days
  variables:
    OPENBLAS_NUM_THREADS: 1

.stage-2:
  extends: .stage-23
  stage: stage-2

.stage-3:
  extends: .stage-23
  stage: stage-3

#
# The following provide templates for various OSes for pre/post info
#

.linux_test_noflags:
  before_script:
    - date
    - hostname
    - grep PRETTY_NAME /etc/os-release
    - nproc
    - lscpu
    - ccache --zero-stats
    - if [ ! -z ${LOAD_MODULES+x} ]; then module --trace load ${LOAD_MODULES}; module list; fi
    - if [ ! -z ${INIT_SCRIPT+x} ]; then echo "sourcing ${INIT_SCRIPT}"; source ${INIT_SCRIPT}; fi
  after_script:
    - date
    - ccache --show-stats

.linux_test_nofflags:
  extends: .linux_test_noflags
  variables:
    MAKE_CFLAGS: -Werror
    MAKE_CXXFLAGS: -Werror

.linux_test:
  extends: .linux_test_noflags
  variables:
    MAKE_CFLAGS: -Werror
    MAKE_CXXFLAGS: -Werror
    MAKE_FFLAGS: -Werror

.freebsd_test:
  variables:
    MAKE_CFLAGS: -Werror
    MAKE_CXXFLAGS: -Werror
    MAKE_FFLAGS: -Werror
  before_script:
    - date
    - hostname
    - freebsd-version
    - echo $(sysctl -n hw.ncpu)
    - ccache --zero-stats
  after_script:
    - date
    - ccache --show-stats

.osx_test:
  variables:
    MAKE_CFLAGS: -Werror
    MAKE_CXXFLAGS: -Werror
    MAKE_FFLAGS: -Werror
  before_script:
    - date
    - hostname
    - sw_vers -productVersion
    - echo $(sysctl -n hw.ncpu)
    - ccache --zero-stats
  after_script:
    - date
    - ccache --show-stats

.opensolaris_test:
  before_script:
    - date
    - hostname
    - uname -a
    - nproc
    - isainfo -x
  after_script:
    - date

.mswin_test:
  before_script:
    - date
    - hostname
    - uname -a
    - nproc
  after_script:
    - date

#
# The following tests run as part of stage-2.
#
# The tags variable used in the tests below connects the particular test with the runners
# listed on the left hand side of https://gitlab.com/petsc/petsc/-/settings/ci_cd.
# For example the test linux-sycl-double  any runner that has the tag 'name:pj01'
# (in a blue box beneath it)
#

freebsd-cxx-cmplx-64idx-dbg:
  extends:
    - .stage-2
    - .freebsd_test
  tags:
    - os:fbsd
  variables:
    TEST_ARCH: arch-ci-freebsd-cxx-cmplx-64idx-dbg

freebsd-c-single-opt:
  extends:
    - .stage-2
    - .freebsd_test
  tags:
    - os:fbsd
  variables:
    TEST_ARCH: arch-ci-freebsd-c-single-opt

linux-cuda-double:
  extends:
    - .stage-3
    - .linux_test
  tags:
    - gpu:nvidia, os:linux, name:p1
  variables:
    TEST_ARCH: arch-ci-linux-cuda-double

linux-gcc-quad-64idx-dbg:
  extends:
    - .stage-2
    - .linux_test
  tags:
    - linux-stage2
  variables:
    TEST_ARCH: arch-ci-linux-gcc-quad-64idx-dbg

linux-gcc-pkgs-opt:
  extends:
    - .stage-2
    - .linux_test
  tags:
    - linux-stage2
  variables:
    TEST_ARCH: arch-ci-linux-gcc-pkgs-opt

linux-gcc-complex-opt-32bit:
  extends:
    - .stage-2
    - .linux_test
  tags:
    - linux-stage2
  variables:
    TEST_ARCH: arch-ci-linux-gcc-complex-opt-32bit

#do not run checkstack on MSWIN-UNI
mswin-uni:
  extends:
    - .stage-2
    - .mswin_test
  tags:
    - win-stage2
  variables:
    PETSC_OPTIONS: -check_pointer_intensity 0 -error_output_stdout -nox -nox_warning -malloc_dump
    TEST_ARCH: arch-ci-mswin-uni

mswin-gnu:
  extends:
    - .stage-2
    - .mswin_test
  tags:
    - win-stage2
  variables:
    TEST_ARCH: arch-ci-mswin-gnu
    MAKE_CFLAGS: -Werror
    MAKE_CXXFLAGS: -Werror
    MAKE_FFLAGS: -Werror
    DISABLE_TESTS: 1
  artifacts:
    reports:
    paths:
    - arch-*/lib/petsc/conf/*.log
    expire_in: 4 days

#
# The following tests run as part of stage-3.
#

freebsd-cxx-cmplx-pkgs-dbg:
  extends:
    - .stage-3
    - .freebsd_test
  tags:
    - os:fbsd
  variables:
    TEST_ARCH: arch-ci-freebsd-cxx-cmplx-pkgs-dbg

freebsd-cxx-pkgs-opt:
  extends:
    - .stage-3
    - .freebsd_test
  tags:
    - os:fbsd
  variables:
    PETSC_OPTIONS: -check_pointer_intensity 0 -error_output_stdout -nox -nox_warning -malloc_dump -saws_port_auto_select -saws_port_auto_select_silent -vecscatter_mpi1 false -options_left false
    TEST_ARCH: arch-ci-freebsd-cxx-pkgs-opt

freebsd-pkgs-opt:
  extends:
    - .stage-3
    - .freebsd_test
  tags:
    - os:fbsd
  variables:
    TEST_ARCH: arch-ci-freebsd-pkgs-opt

linux-hip-double:
  extends:
    - .stage-3
    - .linux_test
  tags:
    - gpu:amd, os:linux, name:hip-txcorp
  variables:
    PATH: /opt/rh/devtoolset-7/root/usr/bin:/opt/rocm/bin:/opt/rocm/llvm/bin:/usr/sbin:/usr/bin:/sbin:/bin
    TEST_ARCH: arch-ci-linux-hip-double

linux-sycl-double:
  extends:
    - .stage-3
    - .linux_test_nofflags
  tags:
    - os:linux, name:pj01
  variables:
    TEST_ARCH: arch-ci-linux-sycl-double
    INIT_SCRIPT: /home/glci/bin/ci-inteloneapi.sh
    DISABLE_TESTS: 1

linux-c-exodus-dbg:
  extends:
    - .stage-3
    - .linux_test
  tags:
    - gpu:nvidia, os:linux, name:frog
  variables:
    PETSC_OPTIONS: -check_pointer_intensity 0 -error_output_stdout -nox -nox_warning -malloc_dump -use_gpu_aware_mpi 0 -checkstack
    TEST_ARCH: arch-ci-linux-c-exodus-dbg
    RUN_GCOV: 1
    TEST_OPTS: -j1 query=requires queryval=cuda

linux-cuda11-double:
  extends:
    - .stage-3
    - .linux_test
  tags:
    - gpu:nvidia, os:linux, name:frog
  variables:
    PETSC_OPTIONS: -check_pointer_intensity 0 -error_output_stdout -nox -nox_warning -malloc_dump -use_gpu_aware_mpi 0 -checkstack
    TEST_ARCH: arch-ci-linux-cuda11-double
    TEST_OPTS: -j1 query=requires queryval=cuda

linux-cuda11-complex:
  extends:
    - .stage-3
    - .linux_test
  tags:
    - gpu:nvidia, os:linux, name:frog
  variables:
    PETSC_OPTIONS: -check_pointer_intensity 0 -error_output_stdout -nox -nox_warning -malloc_dump -use_gpu_aware_mpi 0 -checkstack
    TEST_ARCH: arch-ci-linux-cuda11-complex
    TEST_OPTS: -j1 query=requires queryval=cuda

linux-cuda-double-64idx:
  extends:
    - .stage-3
    - .linux_test
  tags:
    - gpu:nvidia, os:linux, name:p1
  variables:
    TEST_ARCH: arch-ci-linux-cuda-double-64idx
    TEST_OPTS: -j1 query=requires queryval=cuda

linux-cuda-single-cxx:
  extends:
    - .stage-3
    - .linux_test
  tags:
    - gpu:nvidia, os:linux
  variables:
    PETSC_OPTIONS: -check_pointer_intensity 0 -error_output_stdout -nox -nox_warning -malloc_dump -use_gpu_aware_mpi 0 -checkstack
    TEST_ARCH: arch-ci-linux-cuda-single-cxx
    TEST_OPTS: -j1 query=requires queryval=cuda

linux-cuda-uni-pkgs:
  extends:
    - .stage-3
    - .linux_test
  tags:
    - gpu:nvidia, os:linux
  variables:
    TEST_ARCH: arch-ci-linux-cuda-uni-pkgs
    TEST_OPTS: -j4 query=requires queryval=cuda

linux-viennacl:
  extends:
    - .stage-3
    - .linux_test
  tags:
    - gpu:nvidia, os:linux
  variables:
    TEST_ARCH: arch-ci-linux-viennacl
    MAKE_CXXFLAGS: -Werror -Wno-ignored-attributes
    TEST_OPTS: -j1 query=requires queryval=viennacl

linux-without-fc:
  extends:
    - .stage-3
    - .linux_test
  tags:
    - gce-nfs
  variables:
    TEST_ARCH: arch-ci-linux-without-fc

linux-cmplx-single:
  extends:
    - .stage-3
    - .linux_test
  tags:
    - name:si
  variables:
    TEST_ARCH: arch-ci-linux-cmplx-single

linux-gcc-cxx-avx2:
  extends:
    - .stage-3
    - .linux_test
  tags:
    - name:isdp001
  variables:
    TEST_ARCH: arch-ci-linux-gcc-cxx-avx2

linux-clang-avx:
  extends:
    - .stage-3
    - .linux_test
  tags:
    - name:isdp001
  variables:
    TEST_ARCH: arch-ci-linux-clang-avx

linux-knl:
  extends:
    - .stage-3
    - .linux_test
  tags:
    - name:isdp001
  variables:
    TEST_ARCH: arch-ci-linux-knl

linux-intel-mkl-single:
  extends:
    - .stage-3
    - .linux_test_nofflags
  tags:
    - name:isdp001
  variables:
    TEST_ARCH: arch-ci-linux-intel-mkl-single

linux-cxx-cmplx-pkgs-64idx:
  extends:
    - .stage-3
    - .linux_test
  tags:
    - gce-nfs
  variables:
    TEST_ARCH: arch-ci-linux-cxx-cmplx-pkgs-64idx
    LOAD_MODULES: llvm/9.0.0-7fyffox gcc/8.3.0-fjpc5ys cmake/3.14.2-rl3q676

# Set env vars for 'Kokkos + OpenMP' tests, so that they won't give warnings
linux-pkgs-dbg-ftn-interfaces:
  extends:
    - .stage-3
    - .linux_test
  tags:
    - gce-nfs
  variables:
    TEST_ARCH: arch-ci-linux-pkgs-dbg-ftn-interfaces
    LOAD_MODULES: cmake/3.20.5-yjp2hz6
    OMP_PROC_BIND: "false"
    OMP_NUM_THREADS: 4

linux-pkgs-cxx-mlib:
  extends:
    - .stage-3
    - .linux_test
  tags:
    - gce-nfs
  variables:
    PETSC_OPTIONS: -check_pointer_intensity 0 -error_output_stdout -nox -nox_warning -malloc_dump -saws_port_auto_select -saws_port_auto_select_silent -checkstack
    TEST_ARCH: arch-ci-linux-pkgs-cxx-mlib
    LOAD_MODULES: gcc/11.1.0-5ikoznk cmake/3.20.5-yjp2hz6

linux-pkgs-valgrind:
  extends:
    - .stage-3
    - .linux_test
  tags:
    - gce-nfs, linux-fast
  variables:
    TEST_ARCH: arch-ci-linux-pkgs-valgrind
    TIMEOUT: 7200
    LOAD_MODULES: valgrind/3.17.0

linux-pkgs-opt:
  extends:
    - .stage-3
    - .linux_test
  tags:
    - gce-nfs, linux-fast
  variables:
    PETSC_OPTIONS: -check_pointer_intensity 0 -error_output_stdout -nox -nox_warning -malloc_dump -saws_port_auto_select -saws_port_auto_select_silent -checkstack
    TEST_ARCH: arch-ci-linux-pkgs-opt
    LOAD_MODULES: gcc/10.1.0-5hiqhdh

linux-pkgs-gcov:
  extends:
    - .stage-3
    - .linux_test
  tags:
    - gce-nfs, linux-gcov
  variables:
    TEST_ARCH: arch-ci-linux-pkgs-gcov
    RUN_GCOV: 1

linux-cmplx-gcov:
  extends:
    - .stage-3
    - .linux_test
  tags:
    - gce-nfs, linux-gcov
  variables:
    PETSC_OPTIONS: -check_pointer_intensity 0 -error_output_stdout -nox -nox_warning -malloc_dump -vecscatter_mpi1 false -options_left false -checkstack
    TEST_ARCH: arch-ci-linux-cmplx-gcov
    LOAD_MODULES: gcc/8.3.0-fjpc5ys
    RUN_GCOV: 1

linux-matlab-ilp64-gcov:
  extends:
    - .stage-3
    - .linux_test
  tags:
    - gce-nfs, linux-gcov
  variables:
    TEST_ARCH: arch-ci-linux-matlab-ilp64-gcov
    LOAD_MODULES: matlab/R2018a
    RUN_GCOV: 1
  allow_failure: true

linux-gcov:
  extends:
    - .stage-3
    - .linux_test
  tags:
    - gce-nfs, linux-gcov
  variables:
    TEST_ARCH: arch-ci-linux-gcov
    RUN_GCOV: 1

linux-pgi:
  extends:
    - .stage-3
    - .linux_test_noflags
  tags:
    - gce-nfs, linux-mcpu
  variables:
    TEST_ARCH: arch-ci-linux-pgi
    LOAD_MODULES: hpc_sdk/20.9

linux-nagfor:
  extends:
    - .stage-3
    - .linux_test_nofflags
  tags:
    - gce-nfs, linux-mcpu
  variables:
    LOAD_MODULES: nag/6.1
    TEST_ARCH: arch-ci-linux-nagfor

linux-intel-cmplx:
  extends:
    - .stage-3
    - .linux_test_nofflags
  tags:
    - gce-nfs
  variables:
    TEST_ARCH: arch-ci-linux-intel-cmplx
    LOAD_MODULES: intel-mkl/19.5 intel/19.0-nompilib cmake/3.20.5-yjp2hz6
    ENABLE_PETSC4PY_LDPRELOAD: 1

linux-xsdk-dbg:
  extends:
    - .stage-3
    - .linux_test
  tags:
    - gce-nfs
  variables:
    TEST_ARCH: arch-ci-linux-xsdk-dbg
    LOAD_MODULES: gcc/8.3.0-fjpc5ys

linux-analyzer:
  extends:
    - .stage-2
    - .linux_test
  tags:
    - gce-nfs-short
  script:
    - printf "PATH:$PATH\n"
    - printf "PYTHONPATH:$PYTHONPATH\n"
    - printf "PETSC_OPTIONS:$PETSC_OPTIONS\n"
    - if [ ! -z ${CI_MERGE_REQUEST_SOURCE_BRANCH_NAME+x} ]; then printf "CI_MERGE_REQUEST_SOURCE_BRANCH_NAME:$CI_MERGE_REQUEST_SOURCE_BRANCH_NAME\n" ;fi
    - printf "./config/examples/${TEST_ARCH}.py\n"
    - cat ./config/examples/${TEST_ARCH}.py
    - ./config/examples/${TEST_ARCH}.py
    - make LINTER_OPTIONS="${LINTER_OPTIONS}" test-lint
    - make LINTER_OPTIONS="${LINTER_OPTIONS}" lint
  variables:
    TEST_ARCH: arch-ci-linux-analyzer
    LOAD_MODULES: llvm/11.0.0-snbtima cmake/3.20.0-vov726r
    LINTER_OPTIONS: "--PETSC_ARCH=${TEST_ARCH} --clang_lib=`llvm-config --libdir`/libclang.so.11 --verbose --werror"
  artifacts:
    paths:
    - ${TEST_ARCH}/lib/petsc/conf/*.log
    - ./petscLintPatches/*.patch

linux-intel:
  extends:
    - .stage-3
    - .linux_test_nofflags
  tags:
    - gce-nfs
  variables:
    TEST_ARCH: arch-ci-linux-intel
    LOAD_MODULES: intel-mkl/19.5 intel/19.0-nompilib

linux-opt-misc:
  extends:
    - .stage-3
    - .linux_test
  tags:
    - gce-nfs, linux-fast
  variables:
    TEST_ARCH: arch-ci-linux-opt-misc
    LOAD_MODULES: gcc/6.5.0-57usejd

linux-pkgs-64idx:
  extends:
    - .stage-3
    - .linux_test
  tags:
    - gce-nfs, linux-mcpu
  variables:
    TEST_ARCH: arch-ci-linux-pkgs-64idx
    LOAD_MODULES: cmake/3.20.5-yjp2hz6 intel-mkl/19.5

linux-64idx-i8:
  extends:
    - .stage-3
    - .linux_test
  tags:
    - gce-nfs
  variables:
    TEST_ARCH: arch-ci-linux-64idx-i8

linux-gcc-ifc-cmplx:
  extends:
    - .stage-3
    - .linux_test_nofflags
  tags:
    - gce-nfs
  variables:
    TEST_ARCH: arch-ci-linux-gcc-ifc-cmplx
    LOAD_MODULES: intel/19.0-nompilib cmake/3.20.0-vov726r

linux-opt-cxx-quad:
  extends:
    - .stage-3
    - .linux_test
  tags:
    - gce-nfs
  variables:
    TEST_ARCH: arch-ci-linux-opt-cxx-quad

linux-ILP64:
  extends:
    - .stage-3
    - .linux_test
  tags:
    - gce-nfs
  variables:
    TEST_ARCH: arch-ci-linux-ILP64
    LOAD_MODULES: mpich/2-1.5-gcc750

linux-64idx-i8-uni:
  extends:
    - .stage-3
    - .linux_test
  tags:
    - gce-nfs
  variables:
    TEST_ARCH: arch-ci-linux-64idx-i8-uni

mswin-intel-cxx-cmplx:
  extends:
    - .stage-3
    - .mswin_test
  tags:
    - os:win
  variables:
    TEST_ARCH: arch-ci-mswin-intel-cxx-cmplx

#mswin-intel:
#  extends:
#    - .stage-3
#    - .mswin_test
#  tags:
#    - os:win
#  variables:
#    TEST_ARCH: arch-ci-mswin-intel

#mswin-opt-impi:
#  extends:
#    - .stage-3
#    - .mswin_test
#  tags:
#    - os:win
#  variables:
#    TEST_ARCH: arch-ci-mswin-opt-impi
#    DISABLE_TESTS: 1

opensolaris-pkgs-opt:
  extends:
    - .stage-3
    - .opensolaris_test
  tags:
    - name:n-gage
  variables:
    TEST_ARCH: arch-ci-opensolaris-pkgs-opt

opensolaris-cmplx-pkgs-dbg:
  extends:
    - .stage-3
    - .opensolaris_test
  tags:
    - name:n-gage
  variables:
    TEST_ARCH: arch-ci-opensolaris-cmplx-pkgs-dbg

opensolaris-misc:
  extends:
    - .stage-3
    - .opensolaris_test
  tags:
    - name:n-gage
  variables:
    TEST_ARCH: arch-ci-opensolaris-misc

osx-cxx-cmplx-pkgs-dbg:
  extends:
    - .stage-3
    - .osx_test
  tags:
    - os:macos
  variables:
    TEST_ARCH: arch-ci-osx-cxx-cmplx-pkgs-dbg

osx-cxx-pkgs-opt:
  extends:
    - .stage-3
    - .osx_test
  tags:
    - os:macos, opt
  variables:
    PETSC_OPTIONS: -check_pointer_intensity 0 -error_output_stdout -nox -nox_warning -malloc_dump -saws_port_auto_select -saws_port_auto_select_silent -vecscatter_mpi1 false -options_left false
    TEST_ARCH: arch-ci-osx-cxx-pkgs-opt
    MAKE_CXXFLAGS: -Werror -Wno-pass-failed

osx-dbg:
  extends:
    - .stage-3
    - .osx_test
  tags:
    - os:macos
  variables:
    TEST_ARCH: arch-ci-osx-dbg

osx-xsdk-opt:
  extends:
    - .stage-3
    - .osx_test
  tags:
    - os:macos, opt
  variables:
    TEST_ARCH: arch-ci-osx-xsdk-opt

# job for analyzing the final coverage results
analyze-pipeline:
  extends: .test
  stage: .post
  tags:
    - gce-nfs-short
  dependencies:
    - linux-c-exodus-dbg
    - linux-pkgs-gcov
    - linux-cmplx-gcov
    - linux-matlab-ilp64-gcov
    - linux-gcov
  variables:
    PETSC_ARCH: arch-ci-analyze-pipeline
  before_script:
    - date
    - hostname
  script:
  - ./configure --with-mpi=0 --with-cxx=0 --with-c2html
  - make srchtml
  - make mergegcov
  artifacts:
    name: "$CI_JOB_NAME"
    when: always
    paths:
    - arch-ci-analyze-pipeline/*
    expire_in: 4 days


#
# Base job for a documentation build
#
.docs:
  stage: stage-2
  tags:
    - name:pj02
  before_script:
    - VENV=venv-petsc-docs &&
      python3 -m venv $VENV &&
      . $VENV/bin/activate &&
      cd doc &&
      pip install -r requirements.txt
  allow_failure: true

#
# Build documentation and make available for review using GitLab pages
#
docs-review:
  extends:
    - .docs
    - .test-basic
  script:
    - make html BUILDDIR="../public" SPHINXOPTS="-T -E"
    - make latexpdf && mkdir -p ../public/docs/manual && cp _build/latex/manual.pdf ../public/html/docs/manual/
  environment:
    name: review/$CI_COMMIT_REF_NAME
    url: https://$CI_PROJECT_NAMESPACE.gitlab.io/-/$CI_PROJECT_NAME/-/jobs/$CI_JOB_ID/artifacts/public/html/index.html
  artifacts:
    paths:
      - public
  except:
    variables:
      - $PETSC_CI_SCHEDULED =~ /yes/

#
# Deploy documentation using GitLab pages
#
pages:  # this job name has special meaning to GitLab
  extends: .docs
  interruptible: true
  script:
    - mkdir -p ../public/ && cp public/* ../public/
    - git fetch --unshallow --no-tags origin +release:remotes/origin/release +main:remotes/origin/main
    - git checkout origin/main && make website-deploy BUILDDIR="../public/main" && make latexpdf && mkdir -p ../public/main/docs/manual && cp _build/latex/manual.pdf ../public/main/docs/manual/
    - make clean BUILDDIR="../public/release"
    - git checkout origin/release && make website-deploy BUILDDIR="../public/release" && make latexpdf && mkdir -p ../public/release/docs/manual && cp _build/latex/manual.pdf ../public/release/docs/manual/
  only:
    variables:
      - $PETSC_CI_SCHEDULED == "yes"
  artifacts:
    paths:
      - public

#
#
# The following tests are experimental; more tests by users at other sites may be added below this.  Experimental test
# that fail produce a warning, but do not block execution of a pipeline.
#

.test-experimental:
  extends: .test
  allow_failure: true

