-
Notifications
You must be signed in to change notification settings - Fork 515
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FABN-1386: Doc publishing fixes (#40)
- Reference credentials in pipeline script - Git and find usage tweaked for cross-platform compatibility - Ensure publishing script fails fast on any errors - Add some additional information output - Correct target URL for the root index.html redirect - Replace all root publish files if building master branch Signed-off-by: Mark S. Lewis <[email protected]>
- Loading branch information
1 parent
fb17112
commit b4b04ad
Showing
6 changed files
with
124 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,89 +1,108 @@ | ||
#!/bin/bash -e | ||
#!/bin/bash | ||
# | ||
# Copyright IBM Corp All Rights Reserved | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
|
||
set -e -o pipefail | ||
|
||
# Input environment variables: | ||
: "${NPM_TOKEN:?}" # The npm publishing auth token | ||
: "${PROJECT_DIR:?}" # The project root directory | ||
|
||
readonly NODE_MODULES="fabric-protos fabric-common fabric-ca-client fabric-client fabric-network" | ||
|
||
npmPublish() { | ||
if [[ "$CURRENT_TAG" = *"skip"* ]]; then | ||
echo -e "\033[34m----> Don't publish $1 npm modules on skip tag \033[0m" | ||
elif [[ "$CURRENT_TAG" = *"unstable"* ]]; then | ||
echo | ||
# Get the current unstable version of a module from npm registry | ||
UNSTABLE_VER=$(npm dist-tags ls "$1" | awk "/$CURRENT_TAG"":"/'{ | ||
ver=$NF | ||
rel=$NF | ||
sub(/.*\./,"",rel) | ||
sub(/\.[[:digit:]]+$/,"",ver) | ||
print ver"."rel+1}') | ||
if [[ $UNSTABLE_VER = "" ]]; then | ||
publishAllPackages() { | ||
local module moduleDir | ||
for module in ${NODE_MODULES}; do | ||
moduleDir="${PROJECT_DIR}/${module}" | ||
if [ -d "${moduleDir}" ]; then | ||
echo -e "\033[32m Publishing ${module} \033[0m" | ||
(cd "${moduleDir}" && publishPackage "${module}") | ||
fi | ||
done | ||
} | ||
|
||
publishPackage() { | ||
readPackageVersion | ||
|
||
if [[ ${CURRENT_TAG} = *"skip"* ]]; then | ||
echo -e "\033[34m----> Don't publish $1 npm modules on skip tag \033[0m" | ||
return | ||
fi | ||
|
||
configureNpm | ||
|
||
if [[ ${CURRENT_TAG} = *"unstable"* ]]; then | ||
publishUnstablePackage "$1" | ||
else | ||
publishReleasePackage "$1" | ||
fi | ||
} | ||
|
||
readPackageVersion() { | ||
# Get the unstable tag from package.json | ||
CURRENT_TAG=$(grep '"tag":' package.json | cut -d\" -f4) | ||
echo -e "\033[32m ======> Current TAG: ${CURRENT_TAG} \033[0m" | ||
# Get the version from package.json | ||
RELEASE_VERSION=$(grep '"version":' package.json | cut -d\" -f4) | ||
echo -e "\033[32m ======> Current Version: ${RELEASE_VERSION} \033[0m" | ||
} | ||
|
||
configureNpm() { | ||
echo '//registry.npmjs.org/:_authToken=${NPM_TOKEN}' > '.npmrc' | ||
} | ||
|
||
publishUnstablePackage() { | ||
local module | ||
# Get the current unstable version of a module from npm registry | ||
UNSTABLE_VER=$(npm dist-tags ls "$1" | awk "/${CURRENT_TAG}:"/'{ | ||
ver=$NF | ||
rel=$NF | ||
sub(/.*\./,"",rel) | ||
sub(/\.[[:digit:]]+$/,"",ver) | ||
print ver"."rel+1 | ||
}') | ||
if [[ -z ${UNSTABLE_VER} ]]; then | ||
echo -e "\033[34m ----> unstable ver is blank \033[0m" | ||
UNSTABLE_INCREMENT=1 | ||
else | ||
else | ||
# Get last digit of the unstable version built above | ||
UNSTABLE_INCREMENT=$(echo $UNSTABLE_VER| rev | cut -d '.' -f 1 | rev) | ||
fi | ||
echo -e "\033[32m======> UNSTABLE_INCREMENT:" $UNSTABLE_INCREMENT "\033[0m" | ||
# Append last digit with the package.json version | ||
export UNSTABLE_INCREMENT_VERSION=$RELEASE_VERSION.$UNSTABLE_INCREMENT | ||
echo -e "\033[32m======> UNSTABLE_INCREMENT_VERSION:" $UNSTABLE_INCREMENT_VERSION "\033[0" | ||
for module in ${NODE_MODULES}; do | ||
sed -i "s/\"${module}\": \".*\"/\"${module}\": \"${CURRENT_TAG}\"/" package.json | ||
done | ||
|
||
# Replace existing version with $UNSTABLE_INCREMENT_VERSION | ||
sed -i 's/\(.*\"version\"\: \"\)\(.*\)/\1'$UNSTABLE_INCREMENT_VERSION\"\,'/' package.json | ||
# Show Version after modify the package.json with latest version to publish | ||
grep '"version":' package.json | cut -d\" -f4 | ||
# Publish unstable versions to npm registry | ||
npm publish --tag $CURRENT_TAG | ||
if [ $? != 0 ]; then | ||
echo -e "\033[31m FAILED to publish $CURRENT_TAG of $1 npm module" "\033[0m" | ||
exit 1 | ||
fi | ||
echo -e "\033[32m ========> PUBLISHED $CURRENT_TAG tag of $1 npm module SUCCESSFULLY" "\033[0m" | ||
UNSTABLE_INCREMENT=$(echo "${UNSTABLE_VER}" | rev | cut -d '.' -f 1 | rev) | ||
fi | ||
echo -e "\033[32m======> UNSTABLE_INCREMENT: ${UNSTABLE_INCREMENT} \033[0m" | ||
# Append last digit with the package.json version | ||
export UNSTABLE_INCREMENT_VERSION="${RELEASE_VERSION}.${UNSTABLE_INCREMENT}" | ||
echo -e "\033[32m======> UNSTABLE_INCREMENT_VERSION: ${UNSTABLE_INCREMENT_VERSION} \033[0m" | ||
for module in ${NODE_MODULES}; do | ||
sed -i "s/\"${module}\": \".*\"/\"${module}\": \"${CURRENT_TAG}\"/" package.json | ||
done | ||
|
||
# Replace existing version with $UNSTABLE_INCREMENT_VERSION | ||
sed -i 's/\(.*\"version\"\: \"\)\(.*\)/\1'"${UNSTABLE_INCREMENT_VERSION}"\"\,'/' package.json | ||
# Show Version after modify the package.json with latest version to publish | ||
grep '"version":' package.json | cut -d\" -f4 | ||
# Publish unstable versions to npm registry | ||
npmPublish "$1" | ||
} | ||
|
||
else | ||
# Publish node modules on latest tag | ||
echo -e "\033[32m ========> PUBLISH $RELEASE_VERSION" "\033[0m" | ||
publishReleasePackage() { | ||
local module | ||
echo -e "\033[32m ========> PUBLISH $RELEASE_VERSION \033[0m" | ||
for module in ${NODE_MODULES}; do | ||
sed -i "s/\"${module}\": \".*\"/\"${module}\": \"${CURRENT_TAG}\"/" package.json | ||
sed -i "s/\"${module}\": \".*\"/\"${module}\": \"${CURRENT_TAG}\"/" package.json | ||
done | ||
|
||
npm publish --tag $CURRENT_TAG | ||
if [ $? != 0 ]; then | ||
echo -e "\033[31m FAILED TO PUBLISH $CURRENT_TAG of $1 npm module" "\033[0m" | ||
exit 1 | ||
fi | ||
echo -e "\033[32m ========> PUBLISHED $CURRENT_TAG tag of $1 npm module SUCCESSFULLY" "\033[0m" | ||
fi | ||
npmPublish "$1" | ||
} | ||
|
||
versions() { | ||
# Get the unstable tag from package.json | ||
CURRENT_TAG=$(grep '"tag":' package.json | cut -d\" -f4) | ||
echo -e "\033[32m ======> Current TAG: $CURRENT_TAG" "\033[0m" | ||
# Get the version from package.json | ||
RELEASE_VERSION=$(grep '"version":' package.json | cut -d\" -f4) | ||
echo -e "\033[32m ======> Current Version: $RELEASE_VERSION" "\033[0m" | ||
npmPublish() { | ||
npm publish --tag "${CURRENT_TAG}" || { | ||
echo -e "\033[31m FAILED to publish ${CURRENT_TAG} of $1 npm module \033[0m" | ||
exit 1 | ||
} | ||
echo -e "\033[32m ========> PUBLISHED ${CURRENT_TAG} tag of $1 npm module SUCCESSFULLY \033[0m" | ||
} | ||
|
||
# Set NPM_TOKEN from CI configuration | ||
# Please post in #ci-pipeline channel if you observe npm_token issue | ||
npm config set "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" | ||
|
||
# Publish node modules | ||
for module in ${NODE_MODULES}; do | ||
moduleDir="${PROJECT_DIR}/${module}" | ||
if [ -d "${moduleDir}" ]; then | ||
echo -e "\033[32m Publishing ${module}" "\033[0m" | ||
(cd "${moduleDir}" && versions && npmPublish "${module}") | ||
fi | ||
done | ||
publishAllPackages |