From 23df733b71e9cb79f3ff4f5447caf8d75c475913 Mon Sep 17 00:00:00 2001 From: Haowei Cai Date: Tue, 26 Oct 2021 11:28:29 -0700 Subject: [PATCH 1/3] Run release-notes tool only when we actually pull commits into the release branch --- scripts/release.sh | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/scripts/release.sh b/scripts/release.sh index f364dba3e8..d88564857f 100755 --- a/scripts/release.sh +++ b/scripts/release.sh @@ -140,26 +140,28 @@ if [[ $CLIENT_VERSION != *"snapshot"* ]]; then git pull -X theirs upstream master --no-edit # Collect release notes from master branch - start_sha=$(git log ${remote_branch}..upstream/master | grep ^commit | tail -n1 | sed 's/commit //g') - end_sha=$(git log ${remote_branch}..upstream/master | grep ^commit | head -n1 | sed 's/commit //g') - output="/tmp/python-master-relnote.md" - release-notes --dependencies=false --org kubernetes-client --repo python --start-sha $start_sha --end-sha $end_sha --output $output - sed -i 's/(\[\#/(\[kubernetes-client\/python\#/g' $output - - 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" - master_release_notes=$(sed -n "/$section/,/###/{/###/!p}" $output | sed -n "{/^$/!p}" | sed ':a;N;$!ba;s/\n/\\n/g') - util::changelog::write_changelog v$CLIENT_VERSION "$section" "$master_release_notes" - done - git add . - if ! git diff-index --quiet --cached HEAD; then - util::changelog::update_release_api_version $CLIENT_VERSION $CLIENT_VERSION $new_k8s_api_version + if [[ $(git log ${remote_branch}..upstream/master | grep ^commit) ]]; then + start_sha=$(git log ${remote_branch}..upstream/master | grep ^commit | tail -n1 | sed 's/commit //g') + end_sha=$(git log ${remote_branch}..upstream/master | grep ^commit | head -n1 | sed 's/commit //g') + output="/tmp/python-master-relnote.md" + release-notes --dependencies=false --org kubernetes-client --repo python --start-sha $start_sha --end-sha $end_sha --output $output + sed -i 's/(\[\#/(\[kubernetes-client\/python\#/g' $output + + 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" + master_release_notes=$(sed -n "/$section/,/###/{/###/!p}" $output | sed -n "{/^$/!p}" | sed ':a;N;$!ba;s/\n/\\n/g') + util::changelog::write_changelog v$CLIENT_VERSION "$section" "$master_release_notes" + done git add . - git commit -m "update changelog with release notes from master branch" + if ! git diff-index --quiet --cached HEAD; then + util::changelog::update_release_api_version $CLIENT_VERSION $CLIENT_VERSION $new_k8s_api_version + git add . + git commit -m "update changelog with release notes from master branch" + fi fi fi From 4fb04c075805e8084f674af47a4dfea3f31ecb45 Mon Sep 17 00:00:00 2001 From: Haowei Cai Date: Tue, 26 Oct 2021 13:50:29 -0700 Subject: [PATCH 2/3] Only collect release notes from tmp output file if the file is non-empty --- scripts/release.sh | 35 +++++++++++++++++++---------------- scripts/update-submodule.sh | 32 ++++++++++++++++++-------------- 2 files changed, 37 insertions(+), 30 deletions(-) diff --git a/scripts/release.sh b/scripts/release.sh index d88564857f..017a5c000b 100755 --- a/scripts/release.sh +++ b/scripts/release.sh @@ -143,24 +143,27 @@ if [[ $CLIENT_VERSION != *"snapshot"* ]]; then if [[ $(git log ${remote_branch}..upstream/master | grep ^commit) ]]; then start_sha=$(git log ${remote_branch}..upstream/master | grep ^commit | tail -n1 | sed 's/commit //g') end_sha=$(git log ${remote_branch}..upstream/master | grep ^commit | head -n1 | sed 's/commit //g') - output="/tmp/python-master-relnote.md" + output="/tmp/python-master-relnote-$(date +%s).md" release-notes --dependencies=false --org kubernetes-client --repo python --start-sha $start_sha --end-sha $end_sha --output $output - sed -i 's/(\[\#/(\[kubernetes-client\/python\#/g' $output - - 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" - master_release_notes=$(sed -n "/$section/,/###/{/###/!p}" $output | sed -n "{/^$/!p}" | sed ':a;N;$!ba;s/\n/\\n/g') - util::changelog::write_changelog v$CLIENT_VERSION "$section" "$master_release_notes" - done - git add . - if ! git diff-index --quiet --cached HEAD; then - util::changelog::update_release_api_version $CLIENT_VERSION $CLIENT_VERSION $new_k8s_api_version + # Collect release notes from the output if non-empty + if [ -s $output ]; then + sed -i 's/(\[\#/(\[kubernetes-client\/python\#/g' $output + + 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" + master_release_notes=$(sed -n "/$section/,/###/{/###/!p}" $output | sed -n "{/^$/!p}" | sed ':a;N;$!ba;s/\n/\\n/g') + util::changelog::write_changelog v$CLIENT_VERSION "$section" "$master_release_notes" + done git add . - git commit -m "update changelog with release notes from master branch" + if ! git diff-index --quiet --cached HEAD; then + util::changelog::update_release_api_version $CLIENT_VERSION $CLIENT_VERSION $new_k8s_api_version + git add . + git commit -m "update changelog with release notes from master branch" + fi fi fi fi diff --git a/scripts/update-submodule.sh b/scripts/update-submodule.sh index 45431b37e0..8c64fa555b 100755 --- a/scripts/update-submodule.sh +++ b/scripts/update-submodule.sh @@ -50,20 +50,24 @@ 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" +output="/tmp/python-base-relnote-$(date +%s).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 +if [ -s $output ]; then + 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 + # 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." + rm -f $output + echo "Successfully updated CHANGELOG for submodule." +else + echo "No CHANGELOG for submodule." +fi From 029603980be76b67accf290bc4c68a1cf60f8b3f Mon Sep 17 00:00:00 2001 From: Haowei Cai Date: Tue, 26 Oct 2021 14:06:25 -0700 Subject: [PATCH 3/3] Add comments about what git add . does --- scripts/release.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/release.sh b/scripts/release.sh index 017a5c000b..a5e4dc6f3d 100755 --- a/scripts/release.sh +++ b/scripts/release.sh @@ -158,10 +158,10 @@ if [[ $CLIENT_VERSION != *"snapshot"* ]]; then master_release_notes=$(sed -n "/$section/,/###/{/###/!p}" $output | sed -n "{/^$/!p}" | sed ':a;N;$!ba;s/\n/\\n/g') util::changelog::write_changelog v$CLIENT_VERSION "$section" "$master_release_notes" done - git add . + git add . # Allows us to check if there are any staged release note changes if ! git diff-index --quiet --cached HEAD; then util::changelog::update_release_api_version $CLIENT_VERSION $CLIENT_VERSION $new_k8s_api_version - git add . + git add . # Include the API version update before we commit git commit -m "update changelog with release notes from master branch" fi fi