Skip to content

Commit e0e60fa

Browse files
authored
Merge pull request #1602 from roycaihw/handle-no-master-change
Run release-notes tool only when we actually pull commits into the release branch
2 parents a766a5f + 0296039 commit e0e60fa

File tree

2 files changed

+43
-34
lines changed

2 files changed

+43
-34
lines changed

scripts/release.sh

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -140,26 +140,31 @@ if [[ $CLIENT_VERSION != *"snapshot"* ]]; then
140140
git pull -X theirs upstream master --no-edit
141141

142142
# Collect release notes from master branch
143-
start_sha=$(git log ${remote_branch}..upstream/master | grep ^commit | tail -n1 | sed 's/commit //g')
144-
end_sha=$(git log ${remote_branch}..upstream/master | grep ^commit | head -n1 | sed 's/commit //g')
145-
output="/tmp/python-master-relnote.md"
146-
release-notes --dependencies=false --org kubernetes-client --repo python --start-sha $start_sha --end-sha $end_sha --output $output
147-
sed -i 's/(\[\#/(\[kubernetes-client\/python\#/g' $output
148-
149-
IFS_backup=$IFS
150-
IFS=$'\n'
151-
sections=($(grep "^### " $output))
152-
IFS=$IFS_backup
153-
for section in "${sections[@]}"; do
154-
# ignore section titles and empty lines; replace newline with liternal "\n"
155-
master_release_notes=$(sed -n "/$section/,/###/{/###/!p}" $output | sed -n "{/^$/!p}" | sed ':a;N;$!ba;s/\n/\\n/g')
156-
util::changelog::write_changelog v$CLIENT_VERSION "$section" "$master_release_notes"
157-
done
158-
git add .
159-
if ! git diff-index --quiet --cached HEAD; then
160-
util::changelog::update_release_api_version $CLIENT_VERSION $CLIENT_VERSION $new_k8s_api_version
161-
git add .
162-
git commit -m "update changelog with release notes from master branch"
143+
if [[ $(git log ${remote_branch}..upstream/master | grep ^commit) ]]; then
144+
start_sha=$(git log ${remote_branch}..upstream/master | grep ^commit | tail -n1 | sed 's/commit //g')
145+
end_sha=$(git log ${remote_branch}..upstream/master | grep ^commit | head -n1 | sed 's/commit //g')
146+
output="/tmp/python-master-relnote-$(date +%s).md"
147+
release-notes --dependencies=false --org kubernetes-client --repo python --start-sha $start_sha --end-sha $end_sha --output $output
148+
# Collect release notes from the output if non-empty
149+
if [ -s $output ]; then
150+
sed -i 's/(\[\#/(\[kubernetes-client\/python\#/g' $output
151+
152+
IFS_backup=$IFS
153+
IFS=$'\n'
154+
sections=($(grep "^### " $output))
155+
IFS=$IFS_backup
156+
for section in "${sections[@]}"; do
157+
# ignore section titles and empty lines; replace newline with liternal "\n"
158+
master_release_notes=$(sed -n "/$section/,/###/{/###/!p}" $output | sed -n "{/^$/!p}" | sed ':a;N;$!ba;s/\n/\\n/g')
159+
util::changelog::write_changelog v$CLIENT_VERSION "$section" "$master_release_notes"
160+
done
161+
git add . # Allows us to check if there are any staged release note changes
162+
if ! git diff-index --quiet --cached HEAD; then
163+
util::changelog::update_release_api_version $CLIENT_VERSION $CLIENT_VERSION $new_k8s_api_version
164+
git add . # Include the API version update before we commit
165+
git commit -m "update changelog with release notes from master branch"
166+
fi
167+
fi
163168
fi
164169
fi
165170

scripts/update-submodule.sh

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,20 +50,24 @@ git submodule update --remote
5050
# download release notes
5151
start_sha=$(git diff | grep "^-Subproject commit " | sed 's/-Subproject commit //g')
5252
end_sha=$(git diff | grep "^+Subproject commit " | sed 's/+Subproject commit //g')
53-
output="/tmp/python-base-relnote.md"
53+
output="/tmp/python-base-relnote-$(date +%s).md"
5454
release-notes --dependencies=false --org kubernetes-client --repo python-base --start-sha $start_sha --end-sha $end_sha --output $output
55-
sed -i 's/(\[\#/(\[kubernetes-client\/python-base\#/g' $output
55+
if [ -s $output ]; then
56+
sed -i 's/(\[\#/(\[kubernetes-client\/python-base\#/g' $output
5657

57-
# update changelog
58-
IFS_backup=$IFS
59-
IFS=$'\n'
60-
sections=($(grep "^### " $output))
61-
IFS=$IFS_backup
62-
for section in "${sections[@]}"; do
63-
# ignore section titles and empty lines; replace newline with liternal "\n"
64-
release_notes=$(sed -n "/$section/,/###/{/###/!p}" $output | sed -n "{/^$/!p}" | sed ':a;N;$!ba;s/\n/\\n/g')
65-
util::changelog::write_changelog "$TARGET_RELEASE" "$section" "$release_notes"
66-
done
58+
# update changelog
59+
IFS_backup=$IFS
60+
IFS=$'\n'
61+
sections=($(grep "^### " $output))
62+
IFS=$IFS_backup
63+
for section in "${sections[@]}"; do
64+
# ignore section titles and empty lines; replace newline with liternal "\n"
65+
release_notes=$(sed -n "/$section/,/###/{/###/!p}" $output | sed -n "{/^$/!p}" | sed ':a;N;$!ba;s/\n/\\n/g')
66+
util::changelog::write_changelog "$TARGET_RELEASE" "$section" "$release_notes"
67+
done
6768

68-
rm -f $output
69-
echo "Successfully updated CHANGELOG for submodule."
69+
rm -f $output
70+
echo "Successfully updated CHANGELOG for submodule."
71+
else
72+
echo "No CHANGELOG for submodule."
73+
fi

0 commit comments

Comments
 (0)