From a4224e83a632b00c01fb1604f298244fb70aaf49 Mon Sep 17 00:00:00 2001 From: Daniel Wong <97631336+daniel-wong-dfinity-org@users.noreply.github.com> Date: Sat, 11 Jan 2025 00:19:35 +0100 Subject: [PATCH] feat(governance-tools): Populate "Features & Fixes" section of SNS proposals from unreleased_changelog.md. (#3405) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # Future Work Add entry to SNS CHANGELOG.md files from unreleased_changelog.md, like how we do with NNS. This just involves making some (small?) changes to the add-release-to-changelog.sh script. # References [👈 Previous PR][prev] [prev]: https://github.com/dfinity/ic/pull/3388 --------- Co-authored-by: Max Summe --- .../nns-tools/add-release-to-changelog.sh | 5 +- testnet/tools/nns-tools/lib/proposals.sh | 50 ++++++++++++++++--- testnet/tools/nns-tools/lib/util.sh | 30 +++++++++++ 3 files changed, 75 insertions(+), 10 deletions(-) diff --git a/testnet/tools/nns-tools/add-release-to-changelog.sh b/testnet/tools/nns-tools/add-release-to-changelog.sh index ce10ccbbfef..e3ca0d7d033 100755 --- a/testnet/tools/nns-tools/add-release-to-changelog.sh +++ b/testnet/tools/nns-tools/add-release-to-changelog.sh @@ -94,13 +94,10 @@ fi # TODO: Verify that there are no uncommited changes in this dir, the canister's primary code path. # Construct new entry for CHANGELOG.md -# -# Python is used to filter out empty sections. -# Python is used because I cannot figure out how to do that using mac sed. NEW_FEATURES_AND_FIXES=$( sed '1,/^# Next Upgrade Proposal$/d' \ unreleased_changelog.md \ - | python3 -c 'import sys, re; s = sys.stdin.read(); print(re.sub(r"## [\w ]+\n+(?=##|\Z)", "", s).strip())' + | filter_out_empty_markdown_sections ) if [[ -z "${NEW_FEATURES_AND_FIXES}" ]]; then echo >&2 diff --git a/testnet/tools/nns-tools/lib/proposals.sh b/testnet/tools/nns-tools/lib/proposals.sh index addc68e0026..acce6003a3d 100644 --- a/testnet/tools/nns-tools/lib/proposals.sh +++ b/testnet/tools/nns-tools/lib/proposals.sh @@ -129,9 +129,7 @@ generate_nns_upgrade_proposal_text() { RELATIVE_CODE_LOCATION="$(echo "$CANISTER_CODE_LOCATION" | sed "s/$ESCAPED_IC_REPO/./g")" # If the canister has an unrelease_changelog.md file, use that to populate - # the "Features & Fixes" section of the upgrade proposal. Eventually, all of - # our canisters will have such a file, but for now, we are still test - # driving this process. + # the "Features & Fixes" section of the upgrade proposal. FEATURES_AND_FIXES="TODO Hand-craft this section." PRIMARY_CANISTER_CODE_LOCATION=$(echo "${CANISTER_CODE_LOCATION}" | cut -d' ' -f1) UNRELEASED_CHANGELOG_PATH="${PRIMARY_CANISTER_CODE_LOCATION}/unreleased_changelog.md" @@ -140,8 +138,21 @@ generate_nns_upgrade_proposal_text() { sed -n '/# Next Upgrade Proposal/,$p' \ "${UNRELEASED_CHANGELOG_PATH}" \ | tail -n +3 \ - | sed 's/^## /### /g' + | filter_out_empty_markdown_sections \ + | increment_markdown_heading_levels ) + if [[ -z "${FEATURES_AND_FIXES}" ]]; then + print_yellow "The unreleased_changelog.md has nothing interesting in it." >&2 + print_yellow 'Therefore, Some hand crafting of "Features & Fixes" will be required.' >&2 + FEATURES_AND_FIXES='TODO Hand-craft this section. unreleased_changelog.md was empty. It might be +that this is just a "maintenance" release; i.e. we are not trying to ship +any behavior changes. Instead, we just want the build in production to not +get too old. One reason to run recent builds is so that the next release +does not have a huge amount of changes in it.' + fi + else + print_yellow 'No unreleased_changelog.md file for ${CANISTER_NAME}.' >&2 + print_yellow 'The "Features & Fixes" section will need to be written by hand.' >&2 fi ARGS_HASH="" @@ -270,6 +281,33 @@ generate_sns_bless_wasm_proposal_text() { ESCAPED_IC_REPO=$(printf '%s\n' "$IC_REPO" | sed -e 's/[]\/$*.^[]/\\&/g') RELATIVE_CODE_LOCATION="$(echo "$CANISTER_CODE_LOCATION" | sed "s/$ESCAPED_IC_REPO/./g")" + # If the canister has an unrelease_changelog.md file, use that to populate + # the "Features & Fixes" section of the proposal. + FEATURES_AND_FIXES="TODO Hand-craft this section." + PRIMARY_CANISTER_CODE_LOCATION=$(echo "${CANISTER_CODE_LOCATION}" | cut -d' ' -f1) + UNRELEASED_CHANGELOG_PATH="${PRIMARY_CANISTER_CODE_LOCATION}/unreleased_changelog.md" + if [[ -e "${UNRELEASED_CHANGELOG_PATH}" ]]; then + FEATURES_AND_FIXES=$( + sed -n '/# Next Upgrade Proposal/,$p' \ + "${UNRELEASED_CHANGELOG_PATH}" \ + | tail -n +3 \ + | filter_out_empty_markdown_sections \ + | increment_markdown_heading_levels + ) + if [[ -z "${FEATURES_AND_FIXES}" ]]; then + print_yellow "The unreleased_changelog.md has nothing interesting in it." >&2 + print_yellow 'Therefore, Some hand crafting of "Features & Fixes" will be required.' >&2 + FEATURES_AND_FIXES='TODO Hand-craft this section. unreleased_changelog.md was empty. It might be +that this is just a "maintenance" release; i.e. we are not trying to ship +any behavior changes. Instead, we just want the build in production to not +get too old. One reason to run recent builds is so that the next release +does not have a huge amount of changes in it.' + fi + else + print_yellow 'No unreleased_changelog.md file for ${CANISTER_NAME}.' >&2 + print_yellow 'The "Features & Fixes" section will need to be written by hand.' >&2 + fi + OUTPUT=$( cat <<++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ # Publish SNS $CAPITALIZED_CANISTER_TYPE WASM Built at Commit $SHORT_NEXT_COMMIT @@ -280,9 +318,9 @@ __Source code__: [$NEXT_COMMIT][new-commit] [new-commit]: https://github.com/dfinity/ic/tree/$NEXT_COMMIT -## Summary +## Features & Fixes -TODO add a summary of changes +$FEATURES_AND_FIXES ## New Commits diff --git a/testnet/tools/nns-tools/lib/util.sh b/testnet/tools/nns-tools/lib/util.sh index 190a27d1c4f..fc1d3e8accb 100644 --- a/testnet/tools/nns-tools/lib/util.sh +++ b/testnet/tools/nns-tools/lib/util.sh @@ -134,3 +134,33 @@ confirm() { exit 1 fi } + +#### Markdown + +filter_out_empty_markdown_sections() { + # Python is used, because I'm not sure how to do this with sed. + python3 -c 'import sys, re +s = sys.stdin.read() +print(re.sub( + r"^(#+) [\w ]+\n+(?=\1 |\Z)", + "", # Replace with nothing. + s, # Input. + 0, # Unlimited replacements. + re.MULTILINE, +) +.strip())' +} + +increment_markdown_heading_levels() { + # Python is used, because I'm not sure how to do this with sed. + python3 -c 'import sys, re +s = sys.stdin.read() +print(re.sub( + r"^(#+)", # Grab Markdown heading. + r"\1# ", # Add another # character to increase the level. + s, # Input. + 0, # Unlimited replacements. + re.MULTILINE, +) +.strip())' +}