Skip to content

Commit a15e507

Browse files
rghetiajmacd
andauthoredMar 21, 2020
Scripts for releasing. (#576)
* Scripts for releasing. - fixes #510 * fix review comments. Co-authored-by: Joshua MacDonald <jmacd@users.noreply.github.com>
1 parent 7623fc5 commit a15e507

File tree

3 files changed

+175
-0
lines changed

3 files changed

+175
-0
lines changed
 

‎RELEASING.md

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Release Process
2+
3+
## Pre-Release
4+
Update go.mod for submodules to depend on the new release which will happen
5+
in the next step. This will create build failure for those who depend
6+
on the master branch instead or released version. But they shouldn't be
7+
depending on the master. So it is not a concern.
8+
9+
1. Run the pre-release script. It creates a branch pre_release_<tag> to make the changes.
10+
2. Verify the changes.
11+
3. Push the changes to upstream.
12+
4. Create a PR on github and merge the PR once approved.
13+
14+
```
15+
./pre-release.sh -t <new tag>
16+
git diff master
17+
git push
18+
```
19+
20+
21+
## Tag
22+
Now create a new Tag on the commit hash of the changes made in pre-release step.
23+
Use the same tag as used in the pre-release step.
24+
25+
1. Run the tag.sh script.
26+
2. Push tags upstream. Make sure you run this for all sub-modules as well.
27+
28+
```
29+
./tag.sh -t <new tag> -c <commit-hash>
30+
git push upstream <new tag>
31+
git push upstream <submodules-path/new tag>
32+
```
33+
34+
## Release
35+
Now create a release for the new tag on github. tag.sh script generates commit logs since
36+
last release. Use that to draft the new release.

‎pre_release.sh

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#!/bin/sh
2+
3+
set -e
4+
5+
help()
6+
{
7+
printf "\n"
8+
printf "Usage: $0 -t tag\n"
9+
printf "\t-t Unreleased tag. Update all go.mod with this tag.\n"
10+
exit 1 # Exit script after printing help
11+
}
12+
13+
while getopts "t:" opt
14+
do
15+
case "$opt" in
16+
t ) TAG="$OPTARG" ;;
17+
? ) help ;; # Print help
18+
esac
19+
done
20+
21+
# Print help in case parameters are empty
22+
if [ -z "$TAG" ]
23+
then
24+
printf "Tag is missing\n";
25+
help
26+
fi
27+
28+
# Validate semver
29+
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-]+)*)?$"
30+
if [[ "${TAG}" =~ ${SEMVER_REGEX} ]]; then
31+
printf "${TAG} is valid semver tag.\n"
32+
else
33+
printf "${TAG} is not a valid semver tag.\n"
34+
exit -1
35+
fi
36+
37+
TAG_FOUND=`git tag --list ${TAG}`
38+
if [ ${TAG_FOUND} = ${TAG} ] ; then
39+
printf "Tag ${TAG} already exists\n"
40+
exit -1
41+
fi
42+
43+
44+
cd $(dirname $0)
45+
46+
# Update go.mod
47+
git checkout -b pre_release_${TAG} master
48+
PACKAGE_DIRS=$(find . -mindepth 2 -type f -name 'go.mod' -exec dirname {} \; | egrep -v 'tools' | sed 's/^\.\///' | sort)
49+
50+
for dir in $PACKAGE_DIRS; do
51+
sed -i .bak "s/opentelemetry.io\/otel\([^ ]*\) v[0-9]*\.[0-9]*\.[0-9]/opentelemetry.io\/otel\1 ${TAG}/" ${dir}/go.mod
52+
rm -f ${dir}/go.mod.bak
53+
done
54+
55+
# Run lint to update go.sum
56+
make lint
57+
58+
# Add changes and commit.
59+
git add .
60+
make ci
61+
git commit -m "Prepare for releasing $TAG"
62+
63+
printf "Now run following to verify the changes.\ngit diff master\n"
64+
printf "\nThen push the changes to upstream\n"

‎tag.sh

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
help()
6+
{
7+
printf "\n"
8+
printf "Usage: $0 -t tag -c commit-hash\n"
9+
printf "\t-t New tag that you would like to create\n"
10+
printf "\t-c Commit hash to associate with the new tag\n"
11+
exit 1 # Exit script after printing help
12+
}
13+
14+
while getopts "t:c:" opt
15+
do
16+
case "$opt" in
17+
t ) TAG="$OPTARG" ;;
18+
c ) COMMIT_HASH="$OPTARG" ;;
19+
? ) help ;; # Print help
20+
esac
21+
done
22+
23+
# Print help in case parameters are empty
24+
if [ -z "$TAG" ] || [ -z "${COMMIT_HASH}" ]
25+
then
26+
printf "Some or all of the parameters are missing\n";
27+
help
28+
fi
29+
30+
# Validate semver
31+
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-]+)*)?$"
32+
33+
34+
if [[ "${TAG}" =~ ${SEMVER_REGEX} ]]; then
35+
printf "${TAG} is valid semver tag.\n"
36+
else
37+
printf "${TAG} is not a valid semver tag.\n"
38+
exit -1
39+
fi
40+
41+
cd $(dirname $0)
42+
43+
# Check if the commit-hash is valid
44+
COMMIT_FOUND=`git log -50 --pretty=format:"%H" | grep ${COMMIT_HASH}`
45+
if [ "${COMMIT_FOUND}" != "${COMMIT_HASH}" ] ; then
46+
printf "Commit ${COMMIT_HASH} not found\n"
47+
exit -1
48+
fi
49+
50+
# Check if the tag doesn't alread exists.
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+
# Save most recent tag for generating logs
58+
TAG_CURRENT=`git tag | grep '^v' | tail -1`
59+
60+
PACKAGE_DIRS=$(find . -mindepth 2 -type f -name 'go.mod' -exec dirname {} \; | egrep -v 'tools' | sed 's/^\.\///' | sort)
61+
62+
# Create tag for root module
63+
git tag -a "${TAG}" -m "Version ${TAG}" ${COMMIT_HASH}
64+
65+
# Create tag for submodules
66+
for dir in $PACKAGE_DIRS; do
67+
git tag -a "${dir}/${TAG}" -m "Version ${dir}/${TAG}" ${COMMIT_HASH}
68+
done
69+
70+
# Generate commit logs
71+
printf "New tag ${TAG} created.\n"
72+
printf "\n\n\nChange log since previous tag ${TAG_CURRENT}\n"
73+
printf "======================================\n"
74+
git --no-pager log --pretty=oneline ${TAG_CURRENT}..${TAG}
75+

0 commit comments

Comments
 (0)
Please sign in to comment.