Skip to content

Commit

Permalink
feat: generate notes based on run id
Browse files Browse the repository at this point in the history
  • Loading branch information
benbrandt committed Jan 27, 2025
1 parent d58180a commit 4feac07
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/package_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,6 @@ jobs:
key: wasi-sdk-25.0.0

- run: cargo run -- install-build-tools
- run: cargo run -- build ${{ inputs.project }} ${{ inputs.version }} ${{ inputs.python_3_12 && '--python-versions py3-12' || '' }} ${{ inputs.python_3_13 && '--python-versions py3-13' || '' }} ${{ inputs.publish && '--publish' || '' }}
- run: cargo run -- build ${{ inputs.project }} ${{ inputs.version }} ${{ inputs.python_3_12 && '--python-versions py3-12' || '' }} ${{ inputs.python_3_13 && '--python-versions py3-13' || '' }} ${{ inputs.publish && '--publish --repo ${{ github.repository }} --run-id ${{ github.run_id }}' || '' }}
env:
GH_TOKEN: ${{ github.token }}
20 changes: 9 additions & 11 deletions src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ pub async fn build_and_publish(
release_version: &str,
output_dir: Option<PathBuf>,
python_versions: &[PythonVersion],
publish: bool,
publish_notes: Option<String>,
) -> anyhow::Result<()> {
let wheel_paths = build(project, release_version, output_dir, python_versions).await?;

if publish {
publish_release(project, release_version, &wheel_paths).await?;
if let Some(notes) = publish_notes {
publish_release(project, release_version, &wheel_paths, &notes).await?;
}

Ok(())
Expand Down Expand Up @@ -90,23 +90,21 @@ async fn publish_release(
project: SupportedProjects,
release_version: &str,
wheel_paths: &[PathBuf],
notes: &str,
) -> anyhow::Result<()> {
let tag = format!("{project}/v{release_version}");
let notes = format!("Generated using `wasi-wheels build {project} {release_version}`");

let hashes = generate_hashes(wheel_paths).await?;
let temp_dir = tempfile::tempdir()?;
let hashes_path = temp_dir.path().join("hashes.txt");
fs::write(&hashes_path, hashes).await?;

run(Command::new("gh").args(
[
"release", "create", &tag, "--title", &tag, "--notes", &notes,
]
.into_iter()
.map(OsStr::new)
.chain(wheel_paths.iter().map(|p| p.as_os_str()))
.chain(once(hashes_path.as_os_str())),
["release", "create", &tag, "--title", &tag, "--notes", notes]
.into_iter()
.map(OsStr::new)
.chain(wheel_paths.iter().map(|p| p.as_os_str()))
.chain(once(hashes_path.as_os_str())),
))
.await
}
Expand Down
32 changes: 30 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use std::path::PathBuf;

use clap::{Parser, Subcommand};
use clap::{Args, Parser, Subcommand};
use wasi_wheels::{
build_and_publish, download_package, install_build_tools, PythonVersion, SupportedProjects,
};
Expand Down Expand Up @@ -40,12 +40,39 @@ enum Commands {
/// Optionally publish the wheel as a release in GitHub
#[arg(long)]
publish: bool,
/// Optionally publish the wheel as a release in GitHub
#[command(flatten)]
publish_flags: PublishFlags,
/// Python versions to build with. Defaults to all supported versions
#[arg(long, value_enum, default_values_t=[PythonVersion::Py3_12, PythonVersion::Py3_13])]
python_versions: Vec<PythonVersion>,
},
}

#[derive(Args, Debug)]
#[group(requires = "publish")]
struct PublishFlags {
/// Which repository this is being released for: <user>/<repo>
#[arg(long)]
repo: Option<String>,
/// Which run id was used when building in CI
#[arg(long)]
run_id: Option<usize>,
}

impl PublishFlags {
/// Generate info about the run context
fn run_info(&self) -> String {
match (self.repo.as_ref(), self.run_id) {
(None | Some(_), None) => "No provided run information".to_string(),
(None, Some(run_id)) => format!("Built with run {run_id}"),
(Some(repo), Some(run_id)) => {
format!("Built with run https://github.com/{repo}/actions/runs/{run_id}")
}
}
}
}

#[tokio::main]
async fn main() -> anyhow::Result<()> {
let cli = Cli::parse();
Expand All @@ -63,13 +90,14 @@ async fn main() -> anyhow::Result<()> {
output_dir,
publish,
python_versions,
publish_flags,
} => {
build_and_publish(
project,
&release_version,
output_dir,
&python_versions,
publish,
publish.then(|| publish_flags.run_info()),
)
.await
}
Expand Down

0 comments on commit 4feac07

Please sign in to comment.