Skip to content

Commit 683ea36

Browse files
authored
Merge pull request #1419 from roycaihw/release-automation
add update-submodule script
2 parents b313b5e + 83d294e commit 683ea36

File tree

4 files changed

+248
-2
lines changed

4 files changed

+248
-2
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<!-- Thanks for sending a pull request! Here are some tips for you:
2+
3+
1. If this is your first time, please read our contributor guidelines: https://git.k8s.io/community/contributors/guide/first-contribution.md#your-first-contribution and developer guide https://git.k8s.io/community/contributors/devel/development.md#development-guide
4+
2. Please label this pull request according to what type of issue you are addressing, especially if this is a release targeted pull request. For reference on required PR/issue labels, read here:
5+
https://git.k8s.io/community/contributors/devel/sig-release/release.md#issuepr-kind-label
6+
3. Ensure you have added or ran the appropriate tests for your PR: https://git.k8s.io/community/contributors/devel/sig-testing/testing.md
7+
4. If you want *faster* PR reviews, read how: https://git.k8s.io/community/contributors/guide/pull-requests.md#best-practices-for-faster-reviews
8+
5. If the PR is unfinished, see how to mark it: https://git.k8s.io/community/contributors/guide/pull-requests.md#marking-unfinished-pull-requests
9+
-->
10+
11+
#### What type of PR is this?
12+
13+
<!--
14+
Add one of the following kinds:
15+
/kind bug
16+
/kind cleanup
17+
/kind documentation
18+
/kind feature
19+
/kind design
20+
21+
Optionally add one or more of the following kinds if applicable:
22+
/kind api-change
23+
/kind deprecation
24+
/kind failing-test
25+
/kind flake
26+
/kind regression
27+
-->
28+
29+
#### What this PR does / why we need it:
30+
31+
#### Which issue(s) this PR fixes:
32+
<!--
33+
*Automatically closes linked issue when PR is merged.
34+
Usage: `Fixes #<issue number>`, or `Fixes (paste link of issue)`.
35+
_If PR is about `failing-tests or flakes`, please post the related issues/tests in a comment and do not use `Fixes`_*
36+
-->
37+
Fixes #
38+
39+
#### Special notes for your reviewer:
40+
41+
#### Does this PR introduce a user-facing change?
42+
<!--
43+
If no, just write "NONE" in the release-note block below.
44+
If yes, a release note is required:
45+
Enter your extended release note in the block below. If the PR requires additional action from users switching to the new release, include the string "action required".
46+
47+
For more information on release notes see: https://git.k8s.io/community/contributors/guide/release-notes.md
48+
-->
49+
```release-note
50+
51+
```
52+
53+
#### Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:
54+
55+
<!--
56+
This section can be blank if this pull request does not require a release note.
57+
58+
When adding links which point to resources within git repositories, like
59+
KEPs or supporting documentation, please reference a specific commit and avoid
60+
linking directly to the master branch. This ensures that links reference a
61+
specific point in time, rather than a document that may change over time.
62+
63+
See here for guidance on getting permanent links to files: https://help.github.com/en/articles/getting-permanent-links-to-files
64+
65+
Please use the following format for linking documentation:
66+
- [KEP]: <link>
67+
- [Usage]: <link>
68+
- [Other doc]: <link>
69+
-->
70+
```docs
71+
72+
```

devel/submodules.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ git submodule update --init
2323
If you changed [kubernetes-client/python-base](https://github.com/kubernetes-client/python-base) and want to pull your changes into this repo run this command:
2424

2525
```bash
26-
git submodule update --remote
26+
scripts/update-submodule.sh
2727
```
2828

29-
Once updated, you should create a new PR to commit changes to the repository.
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: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#!/bin/bash
2+
3+
# Copyright 2021 The Kubernetes Authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
18+
# Update python-base submodule and collect release notes.
19+
# Usage:
20+
#
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
29+
30+
set -o errexit
31+
set -o nounset
32+
set -o pipefail
33+
34+
repo_root="$(git rev-parse --show-toplevel)"
35+
declare -r repo_root
36+
cd "${repo_root}"
37+
38+
source scripts/util/changelog.sh
39+
go get k8s.io/release/cmd/release-notes
40+
41+
TARGET_RELEASE=${TARGET_RELEASE:-"v$(grep "^CLIENT_VERSION = \"" scripts/constants.py | sed "s/CLIENT_VERSION = \"//g" | sed "s/\"//g")"}
42+
43+
# update submodule
44+
git submodule update --remote
45+
46+
# download 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
52+
53+
# update changelog
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
63+
64+
rm -f $output
65+
echo "Successfully updated CHANGELOG for submodule."

scripts/util/changelog.sh

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
#!/bin/bash
2+
3+
# Copyright 2021 The Kubernetes Authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
changelog="$(git rev-parse --show-toplevel)/CHANGELOG.md"
18+
19+
function util::changelog::has_release {
20+
local release=$1
21+
return $(grep -q "^# $release$" $changelog)
22+
}
23+
24+
# find_release_start returns the number of the first line of the given release
25+
function util::changelog::find_release_start {
26+
local release=$1
27+
echo $(grep -n "^# $release$" $changelog | head -1 | cut -d: -f1)
28+
}
29+
30+
# find_release_end returns the number of the last line of the given release
31+
function util::changelog::find_release_end {
32+
local release=$1
33+
34+
local release_start=$(util::changelog::find_release_start $release)
35+
local next_release_index=0
36+
local releases=($(grep -n "^# " $changelog | cut -d: -f1))
37+
for i in "${!releases[@]}"; do
38+
if [[ "${releases[$i]}" = "$release_start" ]]; then
39+
next_release_index=$((i+1))
40+
break
41+
fi
42+
done
43+
# return the line before the next release
44+
echo $((${releases[${next_release_index}]}-1))
45+
}
46+
47+
# has_section returns if the given section exists between start and end
48+
function util::changelog::has_section_in_range {
49+
local section="$1"
50+
local start=$2
51+
local end=$3
52+
53+
local lines=($(grep -n "$section" "$changelog" | cut -d: -f1))
54+
for i in "${!lines[@]}"; do
55+
if [[ ${lines[$i]} -ge $start && ${lines[$i]} -le $end ]]; then
56+
return 0
57+
fi
58+
done
59+
return 1
60+
}
61+
62+
# find_section returns the number of the first line of the given section
63+
function util::changelog::find_section_in_range {
64+
local section="$1"
65+
local start=$2
66+
local end=$3
67+
68+
local line="0"
69+
local lines=($(grep -n "$section" "$changelog" | cut -d: -f1))
70+
for i in "${!lines[@]}"; do
71+
if [[ ${lines[$i]} -ge $start && ${lines[$i]} -le $end ]]; then
72+
line=${lines[$i]}
73+
break
74+
fi
75+
done
76+
echo $line
77+
}
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)