Use CMake to propagate versions and hashes to gitlab jobs
[alexxy/gromacs.git] / admin / gitlab-ci / documentation.gitlab-ci.yml
index e1b6097ffa74fdfa583fc4c719e91199e2b764df..5018fdfc450b8d3c293a693ad951254f8f295d9e 100644 (file)
 # Build documentation and web page.
 
-.configure-docs:
+.docs:configure:
   extends:
-    - .configure-extends-template
-    - .configure-docs-template
-    - .documentation-before-script-template
-
-.configure-docs-release:
-  extends:
-    - .configure-extends-template
-    - .configure-docs-release-template
-    - .documentation-before-script-template
-
-.build-docs-binary:
-  extends:
-    - .build-extends-template
-    - .build-cache-template
-    - .build-docs-binary-template
-    - .documentation-before-script-template
-
-.build-docs-webpage:
-  extends:
-    - .binary-build-template
-    - .variables-template
-    - .tags-template
-    - .no-cache-template
-    - .build-docs-webpage-template
-    - .documentation-before-script-template
-
-configure-docs:
-  extends:
-    - .configure-docs
-  needs:
-    - job: simple-build
-      artifacts: false
+    - .variables:default
+    - .gromacs:base:configure
+    - .before_script:default
+  # TODO (#3480) this should be organized more like the current documentation.py script
+  image: ${CI_REGISTRY}/gromacs/gromacs/ci-ubuntu-20.04-llvm-7-docs
+  stage: configure-build
+  cache: {}
   variables:
-    BUILD_DIR: build-docs
-    CMAKE_EXTRA_OPTIONS: -DGMX_BUILD_HELP=on -DGMX_BUILD_MANUAL=on
-  except:
-    variables:
-      - $GROMACS_RELEASE
+    KUBERNETES_CPU_LIMIT: 1
+    KUBERNETES_CPU_REQUEST: 1
+    KUBERNETES_MEMORY_REQUEST: 2Gi
+    CMAKE_COMPILER_SCRIPT: "-DCMAKE_C_COMPILER=clang-7 -DCMAKE_CXX_COMPILER=clang++-7"
+    CMAKE_SIMD_OPTIONS: "-DGMX_SIMD=None"
+    CMAKE_MPI_OPTIONS: "-DGMX_THREAD_MPI=OFF"
+    CMAKE_PRECISION_OPTIONS: "-DGMX_DOUBLE=OFF"
+    CMAKE_BUILD_TYPE_OPTIONS: "-DCMAKE_BUILD_TYPE=Debug"
+    CMAKE_GPU_OPTIONS: "-DGMX_GPU=OFF"
+    CMAKE_GMXAPI_OPTIONS: "-DGMX_PYTHON_PACKAGE=ON"
+  script:
+    - if [[ ! -z $GROMACS_RELEASE && $GROMACS_RELEASE == "true" ]] ; then
+      REL_OPTION="-DGMX_BUILD_TARBALL=ON" ;
+      else
+      REL_OPTION="-DGMX_BUILD_TARBALL=OFF" ;
+      fi
+    - echo $CMAKE_COMPILER_SCRIPT
+    - echo $CMAKE_EXTRA_OPTIONS
+    - echo $CMAKE_SIMD_OPTIONS
+    - echo $CMAKE_GPU_OPTIONS
+    - echo $CMAKE_MPI_OPTIONS
+    - echo $CMAKE_PRECISION_OPTIONS
+    - echo $CMAKE_BUILD_TYPE_OPTIONS
+    - echo $CMAKE_GMXAPI_OPTIONS
+    - echo $REL_OPTION
+    - if [[ -d $BUILD_DIR ]] ; then
+      rm -rf $BUILD_DIR && mkdir $BUILD_DIR ;
+      else
+      echo "Preparing new build directory" ;
+      mkdir $BUILD_DIR ;
+      fi
+    - cd $BUILD_DIR
+    # Running CMake with the venv activated should not be strictly necessary,
+    # but helps to find and cache self-consistent Python and Sphinx details
+    # without additional hinting. Once CMakeCache.txt exists, the later stages
+    # should work fine without reactivating the venv.
+    - source /root/venv/py3.7/bin/activate
+    - cmake ..
+      -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache
+      $CMAKE_COMPILER_SCRIPT
+      $CMAKE_EXTRA_OPTIONS
+      $CMAKE_SIMD_OPTIONS
+      $CMAKE_MPI_OPTIONS
+      $CMAKE_PRECISION_OPTIONS
+      $CMAKE_BUILD_TYPE_OPTIONS
+      $CMAKE_GPU_OPTIONS
+      $CMAKE_GMXAPI_OPTIONS
+      $REL_OPTION
+      -DCMAKE_INSTALL_PREFIX=../$INSTALL_DIR -DGMX_COMPILER_WARNINGS=ON
+      2>&1 | tee cmakeLog.log
+    - awk '/CMake Warning/,/^--|^$/' cmakeLog.log | tee cmakeErrors.log
+    - if [ -s cmakeErrors.log  ] ; then echo "Found CMake warning while processing build"; cat cmakeErrors.log ; exit 1; fi
+    - cd ..
+  artifacts:
+    name: docs-artifacts-$CI_COMMIT_REF_SLUG
+    when: always
+    expire_in: 1 week
+    paths:
+      - $BUILD_DIR
 
