Add cmake-verify job template 40/11940/6
authorThanh Ha <thanh.ha@linuxfoundation.org>
Tue, 24 Jul 2018 00:54:58 +0000 (20:54 -0400)
committerThanh Ha <thanh.ha@linuxfoundation.org>
Tue, 24 Jul 2018 16:55:27 +0000 (12:55 -0400)
CMake verify job template for building CMake based projects.

Issue: RELENG-1074
Change-Id: Iccd3bab1d9f17071583a03e84b35bcd729161195
Signed-off-by: Thanh Ha <thanh.ha@linuxfoundation.org>
docs/index.rst
docs/jjb/lf-c-cpp-jobs.rst [new file with mode: 0644]
docs/jjb/lf-macros.rst
jjb/lf-c-cpp-jobs.yaml [new file with mode: 0644]
jjb/lf-macros.yaml
shell/cmake-build.sh [new file with mode: 0644]

index e275c85..4c2b447 100644 (file)
@@ -40,14 +40,10 @@ Job template code is in the `jjb/` directory but documentation is in the
 `docs/jjb/` directory of this project.
 
 .. toctree::
+   :glob:
    :maxdepth: 1
 
-   jjb/lf-ci-jobs
-   jjb/lf-macros
-   jjb/lf-maven-jobs
-   jjb/lf-node-jobs
-   jjb/lf-python-jobs
-   jjb/lf-rtd-jobs
+   jjb/*
 
 Indices and tables
 ==================
diff --git a/docs/jjb/lf-c-cpp-jobs.rst b/docs/jjb/lf-c-cpp-jobs.rst
new file mode 100644 (file)
index 0000000..9e0cf7b
--- /dev/null
@@ -0,0 +1,53 @@
+##########
+C/C++ Jobs
+##########
+
+Job Templates
+=============
+
+CMake Verify
+------------
+
+Verify job which runs cmake && make && make install to test a project build..
+
+:Template Names:
+
+    - {project-name}-cmake-verify-{stream}
+    - gerrit-cmake-verify
+    - github-cmake-verify
+
+:Required parameters:
+
+    :build-node: The node to run build on.
+    :jenkins-ssh-credential: Credential to use for SSH.
+        (Configure in defaults.yaml)
+
+:Optional parameters:
+
+    :branch: Git branch to fetch for the build. (default: master)
+    :build-days-to-keep: Days to keep build logs in Jenkins. (default: 7)
+    :build-dir: Directory to build the project in. (default: $WORKSPACE/target)
+    :build-timeout: Timeout in minutes before aborting build. (default: 60)
+    :cmake-opts: Parameters to pass to cmake. (default: '')
+    :git-url: URL clone project from. (default: $GIT_URL/$PROJECT)
+    :install-prefix: CMAKE_INSTALL_PREFIX to use for install.
+        (default: $BUILD_DIR/output)
+
+        .. code-block:: bash
+           :caption: Example
+
+           install-prefix: |
+               #!/bin/bash
+               echo "Hello World."
+
+    :make-opts: Parameters to pass to make. (default: '')
+    :pre-build: Shell script to run before performing build. Useful for
+        setting up dependencies. (default: '')
+    :stream: Keyword that to represent a release code-name.
+        Often the same as the branch. (default: master)
+    :submodule-recursive: Whether to checkout submodules recursively.
+        (default: true)
+
+    :gerrit_verify_triggers: Override Gerrit Triggers.
+    :gerrit_trigger_file_paths: Override file paths which to filter which file
+        modifications will trigger a build.
index 419c2c6..8a4fb0c 100644 (file)
@@ -228,6 +228,12 @@ Forcibly removes all of the docker images.
 Parameters
 ==========
 
+lf-cmake-parameters
+-------------------
+
+Provides parameters needed by CMake. Should be used by any jobs that need to
+call the ``cmake && make && make install`` pattern.
+
 lf-infra-maven-parameters
 -------------------------
 
diff --git a/jjb/lf-c-cpp-jobs.yaml b/jjb/lf-c-cpp-jobs.yaml
new file mode 100644 (file)
index 0000000..a5da02b
--- /dev/null
@@ -0,0 +1,132 @@
+---
+################
+# CMAKE VERIFY #
+################
+
+- lf_cmake_verify: &lf_cmake_verify
+    name: lf-cmake-verify
+
+    ######################
+    # Default parameters #
+    ######################
+
+    branch: master
+    build-days-to-keep: 7
+    build-dir: '$WORKSPACE/target'
+    build-timeout: 15
+    cmake-opts: ''
+    git-url: '$GIT_URL/$PROJECT'
+    install-prefix: '$BUILD_DIR/output'
+    make-opts: ''
+    pre-build: ''
+    stream: master
+    submodule-recursive: true
+
+    gerrit_verify_triggers:
+      - patchset-created-event:
+          exclude-drafts: true
+          exclude-trivial-rebase: false
+          exclude-no-code-change: false
+      - draft-published-event
+      - comment-added-contains-event:
+          comment-contains-value: '^Patch Set[ ]+[0-9]+:([ ]+|[\n]+)(recheck|reverify)$'
+
+    gerrit_trigger_file_paths:
+      - compare-type: REG_EXP
+        pattern: '.*'
+
+    # github_included_regions MUST match gerrit_trigger_file_paths
+    github_included_regions:
+      - '.*'
+
+    #####################
+    # Job Configuration #
+    #####################
+
+    project-type: freestyle
+    node: '{build-node}'
+
+    properties:
+      - lf-infra-properties:
+          build-days-to-keep: '{build-days-to-keep}'
+
+    parameters:
+      - lf-infra-parameters:
+          project: '{project}'
+          branch: '{branch}'
+          stream: '{stream}'
+          lftools-version: '{lftools-version}'
+      - lf-cmake-parameters:
+          build-dir: '{build-dir}'
+          cmake-opts: '{cmake-opts}'
+          install-prefix: '{install-prefix}'
+          make-opts: '{make-opts}'
+
+    wrappers:
+      - lf-infra-wrappers:
+          build-timeout: '{build-timeout}'
+          jenkins-ssh-credential: '{jenkins-ssh-credential}'
+
+    builders:
+      - shell: '{pre-build}'
+      - shell: !include-raw-escape: ../shell/cmake-build.sh
+
+    publishers:
+      - lf-infra-publish
+
+- job-template:
+    name: '{project-name}-cmake-verify-{stream}'
+    id: gerrit-cmake-verify
+    concurrent: true
+    <<: *lf_cmake_verify
+
+    scm:
+      - lf-infra-gerrit-scm:
+          branch: '$GERRIT_BRANCH'
+          jenkins-ssh-credential: '{jenkins-ssh-credential}'
+          git-url: '{git-url}'
+          refspec: '$GERRIT_REFSPEC'
+          submodule-recursive: '{submodule-recursive}'
+          choosing-strategy: gerrit
+
+    triggers:
+      - gerrit:
+          server-name: '{gerrit-server-name}'
+          trigger-on: '{obj:gerrit_verify_triggers}'
+          projects:
+            - project-compare-type: 'ANT'
+              project-pattern: '{project}'
+              branches:
+                - branch-compare-type: 'ANT'
+                  branch-pattern: '**/{branch}'
+              file-paths: '{obj:gerrit_trigger_file_paths}'
+
+- job-template:
+    name: '{project-name}-cmake-verify-{stream}'
+    id: github-cmake-verify
+    concurrent: true
+    <<: *lf_cmake_verify
+
+    properties:
+      - lf-infra-properties:
+          build-days-to-keep: '{build-days-to-keep}'
+      - github:
+          url: '{git-url}/{github-org}/{project}'
+
+    scm:
+      - lf-infra-github-scm:
+          url: '{git-clone-url}{github-org}/{project}'
+          refspec: '+refs/pull/*:refs/remotes/origin/pr/*'
+          branch: '$sha1'
+          submodule-recursive: '{submodule-recursive}'
+          choosing-strategy: default
+          jenkins-ssh-credential: '{jenkins-ssh-credential}'
+
+    triggers:
+      - github-pull-request:
+          trigger-phrase: '^(recheck|reverify)$'
+          only-trigger-phrase: false
+          status-context: 'CMake Verify'
+          permit-all: true
+          github-hooks: true
+          included-regions: '{obj:github_included_regions}'
index 1267197..801cf97 100644 (file)
 # PARAMETERS #
 ##############
 
