mirror of
https://github.com/hanzoai/dev.git
synced 2026-10-25 03:32:32 +00:00
feat(cli/preview): run binary without --help; simplify PR preview
- Launch binary directly and pass args (no implicit --help) - Simplify PR preview comment format - Keep history free of platform binaries
This commit is contained in:
@@ -242,12 +242,11 @@ jobs:
|
||||
marker,
|
||||
'### Preview Build',
|
||||
'',
|
||||
'Option A (no auth):',
|
||||
'In your terminal use:',
|
||||
'You can run this right now! In your terminal just use:',
|
||||
'```bash',
|
||||
`code preview pr:${issue_number}`,
|
||||
`code preview ${issue_number}`,
|
||||
'```',
|
||||
'This downloads from the prerelease for this PR (no GitHub token required).',
|
||||
'This will run the version of Code we\'ve created for this issue.',
|
||||
'',
|
||||
'Direct downloads:',
|
||||
`- Linux x86_64 (.zst): ${releaseBase}/code-x86_64-unknown-linux-musl.zst`,
|
||||
@@ -260,13 +259,6 @@ jobs:
|
||||
`- macOS arm64 (.tar.gz): ${releaseBase}/code-aarch64-apple-darwin.tar.gz`,
|
||||
`- Windows x86_64 (.zip): ${releaseBase}/code-x86_64-pc-windows-msvc.exe.zip`,
|
||||
'',
|
||||
'Option B:',
|
||||
'You can also run by Actions run id (requires auth):',
|
||||
'```bash',
|
||||
`code preview ${runId}`,
|
||||
'```',
|
||||
'This will run the version of Code we\'ve created for this issue.',
|
||||
'',
|
||||
'After you run it, please comment here and let me know if it does what you need.',
|
||||
marker
|
||||
].join('\n');
|
||||
|
||||
+10
-30
@@ -156,17 +156,17 @@ struct OrderReplayArgs {
|
||||
|
||||
#[derive(Debug, Parser)]
|
||||
struct PreviewArgs {
|
||||
/// Run id (e.g., 1757...), or pr:<number> to fetch from prerelease assets
|
||||
ref_id: String,
|
||||
/// PR number whose prerelease assets to download (e.g., 115)
|
||||
pr_number: u64,
|
||||
/// Optional owner/repo to override (defaults to just-every/code or $GITHUB_REPOSITORY)
|
||||
#[arg(long = "repo", value_name = "OWNER/REPO")]
|
||||
repo: Option<String>,
|
||||
/// Output directory where the binary will be extracted
|
||||
#[arg(short = 'o', long = "out", value_name = "DIR")]
|
||||
out_dir: Option<PathBuf>,
|
||||
/// Launch the binary with --help after download (default true)
|
||||
#[arg(long = "no-launch", default_value_t = false)]
|
||||
no_launch: bool,
|
||||
/// Additional args to pass to the downloaded binary
|
||||
#[arg(trailing_var_arg = true)]
|
||||
extra: Vec<String>,
|
||||
}
|
||||
|
||||
fn main() -> anyhow::Result<()> {
|
||||
@@ -387,27 +387,7 @@ async fn preview_main(args: PreviewArgs) -> anyhow::Result<()> {
|
||||
let client = reqwest::Client::builder()
|
||||
.user_agent("codex-preview/1")
|
||||
.build()?;
|
||||
|
||||
let ref_id = args.ref_id;
|
||||
let (maybe_pr, maybe_run) = if ref_id.starts_with("pr:") || ref_id.starts_with("pr-") {
|
||||
(ref_id.split(|c| c == ':' || c == '-').nth(1).and_then(|s| s.parse::<u64>().ok()), None)
|
||||
} else if let Ok(n) = ref_id.parse::<u64>() { (None, Some(n)) } else { (None, None) };
|
||||
|
||||
let pr_number: u64 = if let Some(pr) = maybe_pr {
|
||||
pr
|
||||
} else if let Some(run_id) = maybe_run {
|
||||
// Resolve run -> PR via API (requires token)
|
||||
let token = env::var("GH_TOKEN").or_else(|_| env::var("GITHUB_TOKEN"))
|
||||
.context("Set GH_TOKEN (or GITHUB_TOKEN) to resolve run -> PR; or pass pr:<number> to avoid auth.")?;
|
||||
let run_url = format!("https://api.github.com/repos/{owner}/{name}/actions/runs/{run_id}");
|
||||
let run: serde_json::Value = client.get(run_url).bearer_auth(&token).send().await?.error_for_status()?.json().await?;
|
||||
// pull_requests is an array; pick first
|
||||
run.get("pull_requests").and_then(|a| a.as_array()).and_then(|arr| arr.first())
|
||||
.and_then(|pr| pr.get("number")).and_then(|n| n.as_u64())
|
||||
.context("This run is not associated with a pull request; use pr:<number> instead.")?
|
||||
} else {
|
||||
bail!("Unsupported ref. Use pr:<number> or a numeric run id.");
|
||||
};
|
||||
let pr_number: u64 = args.pr_number;
|
||||
|
||||
let tag = format!("preview-pr-{}", pr_number);
|
||||
let base = format!("https://github.com/{owner}/{name}/releases/download/{tag}");
|
||||
@@ -468,7 +448,7 @@ async fn preview_main(args: PreviewArgs) -> anyhow::Result<()> {
|
||||
let bin = first_match(&out_dir, "code-").unwrap_or(out_dir.join("code"));
|
||||
make_exec(&bin);
|
||||
println!("Downloaded preview to {}", bin.display());
|
||||
if !args.no_launch { println!("Launching: {} --help", bin.display()); let _ = std::process::Command::new(&bin).arg("--help").status(); }
|
||||
if !args.extra.is_empty() { let _ = std::process::Command::new(&bin).args(&args.extra).status(); } else { let _ = std::process::Command::new(&bin).status(); }
|
||||
return Ok(());
|
||||
}
|
||||
} else {
|
||||
@@ -479,7 +459,7 @@ async fn preview_main(args: PreviewArgs) -> anyhow::Result<()> {
|
||||
z.extract(&out_dir)?;
|
||||
let exe = first_match(&out_dir, "code-").unwrap_or(out_dir.join("code.exe"));
|
||||
println!("Downloaded preview to {}", exe.display());
|
||||
if !args.no_launch { println!("Launching: {} --help", exe.display()); let _ = std::process::Command::new(&exe).arg("--help").spawn(); }
|
||||
if !args.extra.is_empty() { let _ = std::process::Command::new(&exe).args(&args.extra).spawn(); } else { let _ = std::process::Command::new(&exe).spawn(); }
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
@@ -493,7 +473,7 @@ async fn preview_main(args: PreviewArgs) -> anyhow::Result<()> {
|
||||
if status.success() {
|
||||
make_exec(&dest);
|
||||
println!("Downloaded preview from {} to {}", url_used, dest.display());
|
||||
if !args.no_launch { println!("Launching: {} --help", dest.display()); let _ = std::process::Command::new(&dest).arg("--help").status(); }
|
||||
if !args.extra.is_empty() { let _ = std::process::Command::new(&dest).args(&args.extra).status(); } else { let _ = std::process::Command::new(&dest).status(); }
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
@@ -504,7 +484,7 @@ async fn preview_main(args: PreviewArgs) -> anyhow::Result<()> {
|
||||
fs::copy(&bin, &dest)?;
|
||||
make_exec(&dest);
|
||||
println!("Downloaded preview to {}", dest.display());
|
||||
if !args.no_launch { println!("Launching: {} --help", dest.display()); let _ = std::process::Command::new(&dest).arg("--help").status(); }
|
||||
if !args.extra.is_empty() { let _ = std::process::Command::new(&dest).args(&args.extra).status(); } else { let _ = std::process::Command::new(&dest).status(); }
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user