Skip to content

Commit

Permalink
[WNMGDS-1475] Add release script undo feature and pass args through t…
Browse files Browse the repository at this point in the history
…o 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
  • Loading branch information
pwolfert authored Mar 4, 2022
1 parent b367138 commit f27503f
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 33 deletions.
3 changes: 2 additions & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
81 changes: 49 additions & 32 deletions release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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 ""

0 comments on commit f27503f

Please sign in to comment.