+- parameter:
+    name: lf-cmake-parameters
+    # Parameters useful in CMake builds.
+    parameters:
+      - string:
+          name: BUILD_DIR
+          default: '{build-dir}'
+          description: 'Directory to build the project in.'
+      - string:
+          name: CMAKE_OPTS
+          default: '{cmake-opts}'
+          description: |
+              Options to pass to CMAKE.
+              Example: -DCMAKE_INSTALL_PREFIX=$WORKSPACE/target/output
+      - string:
+          name: INSTALL_PREFIX
+          default: '{install-prefix}'
+          description: 'Install prefix for C/C++ builds. Example: /usr/local'
+      - string:
+          name: MAKE_OPTS
+          default: '{make-opts}'
+          description: 'Options to pass to make. Example: -j8'
+
 - parameter:
     name: lf-infra-maven-parameters
     parameters:
diff --git a/shell/cmake-build.sh b/shell/cmake-build.sh
new file mode 100644 (file)
index 0000000..a6a41e4
--- /dev/null
@@ -0,0 +1,40 @@
+#!/bin/bash
+# SPDX-License-Identifier: EPL-1.0
+##############################################################################
+# Copyright (c) 2018 The Linux Foundation and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+##############################################################################
+echo "---> cmake-build.sh"
+
+build_dir="${BUILD_DIR:-$WORKSPACE/target}"
+cmake_opts="${CMAKE_OPTS:-}"
+make_opts="${MAKE_OPTS:-}"
+# Not a misspelling as shellcheck reports.
+# shellcheck disable=SC2153
+project="${PROJECT//\//\-}"
+
+################
+# Script start #
+################
+
+set -eux -o pipefail
+
+mkdir -p "$build_dir"
+cd "$build_dir" || exit
+# $cmake_opts needs to wordsplit to pass options.
+# shellcheck disable=SC2086
+cmake -DCMAKE_INSTALL_PREFIX="$INSTALL_PREFIX" $cmake_opts ..
+# $make_opts needs to wordsplit to pass options.
+# shellcheck disable=SC2086
+make $make_opts
+make install
+
+mkdir -p "$WORKSPACE/dist"
+tar -cJvf "$WORKSPACE/dist/$project.tar.xz" -C "$INSTALL_PREFIX" .
+
+sudo tar -xvf "$WORKSPACE/dist/$project.tar.xz" -C "/usr/local"
+sudo ldconfig