From 27633f0625f9f705330b1144ff0f7b42d5ab14e0 Mon Sep 17 00:00:00 2001 From: Elliot Date: Thu, 5 Jun 2025 09:22:53 -0500 Subject: [PATCH] add dry-run, npm tags to publish --- README.md | 3 +++ bin/publish.sh | 50 +++++++++++++++++++++++++++++++++++++++++++++----- package.json | 1 + 3 files changed, 49 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 35036a1..0fbc34e 100644 --- a/README.md +++ b/README.md @@ -60,3 +60,6 @@ You will need java installed to run wiremock. ### Running tests To test with coverage run `yarn test:coverage` + +## Publishing +`yarn release` will release the current version. `yarn release:dry-run` can be used to dry-run a release. The npm distribution tag is based on the pre-release semver suffix (1.0.0-ea would) release with the tag `ea`. If no pre-release suffix exists, releases are published with the `latest` tag. diff --git a/bin/publish.sh b/bin/publish.sh index 24bf2ed..5ad0692 100755 --- a/bin/publish.sh +++ b/bin/publish.sh @@ -1,9 +1,49 @@ #!/usr/bin/env bash set -euo pipefail -echo "Running npm publish..." -npm publish +# Default values +dry_run=false -echo "Creating git tag..." -git tag "v${version}" -git push --tags +usage() { + echo "Usage: $0 [-d] [-h]" + echo " -d Perform a dry run without actually publishing or creating git tags" + echo " -h Show this help message" + exit 1 +} + +while getopts ":dh" opt; do + case $opt in + d) + dry_run=true + ;; + h) + usage + ;; + \?) + echo "Invalid option: -$OPTARG" + usage + ;; + esac +done + +version=$(node -p "require('./package.json').version") +if [[ $version == *-* ]]; then + # Extract suffix after the last dash (e.g., "1.0.0-ea" -> "ea") + tag="${version##*-}" +else + # No suffix, use latest tag + tag="latest" +fi + +if [[ "$dry_run" == true ]]; then + npm publish --tag "$tag" --dry-run + + echo "DRY RUN: Skipping git tag and push operations" +else + echo "Publishing version $version with tag '$tag'..." + npm publish --tag "$tag" + + echo "Creating git tag..." + git tag "v${version}" + git push --tags +fi diff --git a/package.json b/package.json index 34b39d6..b83cec7 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,7 @@ "prepack": "tsc -b --clean && tsc -b --force", "bump": "node bin/bump-version.js", "release": "bin/publish.sh", + "release:dry-run": "bin/publish.sh -d", "docs": "typedoc" }, "files": [