Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. #! /usr/bin/env bash
  2.  
  3. if [[ -z $2 ]]; then
  4. echo -e "You must pass in a commit message and the project name"
  5. exit
  6. fi
  7.  
  8. if [[ ! -z $3 ]]; then
  9. echo -e "Too many parameters"
  10. exit
  11. fi
  12.  
  13. # IFS is the default separator of white space
  14. # BASH_REMATCH gets the first Regular Express match
  15. function git_branch {
  16. local git_status="$(git status 2> /dev/null)"
  17. local on_branch="On branch ([^${IFS}]*)"
  18. local on_commit="HEAD detached at ([^${IFS}]*)"
  19.  
  20. if [[ $git_status =~ $on_branch ]]; then
  21. local branch=${BASH_REMATCH[1]}
  22. echo "$branch"
  23. elif [[ $git_status =~ $on_commit ]]; then
  24. local commit=${BASH_REMATCH[1]}
  25. echo "$commit"
  26. fi
  27. }
  28.  
  29. OLD_TAG_VERSION=`git tag --sort=taggerdate | tail -1 | sed -En "s/v(.*)/\1/p"`
  30. TAG_VERSION=v`semver-inc -p $OLD_TAG_VERSION`
  31. BRANCH=`git_branch`
  32. TAG_STRING="$1 for $2 on branch `git_branch` with tag ${TAG_VERSION}."
  33. echo $TAG_STRING
  34.  
  35. function push_tag() {
  36. git status
  37. git add .
  38. git commit -m "${TAG_STRING} $NOW"
  39. git push --set-upstream origin ${BRANCH}
  40.  
  41. git tag -a "${TAG_VERSION}" -m "${TAG_STRING}"
  42. git push origin "${TAG_VERSION}"
  43. }
  44.  
  45. push_tag
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement