2
0

pre_release.sh 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #!/bin/bash
  2. # Copyright The OpenTelemetry Authors
  3. # SPDX-License-Identifier: Apache-2.0
  4. set -e
  5. usage() { echo "Usage: $0 -t <tag>" 1>&2; exit 1; }
  6. while getopts ":t:" o; do
  7. case "${o}" in
  8. t)
  9. tag=${OPTARG}
  10. ;;
  11. *)
  12. usage
  13. ;;
  14. esac
  15. done
  16. if [ ! -z "${t}" ]; then
  17. usage
  18. fi
  19. #validate tag
  20. semver_regex="^(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)(\\-[0-9A-Za-z-]+(\\.[0-9A-Za-z-]+)*)?(\\+[0-9A-Za-z-]+(\\.[0-9A-Za-z-]+)*)?$"
  21. if [[ ${tag} =~ ${semver_regex} ]]; then
  22. echo "${tag} is valid semver tag"
  23. else
  24. echo "Error: ${tag} is not a valid semver tag. Exiting"
  25. exit 1
  26. fi
  27. #ensure tag doesn't exits
  28. if [[ $(git tag --list ${tag}) ]]; then
  29. echo "Error: Tag ${tag} already exists. Exiting"
  30. exit 1
  31. fi
  32. if ! git diff --quiet; then \
  33. echo "Error: Working tree is not clean, can't proceed with the release process\n"
  34. git status
  35. git diff
  36. exit 1
  37. fi
  38. # check changelog exists
  39. changelog_file="./CHANGELOG.md"
  40. if [ ! -f $changelog_file ]; then
  41. echo "Error: $changelog_file doesn't exist. Ensure that you are running this script from repo root directory "
  42. exit 1
  43. fi
  44. if ! grep -q "^\#\# \[Unreleased\]$" "$changelog_file" ; then
  45. echo "Error: $changelog_file doesn't contain Unreleased information. Please update the file with changes and run this script again."
  46. exit 1
  47. fi
  48. git checkout -b pre_release_${tag} main
  49. if [ $? -ne 0 ]; then
  50. echo "Error: Cannot create release branch. Ensure you have sufficient permissions to repo and try again."
  51. exit 1
  52. fi
  53. # update CHANGELOG.md
  54. date=$(date '+%Y-%m-%d')
  55. sed -i "/\#\# \[Unreleased\]/a\\ \n\#\# \[${tag}\] ${date}" $changelog_file
  56. if [ $? -ne 0 ]; then
  57. echo "Error: Cannot update CHANGELOG.md file. Update it manually, create the ${tag} and push changes to upstream"
  58. exit 1
  59. fi
  60. git add CHANGELOG.md
  61. git commit -m "Prepare for releasing ${tag}"
  62. echo "Now validate the changes using git diff main, create the ${tag} and push changes to upstream"
  63. echo