-configure-docs-gmxapi:
+.docs:configure:release:
   extends:
-    - .configure-docs
-    - .configure-gmxapi-template
-  needs:
-    - job: simple-build
-      artifacts: false
+    - .variables:default
+    - .gromacs:base:configure
+    - .before_script:default
+    - .rules:nightly-only-for-release
+  # TODO (#3480) this should be organized more like the current documentation.py script
+  image: ${CI_REGISTRY}/gromacs/gromacs/ci-ubuntu-20.04-llvm-7-docs
+  stage: release-configure
+  cache: {}
   variables:
-    BUILD_DIR: build-docs-gmxapi
-    CMAKE_EXTRA_OPTIONS: -DGMX_BUILD_HELP=on -DGMX_BUILD_MANUAL=on
-  except:
-    variables:
-      - $GROMACS_RELEASE
+    KUBERNETES_CPU_LIMIT: 1
+    KUBERNETES_CPU_REQUEST: 1
+    KUBERNETES_MEMORY_REQUEST: 2Gi
+    CMAKE_COMPILER_SCRIPT: "-DCMAKE_C_COMPILER=clang-7 -DCMAKE_CXX_COMPILER=clang++-7"
+    CMAKE_SIMD_OPTIONS: "-DGMX_SIMD=None"
+    CMAKE_MPI_OPTIONS: "-DGMX_THREAD_MPI=ON"
+    CMAKE_PRECISION_OPTIONS: "-DGMX_DOUBLE=OFF"
+    CMAKE_BUILD_TYPE_OPTIONS: "-DCMAKE_BUILD_TYPE=Debug"
+    CMAKE_GPU_OPTIONS: "-DGMX_GPU=OFF"
+    CMAKE_GMXAPI_OPTIONS: "-DGMX_PYTHON_PACKAGE=ON"
+    RELEASE_BUILD_DIR: release-doc-builds
+    RELEASE_SOURCE: release-source-from-tarball
+    RELEASE_REGRESSIONTESTS: release-regressiontests-from-tarball
+  script:
+    - if [[ $GROMACS_RELEASE == "true" ]] ; then
+      REL_OPTION="-DGMX_BUILD_TARBALL=ON" ;
+      else
+      REL_OPTION="-DGMX_BUILD_TARBALL=OFF" ;
+      fi
+    - echo $CMAKE_COMPILER_SCRIPT
+    - echo $CMAKE_EXTRA_OPTIONS
+    - echo $CMAKE_SIMD_OPTIONS
+    - echo $CMAKE_GPU_OPTIONS
+    - echo $CMAKE_MPI_OPTIONS
+    - echo $CMAKE_PRECISION_OPTIONS
+    - echo $CMAKE_BUILD_TYPE_OPTIONS
+    - echo $CMAKE_GMXAPI_OPTIONS
+    - echo $REL_OPTION
+    - VERSION=`sed -n -e '/GMX_VERSION_STRING\b/ s/.*"\(.*\)")/\1/p' VersionInfo-partial.cmake.cmakein`
+    - if [[ $GROMACS_RELEASE != "true" ]] ; then
+      VERSION=$VERSION-dev ;
+      fi
+    - REGTEST_COMPARE=`sed -n -e '/REGRESSIONTEST_MD5SUM/ s/.*"\(.*\)")/\1/p' VersionInfo-partial.cmake.cmakein`
+    - SOURCENAME=gromacs-$VERSION
+    - SOURCETARBALL=$SOURCENAME.tar.gz
+    - REGTESTNAME=regressiontests-$VERSION
+    - REGTESTTARBALL=$REGTESTNAME.tar.gz
+    - SOURCE_MD5SUM=`md5sum $SOURCETARBALL | awk '{print $1}'`
+    - RELEASE_TARBALLS=release-tarballs
+    - rm -rf $RELEASE_TARBALLS $RELEASE_SOURCE $RELEASE_REGRESSIONTESTS && mkdir $RELEASE_TARBALLS
+    - mv $SOURCETARBALL $RELEASE_TARBALLS
+    - mv $REGTESTTARBALL $RELEASE_TARBALLS
+    - cd $RELEASE_TARBALLS
+    # We rename the source and regressiontest directories
+    # to have names for them that don't change for different versions.
+    - tar -xf $SOURCETARBALL
+    - mv $SOURCENAME ../$RELEASE_SOURCE
+    - tar -xf $REGTESTTARBALL
+    - mv $REGTESTNAME ../$RELEASE_REGRESSIONTESTS
+    - rm $SOURCETARBALL $REGTESTTARBALL
+    - cd ..
+    - echo $CMAKE_COMPILER_SCRIPT
+    - echo $CMAKE_EXTRA_OPTIONS
+    - echo $CMAKE_SIMD_OPTIONS
+    - echo $CMAKE_GPU_OPTIONS
+    - echo $CMAKE_MPI_OPTIONS
+    - echo $CMAKE_PRECISION_OPTIONS
+    - echo $CMAKE_BUILD_TYPE_OPTIONS
+    - echo $CMAKE_GMXAPI_OPTIONS
+    - if [[ -d $RELEASE_BUILD_DIR ]] ; then
+      echo "Cleaning up build directory" ;
+      rm -rf $RELEASE_BUILD_DIR && mkdir $RELEASE_BUILD_DIR ;
+      else
+      echo "Preparing new build directory" ;
+      mkdir $RELEASE_BUILD_DIR ;
+      fi
+    - cd $RELEASE_BUILD_DIR
+    - source /root/venv/py3.7/bin/activate
+    - cmake ../$RELEASE_SOURCE/
+      -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache
+      $CMAKE_COMPILER_SCRIPT
+      $CMAKE_EXTRA_OPTIONS
+      $CMAKE_SIMD_OPTIONS
+      $CMAKE_MPI_OPTIONS
+      $CMAKE_PRECISION_OPTIONS
+      $CMAKE_BUILD_TYPE_OPTIONS
+      $CMAKE_GPU_OPTIONS
+      $CMAKE_GMXAPI_OPTIONS
+      $REL_OPTION
+      "-DSOURCE_MD5SUM=$SOURCE_MD5SUM"
+      "-DREGRESSIONTEST_PATH=../$RELEASE_REGRESSIONTESTS"
+      -DCMAKE_INSTALL_PREFIX=../$INSTALL_DIR -DGMX_COMPILER_WARNINGS=ON
+      2>&1 | tee cmakeLog.log
+    - awk '/CMake Warning/,/^--|^$/' cmakeLog.log | tee cmakeErrors.log
+    - if [ -s cmakeErrors.log  ] ; then echo "Found CMake warning while processing build"; cat cmakeErrors.log ; exit 1; fi
+    - cd ..
+  artifacts:
+    name: docs-artifacts-$CI_COMMIT_REF_SLUG
+    when: always
+    expire_in: 1 week
+    paths:
+      - $RELEASE_BUILD_DIR
+      - $RELEASE_REGRESSIONTESTS
+      - $RELEASE_SOURCE
 
