Skip to content

Commit 83d294e

Browse files
committed
fixup! add update-submodule script
1 parent d86a47d commit 83d294e

File tree

3 files changed

+58
-49
lines changed

3 files changed

+58
-49
lines changed

devel/submodules.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@ If you changed [kubernetes-client/python-base](https://github.com/kubernetes-cli
2626
scripts/update-submodule.sh
2727
```
2828

29-
Create a commit "generated python-base update" and send a PR to the main repo.
29+
After the script finishes, please create a commit "generated python-base update" and send a PR to this repository.

scripts/update-submodule.sh

Lines changed: 25 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,18 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17+
1718
# Update python-base submodule and collect release notes.
1819
# Usage:
19-
# scripts/update-submodule.sh
2020
#
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
2429

2530
set -o errexit
2631
set -o nounset
@@ -31,58 +36,30 @@ declare -r repo_root
3136
cd "${repo_root}"
3237

3338
source scripts/util/changelog.sh
39+
go get k8s.io/release/cmd/release-notes
3440

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.
3741
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:\*\*"}
3942

4043
# update submodule
4144
git submodule update --remote
42-
pulls=$(git diff --submodule | egrep -o "^ > Merge pull request #[0-9]+" | sed 's/ > Merge pull request #//g')
4345

4446
# 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
8452

8553
# 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
8763

64+
rm -f $output
8865
echo "Successfully updated CHANGELOG for submodule."

scripts/util/changelog.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,35 @@ function util::changelog::find_section_in_range {
7575
done
7676
echo $line
7777
}
78+
79+
# write_changelog writes release_notes to section in target_release
80+
function util::changelog::write_changelog {
81+
local target_release="$1"
82+
local section="$2"
83+
local release_notes="$3"
84+
85+
# find the place in the changelog that we want to edit
86+
local line_to_edit="1"
87+
if util::changelog::has_release $target_release; then
88+
# the target release exists
89+
release_first_line=$(util::changelog::find_release_start $target_release)
90+
release_last_line=$(util::changelog::find_release_end $target_release)
91+
if util::changelog::has_section_in_range "$section" "$release_first_line" "$release_last_line"; then
92+
# prepend to existing section
93+
line_to_edit=$(($(util::changelog::find_section_in_range "$section" "$release_first_line" "$release_last_line")+1))
94+
else
95+
# add a new section; plus 4 so that the section is placed below "Kubernetes API Version"
96+
line_to_edit=$(($(util::changelog::find_release_start $target_release)+4))
97+
release_notes="$section\n$release_notes\n"
98+
fi
99+
else
100+
# add a new release
101+
release_notes="# $target_release\n\nKubernetes API Version: To Be Updated\n\n$section\n$release_notes\n"
102+
fi
103+
104+
echo "Writing the following release notes to CHANGELOG line $line_to_edit:"
105+
echo -e $release_notes
106+
107+
# update changelog
108+
sed -i "${line_to_edit}i${release_notes}" $changelog
109+
}

0 commit comments

Comments
 (0)