Skip to content

add dry-run, npm tags to publish #35

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
50 changes: 45 additions & 5 deletions bin/publish.sh
Original file line number Diff line number Diff line change
@@ -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
Comment on lines +30 to +33
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to modify this to allow prerelease versions: 1.0.0-ea.0. Currently would extract ea.0 as the tag when we want ea.

npm version prerelease --preid=ea
1.0.0 -> 1.0.0-ea.0

# No suffix, use latest tag
tag="latest"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we'll only want to use latest for the latest major version. If we have branches for prior major versions we are still supporting, we wouldn't want to publish those older versions as latest because that would result in users grabbing that older version when they use npm install @heroku/applink

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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
Loading