From e164665560f046dfce4c1debdfa46fb58b06fc75 Mon Sep 17 00:00:00 2001 From: Joaquin Casares Date: Wed, 3 Aug 2022 15:38:20 -0500 Subject: [PATCH] INF-210 Finishing changes (#3617) * better help message * ensure exit's are respected --- .circleci/triggers/__init__.py | 3 ++ .circleci/triggers/deploy-sdk.py | 2 +- libs/scripts/release.sh | 89 +++++++++++++++++--------------- 3 files changed, 51 insertions(+), 43 deletions(-) diff --git a/.circleci/triggers/__init__.py b/.circleci/triggers/__init__.py index 17dde28594c..aa4120ddb4d 100644 --- a/.circleci/triggers/__init__.py +++ b/.circleci/triggers/__init__.py @@ -48,6 +48,9 @@ def standardize_branch(branches): def ensure_tag_on_master(tag): """Ensure tag has been merged before proceeding""" + if tag == "master": + print("Commit cannot be 'master'.") + exit(1) try: branches = run_cmd( f"git branch -a --contains {tag}", exit_on_error=False diff --git a/.circleci/triggers/deploy-sdk.py b/.circleci/triggers/deploy-sdk.py index 5ff232aeebd..cbde4545ed2 100755 --- a/.circleci/triggers/deploy-sdk.py +++ b/.circleci/triggers/deploy-sdk.py @@ -24,7 +24,7 @@ @click.option( "-u", "--slack-mentions-user", - help="Used for CircleCI @mentions", + help="Used when $CIRCLE_SLACK_MENTIONS_USER is not set, for CircleCI @mentions", envvar="CIRCLE_SLACK_MENTIONS_USER", required=True, ) diff --git a/libs/scripts/release.sh b/libs/scripts/release.sh index d9446d37e65..7a0bbb52523 100755 --- a/libs/scripts/release.sh +++ b/libs/scripts/release.sh @@ -36,50 +36,55 @@ ${CHANGE_LOG}" # Make a new branch off GIT_TAG, bumps npm, # commits with the relevant changelog, and pushes function bump-npm () { - # Configure git client - git config --global user.email "audius-infra@audius.co" - git config --global user.name "audius-infra" - - # Make sure master is up to date - git checkout master -f - git pull - - # only allow tags/commits found on master, release branches, or tags to be deployed - git branch -a --contains ${GIT_TAG} \ - | tee /dev/tty \ - | grep -Eq 'remotes/origin/master|remotes/origin/release' \ - || ( - echo "tag not found on master nor release branches" - exit 1 - ) - - # Ensure working directory clean - git reset --hard ${GIT_TAG} - - # grab change log early, before the version bump - LAST_RELEASED_SHA=$(jq -r '.audius.releaseSHA' package.json) - CHANGE_LOG=$(git-changelog ${LAST_RELEASED_SHA}) - - # Patch the version - VERSION=$(npm version patch) - tmp=$(mktemp) - jq ". += {audius: {releaseSHA: \"${GIT_TAG}\"}}" package.json > "$tmp" \ - && mv "$tmp" package.json - - # Build project - npm i - npm run build - - # Publishing dry run, prior to pushing a branch - npm publish . --access public --dry-run + ( + # Configure git client + git config --global user.email "audius-infra@audius.co" + git config --global user.name "audius-infra" - # Commit to a new branch - git checkout -b ${STUB}-${VERSION} - git add . - git commit -m "$(commit-message)" + # Make sure master is up to date + git checkout master -f + git pull - # Push branch to remote - git push -u origin ${STUB}-${VERSION} + if [[ "${GIT_TAG}" == "master" ]]; then + echo "Commit cannot be 'master'." + exit 1 + fi + + # only allow tags/commits found on master, release branches, or tags to be deployed + git branch -a --contains ${GIT_TAG} \ + | tee /dev/tty \ + | grep -Eq 'remotes/origin/master|remotes/origin/release' \ + || echo "tag not found on master nor release branches" \ + && exit 1 + + # Ensure working directory clean + git reset --hard ${GIT_TAG} + + # grab change log early, before the version bump + LAST_RELEASED_SHA=$(jq -r '.audius.releaseSHA' package.json) + CHANGE_LOG=$(git-changelog ${LAST_RELEASED_SHA}) + + # Patch the version + VERSION=$(npm version patch) + tmp=$(mktemp) + jq ". += {audius: {releaseSHA: \"${GIT_TAG}\"}}" package.json > "$tmp" \ + && mv "$tmp" package.json + + # Build project + npm i + npm run build + + # Publishing dry run, prior to pushing a branch + npm publish . --access public --dry-run + + # Commit to a new branch + git checkout -b ${STUB}-${VERSION} + git add . + git commit -m "$(commit-message)" + + # Push branch to remote + git push -u origin ${STUB}-${VERSION} + ) } # Merge the created branch into master, then delete the branch