Skip to content

Instantly share code, notes, and snippets.

@luisliuchao
Last active December 6, 2019 01:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save luisliuchao/07e2f32f7fffd1b11a03d25ea9df8031 to your computer and use it in GitHub Desktop.
Save luisliuchao/07e2f32f7fffd1b11a03d25ea9df8031 to your computer and use it in GitHub Desktop.
Automatically make a release by incrementing the version number in package.json or with a version number supplied
# SK Release
# https://gist.github.com/bclinkinbeard/1331790
#!/bin/bash
# file in which to update version number
versionFile="package.json"
# extract version number from versionFile
# https://gist.github.com/DarrenN/8c6a5b969481725a4413
version=$(cat $versionFile \
| grep version \
| head -1 \
| awk -F: '{ print $2 }' \
| sed 's/[",]//g' \
| tr -d '[[:space:]]')
if [ $1 ]
then
newVersion=$1
else
newVersion=${version%.*}.$((${version##*.}+1))
fi
versionLabel=v${newVersion}
# current Git branch
branch=$(git symbolic-ref HEAD | sed -e 's,.*/\(.*\),\1,')
# establish branch and tag name variables
devBranch=develop
masterBranch=master
releaseBranch=release/$versionLabel
# pull develop and master
git checkout develop;
git pull;
git checkout master;
git pull;
# create the release branch from the -develop branch
git checkout -b $releaseBranch $devBranch
# and replace version number with new version number
sed -i.backup -E "s/$version/$newVersion/" $versionFile $versionFile
# remove backup file created by sed command
rm $versionFile.backup
# commit version number increment
git commit -am "Release $versionLabel"
# merge release branch with the new version number into master
git checkout $masterBranch
git merge --no-ff --no-edit $releaseBranch
# create tag for new version from -master
git tag $versionLabel
# merge release branch with the new version number back into develop
git checkout $devBranch
git merge --no-ff --no-edit $releaseBranch
# remove release branch
git branch -d $releaseBranch
@luisliuchao
Copy link
Author

run sh sk-release.sh
or
run sh sk-releash.sh 1.1.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment