grafana/scripts/publish-npm-packages.sh
Jack Westbrook efa641040d
Build: Improve NPM publishing (#65171)
* chore(packages): remove redundant npm scripts for publishing packages

* feat(packages): rewrite npm publishing script to work for manual and ci publishes

* ci(drone): update release-canary-npm-packages step to use new script

* docs(packages): update manual release instructions

* wip(packages): attempt to validate packed npm package

* fix(packages): release-canary-npm-packages should provide canary dist-tag

* ci(packages): clean up npm package validation script

* chore(devenv): add verdaccio config to allow anon publishing for easier dev npm testing

* ci(packages): clean up publishing script

* ci(drone): during build-frontend-packages, pack and validate packed tarballs

* chore(codeowners): update for publish/validate npm packages scripts

* ci(packages): fix esm loop bug matching e2e package

* ci(npm-packages): fix failing regex

* style(lib.star): run make format-drone

* style(npm-packages): shellcheck fixes for validate-npm-packages script

* docs(packages): update readme instructions for publishing locally and manually

* refactor(npm-publish): use drone when to trigger canary releases

* chore(drone): remove redundant trigger_npm_publish var

* chore(npm-publish): remove redundant echo
2023-04-18 10:19:37 +02:00

45 lines
1.1 KiB
Bash
Executable File

#!/bin/bash
# Set default values for dist-tag and registry for local development
# to prevent running this script and accidentally publishing to npm
dist_tag="canary"
registry="http://localhost:4873"
# shellcheck source=./scripts/helpers/exit-if-fail.sh
source "$(dirname "$0")/helpers/exit-if-fail.sh"
if [ -z "$NPM_TOKEN" ]; then
echo "The NPM_TOKEN environment variable does not exist."
exit 1
fi
# Parse command line arguments
while [[ $# -gt 0 ]]; do
key="$1"
case $key in
--dist-tag)
dist_tag="$2"
shift # past argument
shift # past value
;;
--registry)
registry="$2"
shift # past argument
shift # past value
;;
*) # unknown option
echo "Unknown option: $1"
exit 1
;;
esac
done
echo "Starting to release $dist_tag version"
echo "$registry/:_authToken=${NPM_TOKEN}" >> ~/.npmrc
# Loop over .tar files in directory and publish them to npm registry
for file in ./npm-artifacts/*.tgz; do
npm publish "$file" --tag "$dist_tag" --registry "$registry"
done