Skip to content
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
5 changes: 5 additions & 0 deletions .sampo/changesets/release-asset-upload-timeout.md
Original file line number Diff line number Diff line change
@@ -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.
5 changes: 5 additions & 0 deletions .sampo/changesets/sampo-update-release-tags.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
cargo/sampo: patch
---

Fixed `sampo update` and the new-version hint never finding a release newer than 0.17.4.
7 changes: 7 additions & 0 deletions .sampo/changesets/uv-workspace-publish.md
Original file line number Diff line number Diff line change
@@ -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/`.
7 changes: 5 additions & 2 deletions crates/sampo-core/src/adapters/pypi/pip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down
67 changes: 67 additions & 0 deletions crates/sampo-core/tests/uv_workspace_publishing.rs
Original file line number Diff line number Diff line change
@@ -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());
}
2 changes: 1 addition & 1 deletion crates/sampo-github-action/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions crates/sampo-github-action/src/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down
47 changes: 23 additions & 24 deletions crates/sampo/src/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
///
Expand Down Expand Up @@ -61,7 +60,7 @@ fn fetch_sampo_releases() -> Result<Vec<Release>> {
Ok(releases)
}

/// Filters releases to only those matching the `sampo-v<version>` tag pattern
/// Filters releases to only those matching the `cargo-sampo-v<version>` tag pattern
/// and returns the one with the highest semver version.
///
/// When `include_prerelease` is false, pre-release versions are excluded
Expand All @@ -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<Version> {
let version_str = tag
.strip_prefix(TAG_PREFIX)
Expand Down Expand Up @@ -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);
Expand All @@ -151,25 +150,25 @@ 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());
}

#[test]
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()
},
Expand All @@ -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]
Expand All @@ -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()
},
Expand All @@ -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");
}
}
20 changes: 16 additions & 4 deletions crates/sampo/src/version_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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<version>` tag pattern,
/// Only considers releases matching the `cargo-sampo-v<version>` tag pattern,
/// excluding pre-release versions to align with `sampo update` defaults.
fn fetch_latest_version() -> Option<String> {
let url = format!(
Expand All @@ -137,7 +137,7 @@ fn fetch_latest_version() -> Option<String> {

let releases: Vec<serde_json::Value> = 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| {
Expand Down Expand Up @@ -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);
Expand Down