Merge pull request #1419 from roycaihw/release-automation

add update-submodule script
This commit is contained in:
Kubernetes Prow Robot 2021-04-20 17:32:10 -07:00 committed by GitHub
commit 683ea3636e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 248 additions and 2 deletions

72
.github/PULL_REQUEST_TEMPLATE.md vendored Normal file
View File

@ -0,0 +1,72 @@
<!-- Thanks for sending a pull request! Here are some tips for you:
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
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:
https://git.k8s.io/community/contributors/devel/sig-release/release.md#issuepr-kind-label
3. Ensure you have added or ran the appropriate tests for your PR: https://git.k8s.io/community/contributors/devel/sig-testing/testing.md
4. If you want *faster* PR reviews, read how: https://git.k8s.io/community/contributors/guide/pull-requests.md#best-practices-for-faster-reviews
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
-->
#### What type of PR is this?
<!--
Add one of the following kinds:
/kind bug
/kind cleanup
/kind documentation
/kind feature
/kind design
Optionally add one or more of the following kinds if applicable:
/kind api-change
/kind deprecation
/kind failing-test
/kind flake
/kind regression
-->
#### What this PR does / why we need it:
#### Which issue(s) this PR fixes:
<!--
*Automatically closes linked issue when PR is merged.
Usage: `Fixes #<issue number>`, or `Fixes (paste link of issue)`.
_If PR is about `failing-tests or flakes`, please post the related issues/tests in a comment and do not use `Fixes`_*
-->
Fixes #
#### Special notes for your reviewer:
#### Does this PR introduce a user-facing change?
<!--
If no, just write "NONE" in the release-note block below.
If yes, a release note is required:
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".
For more information on release notes see: https://git.k8s.io/community/contributors/guide/release-notes.md
-->
```release-note
```
#### Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:
<!--
This section can be blank if this pull request does not require a release note.
When adding links which point to resources within git repositories, like
KEPs or supporting documentation, please reference a specific commit and avoid
linking directly to the master branch. This ensures that links reference a
specific point in time, rather than a document that may change over time.
See here for guidance on getting permanent links to files: https://help.github.com/en/articles/getting-permanent-links-to-files
Please use the following format for linking documentation:
- [KEP]: <link>
- [Usage]: <link>
- [Other doc]: <link>
-->
```docs
```

View File

@ -23,7 +23,7 @@ git submodule update --init
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:
```bash
git submodule update --remote
scripts/update-submodule.sh
```
Once updated, you should create a new PR to commit changes to the repository.
After the script finishes, please create a commit "generated python-base update" and send a PR to this repository.

65
scripts/update-submodule.sh Executable file
View File

@ -0,0 +1,65 @@
#!/bin/bash
# Copyright 2021 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Update python-base submodule and collect release notes.
# Usage:
#
# $ scripts/update-submodule.sh
#
# # To update the release notes for a specific release (e.g. v18.17.0a1):
# $ TARGET_RELEASE="v18.17.0a1" scripts/update-submodule.sh
#
# After the script finishes, please create a commit "generated python-base update"
# and send a PR to this repository.
# TODO(roycaihw): make the script send a PR
set -o errexit
set -o nounset
set -o pipefail
repo_root="$(git rev-parse --show-toplevel)"
declare -r repo_root
cd "${repo_root}"
source scripts/util/changelog.sh
go get k8s.io/release/cmd/release-notes
TARGET_RELEASE=${TARGET_RELEASE:-"v$(grep "^CLIENT_VERSION = \"" scripts/constants.py | sed "s/CLIENT_VERSION = \"//g" | sed "s/\"//g")"}
# update submodule
git submodule update --remote
# download release notes
start_sha=$(git diff | grep "^-Subproject commit " | sed 's/-Subproject commit //g')
end_sha=$(git diff | grep "^+Subproject commit " | sed 's/+Subproject commit //g')
output="/tmp/python-base-relnote.md"
release-notes --dependencies=false --org kubernetes-client --repo python-base --start-sha $start_sha --end-sha $end_sha --output $output
sed -i 's/(\[\#/(\[kubernetes-client\/python-base\#/g' $output
# update changelog
IFS_backup=$IFS
IFS=$'\n'
sections=($(grep "^### " $output))
IFS=$IFS_backup
for section in "${sections[@]}"; do
# ignore section titles and empty lines; replace newline with liternal "\n"
release_notes=$(sed -n "/$section/,/###/{/###/!p}" $output | sed -n "{/^$/!p}" | sed ':a;N;$!ba;s/\n/\\n/g')
util::changelog::write_changelog "$TARGET_RELEASE" "$section" "$release_notes"
done
rm -f $output
echo "Successfully updated CHANGELOG for submodule."

109
scripts/util/changelog.sh Executable file
View File

@ -0,0 +1,109 @@
#!/bin/bash
# Copyright 2021 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
changelog="$(git rev-parse --show-toplevel)/CHANGELOG.md"
function util::changelog::has_release {
local release=$1
return $(grep -q "^# $release$" $changelog)
}
# find_release_start returns the number of the first line of the given release
function util::changelog::find_release_start {
local release=$1
echo $(grep -n "^# $release$" $changelog | head -1 | cut -d: -f1)
}
# find_release_end returns the number of the last line of the given release
function util::changelog::find_release_end {
local release=$1
local release_start=$(util::changelog::find_release_start $release)
local next_release_index=0
local releases=($(grep -n "^# " $changelog | cut -d: -f1))
for i in "${!releases[@]}"; do
if [[ "${releases[$i]}" = "$release_start" ]]; then
next_release_index=$((i+1))
break
fi
done
# return the line before the next release
echo $((${releases[${next_release_index}]}-1))
}
# has_section returns if the given section exists between start and end
function util::changelog::has_section_in_range {
local section="$1"
local start=$2
local end=$3
local lines=($(grep -n "$section" "$changelog" | cut -d: -f1))
for i in "${!lines[@]}"; do
if [[ ${lines[$i]} -ge $start && ${lines[$i]} -le $end ]]; then
return 0
fi
done
return 1
}
# find_section returns the number of the first line of the given section
function util::changelog::find_section_in_range {
local section="$1"
local start=$2
local end=$3
local line="0"
local lines=($(grep -n "$section" "$changelog" | cut -d: -f1))
for i in "${!lines[@]}"; do
if [[ ${lines[$i]} -ge $start && ${lines[$i]} -le $end ]]; then
line=${lines[$i]}
break
fi
done
echo $line
}
# write_changelog writes release_notes to section in target_release
function util::changelog::write_changelog {
local target_release="$1"
local section="$2"
local release_notes="$3"
# find the place in the changelog that we want to edit
local line_to_edit="1"
if util::changelog::has_release $target_release; then
# the target release exists
release_first_line=$(util::changelog::find_release_start $target_release)
release_last_line=$(util::changelog::find_release_end $target_release)
if util::changelog::has_section_in_range "$section" "$release_first_line" "$release_last_line"; then
# prepend to existing section
line_to_edit=$(($(util::changelog::find_section_in_range "$section" "$release_first_line" "$release_last_line")+1))
else
# add a new section; plus 4 so that the section is placed below "Kubernetes API Version"
line_to_edit=$(($(util::changelog::find_release_start $target_release)+4))
release_notes="$section\n$release_notes\n"
fi
else
# add a new release
release_notes="# $target_release\n\nKubernetes API Version: To Be Updated\n\n$section\n$release_notes\n"
fi
echo "Writing the following release notes to CHANGELOG line $line_to_edit:"
echo -e $release_notes
# update changelog
sed -i "${line_to_edit}i${release_notes}" $changelog
}