Skip to content

Commit

Permalink
Merge pull request #139 from zowe/better-deploy
Browse files Browse the repository at this point in the history
Smoke test part 2
  • Loading branch information
zFernand0 authored Jul 8, 2021
2 parents 544b52c + a772ffe commit 17b1cea
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 41 deletions.
112 changes: 71 additions & 41 deletions scripts/deploy-zowe-cli-component.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -70,60 +70,90 @@ def OLD_PKG_VER = ""
def VERSIONS_MATCH = true

import java.text.SimpleDateFormat;
import java.util.concurrent.TimeUnit

node('ca-jenkins-agent') {
try {
checkout scm
stage('Deploy package') {
PKG_TAG = params.PKG_TAG
def getPkgInfo = load 'scripts/getPackageInfo.groovy'
sh "rm -f .npmrc || exit 0"
sh "rm -f ~/.npmrc || exit 0"
sh "chmod +x ./scripts/npm_login.sh"

def tgzUrl = ""
def viewOpts = "--${CONST.scope}:registry=${CONST.artifactory}"
try {
PKG_VERSION = getPkgInfo("${CONST.scope}/${params.PKG_NAME}@${PKG_TAG}", viewOpts, "version")
tgzUrl = getPkgInfo("${CONST.scope}/${params.PKG_NAME}@${PKG_TAG}", viewOpts, "dist.tarball")
} catch (e) {
error "${e.getMessage()}"
}
timeout(time: 10, unit: 'MINUTES') {
PKG_TAG = params.PKG_TAG
def getPkgInfo = load 'scripts/getPackageInfo.groovy'
sh "rm -f .npmrc || exit 0"
sh "rm -f ~/.npmrc || exit 0"
sh "chmod +x ./scripts/npm_login.sh"

def tgzUrl = ""
def viewOpts = "--${CONST.scope}:registry=${CONST.artifactory}"
try {
PKG_VERSION = getPkgInfo("${CONST.scope}/${params.PKG_NAME}@${PKG_TAG}", viewOpts, "version")
tgzUrl = getPkgInfo("${CONST.scope}/${params.PKG_NAME}@${PKG_TAG}", viewOpts, "dist.tarball")
} catch (e) {
error "${e.getMessage()}"
}

def fullPkgName = "${params.PKG_NAME}-${PKG_VERSION}.tgz"
// Download the tgz file
sh "curl --silent \"${tgzUrl}\" > ${fullPkgName}"
def fullPkgName = "${params.PKG_NAME}-${PKG_VERSION}.tgz"
// Download the tgz file
sh "curl --silent \"${tgzUrl}\" > ${fullPkgName}"

withCredentials([usernamePassword(credentialsId: CONST.distId, usernameVariable: 'USERNAME', passwordVariable: 'TOKEN')]) {
sh "echo \"//${rmProt(CONST.distRegistry)}:_authToken=$TOKEN\" > ~/.npmrc"
sh "echo \"registry=${CONST.distRegistry}\" >> ~/.npmrc"
}
withCredentials([usernamePassword(credentialsId: CONST.distId, usernameVariable: 'USERNAME', passwordVariable: 'TOKEN')]) {
sh "echo \"//${rmProt(CONST.distRegistry)}:_authToken=$TOKEN\" > ~/.npmrc"
sh "echo \"registry=${CONST.distRegistry}\" >> ~/.npmrc"
}

try {
try {
OLD_PKG_VER = getPkgInfo("${CONST.scope}/${params.PKG_NAME}@${PKG_TAG}")
} catch (e) {
} catch (e) {
// Do not error out
echo "${e.getMessage()}"
}
}

if (OLD_PKG_VER == PKG_VERSION) {
VERSIONS_MATCH = true
echo "Package: ${CONST.scope}/${params.PKG_NAME}@${PKG_VERSION} already exists"
} else {
try {
OLD_PKG_VER = getPkgInfo("${CONST.scope}/${params.PKG_NAME}@${PKG_VERSION}")
if (OLD_PKG_VER == PKG_VERSION) {
VERSIONS_MATCH = true
echo "Package: ${CONST.scope}/${params.PKG_NAME}@${PKG_VERSION} already exists, adding tag ${PKG_TAG}"
sh "npm dist-tag add ${CONST.scope}/${params.PKG_NAME}@${PKG_VERSION} ${PKG_TAG}"
} catch (e) {
VERSIONS_MATCH = false
sh "chmod +x ./scripts/repackage_tar.sh"
sh "./scripts/repackage_tar.sh ${fullPkgName} ${CONST.distRegistry} ${PKG_VERSION}"
if (PKG_TAG != PKG_VERSION) {
sh "npm publish ${fullPkgName} --tag ${PKG_TAG} --access public"
} else {
sh "npm publish ${fullPkgName} --access public"
echo "Package: ${CONST.scope}/${params.PKG_NAME}@${PKG_VERSION} already exists"
} else {
try {
OLD_PKG_VER = getPkgInfo("${CONST.scope}/${params.PKG_NAME}@${PKG_VERSION}")
VERSIONS_MATCH = true
echo "Package: ${CONST.scope}/${params.PKG_NAME}@${PKG_VERSION} already exists, adding tag ${PKG_TAG}"
sh "npm dist-tag add ${CONST.scope}/${params.PKG_NAME}@${PKG_VERSION} ${PKG_TAG}"
} catch (e) {
VERSIONS_MATCH = false
sh "chmod +x ./scripts/repackage_tar.sh"
sh "./scripts/repackage_tar.sh ${fullPkgName} ${CONST.distRegistry} ${PKG_VERSION}"
if (PKG_TAG != PKG_VERSION) {
sh "npm publish ${fullPkgName} --tag ${PKG_TAG} --access public"
} else {
sh "npm publish ${fullPkgName} --access public"
}
}

echo "Waiting for published version to appear on NPM registry"
def taggedVersion
while (taggedVersion != PKG_VERSION) {
sleep time: 1000, unit: TimeUnit.MILLISECONDS
taggedVersion = sh(returnStdout: true, script: "npm view ${CONST.scope}/${params.PKG_NAME}@${PKG_TAG} version").trim()
}

echo "Verifying that deployed package can be installed"
def installError
dir(pwd(tmp: true)) {
try {
sh "npm install ${CONST.scope}/${params.PKG_NAME}@${PKG_TAG} --${CONST.scope}:registry=${CONST.distRegistry}"
} catch (error) {
installError = error
}
}

if (installError != null) {
if (OLD_PKG_VER != "") {
echo "Install failed, reverting tag ${PKG_TAG} to v${OLD_PKG_VER}"
sh "npm dist-tag add ${CONST.scope}/${params.PKG_NAME}@${OLD_PKG_VER} ${PKG_TAG}"
}

throw installError
}

sh "rm -f ~/.npmrc || exit 0"
}
}
Expand All @@ -142,7 +172,7 @@ node('ca-jenkins-agent') {
if (buildStatus.equals("SUCCESS")) {
if (VERSIONS_MATCH) {
details = "${details} was not required."
// Prevent sendind undesired emails to everyone
// Prevent sending undesired emails to everyone
recipients = ""
} else {
details = "${details} has been placed in ${CONST.distRegistry}"
Expand Down
8 changes: 8 additions & 0 deletions scripts/repackage_tar.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ mv package.json ../../$tarfile_package.json
# Replace package json with our new one
mv package_new.json package.json

# Check that all dependencies are valid
npmDeps=`node -e "package = require('./package.json');
Object.entries(package.dependencies).forEach(([name, version]) => console.log(name + '@' + version));"`
for pkgSpec in $npmDeps; do
echo "Validating dependency $pkgSpec..."
npm view $pkgSpec || exit 1
done

# Update npm-shrinkwrap.json if necessary
if [ -e "npm-shrinkwrap.json" ]; then
# Create a production environment (taking in consideration the npm-shrinkwrap)
Expand Down

0 comments on commit 17b1cea

Please sign in to comment.