Add CMake Stage job 71/12071/2
authorThanh Ha <thanh.ha@linuxfoundation.org>
Wed, 1 Aug 2018 21:37:07 +0000 (17:37 -0400)
committerThanh Ha <thanh.ha@linuxfoundation.org>
Wed, 1 Aug 2018 22:14:20 +0000 (18:14 -0400)
Issue: RELENG-1108
Change-Id: I6b295c1ceefc1c77fbe3311a8fdf314849b35cd0
Signed-off-by: Thanh Ha <thanh.ha@linuxfoundation.org>
docs/jjb/lf-c-cpp-jobs.rst
jjb/lf-c-cpp-jobs.yaml
shell/cmake-stage.sh [new file with mode: 0644]

index 044a852..4d6d4ce 100644 (file)
@@ -5,6 +5,73 @@ C/C++ Jobs
 Job Templates
 =============
 
+CMake Stage
+-----------
+
+Stage job which runs cmake && make && make install and then packages the
+project into a tar.xz tarball to produce a release candidate.
+
+:Template Names:
+
+    - {project-name}-cmake-stage-{stream}
+    - gerrit-cmake-stage
+    - github-cmake-stage
+
+:Comment Trigger: stage-release
+
+:Required parameters:
+
+    :build-node: The node to run build on.
+    :jenkins-ssh-credential: Credential to use for SSH.
+        (Configure in defaults.yaml)
+    :nexus-group-id: The Maven style Group ID for the namespace of the project
+        in Nexus.
+    :staging-profile-id: The unique Nexus Staging Profile ID for the project.
+        Contact your infra admin if you do not know it.
+
+: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)
+    :version: (default: '') Project version to stage release as. There are 2
+        methods for using this value:
+
+        1) Defined explicitly here.
+        2) Leave this value blank and set /tmp/artifact_version
+
+        Use method 2 in conjunction with 'pre-build' configuration to
+        generate the artifact_version automatically from files in the
+        project's repository. For example with pre-build script:
+
+        .. code-block:: bash
+
+           #!/bin/bash
+           MAJOR_VERSION="$(grep 'set(OCIO_VERSION_MAJOR' CMakeLists.txt | awk '{{print $NF}}' | awk -F')' '{{print $1}}')"
+           MINOR_VERSION="$(grep 'set(OCIO_VERSION_MINOR' CMakeLists.txt | awk '{{print $NF}}' | awk -F')' '{{print $1}}')"
+           PATCH_VERSION="$(grep 'set(OCIO_VERSION_PATCH' CMakeLists.txt | awk '{{print $NF}}' | awk -F')' '{{print $1}}')"
+           echo "${{MAJOR_VERSION}}.${{MINOR_VERSION}}.${{PATCH_VERSION}}" > /tmp/artifact_version
+
 CMake Verify
 ------------
 
index 8700341..6b24038 100644 (file)
@@ -1,4 +1,165 @@
 ---
