pulumi/scripts/make_release.sh
Matt Ellis 6843162f98 Ensure correct version is in published package
We need to take the package.json from the folder (which will have been
rewritten by the build to include the version number) instead of the
version we have checked into the tree (which has ${VERSION} as a version)

Windows didn't have this issue, but it did include some stuff we did
not include in the unified release, so I cleaned that up as well.
2017-12-04 23:09:48 -08:00

56 lines
1.7 KiB
Bash
Executable file

#!/bin/bash
# make_release.sh will create a build package ready for publishing.
set -o nounset -o errexit -o pipefail
ROOT=$(dirname $0)/..
PUBDIR=$(mktemp -du)
GITHASH=$(git rev-parse HEAD)
PUBFILE=$(dirname ${PUBDIR})/${GITHASH}.tgz
VERSION=$(git describe --tags 2>/dev/null)
# Figure out which branch we're on. Prefer $TRAVIS_BRANCH, if set, since
# Travis leaves us at detached HEAD and `git rev-parse` just returns "HEAD".
BRANCH=${TRAVIS_BRANCH:-$(git rev-parse --abbrev-ref HEAD)}
declare -a PUBTARGETS=(${GITHASH} ${VERSION} ${BRANCH})
# usage: run_go_build <path-to-package-to-build>
function run_go_build() {
local bin_suffix=""
local output_name=$(basename $(cd "$1" ; pwd))
if [ "$(go env GOOS)" = "windows" ]; then
bin_suffix=".exe"
fi
mkdir -p "${PUBDIR}/bin"
go build -ldflags "-X main.version=${VERSION}" -o "${PUBDIR}/bin/${output_name}${bin_suffix}" "$1"
}
# usage: copy_package <path-to-module> <module-name>
copy_package() {
local module_root=${PUBDIR}/node_modules/$2
mkdir -p "${module_root}"
cp -R "$1" "${module_root}/"
if [ -e "${module_root}/node_modules" ]; then
rm -rf "${module_root}/node_modules"
fi
if [ -e "${module_root}/tests" ]; then
rm -rf "${module_root}/tests"
fi
}
# Build binaries
run_go_build "${ROOT}"
# Copy over the langhost and dynamic provider
cp ${ROOT}/sdk/nodejs/pulumi-langhost-nodejs ${PUBDIR}/bin/
cp ${ROOT}/sdk/nodejs/pulumi-provider-pulumi-nodejs ${PUBDIR}/bin/
# Copy packages
copy_package "${ROOT}/sdk/nodejs/bin/." "pulumi"
# Tar up the file and then print it out for use by the caller or script.
tar -czf ${PUBFILE} -C ${PUBDIR} .
echo ${PUBFILE} ${PUBTARGETS[@]}