Skip to content

Commit 33d9df8

Browse files
committed
Add script to generate patch release notes
1 parent fcd1e5f commit 33d9df8

File tree

1 file changed

+97
-0
lines changed

1 file changed

+97
-0
lines changed

hack/generate-patch-release-notes.sh

+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
#!/bin/bash
2+
3+
# Usage: generate_patch_release_notes.sh
4+
#
5+
# Generates and creates commits for GCP CSI driver patch release notes.
6+
#
7+
# Required environment variables:
8+
# CSI_RELEASE_TOKEN: Github token needed for generating release notes
9+
#
10+
# Prerequisites:
11+
# - This script creates and deletes the origin/changelog branch in your git
12+
# workspace. Make sure you are not using the branch for anything else.
13+
#
14+
# Instructions:
15+
# 1. Update the versions in the $releases array
16+
# 2. Set environment variables
17+
# 3. Run the script
18+
# 4. The script pushes the commits to your origin/changelog branch
19+
# 5. Make any modifications as needed
20+
# 6. Create a PR
21+
#
22+
# Caveats:
23+
# - This script doesn't handle regenerating and updating existing branches.
24+
# - The "--start-rev" option in the release-notes generator is inclusive, which
25+
# causes the last commit from the last patch to show up in the release notes (if
26+
# there was a release note). This needs to be manually modified until a solution is found.
27+
28+
set -e
29+
set -x
30+
31+
repo="gcp-compute-persistent-disk-csi-driver"
32+
releases=(
33+
"1.12.5"
34+
"1.11.7"
35+
"1.10.12"
36+
"1.9.14"
37+
"1.8.18"
38+
"1.7.19"
39+
)
40+
41+
function gen_patch_relnotes() {
42+
rm out.md || true
43+
rm -rf /tmp/k8s-repo || true
44+
GITHUB_TOKEN=$CSI_RELEASE_TOKEN \
45+
release-notes --start-rev=$3 --end-rev=$2 --branch=$2 \
46+
--org=kubernetes-sigs --repo=$1 \
47+
--required-author="" --markdown-links --output out.md
48+
}
49+
50+
script_dir="$(dirname "$(readlink -f "$0")")"
51+
pushd "$script_dir/../CHANGELOG"
52+
53+
# Create branch
54+
git fetch upstream
55+
git checkout master
56+
git rebase upstream/master
57+
58+
branch="changelog"
59+
if [ `git rev-parse --verify "$branch" 2>/dev/null` ]; then
60+
git branch -D "$branch"
61+
fi
62+
git checkout -b $branch
63+
64+
for version in "${releases[@]}"; do
65+
# Parse minor and patch version
66+
minorPatchPattern="(^[[:digit:]]+\.[[:digit:]]+)\.([[:digit:]]+)"
67+
[[ "$version" =~ $minorPatchPattern ]]
68+
minor="${BASH_REMATCH[1]}"
69+
patch="${BASH_REMATCH[2]}"
70+
71+
echo $repo $version $minor $patch
72+
newVer="v$minor.$patch"
73+
prevPatch="$(($patch-1))"
74+
prevVer="v$minor.$prevPatch"
75+
76+
# Generate release notes
77+
gen_patch_relnotes $repo release-$minor $prevVer
78+
cat > tmp.md <<EOF
79+
# $newVer - Changelog since $prevVer
80+
81+
EOF
82+
83+
cat out.md >> tmp.md
84+
echo >> tmp.md
85+
echo >> tmp.md
86+
87+
file="CHANGELOG-$minor.md"
88+
cat $file >> tmp.md
89+
mv tmp.md $file
90+
91+
git add -u
92+
git commit -m "Add changelog for $version"
93+
done
94+
95+
git push -f origin $branch
96+
97+
popd

0 commit comments

Comments
 (0)