Add npm package autopublish for prereleases
This script is very close to the one used in keep-core and keep-ecdsa,
and will eventually be abstracted out once the commonalities and
differences shake out.
@@ -198,6 +198,50 @@ jobs:
root: /tmp/tbtc
paths:
- contracts
+ publish_npm_package:
+ executor: docker-node
+ steps:
+ - attach_workspace:
+ at: /tmp/tbtc
+ - checkout
+ - run:
+ name: Bump and publish npm package
+ working_directory: ~/project/solidity
+ command: |
+ set -x
+ mkdir -p artifacts
+ cp -r /tmp/tbtc/contracts/* artifacts/
+ name=$(jq --raw-output .name package.json)
+ version=$(jq --raw-output .version package.json)
+ preid=$(echo $version | sed -e s/^.*-\\\([^.]*\\\).*$/\\1/)
+
+ # Find the latest published package version matching this preid.
+ # Note that in jq, we wrap the result in an array and then flatten;
+ # this is because npm show json contains a single string if there
+ # is only one matching version, or an array if there are multiple,
+ # and we want to look at an array always.
+ latest_version=$(npm show -json "$name@^$version" version | jq --raw-output "[.] | flatten | sort | .[-1]")
+ latest_version=${latest_version:-$version}
+ if [ -z $latest_version ]; then
+ echo "Latest version calculation failed. Resolved info:"
+ echo "$name@$version ; preid $preid"
+ exit 1
+ fi
+
+ # Update package.json with the latest published package version matching this
+ # preid to prepare for bumping.
+ echo $(jq -M ".version=\"${latest_version}\"" package.json) > package.json
+
+ # Bump without doing any git work. Versioning is a build-time action for us.
+ # Consider including commit id? Would be +<commit id>.
+ npm version prerelease --preid=$preid --no-git-tag-version
+
+ # Fix resolved dependency versions.
+ npm update
+
+ # Publish to npm.
+ echo //registry.npmjs.org/:_authToken=${NPM_TOKEN} > .npmrc
+ npm publish --access=public
publish_contract_data:
executor: gcp-cli/default
steps:
@@ -256,6 +300,13 @@ workflows:
context: keep-dev
requires:
- compile_contracts
+ - publish_npm_package:
+ filters:
+ branches:
+ only: master
+ context: keep-dev
+ requires:
+ - migrate_contracts
- publish_contract_data:
filters:
branches:
@@ -289,6 +340,15 @@ workflows:
context: keep-test
requires:
- compile_contracts
+ - publish_npm_package:
+ filters:
+ tags:
+ only: /^v.*/
+ branches:
+ ignore: /.*/
+ context: keep-test
+ requires:
+ - migrate_contracts
- publish_contract_data:
filters:
tags:
