Skip to content

Commit

Permalink
Move publish.sh to a separate script
Browse files Browse the repository at this point in the history
  • Loading branch information
robhogan authored Sep 20, 2023
1 parent 3de81b4 commit 077c7c6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 20 deletions.
21 changes: 1 addition & 20 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,26 +110,7 @@ jobs:
- checkout
- yarn_install
- run: echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
- run:
name: Publish based on tag conditions
command: |
# Reduce a semver tag name to a Metro's release branch naming convention, eg v0.1.2-alpha.3 -> 0.1.x
RELEASE_BRANCH=$(echo "$CIRCLE_TAG" | awk -F. '{print substr($1, 2) "." $2 ".x"}')
echo "Release branch: $RELEASE_BRANCH"
# Does a release branch contain this tag (hotfix workflow) (0 or 1)
TAG_ON_RELEASE_BRANCH=$(git branch -a --contains "$CIRCLE_TAG" | grep -cFx " remotes/origin/$RELEASE_BRANCH" || true)
echo "Tag is on release branch $RELEASE_BRANCH: $TAG_ON_RELEASE_BRANCH"
# Does main contain this tag (0 or 1)
TAG_ON_MAIN=$(git branch -a --contains "$CIRCLE_TAG" | grep -cFx ' remotes/origin/main' || true)
echo "Tag is on main branch: $TAG_ON_MAIN"
if [ $TAG_ON_RELEASE_BRANCH -eq $TAG_ON_MAIN ]; then
echo "Could not determine whether this tag is 'latest' or a hotfix. Aborting."
exit 1
fi
TAG="latest"
[ "$TAG_ON_RELEASE_BRANCH" -eq 1 ] && TAG=$RELEASE_BRANCH
echo "Using --tag=$TAG"
npm run publish --tag="$TAG"
- run: ./.circleci/scripts/publish.sh
- run: rm ~/.npmrc

workflows:
Expand Down
24 changes: 24 additions & 0 deletions .circleci/scripts/publish.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/sh -eo -pipefail

# Reduce a semver tag name to a Metro's release branch naming convention, eg v0.1.2-alpha.3 -> 0.1.x
RELEASE_BRANCH=$(echo "$CIRCLE_TAG" | awk -F. '{print substr($1, 2) "." $2 ".x"}')
echo "Release branch: $RELEASE_BRANCH"

# Does a release branch contain this tag (hotfix workflow) (0 or 1)
TAG_ON_RELEASE_BRANCH=$(git branch -a --contains "$CIRCLE_TAG" | grep -cFx " remotes/origin/$RELEASE_BRANCH" || true)
echo "Tag is on release branch $RELEASE_BRANCH: $TAG_ON_RELEASE_BRANCH"

# Does main contain this tag (0 or 1)
TAG_ON_MAIN=$(git branch -a --contains "$CIRCLE_TAG" | grep -cFx ' remotes/origin/main' || true)
echo "Tag is on main branch: $TAG_ON_MAIN"

if [ $TAG_ON_RELEASE_BRANCH -eq $TAG_ON_MAIN ]; then
echo "Could not determine whether this tag is 'latest' or a hotfix. Aborting."
exit 1
fi

TAG="latest"
[ "$TAG_ON_RELEASE_BRANCH" -eq 1 ] && TAG=$RELEASE_BRANCH
echo "Using --tag=$TAG"

npm run publish --tag="$TAG"

0 comments on commit 077c7c6

Please sign in to comment.