Merge "Update lf-maven-stage macro with missing parts"
authorThanh Ha (zxiiro) <thanh.ha@linuxfoundation.org>
Wed, 13 Feb 2019 17:52:56 +0000 (17:52 +0000)
committerGerrit Code Review <gerrit@linuxfoundation.org>
Wed, 13 Feb 2019 17:52:56 +0000 (17:52 +0000)
.jjb-test/lf-maven-jobs/maven-sonarcloud.yaml [new file with mode: 0644]
docs/jjb/lf-maven-jobs.rst
docs/jjb/lf-release-management-jobs.rst [new file with mode: 0644]
jjb/lf-maven-jobs.yaml
jjb/lf-release-management-jobs.yaml [new file with mode: 0644]
releasenotes/notes/automate-release-announcements-0b9f2c7f854198ff.yaml [new file with mode: 0644]
releasenotes/notes/sonarcloud-support-7f0d1dcacff44ba4.yaml [new file with mode: 0644]
shell/maven-sonar.sh
shell/release-announce.sh [new file with mode: 0644]

diff --git a/.jjb-test/lf-maven-jobs/maven-sonarcloud.yaml b/.jjb-test/lf-maven-jobs/maven-sonarcloud.yaml
new file mode 100644 (file)
index 0000000..e367729
--- /dev/null
@@ -0,0 +1,15 @@
+---
+- project:
+    name: example-sonarcloud
+    jobs:
+      - gerrit-maven-sonar
+
+    project: 'sonarcloud'
+    project-name: 'sonarcloud'
+    branch: 'master'
+    mvn-settings: 'sonarcloud-settings'
+    mvn-opts: '-Xmx1024m'
+    sonarcloud: true
+    sonarcloud-project-key: KEY
+    sonarcloud-project-organization: ORGANIZATION
+    sonarcloud-api-token: TOKEN
index 25258ae..aca0f5f 100644 (file)
@@ -27,6 +27,20 @@ Runs Sonar against a Maven project.
     :mvn-version: Version of Maven to execute Sonar with.
     :mvn-settings: Maven settings.xml file containing credentials to use.
 
+lf-infra-maven-sonarcloud
+-------------------------
+
+Runs Sonar against a Maven project and pushes results to SonarCloud.
+
+:Required Parameters:
+
+    :java-version: Version of Java to execute Sonar with.
+    :mvn-version: Version of Maven to execute Sonar with.
+    :mvn-settings: Maven settings.xml file containing credentials to use.
+    :sonarcloud-project-key: SonarCloud project key.
+    :sonarcloud-project-organization: SonarCloud project organization.
+    :sonarcloud-api-token: SonarCloud API Token.
+
 lf-maven-build
 --------------
 
@@ -324,6 +338,8 @@ directory is then used later to deploy to Nexus.
 
     :gerrit_release_triggers: Override Gerrit Triggers.
 
+.. _maven-sonar:
+
 Maven Sonar
 -----------
 
@@ -363,6 +379,14 @@ interest in that kind of support.
     :mvn-opts: Sets MAVEN_OPTS. (default: '')
     :mvn-params: Additional mvn parameters to pass to the cli. (default: '')
     :mvn-version: Version of maven to use. (default: mvn35)
+    :sonar-mvn-goals: Maven goals to run for sonar analysis.
+        (default: sonar:sonar)
+    :sonarcloud: Whether or not to use SonarCloud ``true|false``.
+        (default: false)
+    :sonarcloud-project-key: SonarCloud project key. (default: '')
+    :sonarcloud-project-organization: SonarCloud project organization.
+        (default: '')
+    :sonarcloud-api-token: SonarCloud API Token. (default: '')
     :stream: Keyword that can be used to represent a release code-name.
         Often the same as the branch. (default: master)
     :submodule-recursive: Whether to checkout submodules recursively.
@@ -372,6 +396,12 @@ interest in that kind of support.
 
     :gerrit_sonar_triggers: Override Gerrit Triggers.
 
+
+SonarCloud Example:
+
+.. literalinclude:: ../../.jjb-test/lf-maven-jobs/maven-sonarcloud.yaml
+   :language: yaml
+
 Maven Verify
 ------------
 
