forked from open-telemetry/opentelemetry-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprepare_release.sh
More file actions
executable file
·88 lines (81 loc) · 2.75 KB
/
prepare_release.sh
File metadata and controls
executable file
·88 lines (81 loc) · 2.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/bin/bash -x
#
# This script:
# 1. parses the version number from the branch name
# 2. updates version.py files to match that version
# 3. iterates through CHANGELOG.md files and updates any files containing
# unreleased changes
# 4. sets the output variable 'version_updated' to determine whether
# the github action to create a pull request should run. this allows
# maintainers to merge changes back into the release branch without
# triggering unnecessary pull requests
#
VERSION=`echo $1 | awk -F "/" '{print $NF}'`
echo "Using version ${VERSION}"
# check the version matches expected versioning e.g
# 0.6, 0.6b, 0.6b0, 0.6.0
if [[ ! "${VERSION}" =~ ^([0-9])(\.*[0-9]{1,5}[a-b]*){1,3}$ ]]; then
echo "Version number invalid: $VERSION"
exit 1
fi
function update_version_file() {
errors=0
for f in `find . -name version.py`; do
# check if version is already in version.py
grep -q ${VERSION} $f;
rc=$?
if [ $rc == 0 ]; then
errors=1
echo "${f} already contains ${VERSION}"
continue
fi
# update version.py
perl -i -pe "s/__version__.*/__version__ = \"${VERSION}\"/g" ${f};
git add ${f};
echo "Updating ${f}"
done
if [ ${errors} != 0 ]; then
echo "::set-output name=version_updated::0"
exit 0
fi
}
function update_changelog() {
errors=0
RELEASE_DATE=`date +%F`
for f in `find . -name CHANGELOG.md`; do
# check if version is already in CHANGELOG
grep -q ${VERSION} $f;
rc=$?
if [ $rc == 0 ]; then
errors=1
echo "${f} already contains ${VERSION}"
continue
fi
# check if changelog contains any new details
changes=`sed -n '/## Unreleased/,/^##/p' ${f} | grep -v '^##' | wc -w | awk '{$1=$1;print}'`
if [ ${changes} != "0" ]; then
# update CHANGELOG.md
perl -i -pe 's/## Unreleased.*/## Unreleased\n\n## '${VERSION}'\n\nReleased '${RELEASE_DATE}'/' ${f};
git add ${f};
echo "Updating ${f}"
else
echo "Skipping ${f}, no changes detected"
fi
done
if [ ${errors} != 0 ]; then
echo "::set-output name=version_updated::0"
exit 0
fi
}
# create the release branch
git checkout master
git reset --hard origin/master
git checkout -b release/${VERSION}
git push origin release/${VERSION}
# create a temporary branch to create a PR for updated version and changelogs
git checkout -b release/${VERSION}-auto
update_version_file
update_changelog
git commit -m "updating changelogs and version to ${VERSION}"
echo "Time to create a release, here's a sample title:"
echo "[pre-release] Update changelogs, version [${VERSION}]"