Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add publish.sh to publish to NPM-JS and Github Pages. #429

Merged
merged 8 commits into from
Jul 30, 2018
4 changes: 3 additions & 1 deletion bundle-beta.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ echo "Staging: ${staging}"
# │ └ maven
# ├─ y
# │ └─ npm
# └─ node_modules
# ├─ node_modules
# └─ .version

# Creating a `y-npm` registry
echo "Preparing local NPM registry"
Expand Down Expand Up @@ -57,6 +58,7 @@ ln -s node_modules/aws-cdk-docs/dist/docs docs
# Create an archive under ./dist
echo "Creating ZIP bundle"
version="$(cat ${root}/lerna.json | grep version | cut -d '"' -f4)"
echo ${version} > .version
dist=${root}/dist
output=${dist}/aws-cdk-${version}.zip
rm -fr ${dist}
Expand Down
103 changes: 103 additions & 0 deletions publish.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
#!/bin/bash
set -euo pipefail

###
# Usage: ./publish.sh <release-zip>
#
# Publishes the content of a release bundle ZIP file to the standard package
# repositories for the various supported languages:
# * Javascript & TypeScript: NPM
# * Documentation: GitHub Pages
# * (More to come later)
###

if [ $# -ne 1 ]; then
echo "Missing release zip file argument"
echo "Usage: ./publish.sh <release-zip>"
exit 1
fi

RELEASE_BUNDLE=$1
if [ ! -f ${RELEASE_BUNDLE} ]; then
echo "${RELEASE_BUNDLE} is not a file!"
exit 127
fi

###############
# PREPARATION #
###############

declare -a CLEANUP=()
function cleanup() {
for ((i = 0; i < ${#CLEANUP[@]}; i++ ))
do
eval "${CLEANUP[$i]}"
done
echo '🍻 Done!'
}
trap cleanup 'EXIT'


WORK_DIR=$(mktemp -d)
CLEANUP+=("echo '🚮 Cleaning up working directory'" "rm -fr ${WORK_DIR}")
echo "💼 Working directory: ${WORK_DIR}"

echo "🗜 Unzipping release bundle (be patient - this may take a while)"
unzip -q ${RELEASE_BUNDLE} -d ${WORK_DIR}

PKG_VERSION=$(cat ${WORK_DIR}/.version)

#######
# NPM #
#######

echo "📦 Publishing to NPM"
REGISTRY='https://registry.npmjs.org/'
OLD_REGISTRY=$(npm config get registry)
if [ ${OLD_REGISTRY} != ${REGISTRY} ]; then
echo "👉 Switching to NPM registry ${REGISTRY}"
npm config set registry ${REGISTRY}
CLEANUP+=("echo '👈 Resetting NPM registry to ${OLD_REGISTRY}'" "npm config set registry ${OLD_REGISTRY}")
fi

TOKENS=$(npm token list 2>&1 || echo '')
if echo ${TOKENS} | grep 'EAUTHUNKNOWN' > /dev/null; then
echo "🔑 Can't list tokens - apparently missing authentication info"
npm login
fi

for TGZ in $(find ${WORK_DIR}/y/npm -iname '*.tgz'); do
npm publish $TGZ --access=public
done

################
# GitHub Pages #
################

echo "📖 Publishing to GitHub Pages"

GIT_REPO=$(mktemp -d)
CLEANUP+=("echo '🚮 Cleaning up GitHub Pages working copy'" "rm -fr ${GIT_REPO}")

DOC_STAGING=$(mktemp -d)
CLEANUP+=("echo '🚮 Cleaning up Documentations staging directory'" "rm -fr ${DOC_STAGING}")

(
cd ${DOC_STAGING}
${WORK_DIR}/bin/y-npm i aws-cdk-docs --no-save
)

git clone -b gh-pages --depth=1 ssh://github.com/awslabs/aws-cdk ${GIT_REPO}
mkdir -p ${GIT_REPO}/versions

rsync -ar --delete --exclude=/.git --exclude=/versions ${DOC_STAGING}/node_modules/aws-cdk-docs/dist/docs/ ${GIT_REPO}/
rsync -ar --delete ${DOC_STAGING}/node_modules/aws-cdk-docs/dist/docs/ ${GIT_REPO}/versions/${PKG_VERSION}/

(
cd ${GIT_REPO}
git add .
git commit -m "Release ${PKG_VERSION}"
git push
)

echo "✅ All OK!"