blob: e09924b770e07acb9e7c6fd05c38044b6c20681f [file] [log] [blame]
Joey Armstrong5f51f2e2023-01-17 17:06:26 -05001#!/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
17set -e
18
19help()
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
27while getopts "t:" opt
28do
29 case "$opt" in
30 t ) TAG="$OPTARG" ;;
31 ? ) help ;; # Print help
32 esac
33done
34
35# Print help in case parameters are empty
36if [ -z "$TAG" ]
37then
38 printf "Tag is missing\n";
39 help
40fi
41
42# Validate semver
43SEMVER_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-]+)*)?$"
44if [[ "${TAG}" =~ ${SEMVER_REGEX} ]]; then
45 printf "${TAG} is valid semver tag.\n"
46else
47 printf "${TAG} is not a valid semver tag.\n"
48 exit -1
49fi
50
51TAG_FOUND=`git tag --list ${TAG}`
52if [[ ${TAG_FOUND} = ${TAG} ]] ; then
53 printf "Tag ${TAG} already exists\n"
54 exit -1
55fi
56
57# Get version for sdk/opentelemetry.go
58OTEL_VERSION=$(echo "${TAG}" | grep -o '^v[0-9]\+\.[0-9]\+\.[0-9]\+')
59# Strip leading v
60OTEL_VERSION="${OTEL_VERSION#v}"
61
62cd $(dirname $0)
63
64if ! 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
69fi
70
71# Update sdk/opentelemetry.go
72cp ./sdk/opentelemetry.go ./sdk/opentelemetry.go.bak
73sed "s/\(return \"\)[0-9]*\.[0-9]*\.[0-9]*\"/\1${OTEL_VERSION}\"/" ./sdk/opentelemetry.go.bak >./sdk/opentelemetry.go
74rm -f ./sdk/opentelemetry.go.bak
75
76# Update go.mod
77git checkout -b pre_release_${TAG} master
78PACKAGE_DIRS=$(find . -mindepth 2 -type f -name 'go.mod' -exec dirname {} \; | egrep -v 'tools' | sed 's/^\.\///' | sort)
79
80for 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"
84done
85
86# Run lint to update go.sum
87make lint
88
89# Add changes and commit.
90git add .
91make ci
92git commit -m "Prepare for releasing $TAG"
93
94printf "Now run following to verify the changes.\ngit diff master\n"
95printf "\nThen push the changes to upstream\n"