tagger.sh 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #!/bin/bash
  2. #
  3. # Original script is available at https://github.com/paulfantom/travis-helper/blob/master/releasing/releaser.sh
  4. #
  5. # Tags are generated by searching for a keyword in last commit message. Keywords are:
  6. # - [patch] or [fix] to bump patch number
  7. # - [minor], [feature] or [feat] to bump minor number
  8. # - [major] or [breaking change] to bump major number
  9. # All keywords MUST be surrounded with square braces.
  10. #
  11. # Requirements:
  12. # - GITHUB_TOKEN variable set with GitHub token. Access level: repo.public_repo
  13. # - git-semver python package (pip install git-semver)
  14. #
  15. # Note: Exported variables needed by .travis/draft_release.sh
  16. #
  17. # Original script is available at https://github.com/paulfantom/travis-helper/blob/master/releasing/releaser.sh
  18. #
  19. # Copyright: SPDX-License-Identifier: GPL-3.0-or-later
  20. #
  21. # Author : Pawel Krupa (paulfantom)
  22. # Author : Pavlos Emm. Katsoulakis (paul@netdata.cloud)
  23. set -e
  24. # If we are not in netdata git repo, at the top level directory, fail
  25. TOP_LEVEL=$(basename "$(git rev-parse --show-toplevel)")
  26. CWD=$(git rev-parse --show-cdup || echo "")
  27. if [ -n "${CWD}" ] || [ ! "${TOP_LEVEL}" == "netdata" ]; then
  28. echo "Run as .travis/$(basename "$0") from top level directory of netdata git repository"
  29. echo "Changelog generation process aborted"
  30. exit 1
  31. fi
  32. # Figure out what will be new release candidate tag based only on previous ones.
  33. # This assumes that RELEASES are in format of "v0.1.2" and prereleases (RCs) are using "v0.1.2-rc0"
  34. function set_tag_release_candidate() {
  35. LAST_TAG=$(git semver)
  36. echo "Last tag found is: ${LAST_TAG}"
  37. if [[ $LAST_TAG =~ -rc* ]]; then
  38. VERSION=$(echo "$LAST_TAG" | cut -d'-' -f 1)
  39. LAST_RC=$(echo "$LAST_TAG" | cut -d'c' -f 2)
  40. RC=$((LAST_RC + 1))
  41. else
  42. VERSION="$(git semver --next-minor)"
  43. RC=0
  44. echo "Warning: Will set version to ${VERSION} (Last tag: ${LAST_TAG}) while tagged for release candidate generation"
  45. fi
  46. GIT_TAG="v${VERSION}-rc${RC}"
  47. }
  48. echo "Determining TAG"
  49. # Check if current commit is tagged or not
  50. GIT_TAG=$(git tag --points-at)
  51. if [ -z "${GIT_TAG}" ]; then
  52. git semver
  53. # Figure out next tag based on commit message
  54. echo "Last commit message: ${TRAVIS_COMMIT_MESSAGE}"
  55. case "${TRAVIS_COMMIT_MESSAGE}" in
  56. *"[netdata patch release]"*) GIT_TAG="v$(git semver --next-patch)" ;;
  57. *"[netdata minor release]"*) GIT_TAG="v$(git semver --next-minor)" ;;
  58. *"[netdata major release]"*) GIT_TAG="v$(git semver --next-major)" ;;
  59. *"[netdata release candidate]"*) set_tag_release_candidate ;;
  60. *)
  61. echo "Keyword not detected. Exiting..."
  62. exit 0
  63. ;;
  64. esac
  65. fi
  66. echo "Setting up GIT_TAG to ${GIT_TAG}"
  67. export GIT_TAG