From e6df05b5416608de505572628105118e842b9e73 Mon Sep 17 00:00:00 2001 From: rameshthoomu Date: Mon, 15 Oct 2018 14:57:11 -0400 Subject: [PATCH] FABCI-22 Pipeline job configuration Update npm node module and docs publish script with the latest changes Change-Id: Ibbb0af25422faae10ce4ae19f9e1500aeda8e6f0 Signed-off-by: rameshthoomu --- Jenkinsfile.x | 13 ++- Jenkinsfile.z | 13 ++- scripts/Jenkins_Scripts/CI_Script.sh | 40 ++----- scripts/Jenkins_Scripts/Publish_API_Docs.sh | 2 - .../Jenkins_Scripts/Publish_NPM_Modules.sh | 108 +++++++++--------- 5 files changed, 78 insertions(+), 98 deletions(-) diff --git a/Jenkinsfile.x b/Jenkinsfile.x index 3e62ec2bf7..414bf5a466 100644 --- a/Jenkinsfile.x +++ b/Jenkinsfile.x @@ -5,11 +5,12 @@ node ('hyp-x') { // trigger build on x86_64 node try { def ROOTDIR = pwd() // workspace dir (/w/workspace/ + env.NODE_VER = "8.11.3" + env.GO_VER = "1.11.1" env.PROJECT_DIR = "gopath/src/github.com/hyperledger" env.GOPATH = "$WORKSPACE/gopath" - env.JAVA_HOME = "/usr/lib/jvm/java-1.8.0-openjdk-amd64" - env.PATH = "$GOPATH/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:~/npm/bin:/home/jenkins/.nvm/versions/node/v6.9.5/bin:/home/jenkins/.nvm/versions/node/v8.9.4/bin:$PATH" - env.GOROOT = "/opt/go/go1.10.linux.amd64" + env.PATH = "$GOPATH/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:~/npm/bin:/home/jenkins/.nvm/versions/node/v${NODE_VER}/bin:$PATH" + env.GOROOT = "/opt/go${GO_VER}.linux.amd64" env.PATH = "$GOROOT/bin:$PATH" def failure_stage = "none" // delete working directory @@ -56,15 +57,15 @@ node ('hyp-x') { // trigger build on x86_64 node } } -// Pull Fabric, Fabric-ca Images +// Pull Docker Images stage("Pull Docker images") { try { dir("${ROOTDIR}/$PROJECT_DIR/fabric-sdk-node/scripts/Jenkins_Scripts") { - sh './CI_Script.sh --pull_Fabric_Images --pull_Fabric_CA_Image' + sh './CI_Script.sh --pull_Fabric_Images' } } catch (err) { - failure_stage = "Pull fabric, fabric-ca docker images" + failure_stage = "Pull docker images" throw err } } diff --git a/Jenkinsfile.z b/Jenkinsfile.z index 0d2b24012b..d451d7d60f 100644 --- a/Jenkinsfile.z +++ b/Jenkinsfile.z @@ -4,11 +4,14 @@ // node('hyp-z') { try { + def ROOTDIR = pwd() // workspace dir (/w/workspace/ + env.NODE_VER = "8.11.3" + env.GO_VER = "1.11.1" env.PROJECT_DIR = "gopath/src/github.com/hyperledger" env.GOPATH = "$WORKSPACE/gopath" - env.PATH = "$GOPATH/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:~/npm/bin:/home/jenkins/.nvm/versions/node/v6.9.5/bin:/home/jenkins/.nvm/versions/node/v8.9.4/bin:$PATH" - env.GOROOT = "/opt/go/go1.10.linux.s390x" + env.PATH = "$GOPATH/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:~/npm/bin:/home/jenkins/.nvm/versions/node/v${NODE_VER}/bin:$PATH" + env.GOROOT = "/opt/go/go${GO_VER}.linux.s390x" env.PATH = "$GOROOT/bin:$PATH" def failure_stage = "none" // delete working directory @@ -55,15 +58,15 @@ node('hyp-z') { } } -// Pull Fabric, Fabric-ca Images +// Pull Docker Images stage("Pull Docker images") { try { dir("${ROOTDIR}/$PROJECT_DIR/fabric-sdk-node/scripts/Jenkins_Scripts") { - sh './CI_Script.sh --pull_Fabric_Images --pull_Fabric_CA_Image' + sh './CI_Script.sh --pull_Fabric_Images' } } catch (err) { - failure_stage = "Pull fabric, fabric-ca docker images" + failure_stage = "Pull docker images" throw err } } diff --git a/scripts/Jenkins_Scripts/CI_Script.sh b/scripts/Jenkins_Scripts/CI_Script.sh index 620a964b4a..b246fc387d 100755 --- a/scripts/Jenkins_Scripts/CI_Script.sh +++ b/scripts/Jenkins_Scripts/CI_Script.sh @@ -8,12 +8,9 @@ # exit on first error export BASE_FOLDER=$WORKSPACE/gopath/src/github.com/hyperledger -# Modify this when change the image tag export STABLE_TAG=1.3.0-stable -export NEXUS_URL=nexus3.hyperledger.org:10001 +export NEXUS_REPO_URL=nexus3.hyperledger.org:10001 export ORG_NAME="hyperledger/fabric" -# Set this in GOPATH -export NODE_VER=8.9.4 # Default nodejs version # Fetch baseimage version curl -L https://raw.githubusercontent.com/hyperledger/fabric/master/Makefile > Makefile @@ -47,9 +44,6 @@ Parse_Arguments() { --pull_Fabric_Images) pull_Fabric_Images ;; - --pull_Fabric_CA_Image) - pull_Fabric_CA_Image - ;; --clean_Environment) clean_Environment ;; @@ -150,41 +144,22 @@ pull_Thirdparty_Images() { } # pull fabric images from nexus pull_Fabric_Images() { - for IMAGES in peer orderer; do + for IMAGES in peer orderer ca; do echo "-----------> pull $IMAGES image" echo - docker pull $NEXUS_URL/$ORG_NAME-$IMAGES:$STABLE_TAG - docker tag $NEXUS_URL/$ORG_NAME-$IMAGES:$STABLE_TAG $ORG_NAME-$IMAGES - docker tag $NEXUS_URL/$ORG_NAME-$IMAGES:$STABLE_TAG $ORG_NAME-$IMAGES:$STABLE_TAG - docker rmi -f $NEXUS_URL/$ORG_NAME-$IMAGES:$STABLE_TAG + docker pull $NEXUS_REPO_URL/$ORG_NAME-$IMAGES:$STABLE_TAG + docker tag $NEXUS_REPO_URL/$ORG_NAME-$IMAGES:$STABLE_TAG $ORG_NAME-$IMAGES + docker tag $NEXUS_REPO_URL/$ORG_NAME-$IMAGES:$STABLE_TAG $ORG_NAME-$IMAGES:$STABLE_TAG + docker rmi -f $NEXUS_REPO_URL/$ORG_NAME-$IMAGES:$STABLE_TAG done echo docker images | grep hyperledger/fabric } -# pull fabric-ca images from nexus -pull_Fabric_CA_Image() { - echo - for IMAGES in ca; do - echo "-----------> pull $IMAGES image" - echo - docker pull $NEXUS_URL/$ORG_NAME-$IMAGES:$STABLE_TAG - docker tag $NEXUS_URL/$ORG_NAME-$IMAGES:$STABLE_TAG $ORG_NAME-$IMAGES - docker tag $NEXUS_URL/$ORG_NAME-$IMAGES:$STABLE_TAG $ORG_NAME-$IMAGES:$STABLE_TAG - docker rmi -f $NEXUS_URL/$ORG_NAME-$IMAGES:$STABLE_TAG - done - echo - docker images | grep hyperledger/fabric-ca -} + # run sdk e2e tests sdk_E2e_Tests() { echo echo "-----------> Execute NODE SDK E2E Tests" - cd ${WORKSPACE}/gopath/src/github.com/hyperledger/fabric-sdk-node/test/fixtures || exit - docker-compose up >> dockerlogfile.log 2>&1 & - sleep 30 - echo "---------> LIST DOCKER CONTAINERS" - docker ps -a - cd ${WORKSPACE}/gopath/src/github.com/hyperledger/fabric-sdk-node || exit # Install nvm to install multi node versions wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.33.2/install.sh | bash @@ -197,7 +172,6 @@ sdk_E2e_Tests() { # This also depends on the fabric-baseimage. Make sure you modify there as well. echo "------> Use $NODE_VER for >=release-1.1 branches" nvm install $NODE_VER || true - # use nodejs 8.9.4 version nvm use --delete-prefix v$NODE_VER --silent echo "npm version ------> $(npm -v)" diff --git a/scripts/Jenkins_Scripts/Publish_API_Docs.sh b/scripts/Jenkins_Scripts/Publish_API_Docs.sh index b628c9825d..bf9a2b648f 100755 --- a/scripts/Jenkins_Scripts/Publish_API_Docs.sh +++ b/scripts/Jenkins_Scripts/Publish_API_Docs.sh @@ -14,8 +14,6 @@ echo "-------> SDK_COMMIT:" $SDK_COMMIT TARGET_REPO=$NODE_SDK_USERNAME.github.io.git # Clone SDK_NODE API doc repository git clone https://github.com/$NODE_SDK_USERNAME/$TARGET_REPO -# Remove API docs target repository -rm -rf $NODE_SDK_USERNAME.github.io/* # Copy API docs to target repository & push to gh-pages URL cp -r docs/gen/* $NODE_SDK_USERNAME.github.io cd $NODE_SDK_USERNAME.github.io diff --git a/scripts/Jenkins_Scripts/Publish_NPM_Modules.sh b/scripts/Jenkins_Scripts/Publish_NPM_Modules.sh index bc5a83cf9f..c8466c4369 100755 --- a/scripts/Jenkins_Scripts/Publish_NPM_Modules.sh +++ b/scripts/Jenkins_Scripts/Publish_NPM_Modules.sh @@ -6,9 +6,10 @@ # npmPublish() { - if [ $RELEASE = "snapshot" ]; then + + if [[ "$CURRENT_TAG" = *"unstable"* ]] || [[ "$CURRENT_TAG" = *"skip"* ]]; then echo - UNSTABLE_VER=$(npm dist-tags ls "$1" | awk '/unstable/{ + UNSTABLE_VER=$(npm dist-tags ls "$1" | awk "/$CURRENT_TAG"":"/'{ ver=$NF sub(/.*\./,"",rel) sub(/\.[[:digit:]]+$/,"",ver) @@ -16,35 +17,29 @@ npmPublish() { echo "===> UNSTABLE VERSION --> $UNSTABLE_VER" - UNSTABLE_INCREMENT=$(npm dist-tags ls "$1" | awk '/unstable/{ + UNSTABLE_VER=$(npm dist-tags ls "$1" | awk '/$CURRENT_TAG/{ ver=$NF rel=$NF sub(/.*\./,"",rel) sub(/\.[[:digit:]]+$/,"",ver) print ver"."rel+1}') - echo "===> Incremented UNSTABLE VERSION --> $UNSTABLE_INCREMENT" + + # Get last digit of the unstable version of $CURRENT_TAG + UNSTABLE_INCREMENT=$(echo $UNSTABLE_INCREMENT| rev | cut -d '.' -f 1 | rev) + echo "--------> UNSTABLE_INCREMENT : $UNSTABLE_INCREMENT" + + # Append last digit with the package.json version + export UNSTABLE_INCREMENT_VERSION=$RELEASE_VERSION.$UNSTABLE_INCREMENT + echo "--------> UNSTABLE_INCREMENT_VERSION" $UNSTABLE_INCREMENT_VERSION + + + # Replace existing version with $UNSTABLE_INCREMENT_VERSION + sed -i 's/\(.*\"version\"\: \"\)\(.*\)/\1'$UNSTABLE_INCREMENT_VERSION\"\,'/' package.json + npm publish --tag $CURRENT_TAG - #if [ "$1" = "fabric-network" ]; then - # sed -i 's/\(.*\"fabric-client\"\: \"\)\(.*\)/\1'$CLIENT_VER\"\,'/' package.json - # sed -i 's/\(.*\"fabric-ca-client\"\: \"\)\(.*\)/\1'$CA_CLIENT_VER\"\,'/' package.json - #fi - - if [ "$UNSTABLE_VER" = "$CURRENT_RELEASE" ]; then - # Replace existing version with Incremented $UNSTABLE_VERSION - sed -i 's/\(.*\"version\"\: \"\)\(.*\)/\1'$UNSTABLE_INCREMENT\"\,'/' package.json - npm publish --tag unstable - PUBLISHED_VER=$UNSTABLE_INCREMENT - else - # Replace existing version with $CURRENT_RELEASE - sed -i 's/\(.*\"version\"\: \"\)\(.*\)/\1'$CURRENT_RELEASE\"\,'/' package.json - npm publish --tag unstable - PUBLISHED_VER=$CURRENT_RELEASE - fi else - if [[ "$RELEASE" =~ alpha*|preview*|beta*|rc*|^[0-9].[0-9].[0-9]$ ]]; then echo "----> Publish $RELEASE from fabric-sdk-node-npm-release-x86_64 job" - fi fi } @@ -53,13 +48,15 @@ npmPublish() { # Fetch release version # ########################## - versions() { - CURRENT_RELEASE=$(cat package.json | grep version | awk -F\" '{ print $4 }') - echo "===> Current Version --> $CURRENT_RELEASE" - RELEASE=$(cat package.json | grep version | awk -F\" '{ print $4 }' | cut -d "-" -f 2) - echo "===> Current Release --> $RELEASE" + # Get the unstable tag from package.json + CURRENT_TAG=$(cat package.json | grep tag | awk -F\" '{ print $4 }') + echo "===> Current TAG --> $CURRENT_TAG" + + # Get the version from package.json + RELEASE_VERSION=$(cat package.json | grep version | awk -F\" '{ print $4 }') + echo "===> Current Version --> $RELEASE_VERSION" } # Publish unstable npm modules from amd64 ARCH @@ -67,30 +64,37 @@ cd $WORKSPACE/gopath/src/github.com/hyperledger/fabric-sdk-node echo "npm version ------> $(npm -v)" echo "node version ------> $(node -v)" -npm config set //registry.npmjs.org/:_authToken=$NPM_TOKEN - -# publish fabric-ca-client node module -cd fabric-ca-client -versions -npmPublish fabric-ca-client -CA_CLIENT_VER=$PUBLISHED_VER - -# publish fabric-client node module -cd ../fabric-client -versions -npmPublish fabric-client -CLIENT_VER=$PUBLISHED_VER - -# publish fabric-network node module -if [ -d "../fabric-network" ]; then - cd ../fabric-network - versions - npmPublish fabric-network -fi +ARCH=$(uname -m) +echo "-------> ARCH" $ARCH + +if [[ "$ARCH" = "s390x" ]] || [[ "$ARCH" = "ppc64le" ]]; then + echo "--------> Publish npm modules only from x86_64 (x) platform, not from $ARCH (z and p) now. <----" +else + echo "----------> Publish npm node modules from $ARCH <--------" + cd $WORKSPACE/gopath/src/github.com/hyperledger/fabric-sdk-node + npm config set //registry.npmjs.org/:_authToken=$NPM_TOKEN + + # Publish fabric-ca-client node module + cd fabric-ca-client + versions + npmPublish fabric-ca-client + + # Publish fabric-client node module + cd ../fabric-client + versions + npmPublish fabric-client + + # Publish fabric-network node module + if [ -d "../fabric-network" ]; then + cd ../fabric-network + versions + npmPublish fabric-network + fi -# publish fabric-common node module -if [ -d "../fabric-common" ]; then - cd ../fabric-common - versions - npmPublish fabric-common + # Publish fabric-common node module + if [ -d "../fabric-common" ]; then + cd ../fabric-common + versions + npmPublish fabric-common + fi fi