From f27503fff72a138248f17f3d56d4b4f6bbc4ecf6 Mon Sep 17 00:00:00 2001 From: Patrick Wolfert Date: Fri, 4 Mar 2022 09:09:51 -0800 Subject: [PATCH] [WNMGDS-1475] Add release script undo feature and pass args through to lerna command (#1631) * Allow release script args to pass through to the lerna command and add undo feature * Make option parsing more concise * Update next steps documentation * Add design-system-tokens package to lerna ignore list * Fix prompt conditional * Switch to previous branch instead of master --- lerna.json | 3 +- release.sh | 81 +++++++++++++++++++++++++++++++++--------------------- 2 files changed, 51 insertions(+), 33 deletions(-) diff --git a/lerna.json b/lerna.json index f25b1f7fde..e70bbc8c47 100644 --- a/lerna.json +++ b/lerna.json @@ -3,7 +3,8 @@ "packages": ["packages/*"], "ignoreChanges": [ "packages/stylelint-config-design-system/**", - "packages/eslint-config-design-system/**" + "packages/eslint-config-design-system/**", + "packages/design-system-tokens/**" ], "tagVersionPrefix": "core-", "version": "independent", diff --git a/release.sh b/release.sh index 4d9ed0df85..f3a476cddf 100755 --- a/release.sh +++ b/release.sh @@ -8,37 +8,65 @@ YELLOW='\033[0;33m' CYAN='\033[0;36m' NC='\033[0m' # No color +read_previous_commit_tags() { + # Grep the last commit message for package versions + PACKAGE_VERSIONS=$(git log -1 --pretty=%B | grep -o "@.*$") + # Take the first one we find to use in example command + PACKAGE_VERSION=$(echo "$PACKAGE_VERSIONS" | head -1) + # Get it all on one line so we can push these tags at once + TAGS=$(echo "$PACKAGE_VERSIONS" | tr '\n' ' ') +} + +DELETE_LAST=false +EXTRA_OPTS=() + # Parse options while [[ $# -gt 0 ]] do - key="$1" - - case $key in - --force-publish) - FORCE_PUBLISH_PACKAGES="$2" - shift # past argument - shift # past value - ;; - *) - # unknown option - shift # past argument - ;; - esac + case "$1" in + -u|--undo) + DELETE_LAST=true + shift # past argument + ;; + *) + # unknown option + EXTRA_OPTS+=("$1") # save it in an array for later + shift # past argument + ;; + esac done +git fetch --tags + +if [ "$DELETE_LAST" = true ]; then + read_previous_commit_tags + echo "${RED}This release branch and the following tags will be deleted locally and on origin${NC}" + echo "" + echo "${PACKAGE_VERSIONS}" + echo "" + read -p "Are you sure want to continue? (y/n) " -n 1 -r + echo + if [[ $REPLY =~ ^[Yy]$ ]] + then + echo "${GREEN}Undoing last release...${NC}" + CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD) + git tag -d $TAGS + git push origin --delete $TAGS + git push origin --delete $CURRENT_BRANCH + git checkout - + git branch -D $CURRENT_BRANCH + fi + exit 0 +fi + echo "${GREEN}Creating release branch...${NC}" DATE=$(date "+%Y-%m-%d") BRANCH="release-${DATE}" git checkout -b $BRANCH -if [ -n "$FORCE_PUBLISH_PACKAGES" ]; then - git fetch --tags - LERNA_VERSION_ARGS="--force-publish=$FORCE_PUBLISH_PACKAGES" -fi - echo "${GREEN}Bumping version...${NC}" PRE_VERSION_HASH=$(git rev-parse HEAD) -yarn lerna version --no-push $LERNA_VERSION_ARGS +yarn lerna version --no-push ${EXTRA_OPTS[@]} POST_VERSION_HASH=$(git rev-parse HEAD) if [ "$PRE_VERSION_HASH" = "$POST_VERSION_HASH" ]; then @@ -49,12 +77,7 @@ if [ "$PRE_VERSION_HASH" = "$POST_VERSION_HASH" ]; then fi echo "${GREEN}Pushing tag and release commit to Github...${NC}" -# Grep the last commit message for package versions -PACKAGE_VERSIONS=$(git log -1 --pretty=%B | grep -o "@.*$") -# Take the first one we find to use in example command -PACKAGE_VERSION=$(echo "$PACKAGE_VERSIONS" | head -1) -# Get it all on one line so we can push these tags at once -TAGS=$(echo "$PACKAGE_VERSIONS" | tr '\n' ' ') +read_previous_commit_tags git push --set-upstream origin $BRANCH git push origin $TAGS @@ -70,11 +93,5 @@ echo "${YELLOW}NEXT STEPS:${NC}" echo "" echo "${YELLOW} 1. Create a pull request for merging \`${CYAN}$BRANCH${YELLOW}\` into master to save the version bump${NC}" echo "" -echo "${YELLOW} 2. Publish this release to npm by running:${NC}" -echo "" -echo " ${CYAN}\$${NC} yarn publish-release $PACKAGE_VERSION" -echo "" -echo "${YELLOW} 2. Publish this release to npm by running:${NC}" -echo "" -echo " ${CYAN}\$${NC} yarn publish-release $PACKAGE_VERSION" +echo "${YELLOW} 2. Publish this release to npm using the \`${CYAN}publish-packages${YELLOW}\` job${NC}" echo ""