14
14
# See the License for the specific language governing permissions and
15
15
# limitations under the License.
16
16
17
+
17
18
# Update python-base submodule and collect release notes.
18
19
# Usage:
19
- # scripts/update-submodule.sh
20
20
#
21
- # Create a commit "generated python-base update" and send a PR to the main repo.
22
- # NOTE: not all python-base changes are user-facing, and you may want to remove
23
- # some of the non-user-facing release notes from CHANGELOG.md.
21
+ # $ scripts/update-submodule.sh
22
+ #
23
+ # # To update the release notes for a specific release (e.g. v18.17.0a1):
24
+ # $ TARGET_RELEASE="v18.17.0a1" scripts/update-submodule.sh
25
+ #
26
+ # After the script finishes, please create a commit "generated python-base update"
27
+ # and send a PR to this repository.
28
+ # TODO(roycaihw): make the script send a PR
24
29
25
30
set -o errexit
26
31
set -o nounset
@@ -31,58 +36,30 @@ declare -r repo_root
31
36
cd " ${repo_root} "
32
37
33
38
source scripts/util/changelog.sh
39
+ go get k8s.io/release/cmd/release-notes
34
40
35
- # TODO(roycaihw): make the script send a PR by default (standalone mode), and
36
- # have an option to make the script reusable by other release automations.
37
41
TARGET_RELEASE=${TARGET_RELEASE:- " v$( grep " ^CLIENT_VERSION = \" " scripts/constants.py | sed " s/CLIENT_VERSION = \" //g" | sed " s/\" //g" ) " }
38
- SUBMODULE_SECTION=${SUBMODULE_SECTION:- " \*\*Submodule Change:\*\*" }
39
42
40
43
# update submodule
41
44
git submodule update --remote
42
- pulls=$( git diff --submodule | egrep -o " ^ > Merge pull request #[0-9]+" | sed ' s/ > Merge pull request #//g' )
43
45
44
46
# download release notes
45
- release_notes=" "
46
- submodule_repo=" kubernetes-client/python-base"
47
- echo " Downloading release notes from submodule repo."
48
- for pull in ${pulls} ; do
49
- pull_url=" https://github.com/$submodule_repo /pull/${pull} "
50
- echo " +++ Downloading python-base patch to /tmp/${pull} .patch"
51
- curl -o " /tmp/${pull} .patch" -sSL " ${pull_url} .patch"
52
- subject=$( grep -m 1 " ^Subject" " /tmp/${pull} .patch" | sed -e ' s/Subject: \[PATCH//g' | sed ' s/.*] //' )
53
- pull_uid=" $submodule_repo #${pull} "
54
- release_note=" - ${subject} [${pull_uid} ](${pull_url} )\n"
55
- release_notes+=${release_note}
56
- # remove the patch file from /tmp
57
- rm -f " /tmp/${pull} .patch"
58
- done
59
-
60
- # find the place in the changelog that we want to edit
61
- line_to_edit=" 1"
62
- if util::changelog::has_release $TARGET_RELEASE ; then
63
- # the target release exists
64
- release_first_line=$( util::changelog::find_release_start $TARGET_RELEASE )
65
- release_last_line=$( util::changelog::find_release_end $TARGET_RELEASE )
66
- if util::changelog::has_section_in_range " $SUBMODULE_SECTION " " $release_first_line " " $release_last_line " ; then
67
- # prepend to existing section
68
- line_to_edit=$(( $(util:: changelog:: find_section_in_range "$SUBMODULE_SECTION " "$release_first_line " "$release_last_line ")+ 1 ))
69
- release_notes=${release_notes::- 2}
70
- else
71
- # add a new section
72
- line_to_edit=$(( $(util:: changelog:: find_release_start $TARGET_RELEASE )+ 4 ))
73
- release_notes=" $SUBMODULE_SECTION \n$release_notes "
74
- fi
75
- else
76
- # add a new release
77
- # TODO(roycaihw): ideally a parent script updates the generated client and
78
- # fills in the Kubernetes API Version based on the OpenAPI spec.
79
- release_notes=" # $TARGET_RELEASE \n\nKubernetes API Version: TBD\n\n$SUBMODULE_SECTION \n$release_notes "
80
- fi
81
-
82
- echo " Writing the following release notes to CHANGELOG line $line_to_edit :"
83
- echo -e $release_notes
47
+ start_sha=$( git diff | grep " ^-Subproject commit " | sed ' s/-Subproject commit //g' )
48
+ end_sha=$( git diff | grep " ^+Subproject commit " | sed ' s/+Subproject commit //g' )
49
+ output=" /tmp/python-base-relnote.md"
50
+ release-notes --dependencies=false --org kubernetes-client --repo python-base --start-sha $start_sha --end-sha $end_sha --output $output
51
+ sed -i ' s/(\[\#/(\[kubernetes-client\/python-base\#/g' $output
84
52
85
53
# update changelog
86
- sed -i " ${line_to_edit} i${release_notes} " CHANGELOG.md
54
+ IFS_backup=$IFS
55
+ IFS=$' \n '
56
+ sections=($( grep " ^### " $output ) )
57
+ IFS=$IFS_backup
58
+ for section in " ${sections[@]} " ; do
59
+ # ignore section titles and empty lines; replace newline with liternal "\n"
60
+ release_notes=$( sed -n " /$section /,/###/{/###/!p}" $output | sed -n " {/^$/!p}" | sed ' :a;N;$!ba;s/\n/\\n/g' )
61
+ util::changelog::write_changelog " $TARGET_RELEASE " " $section " " $release_notes "
62
+ done
87
63
64
+ rm -f $output
88
65
echo " Successfully updated CHANGELOG for submodule."
0 commit comments