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