diff --git a/docs/jjb/lf-release-management-jobs.rst b/docs/jjb/lf-release-management-jobs.rst
new file mode 100644 (file)
index 0000000..5bf3e93
--- /dev/null
@@ -0,0 +1,20 @@
+---
+Job Templates
+=============
+
+.. _release-announce:
+
+Release Announce
+----------------
+
+Job for lf-releng projects to automate release announcement emails.
+
+:Template Names:
+    - {project-name}-release-announce
+    - gerrit-release-announce
+
+:Required parameters:
+
+    :build-node: The node to run build on.
+    :jenkins-ssh-credential: Credential to use for SSH. (Configured in
+        defaults.yaml)
index f20dbe9..f82d6c6 100644 (file)
     mvn-params: ''
     mvn-version: mvn35
     sonar-mvn-goal: 'sonar:sonar'
+    sonarcloud: false
+    sonarcloud-project-key: ''
+    sonarcloud-project-organization: ''
+    sonarcloud-api-token: ''
     stream: master
     submodule-recursive: true
     submodule-timeout: 10
 
     builders:
       - lf-infra-pre-build
-      - lf-infra-maven-sonar:
-          java-version: '{java-version}'
-          mvn-settings: '{mvn-settings}'
-          mvn-version: '{mvn-version}'
+      # With SonarCloud
+      - conditional-step:
+          condition-kind: boolean-expression
+          condition-expression: '{sonarcloud}'
+          steps:
+            - shell: echo 'Using SonarCloud'
+            - lf-infra-maven-sonarcloud:
+                java-version: '{java-version}'
+                mvn-settings: '{mvn-settings}'
+                mvn-version: '{mvn-version}'
+                sonarcloud-project-key: '{sonarcloud-project-key}'
+                sonarcloud-project-organization: '{sonarcloud-project-organization}'
+                sonarcloud-api-token: '{sonarcloud-api-token}'
+      # With SonarQube
+      - conditional-step:
+          condition-kind: not
+          condition-operand:
+            condition-kind: boolean-expression
+            condition-expression: '{sonarcloud}'
+          steps:
+            - shell: echo 'Using SonarQube'
+            - lf-infra-maven-sonar:
+                java-version: '{java-version}'
+                mvn-settings: '{mvn-settings}'
+                mvn-version: '{mvn-version}'
 
     publishers:
       - lf-jacoco-report
           - ../shell/maven-sonar.sh
       - lf-provide-maven-settings-cleanup
 
+- builder:
+    name: lf-infra-maven-sonarcloud
+    # Run a Sonar build with Maven
+    builders:
+      - lf-maven-install:
+          mvn-version: '{mvn-version}'
+      - lf-update-java-alternatives:
+          java-version: '{java-version}'
+      - inject:
+          # Switch this to the sonar wrapper when JJB 2.0 is available
+          properties-content: |
+            SONAR_HOST_URL=https://sonarcloud.io
+            PROJECT_KEY={sonarcloud-project-key}
+            PROJECT_ORGANIZATION={sonarcloud-project-organization}
+            API_TOKEN={sonarcloud-api-token}
+      - lf-provide-maven-settings:
+          global-settings-file: global-settings
+          settings-file: '{mvn-settings}'
+      - shell: !include-raw-escape:
+          - ../shell/common-variables.sh
+          - ../shell/maven-sonar.sh
+      - lf-provide-maven-settings-cleanup
+
 - job-template:
     name: '{project-name}-sonar'
     id: gerrit-maven-sonar