-build-docs:
+docs:configure:
   extends:
-    - .build-docs-binary
-  stage: documentation
-  needs:
-    - job: simple-build
-      artifacts: false
-    - job: configure-docs
-      artifacts: true
+    - .docs:configure
+    - .rules:basic-push
   variables:
     BUILD_DIR: build-docs
-  except:
-    variables:
-      - $GROMACS_RELEASE
+    CMAKE_EXTRA_OPTIONS: -DGMX_BUILD_HELP=on -DGMX_BUILD_MANUAL=on -DGMX_USE_SIMD_KERNELS=off
 
-build-docs-gmxapi:
+.docs:build:
+  # TODO (#3480) this should be organized more like the current documentation.py script
+  image: ${CI_REGISTRY}/gromacs/gromacs/ci-ubuntu-20.04-llvm-7-docs
+  script:
+    - cd $BUILD_DIR
+    - cmake --build . --target gmx -- -j8
+    - cd ..
+  artifacts:
+    name: docs-artifacts-$CI_COMMIT_REF_SLUG
+    when: always
+    expire_in: 1 week
+    paths:
+      - $BUILD_DIR
+
+docs:build:
   extends:
-    - .build-docs-binary
-    - .gmxapi-extra-installs
+    - .variables:default
+    - .gromacs:base:build
+    - .use-ccache
+    - .docs:build
+    - .before_script:default
+    - .rules:basic-push
   stage: documentation
   needs:
