Created
August 8, 2016 14:12
-
-
Save sixertoy/e64fd426644ea36a693b0126d70d6108 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# Check if there's some unstaged/uncommitted changes | |
if [ -n "$(git status --porcelain)" ]; then | |
echo "[\033[1;31mPlease commit your changes before upgrading application version.\033[m"; | |
exit 1; | |
fi | |
# npm version (major|minor|patch|premajor|preminor|prepatch|prerelease) | |
# @see https://docs.npmjs.com/cli/version | |
SEMVER_TYPE=$2 | |
# current package version | |
CURRENT_PACKAGE_VERSION=$1 | |
# if semver version is not defined | |
if [ -z $SEMVER_TYPE ]; then | |
echo '[\033[1;31mMissing semver type argument.\033[m' | |
exit 1; | |
fi | |
# --------------------- | |
# | |
# Update Application version | |
# Using `npm version` command | |
# | |
NEW_PACKAGE_VERSION=$(npm version $SEMVER_TYPE) | |
# get new package version | |
NEW_PACKAGE_VERSION=v$(echo $NEW_PACKAGE_VERSION | cut -c 2-) | |
# --------------------- | |
# | |
# Generate Changelogs since last version | |
# Output in a Markdown file | |
# | |
FILENAME=changelogs/release_$NEW_PACKAGE_VERSION.md | |
# Using git log to write content | |
git --no-pager log --reverse --pretty=format:' | |
[**%h**](http://github.com/<account>/<project>/commit/%H) | |
*%ad* | |
%B | |
' v$CURRENT_PACKAGE_VERSION.. > $FILENAME | |
# prepend title and version numver | |
echo "### Changelogs v$CURRENT_PACKAGE_VERSION \n$(cat $FILENAME)" >$FILENAME | |
# amend changes to current version commit | |
git add -A . | |
git commit --amend --no-edit | |
exit 0; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment