Skip to content

Commit

Permalink
feat(governance-tools): Populate "Features & Fixes" section of SNS pr…
Browse files Browse the repository at this point in the history
…oposals from unreleased_changelog.md. (#3405)

# 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]: #3388

---------

Co-authored-by: Max Summe <[email protected]>
  • Loading branch information
daniel-wong-dfinity-org and max-dfinity authored Jan 10, 2025
1 parent d3354bf commit a4224e8
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 10 deletions.
5 changes: 1 addition & 4 deletions testnet/tools/nns-tools/add-release-to-changelog.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
50 changes: 44 additions & 6 deletions testnet/tools/nns-tools/lib/proposals.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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=""
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
30 changes: 30 additions & 0 deletions testnet/tools/nns-tools/lib/util.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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())'
}

0 comments on commit a4224e8

Please sign in to comment.