pre_release.sh 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #!/bin/bash
  2. # Copyright The OpenTelemetry Authors
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. set -e
  16. help()
  17. {
  18. printf "\n"
  19. printf "Usage: $0 -t tag\n"
  20. printf "\t-t Unreleased tag. Update all go.mod with this tag.\n"
  21. exit 1 # Exit script after printing help
  22. }
  23. while getopts "t:" opt
  24. do
  25. case "$opt" in
  26. t ) TAG="$OPTARG" ;;
  27. ? ) help ;; # Print help
  28. esac
  29. done
  30. # Print help in case parameters are empty
  31. if [ -z "$TAG" ]
  32. then
  33. printf "Tag is missing\n";
  34. help
  35. fi
  36. # Validate semver
  37. SEMVER_REGEX="^v(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-]+)*)?$"
  38. if [[ "${TAG}" =~ ${SEMVER_REGEX} ]]; then
  39. printf "${TAG} is valid semver tag.\n"
  40. else
  41. printf "${TAG} is not a valid semver tag.\n"
  42. exit -1
  43. fi
  44. TAG_FOUND=`git tag --list ${TAG}`
  45. if [[ ${TAG_FOUND} = ${TAG} ]] ; then
  46. printf "Tag ${TAG} already exists\n"
  47. exit -1
  48. fi
  49. # Get version for version.go
  50. OTEL_VERSION=$(echo "${TAG}" | grep -o '^v[0-9]\+\.[0-9]\+\.[0-9]\+')
  51. # Strip leading v
  52. OTEL_VERSION="${OTEL_VERSION#v}"
  53. cd $(dirname $0)
  54. if ! git diff --quiet; then \
  55. printf "Working tree is not clean, can't proceed with the release process\n"
  56. git status
  57. git diff
  58. exit 1
  59. fi
  60. # Update version.go
  61. cp ./version.go ./version.go.bak
  62. sed "s/\(return \"\)[0-9]*\.[0-9]*\.[0-9]*\"/\1${OTEL_VERSION}\"/" ./version.go.bak >./version.go
  63. rm -f ./version.go.bak
  64. # Update go.mod
  65. git checkout -b pre_release_${TAG} main
  66. PACKAGE_DIRS=$(find . -mindepth 2 -type f -name 'go.mod' -exec dirname {} \; | egrep -v 'tools' | sed 's/^\.\///' | sort)
  67. for dir in $PACKAGE_DIRS; do
  68. cp "${dir}/go.mod" "${dir}/go.mod.bak"
  69. sed "s/opentelemetry.io\/otel\([^ ]*\) v[0-9]*\.[0-9]*\.[0-9]/opentelemetry.io\/otel\1 ${TAG}/" "${dir}/go.mod.bak" >"${dir}/go.mod"
  70. rm -f "${dir}/go.mod.bak"
  71. done
  72. # Run lint to update go.sum
  73. make lint
  74. # Add changes and commit.
  75. git add .
  76. make ci
  77. git commit -m "Prepare for releasing $TAG"
  78. printf "Now run following to verify the changes.\ngit diff main\n"
  79. printf "\nThen push the changes to upstream\n"