Skip to content

Commit

Permalink
chore: provide utils for release candidate post
Browse files Browse the repository at this point in the history
A markdown file provides a template that can be used for a post on Discourse for discussing the
current release candidate. There is also a Python script which gets a list of the closed PRs between
now and the last release. Some of the output from this can be used in the template.

Also provide a script for getting the current versions of crates and binaries. This can be handy if
you lost the output from the bump script.
  • Loading branch information
jacderida committed Jul 23, 2024
1 parent 1c3d037 commit a1ffd44
Show file tree
Hide file tree
Showing 4 changed files with 246 additions and 4 deletions.
108 changes: 108 additions & 0 deletions resources/rc_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
# Release Candidate YYYY.MM.X.Y

*PLEASE DO NOT EDIT THIS POST.*

It should only be edited by the RC owner, i.e., the original poster.

## Binary Versions

* `faucet` __REPLACE__
* `nat-detection` __REPLACE__
* `node-launchpad` __REPLACE__
* `safe` __REPLACE__
* `safenode` __REPLACE__
* `safenode-manager` __REPLACE__
* `safenodemand` __REPLACE__
* `sn_auditor` __REPLACE__
* `safenode_rpc_client` __REPLACE__

## Closed Pull Requests

Replace this with the list of closed PRs since the last version. This is intended to help developers
with their contributions to the changelog.

## Changelog/Testing Contributions

Please reply with a description of any contributions you made that will be included in this release.
The list of closed PRs is provided for reference. You can also provide direction or suggestions as
to how we could test your contributions with community participation.

Use this checklist to track the changelog contributions that are needed.

*Remove people who didn't close any PRs during this cycle.*

You will be ticked off when your reply is provided:

- [] Anselme
- [] Benno
- [] Chris
- [] Josh
- [] Mazzi
- [] Mick
- [] Qi
- [] Roland

## Contribution Template

To provide your contributions for the changelog, the template below can be used:
```
### Network
#### Added
- Provide any added entries or remove the section if it doesn't apply
#### Changed
- Provide any changed entries or remove the section if it doesn't apply
#### Fixed
- Provide any fixed entries or remove the section if it doesn't apply
### Client
#### Added
- Provide any added entries or remove the section if it doesn't apply
#### Changed
- Provide any changed entries or remove the section if it doesn't apply
#### Fixed
- Provide any fixed entries or remove the section if it doesn't apply
### Node Manager
#### Added
- Provide any added entries or remove the section if it doesn't apply
#### Changed
- Provide any changed entries or remove the section if it doesn't apply
#### Fixed
- Provide any fixed entries or remove the section if it doesn't apply
### Launchpad
Remove whole section if it does not apply.
#### Added
- Provide any added entries or remove the section if it doesn't apply
#### Changed
- Provide any changed entries or remove the section if it doesn't apply
#### Fixed
- Provide any fixed entries or remove the section if it doesn't apply
```

If you have any suggestions for testing your contributions with the community, please add them to
your reply, or provide them as a separate reply in the thread.
10 changes: 6 additions & 4 deletions resources/scripts/bump_version_for_rc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ set -e

# This script must run from the root of the repository.

# This allows for, e.g., "alpha" to be passed when calling the script.
pre_release_identifer=${1:-"rc"}

all_crates=($(awk '/members = \[/{flag=1; next} /\]/{flag=0} flag {gsub(/[",]/, ""); print $0}' \
Cargo.toml))

Expand All @@ -16,8 +19,7 @@ fi
declare -A crates_bumped
crates_bumped_with_version=()

# Remove the --allow-dirty flag
release-plz update --allow-dirty 2>&1 | tee bump_version_output
release-plz update 2>&1 | tee bump_version_output

while IFS= read -r line; do
# Sometimes this list can include crates that were not bumped. The presence of "->" indicates
Expand All @@ -38,7 +40,7 @@ git checkout -- .
for crate in "${crates_bumped_with_version[@]}"; do
name=$(echo "$crate" | sed -E 's/-v.*$//')
version=$(echo "$crate" | sed -E 's/^.*-v(.*)$/\1/')
new_version="$version-rc.1"
new_version="${version}-${pre_release_identifer}.1"
echo "Setting $crate to $new_version"
cargo set-version --package $name $new_version
done
Expand All @@ -60,7 +62,7 @@ for crate in "${all_crates[@]}"; do

IFS='.' read -r major minor patch <<< "$version"
patch=$((patch + 1))
new_version="${major}.${minor}.${patch}-rc.1"
new_version="${major}.${minor}.${patch}-${pre_release_identifer}.1"

echo "Safety bump to $new_version"
cargo set-version --package $crate $new_version
Expand Down
105 changes: 105 additions & 0 deletions resources/scripts/list-safe-network-closed-prs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
#!/usr/bin/env python

import os
import sys
from collections import defaultdict
from github import Github

def has_breaking_change(commits):
for commit in commits:
commit_message = commit.commit.message
if '!' in commit_message.split('\n')[0] or 'BREAKING CHANGE' in commit_message:
return True
return False


def main(last_released_pr_number):
token = os.getenv("GITHUB_PAT_SAFE_NETWORK_PR_LIST")
if not token:
raise Exception("The GITHUB_PAT_SAFE_NETWORK_PR_LIST environment variable must be set")

