Skip to content

Commit

Permalink
feat(dist-tag): add script and instructions to manipulate NPM tags
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfig committed Dec 3, 2021
1 parent 8a2cbe2 commit 241c10a
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 3 deletions.
13 changes: 10 additions & 3 deletions MAINTAINERS.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ Once tests pass, you can publish to NPM with the following:

```sh
# Publish to NPM. NOTE: You may have to repeat this several times if there are failures.
# Specify the --dist-tag if you're publishing a new beta release.
yarn lerna publish from-package # --dist-tag=beta
yarn lerna publish from-package
```

Merge the release PR into master. DO NOT REBASE OR SQUASH OR YOU WILL LOSE
Expand All @@ -42,7 +41,15 @@ REFERENCES TO YOUR TAGS.
./scripts/get-released-tags git push origin
```

To make validators' lives easier, create a tag for the chain-id:
If you want to update an NPM dist-tag for the current checked-out Agoric SDK's
packages (to enable `agoric install <TAG>`), use:

```sh
# Use "beta" for <TAG> for example.
./scripts/npm-dist-tag.sh lerna add <TAG>
```

To make validators' lives easier, create a Git tag for the chain-id:

```sh
CHAIN_ID=agoricstage-8 # Change this as necessary
Expand Down
67 changes: 67 additions & 0 deletions scripts/npm-dist-tag.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#! /bin/bash
# npm-dist-tag.sh - add/remove/list dist-tags for NPM registry packages 
# Try: `npm-dist-tag.sh` for usage.

# Exit on any errors.
set -ueo pipefail

# Check the first argument.
OP=$1
case $OP in
lerna)
# npm-dist-tag.sh lerna [args]...
# Run `npm-dist-tag.sh [args]...` in every package directory.

# Find the absolute path to this script.
thisdir=$(cd "$(dirname -- "${BASH_SOURCE[0]}")" > /dev/null && pwd -P)
thisprog=$(basename -- "${BASH_SOURCE[0]}")

# Strip the first argument (`lerna`), so that `$@` gives us remaining args.
shift
exec npm run -- lerna exec --stream --no-bail "$thisdir/$thisprog" ${1+"$@"}
;;
esac

# If the package.json says it's private, we don't have a published version whose
# tags we can manipulate.
priv=$(jq -r .private package.json)
case "$priv" in
true)
echo 1>&2 "Private package, skipping npm-dist-tag.sh"
exit 0
;;
esac

# Find the package name and version from the package.json.
pkg=$(jq -r .name package.json)
version=$(jq -r .version package.json)
# echo "$OP $pkg@$version"

# Get the second argument, if any.
TAG=$2
case $OP in
add)
# Add <tag> to the current-directory package's dist-tags.
npm dist-tag add "$pkg@$version" "$TAG"
;;
remove | rm)
# npm-dist-tag.sh remove <tag>
# Remove <tag> from the current-directory package's dist-tags.
npm dist-tag rm "$pkg" "$TAG"
;;
list | ls)
# npm-dist-tag.sh list [<tag>]
# List the current-directory package's dist-tags.
# If <tag> is given, list only that tag.
if test -n "$TAG"; then
npm dist-tag ls "$pkg" | sed -ne "s/^$TAG: //p"
else
npm dist-tag ls "$pkg"
fi
;;
*)
# Usage instructions.
echo 1>&2 "Usage: $0 [lerna] <add|remove|list> [<tag>]"
exit 1
;;
esac

0 comments on commit 241c10a

Please sign in to comment.