-    - job: simple-build
-      artifacts: false
-    - job: configure-docs-gmxapi
-      artifacts: true
+    - job: docs:configure
   variables:
-    BUILD_DIR: build-docs-gmxapi
-  except:
-    variables:
-      - $GROMACS_RELEASE
-
+    BUILD_DIR: build-docs
 
 # The manual build is built separately so that errors in converting
 # Sphinx to LaTeX and compiling can always be found in the
@@ -95,144 +220,96 @@ build-docs-gmxapi:
 #
 # TODO why are the doxygen and sphinx log files disappearing
 # TODO use a feature from gitlab runner instead of using pipefail to get timings for the job
-webpage:
+.webpage:build:
   extends:
-    - .build-docs-webpage
-  stage: post-test
-  needs:
-    - job: build-docs
-      artifacts: true
-    - job: run-check-source
-      artifacts: false
+    - .variables:default
+    - .gromacs:base:build
+    - .before_script:default
+  # TODO (#3480) this should be organized more like the current documentation.py script
+  image: ${CI_REGISTRY}/gromacs/gromacs/ci-ubuntu-20.04-llvm-7-docs
+  cache: {}
   variables:
-    BUILD_DIR: build-docs
-  except:
-    variables:
-      - $GROMACS_RELEASE
+    KUBERNETES_CPU_LIMIT: 4
+    KUBERNETES_CPU_REQUEST: 2
+    KUBERNETES_MEMORY_REQUEST: 4Gi
+  script:
+    - cd $BUILD_DIR
+    - cmake --build . --target manual -- -j4 | tee docs/manual/all-output.log
+      | grep -i "warning" | grep -v "TeX" | grep -v "Package" || true
+    - cmake --build . --target webpage -- -j4
+    - grep "WARNING:" docs/manual/all-output.log | tee pythonErrors.log || true
+    - grep -i "error" docs/sphinx-*.log | tee sphinxDiagnostics.log || true
+    - grep -i "warning" docs/sphinx-*.log | tee -a sphinxDiagnostics.log || true
+    - if [ -s pythonErrors.log ] ; then echo "Found Python Errors during build"; exit 1; fi
+    - if [ -s sphinxErrors.log ] ; then echo "Found errors during Sphinx documentation build"; cat sphinxErrors.log; exit 1; fi
+    - if [ -s sphinxDiagnostics.log ] ; then echo "Found diagnostic warnings during Sphinx documentation build"; cat sphinxDiagnostics.log; exit 1; fi
+    - cd ..
+  artifacts:
+    name: docs-artifacts-$CI_COMMIT_REF_SLUG
+    when: always
+    expire_in: 1 week
+    paths:
+      - $BUILD_DIR/*.log
+      - $BUILD_DIR/docs/html
+      - $BUILD_DIR/docs/manual/gromacs.log
+      - $BUILD_DIR/docs/manual/all-output.log
+      - $BUILD_DIR/docs/doxygen/doxygen-user.log
+      - $BUILD_DIR/docs/doxygen/doxygen-lib.log
+      - $BUILD_DIR/docs/doxygen/doxygen-full.log
+      - $BUILD_DIR/docs/sphinx-html.log
 
-webpage-gmxapi:
+webpage:build:
   extends:
-    - .build-docs-webpage
-    - .gmxapi-extra-installs
+    - .webpage:build
+    - .rules:basic-push
   stage: post-test
   needs:
-    - job: build-docs-gmxapi
-      artifacts: true
-    - job: run-check-source
-      artifacts: false
-  variables:
-    BUILD_DIR: build-docs-gmxapi
-  except:
-    variables:
-      - $GROMACS_RELEASE
-
-webpage-nightly:
-  extends:
-    - .build-docs-webpage
-    - .configure-gmxapi-template
-  stage: nightly-deploy
-  only:
-    - triggers
-    - schedules
-  except:
-    variables:
-      - $GROMACS_RELEASE
-  needs:
-    - job: simple-build
-      artifacts: false
-    - job: linkchecker
+    - job: docs:build
+    - job: check-source
       artifacts: false
-    - job: webpage-gmxapi
-      artifacts: true
   variables:
-    BUILD_DIR: build-docs-gmxapi
-  script:
-    - tar czf webpage.tar.gz $BUILD_DIR/docs/html/
-  artifacts:
-    when: always
-    paths:
-      - webpage.tar.gz
+    BUILD_DIR: build-docs
 
-webpage-configure-release:
+webpage:configure:
   extends:
-    - .configure-docs-release
-    - .configure-gmxapi-template
-    - .no-cache-template
-  only:
-    refs:
-      - web
-      - schedules
-      - triggers
-    variables:
-      - $GROMACS_RELEASE
+    - .docs:configure:release
+    - .rules:nightly-only-for-release
+  cache: {}
+  tags:
+    - k8s-scilifelab
   dependencies:
-    - package-archive-release
-    - package-regressiontests-release
+    - archive:package
+    - regressiontests:package
     - prepare-release-version
   variables:
-    CMAKE_EXTRA_OPTIONS: -DGMX_BUILD_HELP=on -DGMX_BUILD_MANUAL=on
+    CMAKE_EXTRA_OPTIONS: -DGMX_BUILD_HELP=on -DGMX_BUILD_MANUAL=on -DGMX_USE_SIMD_KERNELS=off
 
 
-webpage-binary-release:
+webpage:dependencies:
   extends:
-    - .build-docs-binary
-    - .gmxapi-extra-installs
+    - .gromacs:base:build
+    - .variables:default
+    - .use-ccache
+    - .docs:build
+    - .before_script:default
+    - .rules:nightly-only-for-release
   stage: release-build
+  tags:
+    - k8s-scilifelab
   needs:
-    - job: webpage-configure-release
-      artifacts: true
+    - job: webpage:configure
   variables:
     BUILD_DIR: release-doc-builds
-  only:
-    refs:
-      - triggers
-      - web
-      - schedules
-    variables:
-      - $GROMACS_RELEASE
 
-webpage-build-release:
+webpage:build:release:
   extends:
-    - .build-docs-webpage
-    - .configure-gmxapi-template
-  dependencies:
-    - webpage-binary-release
-    - webpage-configure-release
+    - .webpage:build
+    - .rules:nightly-only-for-release
   stage: release-prepare-deploy
-  only:
-    refs:
-      - web
-      - schedules
-      - triggers
-    variables:
-      - $GROMACS_RELEASE
-  variables:
-    BUILD_DIR: release-doc-builds
-
-webpage-archive-release:
-  extends:
-    - .build-docs-webpage
-    - .configure-gmxapi-template
-  stage: release-deploy
-  only:
-    refs:
-      - web
-      - triggers
-      - schedules
-    variables:
-      - $GROMACS_RELEASE
+  tags:
+    - k8s-scilifelab
   dependencies:
-    - webpage-build-release
-    - package-archive-release
-    - package-regressiontests-release
+    - webpage:dependencies
+    - webpage:configure
   variables:
     BUILD_DIR: release-doc-builds
-  script:
-    - tar czf webpage.tar.gz $BUILD_DIR/docs/html/
-  artifacts:
-    when: always
-    paths:
-      - webpage.tar.gz
-      - gromacs-*tar.gz
-      - regressiontests-*tar.gz
-