g = Github(token)
repo = g.get_repo("maidsafe/safe_network")

last_released_pr = repo.get_pull(last_released_pr_number)
if not last_released_pr:
raise Exception(f"Could not retrieve PR #{last_released_pr_number}")
last_release_date = last_released_pr.closed_at
if not last_release_date:
raise Exception(f"PR #{last_released_pr_number} has not been merged")

print("Base comparison PR:")
print(f"#{last_released_pr.number}: {last_released_pr.title} closed at {last_released_pr.closed_at}")
print()

pulls = repo.get_pulls(state="closed", sort="updated", direction="desc")
filtered_pulls = []
for pr in pulls:
if not pr.closed_at:
print(f"PR {pr.number} is not closed yet")
continue
print(f"Processing PR {pr.number}...")
if pr.closed_at <= last_release_date:
break
if pr.merged_at:
commits = pr.get_commits()
breaking = has_breaking_change(commits)
filtered_pulls.append({
"number": pr.number,
"title": pr.title,
"author": pr.user.login,
"closed_at": pr.closed_at,
"breaking": breaking,
"commits": commits
})
filtered_pulls.sort(key=lambda pr: pr["closed_at"])

print("Flat list:")
for pr in filtered_pulls:
closed_date = pr["closed_at"].date()
breaking_text = "[BREAKING]" if pr["breaking"] else ""
print(f"{closed_date} #{pr['number']} -- {pr['title']} [@{pr['author']}] {breaking_text}")

print()
grouped_pulls = defaultdict(list)
for pr in filtered_pulls:
grouped_pulls[pr["author"]].append(pr)

print("Grouped by author:")
for author, prs in grouped_pulls.items():
print(f"@{author}")
for pr in prs:
closed_date = pr["closed_at"].date()
breaking_text = "[BREAKING]" if pr["breaking"] else ""
print(f" {closed_date} #{pr['number']} -- {pr['title']} {breaking_text}")
print()

print("Grouped by author with commits:")
for author, prs in grouped_pulls.items():
print(f"@{author}")
for pr in prs:
closed_date = pr["closed_at"].date()
breaking_text = "[BREAKING]" if pr["breaking"] else ""
print(f" {closed_date} #{pr['number']} -- {pr['title']} {breaking_text}")
for commit in pr["commits"]:
print(f" {commit.commit.message.split('\n')[0]}")
print()

print("Grouped by author markdown:")
for author, prs in grouped_pulls.items():
print(f"@{author}")
for pr in prs:
pr_number = pr["number"]
closed_date = pr["closed_at"].date()
breaking_text = "[BREAKING]" if pr["breaking"] else ""
print(f" {closed_date} [#{pr_number}](https://github.com/maidsafe/safe_network/pull/{pr_number}) -- {pr['title']} {breaking_text}")
print()


if __name__ == "__main__":
if len(sys.argv) != 2:
print("Usage: python script.py <last_release_pr_number>")
sys.exit(1)

last_release_pr_number = int(sys.argv[1])
main(last_release_pr_number)
27 changes: 27 additions & 0 deletions resources/scripts/print-versions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env bash

set -e

all_crates=($(awk '/members = \[/{flag=1; next} /\]/{flag=0} flag {gsub(/[",]/, ""); print $0}' \
Cargo.toml))

echo "=================="
echo " Crate Versions "
echo "=================="
for crate in "${all_crates[@]}"; do
version=$(grep "^version" < $crate/Cargo.toml | head -n 1 | awk '{ print $3 }' | sed 's/\"//g')
echo "$crate: $version"
done

echo "==================="
echo " Binary Versions "
echo "==================="
echo "faucet: $(grep "^version" < sn_faucet/Cargo.toml | head -n 1 | awk '{ print $3 }' | sed 's/\"//g')"
echo "nat-detection: $(grep "^version" < nat-detection/Cargo.toml | head -n 1 | awk '{ print $3 }' | sed 's/\"//g')"
echo "node-launchpad: $(grep "^version" < node-launchpad/Cargo.toml | head -n 1 | awk '{ print $3 }' | sed 's/\"//g')"
echo "safe: $(grep "^version" < sn_cli/Cargo.toml | head -n 1 | awk '{ print $3 }' | sed 's/\"//g')"
echo "safenode: $(grep "^version" < sn_node/Cargo.toml | head -n 1 | awk '{ print $3 }' | sed 's/\"//g')"
echo "safenode-manager: $(grep "^version" < sn_node_manager/Cargo.toml | head -n 1 | awk '{ print $3 }' | sed 's/\"//g')"
echo "safenode_rpc_client: $(grep "^version" < sn_node_rpc_client/Cargo.toml | head -n 1 | awk '{ print $3 }' | sed 's/\"//g')"
echo "safenodemand: $(grep "^version" < sn_node_manager/Cargo.toml | head -n 1 | awk '{ print $3 }' | sed 's/\"//g')"
echo "sn_auditor: $(grep "^version" < sn_auditor/Cargo.toml | head -n 1 | awk '{ print $3 }' | sed 's/\"//g')"

0 comments on commit a1ffd44

Please sign in to comment.