tagger.sh 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. # #BASH library
  2. #
  3. # Tags are generated by searching for a keyword in last commit message. Keywords are:
  4. # - [patch] or [fix] to bump patch number
  5. # - [minor], [feature] or [feat] to bump minor number
  6. # - [major] or [breaking change] to bump major number
  7. # All keywords MUST be surrounded with square braces.
  8. #
  9. # Requirements:
  10. # - GITHUB_TOKEN variable set with GitHub token. Access level: repo.public_repo
  11. # - git-semver python package (pip install git-semver)
  12. #
  13. # Original script is available at https://github.com/paulfantom/travis-helper/blob/master/releasing/releaser.sh
  14. #
  15. # Copyright: SPDX-License-Identifier: GPL-3.0-or-later
  16. #
  17. # Author : Pawel Krupa (paulfantom)
  18. # Author : Pavlos Emm. Katsoulakis (paul@netdata.cloud)
  19. # Figure out what will be new release candidate tag based only on previous ones.
  20. # This assumes that RELEASES are in format of "v0.1.2" and prereleases (RCs) are using "v0.1.2-rc0"
  21. function set_tag_release_candidate() {
  22. LAST_TAG=$(git semver)
  23. echo "${0}: Last tag found is: ${LAST_TAG}"
  24. if [[ $LAST_TAG =~ -rc* ]]; then
  25. VERSION=$(echo "$LAST_TAG" | cut -d'-' -f 1)
  26. LAST_RC=$(echo "$LAST_TAG" | cut -d'c' -f 2)
  27. RC=$((LAST_RC + 1))
  28. else
  29. VERSION="$(git semver --next-minor)"
  30. RC=0
  31. echo "${0}: Warning: Will set version to ${VERSION} (Last tag: ${LAST_TAG}) while tagged for release candidate generation"
  32. fi
  33. GIT_TAG="v${VERSION}-rc${RC}"
  34. echo "${0}: Generated a new tag, set to: (${GIT_TAG})"
  35. }
  36. function set_tag_for_release() {
  37. echo "${0}: Checking for tag existence"
  38. if [ -z "${GIT_TAG}" ]; then
  39. echo "${0}: No tag was found, generating a new tag"
  40. git semver
  41. echo "${0}: Last commit message: ${TRAVIS_COMMIT_MESSAGE}"
  42. # Figure out next tag based on commit message
  43. case "${TRAVIS_COMMIT_MESSAGE}" in
  44. *"[netdata patch release]"*) GIT_TAG="v$(git semver --next-patch)" ;;
  45. *"[netdata minor release]"*) GIT_TAG="v$(git semver --next-minor)" ;;
  46. *"[netdata major release]"*) GIT_TAG="v$(git semver --next-major)" ;;
  47. *"[netdata release candidate]"*) set_tag_release_candidate ;;
  48. *)
  49. echo "${0}: Keyword not detected. Nothing to set for GIT_TAG"
  50. ;;
  51. esac
  52. else
  53. echo "${0}: We seem to already have a GIT_TAG set to (${GIT_TAG})"
  54. fi
  55. }