Skip to content

Instantly share code, notes, and snippets.

@rayrutjes
Created November 13, 2017 15:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rayrutjes/8b73a104f2121e669e03777d9978e8aa to your computer and use it in GitHub Desktop.
Save rayrutjes/8b73a104f2121e669e03777d9978e8aa to your computer and use it in GitHub Desktop.
Example of publishing script.
#!/bin/bash
set -eu
readonly CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
if [ "$CURRENT_BRANCH" != master ]; then
echo "You must be on 'master' branch to publish a release, aborting..."
exit 1
fi
if ! git diff-index --quiet HEAD --; then
echo "Working tree is not clean, aborting..."
exit 1
fi
if ! yarn; then
echo "Failed to install yarn dependencies, aborting..."
exit 1
fi
if ! yarn test; then
echo "Tests failed, aborting..."
exit 1
fi
readonly PACKAGE_VERSION=$(< package.json grep version \
| head -1 \
| awk -F: '{ print $2 }' \
| sed 's/[",]//g' \
| tr -d '[:space:]')
npm publish
git tag "v$PACKAGE_VERSION"
git push --tags
echo "Pushed package to npm, and also pushed 'v$PACKAGE_VERSION' tag to git repository."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment