diff --git a/scripts/create-release-pr b/scripts/create-release-pr new file mode 100755 index 0000000000..61a97e0ce1 --- /dev/null +++ b/scripts/create-release-pr @@ -0,0 +1,55 @@ +#!/usr/bin/env bash + +set -e -o pipefail + +CURRENT_BRANCH=`git branch --show-current` +MAIN_BRANCH="master" + +if [[ "${CURRENT_BRANCH}" != "${MAIN_BRANCH}" ]]; then + echo "scripts/publish-release must be run on the ${MAIN_BRANCH}." + echo "Please checkout the ${MAIN_BRANCH} branch with:" + echo "git checkout ${MAIN_BRANCH}" + exit 1 +fi + +if !(command -v gh > /dev/null); then + echo "GitHub CLI is required for this release script." + echo "Please install GitHub CLI and try again:" + echo "https://github.com/cli/cli#installation" + exit 1 +fi + +# hostname is necessary just in case you are logged into the CLI +# GitHub enterprise instance +if !(gh auth status --hostname "github.com" > /dev/null 2>&1); then + echo "Not logged into GitHub". + echo "Please run: gh auth login" + exit 1 +fi + +git pull --rebase origin "${MAIN_BRANCH}" + +# Create a branch with the unix timestamp of the current second +BRANCH_NAME="release-$(date +%s)" + +echo "Creating git branch ${BRANCH_NAME}" +git checkout -b "${BRANCH_NAME}" + +echo "Installing dependencies with yarn..." +yarn +echo "Done installing dependencies with yarn" + +echo "Creating new CLI package(s) versions with yarn lerna version..." +yarn lerna version \ + --allow-branch ${BRANCH_NAME} \ + --no-push \ + --no-git-tag-version \ + --yes +git add . -u +PACKAGE_VERSION=`node -e "console.log(require('./lerna.json').version)"` +echo "Done creating new CLI package(s) versions" + +echo "Creating git commit and pushing to GitHub..." +git commit -m "v${PACKAGE_VERSION}" +git push origin "${BRANCH_NAME}" +gh pr create --title="release v${PACKAGE_VERSION}" --body "release v${PACKAGE_VERSION}" diff --git a/scripts/publish-release b/scripts/publish-release new file mode 100755 index 0000000000..b90196c971 --- /dev/null +++ b/scripts/publish-release @@ -0,0 +1,60 @@ +#!/usr/bin/env bash + +set -e -o pipefail + +CURRENT_BRANCH=`git branch --show-current` +MAIN_BRANCH="master" + +if [[ "${CURRENT_BRANCH}" != "${MAIN_BRANCH}" ]]; then + echo "scripts/publish-release must be run on the ${MAIN_BRANCH}." + echo "Please checkout the ${MAIN_BRANCH} branch with:" + echo "git checkout ${MAIN_BRANCH}" + exit 1 +fi + +if !(command -v gh > /dev/null); then + echo "GitHub CLI is required for this release script." + echo "Please install GitHub CLI and try again:" + echo "https://github.com/cli/cli#installation" + exit 1 +fi + +# hostname is necessary just in case you are logged into the CLI +# GitHub enterprise instance +if !(gh auth status --hostname "github.com" > /dev/null 2>&1); then + echo "Not logged into github". + echo "Please run: gh auth login" + exit 1 +fi + +git pull --rebase origin "${MAIN_BRANCH}" +git fetch origin --tags + +PACKAGE_VERSION=`node -e "console.log(require('./lerna.json').version)"` +TAG_NAME="v${PACKAGE_VERSION}" +EXISTING_REMOTE_TAG=$(git ls-remote origin "refs/tags/${TAG_NAME}") + +if [ -n "${EXISTING_REMOTE_TAG}" ]; then + echo "The tag ${TAG_NAME} already exists on github.com" + echo "This likely means this version has already been published." + echo "Please examine the tag ${TAG_NAME} on github.com/heroku/cli to see the contents of the ${TAG_NAME} release" + echo "You may need to run scripts/create-release-pr to create a new release before running this script" + exit 1 +fi + +echo "Installing dependencies with yarn..." +yarn +echo "Done installing dependencies with yarn" + +echo "publishing packages to npm..." +yarn lerna publish --yes from-package + + +LAST_PUBLISHED_TAG=$(git tag --sort="-version:refname" --list --format="%(refname:strip=2)" | head -n1) + +git tag "${TAG_NAME}" -m "${TAG_NAME}" +git push origin "${TAG_NAME}" + +RELEASE_NOTES=$(git log --graph --format="%h %s" "${LAST_PUBLISHED_TAG}...${TAG_NAME}~1") + +gh release create "${TAG_NAME}" --title="${TAG_NAME}" --notes="${RELEASE_NOTES}"