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-filestore-csi-driver"
32
+ releases=(
33
+ " 1.6.10"
34
+ " 1.5.15"
35
+ )
36
+
37
+ function gen_patch_relnotes() {
38
+ rm out.md || true
39
+ rm -rf /tmp/k8s-repo || true
40
+ GITHUB_TOKEN=$CSI_RELEASE_TOKEN \
41
+ release-notes --start-rev=$3 --end-rev=$2 --branch=$2 \
42
+ --org=kubernetes-sigs --repo=$1 \
43
+ --required-author=" " --markdown-links --output out.md
44
+ }
45
+
46
+ script_dir=" $( dirname " $( readlink -f " $0 " ) " ) "
47
+ pushd " $script_dir /../CHANGELOG"
48
+
49
+ # Create branch
50
+ git fetch upstream
51
+ git checkout master
52
+ git rebase upstream/master
53
+
54
+ branch=" changelog"
55
+ if [ ` git rev-parse --verify " $branch " 2> /dev/null` ]; then
56
+ git branch -D " $branch "
57
+ fi
58
+ git checkout -b $branch
59
+
60
+ for version in " ${releases[@]} " ; do
61
+ # Parse minor and patch version
62
+ minorPatchPattern=" (^[[:digit:]]+\.[[:digit:]]+)\.([[:digit:]]+)"
63
+ [[ " $version " =~ $minorPatchPattern ]]
64
+ minor=" ${BASH_REMATCH[1]} "
65
+ patch=" ${BASH_REMATCH[2]} "
66
+
67
+ echo $repo $version $minor $patch
68
+ newVer=" v$minor .$patch "
69
+ prevPatch=" $(( $patch - 1 )) "
70
+ prevVer=" v$minor .$prevPatch "
71
+
72
+ # Generate release notes
73
+ gen_patch_relnotes $repo release-$minor $prevVer
74
+ cat > tmp.md << EOF
75
+ # $newVer - Changelog since $prevVer
76
+
77
+ EOF
78
+
79
+ cat out.md >> tmp.md
80
+ echo >> tmp.md
81
+ echo >> tmp.md
82
+
83
+ file=" CHANGELOG-$minor .md"
84
+ cat $file >> tmp.md
85
+ mv tmp.md $file
86
+
87
+ git add -u
88
+ git commit -m " Add changelog for $version "
89
+ done
90
+
91
+ git push -f origin $branch
92
+
93
+ popd
0 commit comments