+###############
+# CMAKE STAGE #
+###############
+
+- lf_cmake_stage: &lf_cmake_stage
+    name: lf-cmake-stage
+
+    ######################
+    # Default parameters #
+    ######################
+
+    branch: master
+    build-days-to-keep: 7
+    build-dir: '$WORKSPACE/target'
+    build-timeout: 15
+    cmake-opts: ''
+    git-url: '$GIT_URL/$PROJECT'
+    github-url: 'https://github.com'
+    install-prefix: '$BUILD_DIR/output'
+    make-opts: ''
+    mvn-global-settings: global-settings
+    pre-build: ''
+    stream: master
+    submodule-recursive: true
+    version: ''
+
+    #####################
+    # 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}'
+      - string:
+          name: NEXUS_GROUP_ID
+          default: '{nexus-group-id}'
+          description: 'Project Group ID in Nexus to upload to.'
+      - string:
+          name: STAGING_PROFILE_ID
+          default: '{staging-profile-id}'
+          description: 'Nexus staging profile ID.'
+      - string:
+          name: VERSION
+          default: '{version}'
+          description: |
+              (default: '')
+
+              Project version to stage release as. There are 2 methods for
+              using this value:
+
+                  1) Defined explicitly here.
+                  2) Leave this value blank and set /tmp/artifact_version
+
+              Use method 2 in conjunction with 'pre-build' configuration to
+              generate the artifact_version automatically from files in the
+              project's repository. For example with pre-build script:
+
+              #!/bin/bash
+              MAJOR_VERSION="$(grep 'set(OCIO_VERSION_MAJOR' CMakeLists.txt \
+                  | awk '{{print $NF}}' | awk -F')' '{{print $1}}')"
+              MINOR_VERSION="$(grep 'set(OCIO_VERSION_MINOR' CMakeLists.txt \
+                  | awk '{{print $NF}}' | awk -F')' '{{print $1}}')"
+              PATCH_VERSION="$(grep 'set(OCIO_VERSION_PATCH' CMakeLists.txt \
+                  | awk '{{print $NF}}' | awk -F')' '{{print $1}}')"
+              echo "${{MAJOR_VERSION}}.${{MINOR_VERSION}}.${{PATCH_VERSION}}" > /tmp/artifact_version
+
+    wrappers:
+      - lf-infra-wrappers:
+          build-timeout: '{build-timeout}'
+          jenkins-ssh-credential: '{jenkins-ssh-credential}'
+
+    builders:
+      - shell: !include-raw-escape: ../shell/lftools-install.sh
+      - lf-provide-maven-settings:
+          global-settings-file: '{mvn-global-settings}'
+          settings-file: '{mvn-settings}'
+      - lf-infra-create-netrc:
+          server-id: staging
+      - shell: '{pre-build}'
+      - shell: !include-raw-escape: ../shell/cmake-build.sh
+      - shell: !include-raw-escape: ../shell/cmake-stage.sh
+      - lf-provide-maven-settings-cleanup
+
+    publishers:
+      - lf-infra-publish
+
+- job-template:
+    name: '{project-name}-cmake-stage-{stream}'
+    id: gerrit-cmake-stage
+    concurrent: true
+    <<: *lf_cmake_stage
+
+    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:
+            - comment-added-contains-event:
+                comment-contains-value: '^Patch Set[ ]+[0-9]+:([ ]+|[\n]+)(stage-release)$'
+          projects:
+            - project-compare-type: 'ANT'
+              project-pattern: '{project}'
+              branches:
+                - branch-compare-type: 'ANT'
+                  branch-pattern: '**/{branch}'
+
+- job-template:
+    name: '{project-name}-cmake-stage-{stream}'
+    id: github-cmake-stage
+    concurrent: true
+    <<: *lf_cmake_stage
+
+    properties:
+      - lf-infra-properties:
+          build-days-to-keep: '{build-days-to-keep}'
+      - github:
+          url: '{github-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: '^(stage-release)$'
+          only-trigger-phrase: true
+          status-context: 'CMake Stage'
+          permit-all: true
+          github-hooks: true
+          white-list-target-branches:
+            - '{branch}'
+
+
 ################
 # CMAKE VERIFY #
 ################
diff --git a/shell/cmake-stage.sh b/shell/cmake-stage.sh
new file mode 100644 (file)
index 0000000..5b67edc
--- /dev/null
@@ -0,0 +1,69 @@
+#!/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-stage.sh"
+
+classifier="${CLASSIFIER:-linux-amd64}"
+nexus_group_id="${NEXUS_GROUP_ID:-io.aswf.opencolorio}"
+staging_profile_id="${STAGING_PROFILE_ID:-126694cb53ec54}"
+version="${VERSION:-}"
+
+# shellcheck source=/tmp/v/lftools/bin/activate disable=SC1091
+source "/tmp/v/lftools/bin/activate"
+
+set -eux -o pipefail
+
+if [ -z "${nexus_group_id}" ]; then
+    echo "ERROR: No nexus group ID provided."
+    exit 1
+fi
+
+if [ -z "${staging_profile_id}" ]; then
+    echo "ERROR: No staging profile ID provided."
+    exit 1
+fi
+
+if [ -z "${version}" ]; then
+    if [ -f "/tmp/artifact_version" ]; then
+        version="$(cat /tmp/artifact_version)"
+    else
+        echo "ERROR: No artifact version defined."
+        exit 1
+    fi
+fi
+
+repo_id=$(lftools deploy nexus-stage-repo-create "$NEXUS_URL" "$staging_profile_id")
+
+mapfile -t artifacts < <(ls "$WORKSPACE"/dist)
+for artifact in "${artifacts[@]}"; do
+    lftools deploy file -c "$classifier" "$NEXUS_URL" "$repo_id" \
+        "$nexus_group_id" \
+        "${artifact%.tar.xz}" \
+        "$version" \
+        tar.xz \
+        "$WORKSPACE/dist/$artifact"
+
+    # Create src tar
+    git config tar.tar.xz.command "xz -c"
+    git archive --format=tar.xz HEAD > src.tar.xz
+    lftools deploy file -c "sources" "$NEXUS_URL" "$repo_id" \
+        "$nexus_group_id" \
+        "${artifact%.tar.xz}" \
+        "$version" \
+        tar.xz \
+        src.tar.xz
+done
+
+lftools deploy nexus-stage-repo-close "$NEXUS_URL" "$staging_profile_id" "$repo_id"
+
+PATCH_DIR="$WORKSPACE/archives/patches"
+mkdir -p "$PATCH_DIR"
+echo "$PROJECT" "$(git rev-parse --verify HEAD)" | tee -a "$PATCH_DIR/taglist.log"
+echo "$repo_id" > "$WORKSPACE/archives/staging-repo.txt"