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