diff --git a/jjb/lf-release-management-jobs.yaml b/jjb/lf-release-management-jobs.yaml
new file mode 100644 (file)
index 0000000..5bee429
--- /dev/null
@@ -0,0 +1,56 @@
+---
+####################
+# Release Announce #
+####################
+
+- lf_release_announce: &lf_release_announce
+    name: lf-release-announce
+
+    ######################
+    # Default parameters #
+    ######################
+
+    build-days-to-keep: 7
+    build-timeout: 15
+    disable-job: false
+
+    #####################
+    # Job Configuration #
+    #####################
+
+    project-type: freestyle
+    node: '{build-node}'
+    disabled: '{disable-job}'
+
+    properties:
+      - lf-infra-properties:
+          build-days-to-keep: '{build-days-to-keep}'
+
+    builders:
+      - shell: !include-raw-escape: ../shell/release-announce.sh
+
+    wrappers:
+      - lf-infra-wrappers:
+          build-timeout: '{build-timeout}'
+          jenkins-ssh-credential: '{jenkins-ssh-credential}'
+
+    publishers:
+      - lf-infra-publish
+
+
+- job-template:
+    name: '{project-name}-release-announce'
+    id: gerrit-release-announce
+    <<: *lf_release_announce
+
+    triggers:
+      - gerrit:
+          server-name: '{gerrit-server-name}'
+          trigger-on:
+            - ref-updated-event
+          projects:
+            - project-compare-type: 'ANT'
+              project-pattern: '{project-pattern}'
+              branches:
+                - branch-compare-type: 'ANT'
+                  branch-pattern: 'refs/tags/**'
diff --git a/releasenotes/notes/automate-release-announcements-0b9f2c7f854198ff.yaml b/releasenotes/notes/automate-release-announcements-0b9f2c7f854198ff.yaml
new file mode 100644 (file)
index 0000000..15c68a3
--- /dev/null
@@ -0,0 +1,5 @@
+---
+features:
+  - |
+    New job-template **{project-name}-release-announce** for lf-releng projects
+    to automate release announcement emails.
diff --git a/releasenotes/notes/sonarcloud-support-7f0d1dcacff44ba4.yaml b/releasenotes/notes/sonarcloud-support-7f0d1dcacff44ba4.yaml
new file mode 100644 (file)
index 0000000..ba8b467
--- /dev/null
@@ -0,0 +1,5 @@
+---
+features:
+  - |
+    Add support for pushing Sonar results to SonarCloud. Refer to
+    :ref:`Maven Sonar docs <maven-sonar>` for details.
index 5857234..ae280b2 100644 (file)
@@ -19,18 +19,26 @@ set +u
 
 export MAVEN_OPTS
 
+declare -a params
+params+=("--global-settings $GLOBAL_SETTINGS_FILE")
+params+=("--settings $SETTINGS_FILE")
+
 # Disable SC2086 because we want to allow word splitting for $MAVEN_* parameters.
 # shellcheck disable=SC2086
 $MVN clean install \
     -e -Dsonar \
-    --global-settings "$GLOBAL_SETTINGS_FILE" \
-    --settings "$SETTINGS_FILE" \
+    ${params[*]} \
     $MAVEN_OPTIONS $MAVEN_PARAMS
 
+if [ "$SONAR_HOST_URL" = "https://sonarcloud.io" ]; then
+    params+=("-Dsonar.projectKey=$PROJECT_KEY")
+    params+=("-Dsonar.organization=$PROJECT_ORGANIZATION")
+    params+=("-Dsonar.login=$API_TOKEN")
+fi
+
 # Disable SC2086 because we want to allow word splitting for $MAVEN_* parameters.
 # shellcheck disable=SC2086
-$MVN $SONAR_MAVEN_GOAL \
+"$MVN" $SONAR_MAVEN_GOAL \
     -e -Dsonar -Dsonar.host.url="$SONAR_HOST_URL" \
-    --global-settings "$GLOBAL_SETTINGS_FILE" \
-    --settings "$SETTINGS_FILE" \
+    ${params[*]} \
     $MAVEN_OPTIONS $MAVEN_PARAMS
diff --git a/shell/release-announce.sh b/shell/release-announce.sh
new file mode 100644 (file)
index 0000000..fd1afe6
--- /dev/null
@@ -0,0 +1,32 @@
+#!/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
+##############################################################################
+
+PROJECT="${GERRIT_PROJECT#releng/}"  # For releng projects strip the prefix
+TAG_NAME="${GERRIT_REFNAME#refs/tags/}"
+
+set -eux -o pipefail
+
+mail_opts=()
+mail_opts+=("-r" "LF Releng <lf-releng@lists.linuxfoundation.org>")
+mail_opts+=("-s" "$PROJECT $TAG_NAME released")
+mail_opts+=("lf-releng@lists.linuxfoundation.org")
+
+mail "${mail_opts[@]}" << EOF
+Hi Everyone,
+
+$PROJECT $TAG_NAME is released. Thanks to everyone who contributed
+to this release. Release notes are available online at:
+
+https://docs.releng.linuxfoundation.org/projects/$PROJECT/en/latest/release-notes.html#${TAG_NAME}
+
+Cheers,
+LF Releng
+EOF