This is an automated email from the ASF dual-hosted git repository.

sijie pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/bookkeeper.git


The following commit(s) were added to refs/heads/master by this push:
     new 16ef25b  Allow CI to publish a snapshot version with gitsha information
16ef25b is described below

commit 16ef25b64ef3f9a3bef00a382dc1ae2a58bdd108
Author: Sijie Guo <[email protected]>
AuthorDate: Wed May 30 00:55:27 2018 -0700

    Allow CI to publish a snapshot version with gitsha information
    
    Descriptions of the changes in this PR:
    
    *Motivation*
    
    Currently bookkeeper publishes a snapshot release nightly to maven 
artifacts. It provides a convenient solution for people to try out new 
bookkeeper releases as soon as the changes land in master branch. However 
sometime it is also problematic when you reference this snapshot version in 
other projects, subsequent changes in bookkeeper might potentially break those 
projects.
    
    *Solution*
    
    Update the CI to provide a mechanism to publish a snapshot version with 
gitsha information. so it can publish a snapshot version that is pinned to the 
given gitsha. so the projects can safely use a snapshot version for development 
without worrying bookkeeper changes break it.
    
    *NOTES*
    
    The mechanism is a manual operation. It should be used when it is needed.
    
    Author: Sijie Guo <[email protected]>
    
    Reviewers: Enrico Olivelli <[email protected]>, Jia Zhai <None>
    
    This closes #1454 from sijie/publish_snapshot_with_gitsha
---
 .../job_bookkeeper_release_nightly_snapshot.groovy | 21 +++++++++++++++++
 dev/common.sh                                      |  7 ++++++
 dev/{common.sh => update-snapshot-version.sh}      | 26 +++++++++++++---------
 3 files changed, 43 insertions(+), 11 deletions(-)

diff --git a/.test-infra/jenkins/job_bookkeeper_release_nightly_snapshot.groovy 
b/.test-infra/jenkins/job_bookkeeper_release_nightly_snapshot.groovy
index 1a045d4..3b66ca8 100644
--- a/.test-infra/jenkins/job_bookkeeper_release_nightly_snapshot.groovy
+++ b/.test-infra/jenkins/job_bookkeeper_release_nightly_snapshot.groovy
@@ -37,7 +37,28 @@ freeStyleJob('bookkeeper_release_nightly_snapshot') {
       'Release Snapshot',
       '/release-snapshot')
 
+  parameters {
+      stringParam(
+          'sha1',
+          defaultBranch,
+          'Commit id or refname (eg: origin/pr/9/head) you want to build.')
+        
+      stringParam(
+          'PUBLISH_GITSHA',
+          'false',
+          'Whether to publish a snapshot with gitsha information. Options: 
(true|false).')
+  }
+
   steps {
+    // update snapshot version if `PUBLISH_GITSHA` is `true`
+    shell '''
+export MAVEN_HOME=/home/jenkins/tools/maven/latest
+export PATH=$JAVA_HOME/bin:$MAVEN_HOME/bin:$PATH
+export MAVEN_OPTS=-Xmx2048m
+
+./dev/update-snapshot-version.sh
+    '''.stripIndent().trim()
+
     maven {
       // Set maven parameters.
       common_job_properties.setMavenConfig(delegate)
diff --git a/dev/common.sh b/dev/common.sh
index fb4be74..d4f3d3f 100644
--- a/dev/common.sh
+++ b/dev/common.sh
@@ -29,6 +29,13 @@ function get_bk_version() {
     echo ${bk_version}
 }
 
+function get_snapshot_version_with_gitsha() {
+    local gitsha=$(git rev-parse --short HEAD)
+    local commitdate=$(git log -1 --date=format:'%Y%m%d' --pretty=format:%cd)
+    local version=$(get_bk_version)
+    echo ${version/-SNAPSHOT/}-${commitdate}-${gitsha}-SNAPSHOT
+}
+
 export BK_DEV_DIR=`dirname "$0"`
 export BK_HOME=`cd ${BK_DEV_DIR}/..;pwd`
 export BK_VERSION=`get_bk_version`
diff --git a/dev/common.sh b/dev/update-snapshot-version.sh
old mode 100644
new mode 100755
similarity index 59%
copy from dev/common.sh
copy to dev/update-snapshot-version.sh
index fb4be74..59adf07
--- a/dev/common.sh
+++ b/dev/update-snapshot-version.sh
@@ -20,15 +20,19 @@
 # under the License.
 #
 
-function get_bk_version() {
-    bk_version=$(mvn -q \
-    -Dexec.executable="echo" \
-    -Dexec.args='${project.version}' \
-    --non-recursive \
-    org.codehaus.mojo:exec-maven-plugin:1.3.1:exec)
-    echo ${bk_version}
-}
+###############################################################################
+# Script to update the maven project version to a snapshot version with gitsha
+# before publishing snapshot versions.
+#
+# usage: ./dev/update-snapshot-version.sh
+
+source `dirname "$0"`/common.sh
+
+OLD_VERSION=$(get_bk_version)
+if [ "x${PUBLISH_GITSHA}" = "xtrue" ]; then
+    NEW_VERSION=$(get_snapshot_version_with_gitsha)
+    echo "Update version from ${OLD_VERSION} to ${NEW_VERSION}"
 
-export BK_DEV_DIR=`dirname "$0"`
-export BK_HOME=`cd ${BK_DEV_DIR}/..;pwd`
-export BK_VERSION=`get_bk_version`
+    mvn versions:set -Dstream -DnewVersion=${NEW_VERSION} 
+    mvn versions:commit -Dstream
+fi

-- 
To stop receiving notification emails like this one, please contact
[email protected].

Reply via email to