From e0f960da6f6b8031948907cae41f1665eeb9128e Mon Sep 17 00:00:00 2001 From: Goulven CLEC'H Date: Sun, 29 Nov 2026 12:19:32 +0100 Subject: [PATCH 1/2] fix(sampo/core/github-action): apply pre-release audit fixes --- .../release-asset-upload-timeout.md | 5 ++ .../changesets/sampo-update-release-tags.md | 5 ++ .sampo/changesets/uv-workspace-publish.md | 7 ++ crates/sampo-core/src/adapters/pypi/pip.rs | 7 +- .../tests/uv_workspace_publishing.rs | 67 +++++++++++++++++++ crates/sampo-github-action/src/github.rs | 4 ++ crates/sampo/src/update.rs | 47 +++++++------ crates/sampo/src/version_check.rs | 20 ++++-- 8 files changed, 132 insertions(+), 30 deletions(-) create mode 100644 .sampo/changesets/release-asset-upload-timeout.md create mode 100644 .sampo/changesets/sampo-update-release-tags.md create mode 100644 .sampo/changesets/uv-workspace-publish.md create mode 100644 crates/sampo-core/tests/uv_workspace_publishing.rs diff --git a/.sampo/changesets/release-asset-upload-timeout.md b/.sampo/changesets/release-asset-upload-timeout.md new file mode 100644 index 00000000..70ef1726 --- /dev/null +++ b/.sampo/changesets/release-asset-upload-timeout.md @@ -0,0 +1,5 @@ +--- +cargo/sampo-github-action: patch +--- + +Fixed the GitHub Action failing to upload a release asset that takes more than 30 seconds to send. diff --git a/.sampo/changesets/sampo-update-release-tags.md b/.sampo/changesets/sampo-update-release-tags.md new file mode 100644 index 00000000..e73332c1 --- /dev/null +++ b/.sampo/changesets/sampo-update-release-tags.md @@ -0,0 +1,5 @@ +--- +cargo/sampo: patch +--- + +Fixed `sampo update` and the new-version hint never finding a release newer than 0.17.4. diff --git a/.sampo/changesets/uv-workspace-publish.md b/.sampo/changesets/uv-workspace-publish.md new file mode 100644 index 00000000..001d75a9 --- /dev/null +++ b/.sampo/changesets/uv-workspace-publish.md @@ -0,0 +1,7 @@ +--- +cargo/sampo: patch +cargo/sampo-core: patch +cargo/sampo-github-action: patch +--- + +In Python (PyPI) projects, fixed `sampo publish` finding no file to upload for a uv workspace member, whose build landed in the workspace root's `dist/`. diff --git a/crates/sampo-core/src/adapters/pypi/pip.rs b/crates/sampo-core/src/adapters/pypi/pip.rs index 7b671fe7..a29cf0b4 100644 --- a/crates/sampo-core/src/adapters/pypi/pip.rs +++ b/crates/sampo-core/src/adapters/pypi/pip.rs @@ -388,9 +388,12 @@ pub(super) fn publish(manifest_path: &Path, dry_run: bool, extra_args: &[String] .map_err(|e| SampoError::Publish(format!("failed to clean dist directory: {}", e)))?; } - // Build the package using uv build + // Build the package using uv build. A workspace member otherwise builds into the + // workspace root's `dist/`. let mut build_cmd = Command::new("uv"); - build_cmd.arg("build").current_dir(manifest_dir); + build_cmd + .args(["build", "--out-dir", "dist"]) + .current_dir(manifest_dir); println!("Running: {}", format_command_display(&build_cmd)); diff --git a/crates/sampo-core/tests/uv_workspace_publishing.rs b/crates/sampo-core/tests/uv_workspace_publishing.rs new file mode 100644 index 00000000..92e89141 --- /dev/null +++ b/crates/sampo-core/tests/uv_workspace_publishing.rs @@ -0,0 +1,67 @@ +//! Its own test binary: it overrides `PATH` process-wide. +#![cfg(unix)] + +mod common; + +use sampo_core::publish::PublishExtraArgs; +use std::fs; +use std::os::unix::fs::PermissionsExt; +use std::path::Path; + +/// A private index keeps the publish away from the public PyPI registry check. +const MEMBER_MANIFEST: &str = "[project]\nname = \"pkg-a\"\nversion = \"1.0.0\"\n\n\ + [[tool.uv.index]]\nname = \"internal\"\nurl = \"https://pypi.example.com/simple/\"\n\ + publish-url = \"https://pypi.example.com/upload/\"\n"; + +/// A uv workspace with one member, and a `uv` stub that, like uv, builds into the workspace +/// root's `dist/` unless told otherwise and publishes only what the current `dist/` holds. +fn uv_workspace(root: &Path) -> std::sync::MutexGuard<'static, ()> { + let bin = root.join("fake-bin"); + fs::create_dir_all(&bin).unwrap(); + let uv = bin.join("uv"); + fs::write( + &uv, + format!( + "#!/bin/sh\n\ + PATH=/usr/bin:/bin\n\ + case \"$1\" in\n\ + build)\n\ + out='{}/dist'\n\ + [ \"$2\" = \"--out-dir\" ] && out=\"$3\"\n\ + mkdir -p \"$out\" && : > \"$out/pkg_a-1.0.0.tar.gz\"\n\ + ;;\n\ + publish)\n\ + ls dist/* >/dev/null 2>&1 || {{ echo 'error: No files found to publish' >&2; exit 2; }}\n\ + ;;\n\ + esac\n", + root.display() + ), + ) + .unwrap(); + fs::set_permissions(&uv, fs::Permissions::from_mode(0o755)).unwrap(); + + fs::write( + root.join("pyproject.toml"), + "[tool.uv.workspace]\nmembers = [\"pkgs/*\"]\n", + ) + .unwrap(); + fs::create_dir_all(root.join("pkgs/a")).unwrap(); + fs::write(root.join("pkgs/a/pyproject.toml"), MEMBER_MANIFEST).unwrap(); + + let guard = common::use_only(&bin); + common::commit_repo(root, ""); + guard +} + +#[test] +fn a_uv_workspace_member_is_published_from_its_own_dist() { + let temp = tempfile::tempdir().unwrap(); + let root = temp.path(); + let _guard = uv_workspace(root); + + let output = sampo_core::run_publish(root, false, &PublishExtraArgs::default()).unwrap(); + + assert_eq!(output.tags, ["pkg-a-v1.0.0"]); + assert!(root.join("pkgs/a/dist/pkg_a-1.0.0.tar.gz").exists()); + assert!(!root.join("dist").exists()); +} diff --git a/crates/sampo-github-action/src/github.rs b/crates/sampo-github-action/src/github.rs index 7ae2c606..b6256b4e 100644 --- a/crates/sampo-github-action/src/github.rs +++ b/crates/sampo-github-action/src/github.rs @@ -5,6 +5,9 @@ use serde::{Deserialize, Serialize}; use std::path::Path; use std::time::Duration; +/// GitHub accepts assets of up to 2 GiB, too large for the client's default timeout. +const ASSET_UPLOAD_TIMEOUT: Duration = Duration::from_secs(30 * 60); + #[derive(Debug, Serialize)] struct CreatePullRequestPayload { title: String, @@ -753,6 +756,7 @@ impl GitHubClient { .header("Accept", "application/vnd.github+json") .header("Content-Type", "application/octet-stream") .header("X-GitHub-Api-Version", "2022-11-28") + .timeout(ASSET_UPLOAD_TIMEOUT) .body(asset_bytes) .send() .map_err(|e| ActionError::SampoCommandFailed { diff --git a/crates/sampo/src/update.rs b/crates/sampo/src/update.rs index 6476a570..249552b3 100644 --- a/crates/sampo/src/update.rs +++ b/crates/sampo/src/update.rs @@ -2,7 +2,7 @@ use crate::cli::UpdateArgs; use crate::ui::{log_info, log_success_value, log_warning, prompt_theme}; -use crate::version_check::CURRENT_VERSION; +use crate::version_check::{CURRENT_VERSION, TAG_PREFIX}; use sampo_core::errors::{Result, SampoError}; use self_update::backends::github::{ReleaseList, Update}; use self_update::update::Release; @@ -11,7 +11,6 @@ use semver::Version; const REPO_OWNER: &str = "bruits"; const REPO_NAME: &str = "sampo"; const BIN_NAME: &str = "sampo"; -const TAG_PREFIX: &str = "sampo-v"; /// Runs the update command. /// @@ -61,7 +60,7 @@ fn fetch_sampo_releases() -> Result> { Ok(releases) } -/// Filters releases to only those matching the `sampo-v` tag pattern +/// Filters releases to only those matching the `cargo-sampo-v` tag pattern /// and returns the one with the highest semver version. /// /// When `include_prerelease` is false, pre-release versions are excluded @@ -84,7 +83,7 @@ fn find_latest_sampo_release(releases: &[Release], include_prerelease: bool) -> }) } -/// Parses a semver version from a tag like `sampo-v0.13.0`. +/// Parses a semver version from a tag like `cargo-sampo-v0.13.0`. fn parse_version_from_tag(tag: &str) -> Result { let version_str = tag .strip_prefix(TAG_PREFIX) @@ -130,13 +129,13 @@ mod tests { #[test] fn parse_version_from_valid_tag() { - let v = parse_version_from_tag("sampo-v0.13.0").unwrap(); + let v = parse_version_from_tag("cargo-sampo-v0.13.0").unwrap(); assert_eq!(v, Version::new(0, 13, 0)); } #[test] fn parse_version_from_prerelease_tag() { - let v = parse_version_from_tag("sampo-v1.0.0-alpha.1").unwrap(); + let v = parse_version_from_tag("cargo-sampo-v1.0.0-alpha.1").unwrap(); assert_eq!(v.major, 1); assert_eq!(v.minor, 0); assert_eq!(v.patch, 0); @@ -151,7 +150,7 @@ mod tests { #[test] fn parse_version_rejects_invalid_version() { - let result = parse_version_from_tag("sampo-vnot-a-version"); + let result = parse_version_from_tag("cargo-sampo-vnot-a-version"); assert!(result.is_err()); } @@ -159,17 +158,17 @@ mod tests { fn find_latest_selects_highest_stable_version_by_default() { let releases = vec![ Release { - name: "sampo-v0.12.0".to_string(), + name: "cargo-sampo-v0.12.0".to_string(), version: "0.12.0".to_string(), ..Default::default() }, Release { - name: "sampo-v0.13.0".to_string(), + name: "cargo-sampo-v0.13.0".to_string(), version: "0.13.0".to_string(), ..Default::default() }, Release { - name: "sampo-v0.11.0".to_string(), + name: "cargo-sampo-v0.11.0".to_string(), version: "0.11.0".to_string(), ..Default::default() }, @@ -181,55 +180,55 @@ mod tests { ]; let latest = find_latest_sampo_release(&releases, false).unwrap(); - assert_eq!(latest.name, "sampo-v0.13.0"); + assert_eq!(latest.name, "cargo-sampo-v0.13.0"); } #[test] fn find_latest_excludes_prerelease_by_default() { let releases = vec![ Release { - name: "sampo-v0.13.0".to_string(), + name: "cargo-sampo-v0.13.0".to_string(), version: "0.13.0".to_string(), ..Default::default() }, Release { - name: "sampo-v1.0.0-alpha.1".to_string(), + name: "cargo-sampo-v1.0.0-alpha.1".to_string(), version: "1.0.0-alpha.1".to_string(), ..Default::default() }, Release { - name: "sampo-v1.0.0-beta.2".to_string(), + name: "cargo-sampo-v1.0.0-beta.2".to_string(), version: "1.0.0-beta.2".to_string(), ..Default::default() }, ]; let latest = find_latest_sampo_release(&releases, false).unwrap(); - assert_eq!(latest.name, "sampo-v0.13.0"); + assert_eq!(latest.name, "cargo-sampo-v0.13.0"); } #[test] fn find_latest_includes_prerelease_when_enabled() { let releases = vec![ Release { - name: "sampo-v0.13.0".to_string(), + name: "cargo-sampo-v0.13.0".to_string(), version: "0.13.0".to_string(), ..Default::default() }, Release { - name: "sampo-v1.0.0-alpha.1".to_string(), + name: "cargo-sampo-v1.0.0-alpha.1".to_string(), version: "1.0.0-alpha.1".to_string(), ..Default::default() }, Release { - name: "sampo-v1.0.0-beta.2".to_string(), + name: "cargo-sampo-v1.0.0-beta.2".to_string(), version: "1.0.0-beta.2".to_string(), ..Default::default() }, ]; let latest = find_latest_sampo_release(&releases, true).unwrap(); - assert_eq!(latest.name, "sampo-v1.0.0-beta.2"); + assert_eq!(latest.name, "cargo-sampo-v1.0.0-beta.2"); } #[test] @@ -248,12 +247,12 @@ mod tests { fn find_latest_returns_error_when_only_prereleases_and_not_included() { let releases = vec![ Release { - name: "sampo-v1.0.0-alpha.1".to_string(), + name: "cargo-sampo-v1.0.0-alpha.1".to_string(), version: "1.0.0-alpha.1".to_string(), ..Default::default() }, Release { - name: "sampo-v1.0.0-beta.1".to_string(), + name: "cargo-sampo-v1.0.0-beta.1".to_string(), version: "1.0.0-beta.1".to_string(), ..Default::default() }, @@ -269,18 +268,18 @@ mod tests { fn find_latest_ignores_invalid_versions() { let releases = vec![ Release { - name: "sampo-vinvalid".to_string(), + name: "cargo-sampo-vinvalid".to_string(), version: "invalid".to_string(), ..Default::default() }, Release { - name: "sampo-v0.10.0".to_string(), + name: "cargo-sampo-v0.10.0".to_string(), version: "0.10.0".to_string(), ..Default::default() }, ]; let latest = find_latest_sampo_release(&releases, false).unwrap(); - assert_eq!(latest.name, "sampo-v0.10.0"); + assert_eq!(latest.name, "cargo-sampo-v0.10.0"); } } diff --git a/crates/sampo/src/version_check.rs b/crates/sampo/src/version_check.rs index 383c8ab6..15cc8eab 100644 --- a/crates/sampo/src/version_check.rs +++ b/crates/sampo/src/version_check.rs @@ -20,8 +20,8 @@ const REQUEST_TIMEOUT_SECS: u64 = 3; const REPO_OWNER: &str = "bruits"; const REPO_NAME: &str = "sampo"; -/// Tag prefix for Sampo CLI releases. -const TAG_PREFIX: &str = "sampo-v"; +/// Tag prefix of the CLI's GitHub releases, as `tag_format` in `.sampo/config.toml` renders it. +pub const TAG_PREFIX: &str = "cargo-sampo-v"; /// Current CLI version (from Cargo.toml at compile time). pub const CURRENT_VERSION: &str = env!("CARGO_PKG_VERSION"); @@ -115,7 +115,7 @@ fn write_cache(version: &str) -> io::Result<()> { /// Returns `None` on network errors, timeouts, or parse failures—these are /// silently ignored since version checking is best-effort. /// -/// Only considers releases matching the `sampo-v` tag pattern, +/// Only considers releases matching the `cargo-sampo-v` tag pattern, /// excluding pre-release versions to align with `sampo update` defaults. fn fetch_latest_version() -> Option { let url = format!( @@ -137,7 +137,7 @@ fn fetch_latest_version() -> Option { let releases: Vec = response.json().ok()?; - // Find the highest stable version among sampo-v* tags + // Find the highest stable version among cargo-sampo-v* tags releases .iter() .filter_map(|release| { @@ -250,6 +250,18 @@ mod tests { assert!(!is_newer("", "1.0.0")); } + #[test] + fn tag_prefix_follows_the_repository_tag_format() { + let root = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("../.."); + // The published crate ships without the repository's Sampo config. + if !root.join(".sampo/config.toml").exists() { + return; + } + let config = sampo_core::Config::load(&root).expect("the repository's Sampo config"); + let tag = config.build_tag_name(sampo_core::PackageKind::Cargo, "sampo", CURRENT_VERSION); + assert_eq!(tag, format!("{TAG_PREFIX}{CURRENT_VERSION}")); + } + #[test] fn current_version_is_valid_semver() { let parsed = Version::parse(CURRENT_VERSION); From c339929ff7ea60d9011e0f2942277eb0cee132b3 Mon Sep 17 00:00:00 2001 From: Goulven CLEC'H Date: Sun, 29 Nov 2026 15:36:27 +0100 Subject: [PATCH 2/2] docs(github-action): fix cargo token in readme example --- crates/sampo-github-action/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/sampo-github-action/README.md b/crates/sampo-github-action/README.md index fea3c3f3..912b4ae8 100644 --- a/crates/sampo-github-action/README.md +++ b/crates/sampo-github-action/README.md @@ -41,7 +41,7 @@ jobs: # Options here, see below env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - CARGO_TOKEN: ${{ secrets.CARGO_TOKEN }} # For Cargo packages (optional) + CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_TOKEN }} # For Cargo packages (optional) NPM_TOKEN: ${{ secrets.NPM_TOKEN }} # For npm packages (optional, not needed with trusted publishing) HEX_API_KEY: ${{ secrets.HEX_API_KEY }} # For Hex packages (optional) UV_PUBLISH_TOKEN: ${{ secrets.PYPI_TOKEN }} # For PyPI packages via uv (optional)