Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

release notes generator + spec version bump CI check fix + rust 1.81 fixes #793

Merged
merged 27 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/check-devnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name: Devnet Deploy Check
on:
pull_request:
branches: [devnet, devnet-ready]
types: [labeled, unlabeled, synchronize]

env:
CARGO_TERM_COLOR: always
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/check-finney.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name: Finney Deploy Check
on:
pull_request:
branches: [finney, main]
types: [labeled, unlabeled, synchronize]

env:
CARGO_TERM_COLOR: always
Expand Down Expand Up @@ -51,4 +52,4 @@ jobs:
runtime-package: "node-subtensor-runtime"
node-uri: "wss://entrypoint-finney.opentensor.ai:443"
checks: "pre-and-post"
extra-args: "--disable-spec-version-check --no-weight-warnings"
extra-args: "--disable-spec-version-check --no-weight-warnings"
1 change: 1 addition & 0 deletions .github/workflows/check-testnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name: Testnet Deploy Check
on:
pull_request:
branches: [testnet, testnet-ready]
types: [labeled, unlabeled, synchronize]

env:
CARGO_TERM_COLOR: always
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ indexing-slicing = "deny"
arithmetic-side-effects = "deny"
type_complexity = "allow"
unwrap-used = "deny"
manual_inspect = "allow"

[workspace.dependencies]
cargo-husky = { version = "1", default-features = false }
Expand Down
4 changes: 3 additions & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ fn collect_rust_files(dir: &Path) -> Vec<PathBuf> {
let mut rust_files = Vec::new();

for entry in WalkDir::new(dir) {
let entry = entry.unwrap();
let Ok(entry) = entry else {
continue;
};
let path = entry.path();

// Skip any path that contains "target" directory
Expand Down
173 changes: 173 additions & 0 deletions scripts/release_notes.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
#!/usr/bin/env rust-script
// ^ `cargo install rust-script` to be able to run this script

use core::{fmt::Display, str::FromStr};
use std::{env, process::Command};

fn eval(cmd: impl Display, print: bool) -> Result<String, String> {
if print {
println!("$ {}", cmd);
}
let output = Command::new("sh")
.arg("-c")
.arg(cmd.to_string())
.output()
.expect("failed to execute process");
if print {
println!("{}", String::from_utf8(output.stdout.clone()).unwrap());
eprintln!("{}", String::from_utf8(output.stderr.clone()).unwrap());
}
if !output.status.success() {
return Err(String::from_utf8(output.stderr).unwrap());
}
Ok(String::from_utf8(output.stdout).unwrap().trim().to_string())
}

#[derive(Copy, Clone, PartialEq, Eq, Debug)]
enum Network {
Mainnet,
Testnet,
}

impl FromStr for Network {
type Err = ();

fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"mainnet" => Ok(Network::Mainnet),
"testnet" => Ok(Network::Testnet),
_ => Err(()),
}
}
}

fn main() {
let network = env::var("NETWORK")
.unwrap_or_else(|_| "mainnet".to_string())
.parse::<Network>()
.unwrap_or_else(|_| panic!("Invalid NETWORK value"));
println!("Network: {:?}", network);

let all_tags = env::var("PREVIOUS_TAG")
.unwrap_or_else(|_| eval("git tag --sort=-creatordate", false).unwrap())
.split("\n")
.map(|s| s.trim().to_string())
.collect::<Vec<String>>();

let previous_tag = match network {
Network::Mainnet => all_tags
.iter()
.find(|tag| tag.starts_with("v") && !tag.ends_with("-pre-release"))
.expect("could not find a valid mainnet tag!"),
Network::Testnet => all_tags
.iter()
.find(|tag| tag.starts_with("v") && tag.ends_with("-pre-release"))
.expect("could not find a valid testnet tag!"),
};
println!("Previous release tag: {}", previous_tag);

let branch = env::var("BRANCH").unwrap_or(
match network {
Network::Mainnet => "testnet",
Network::Testnet => "devnet",
}
.to_string(),
);
println!("Branch: {}", branch);

println!(
"Generating release notes for all merges since {}...",
previous_tag,
);
let merges = eval(
format!(
"git log --merges --pretty=format:'%s' {}..{}",
branch, previous_tag,
),
false,
)
.unwrap()
.split("\n")
.map(|s| s.trim().to_string())
.filter(|s| {
!s.is_empty()
&& s.starts_with("Merge pull request #")
&& !s.ends_with("from opentensor/devnet-ready")
&& !s.ends_with("from opentensor/testnet-ready")
&& !s.ends_with("from opentensor/devnet")
&& !s.ends_with("from opentensor/testnet")
})
.collect::<Vec<String>>();

println!("");
println!("Filtered merges:\n{}", merges.join("\n"));

println!("");
let pr_numbers = merges
.iter()
.map(|s| s.split(" ").collect::<Vec<&str>>()[3].trim_start_matches("#"))
.collect::<Vec<&str>>();
println!("PR numbers:\n{:?}", pr_numbers);

println!("");
println!("Fetching PR titles...");
let pr_titles = pr_numbers
.iter()
.map(|pr_number| {
print!("#{}: ", pr_number);
let title = eval(format!("gh pr view {} --json title", pr_number), false)
.unwrap()
.trim()
.to_string();
if !title.starts_with("{\"title\":\"") {
panic!("Malformed PR title: {}", title);
}
let title = title
.trim_start_matches("{\"title\":\"")
.trim_end_matches("\"}")
.trim()
.to_string();
println!("{}", title);
title
})
.collect::<Vec<String>>();

println!("");
println!("Fetching PR authors...");
let pr_authors = pr_numbers
.iter()
.map(|pr_number| {
print!("#{}: ", pr_number);
let author = eval(
format!("gh pr view {} --json author | jq .author.login", pr_number),
false,
)
.unwrap()
.trim()
.trim_start_matches("\"")
.trim_end_matches("\"")
.to_string();
println!("{}", author);
author
})
.collect::<Vec<String>>();

println!("");
println!("generated release notes:");
let release_notes = "## What's Changed\n".to_string();
let release_notes = release_notes
+ &pr_numbers
.iter()
.zip(pr_titles.iter())
.zip(pr_authors.iter())
.map(|((pr_number, pr_title), pr_author)| {
format!("- {} in #{} by @{}\n", pr_title, pr_number, pr_author)
})
.collect::<String>();
println!("{}", release_notes);

println!("");
println!("writing release notes to /tmp/release_notes.md");
std::fs::write("/tmp/release_notes.md", release_notes).unwrap();
println!("done!");
}
Loading