diff --git a/.circleci/config.yml b/.circleci/config.yml index b9aaeb3ead3..8def7aa4197 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -107,6 +107,24 @@ jobs: --source-disk-zone="$GOOGLE_COMPUTE_ZONE" \ --storage-location=us + publish-libs: + docker: + - image: circleci/node:14.17.5 + resource_class: xlarge + steps: + - checkout + - diff-if-necessary: + service: libs + - setup_remote_docker + - add_ssh_keys: + fingerprints: + - "ee:b0:fd:fb:ba:c8:37:7a:f9:67:15:92:9f:02:97:3e" + - run: + name: Bump and Publish Libs + command: | + export PROTOCOL_DIR=/home/circleci/project + libs/scripts/release.sh + test-mad-dog-e2e: parameters: mad-dog-type: @@ -812,6 +830,18 @@ workflows: filters: branches: only: /(^master$)/ + - hold-publish-libs: + type: approval + filters: + branches: + only: /(^master$)/ + - publish-libs: + name: publish-libs + requires: + - hold-publish-libs + filters: + branches: + only: /(^master$)/ # test master at midnight daily test-nightly: diff --git a/libs/scripts/release.sh b/libs/scripts/release.sh new file mode 100755 index 00000000000..8953fc4b229 --- /dev/null +++ b/libs/scripts/release.sh @@ -0,0 +1,90 @@ +#!/usr/bin/env bash + +# ONLY TO BE RUN ON MASTER +# master is assumed when using -f and --hard git parameters + +set -ex + +# Finds the lastest commit that looks like a version commit, +# and gets the list of commits after that +function git-changelog () { + # Find the latest release commit by using the last time the first `version` key changed + version_line_number=$(grep -m 1 -n version package.json | cut -d: -f 1) + release_commit=$(git blame -L ${version_line_number},+1 --porcelain -- package.json | awk 'NR==1{ print $1 }') + + # Print the log as "- [] " + git log --pretty=format:"- %cd [%h] %s [%an]" --date=short $release_commit..HEAD +} + +# formats a commit message using the bumped ${VERSION} and ${CHANGE_LOG} +function commit-message () { + echo "Bump ${STUB} to ${VERSION} + +## Changelog + +${CHANGE_LOG}" +} + +# Make a new branch off the master branch, 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 + + # Ensure working directory clean + git reset --hard origin/master + + # grab change log early, before the version bump + CHANGE_LOG=$(git-changelog) + + # Patch the version + VERSION=$(npm version patch) + + # 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, and tag + git checkout -b ${STUB}-${VERSION} + git add . + git commit -m "$(commit-message)" + git tag -a @audius/${STUB}@${VERSION} -m "$(commit-message)" + + # Push branch and tags to remote + git push -u origin ${STUB}-${VERSION} + git push origin --tags +} + +# Merge the created branch into master, then delete the branch +function merge-bump () { + git checkout master -f + git merge ${STUB}-${VERSION} -m "$(commit-message)" + + # git push -u origin master + + # clean up release branches + # git push origin :${STUB}-${VERSION} +} + +# publish to npm +function publish () { + echo + # npm publish . --access public +} + +# configuration +STUB=sdk +cd ${PROTOCOL_DIR}/libs + +# perform release +bump-npm +merge-bump +publish