-
-
Save bclinkinbeard/1331790 to your computer and use it in GitHub Desktop.
| #!/bin/bash | |
| # current Git branch | |
| branch=$(git symbolic-ref HEAD | sed -e 's,.*/\(.*\),\1,') | |
| # v1.0.0, v1.5.2, etc. | |
| versionLabel=v$1 | |
| # establish branch and tag name variables | |
| devBranch=develop | |
| masterBranch=master | |
| releaseBranch=release-$versionLabel | |
| # create the release branch from the -develop branch | |
| git checkout -b $releaseBranch $devBranch | |
| # file in which to update version number | |
| versionFile="version.txt" | |
| # find version number assignment ("= v1.5.5" for example) | |
| # and replace it with newly specified version number | |
| sed -i.backup -E "s/\= v[0-9.]+/\= $versionLabel/" $versionFile $versionFile | |
| # remove backup file created by sed command | |
| rm $versionFile.backup | |
| # commit version number increment | |
| git commit -am "Incrementing version number to $versionLabel" | |
| # merge release branch with the new version number into master | |
| git checkout $masterBranch | |
| git merge --no-ff $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 $releaseBranch | |
| # remove release branch | |
| git branch -d $releaseBranch |
This is interesting, do you have an actual project where you use it? I also need to maintain a changelog and docs version, I may implement it this way.
shall i add this script in groovy for pipeline for automatic branch cut and build management????please suggest
These changes , how do i apply to Repo level , Can i use any specific command ? Please advice
Funny that I just stumbled on this @bclinkinbeard - hope all is well man. I just did a google search for exactly what you have in this gist. I'll probably do something very similar to get some basic info into my build-info for docker containers and my react app.
Thanks!
Thank you !
Thank you 👍
@bclinkinbeard - Thanks for this.
what is the purpose of line 4? Doesn't look like it's being used anywhere in the script
"# current Git branch
branch=$(git symbolic-ref HEAD | sed -e 's,./(.),\1,')"
Hi @wisdom-17,
Line 4 is used in order to grab the versionLabel. I agree, the variable 'branch' is never used, but the rest of line 4 is used for line 7.
# current Git branch
branch=$(git symbolic-ref HEAD | sed -e 's,.*/\(.*\),\1,')
# v1.0.0, v1.5.2, etc.
versionLabel=v$1
What is the purpose of the version file? Didn't get it...
Hi @JoneSabino,
A lot of programs out there have one or more files that have the version number in them. For instance, most Unix programs you can run "--version" or "-V" and they will print out the current version. For bclinkinbeard's case, it appears he has this stored in a file named 'version.txt'. This could be convenient for a program to quickly query if needed, but I bet there are a lot of other schemas people use to store the version number (if they do this at all)
Thanks for sharing.
isn't simpler to do
echo "$versionLabel" > $versionFile
instead of
# find version number assignment ("= v1.5.5" for example)
# and replace it with newly specified version number
sed -i.backup -E "s/\= v[0-9.]+/\= $versionLabel/" $versionFile $versionFile
# remove backup file created by sed command
rm $versionFile.backup
Usage from Terminal:
./release.sh 1.0.0
./release.sh 1.5.7
Some things to note: