Add a GitHub Actions warning to the `uv venv` behavior change

This commit is contained in:
Zanie Blue 2025-07-16 13:06:34 -05:00
parent f84abadc23
commit 262ac1e196
7 changed files with 78 additions and 2 deletions

View File

@ -777,6 +777,29 @@ jobs:
fi
done
uv-venv-annotation-test-linux:
timeout-minutes: 10
needs: build-binary-linux-libc
name: "`uv venv` annotation test | linux"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: "Download binary"
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
with:
name: uv-linux-libc-${{ github.sha }}
- name: "Prepare binary"
run: |
chmod +x ./uv
chmod +x ./uvx
- name: "Run `uv venv` twice"
run: |
./uv venv
./uv venv
smoke-test-linux:
timeout-minutes: 10
needs: build-binary-linux-libc

2
Cargo.lock generated
View File

@ -6010,6 +6010,7 @@ dependencies = [
"uv-pypi-types",
"uv-python",
"uv-shell",
"uv-static",
"uv-version",
"uv-warnings",
]
@ -6021,6 +6022,7 @@ dependencies = [
"anstream",
"owo-colors",
"rustc-hash",
"uv-static",
]
[[package]]

View File

@ -534,7 +534,7 @@ impl EnvVars {
#[attr_hidden]
pub const GIT_CEILING_DIRECTORIES: &'static str = "GIT_CEILING_DIRECTORIES";
/// Used for trusted publishing via `uv publish`.
/// Used to detect if running in GitHub Actions, e.g., for trusted publishing via `uv publish`.
pub const GITHUB_ACTIONS: &'static str = "GITHUB_ACTIONS";
/// Used for trusted publishing via `uv publish`. Contains the oidc token url.

View File

@ -26,6 +26,7 @@ uv-fs = { workspace = true }
uv-pypi-types = { workspace = true }
uv-python = { workspace = true }
uv-shell = { workspace = true }
uv-static = { workspace = true }
uv-version = { workspace = true }
uv-warnings = { workspace = true }

View File

@ -19,7 +19,7 @@ use uv_python::managed::{PythonMinorVersionLink, create_link_to_executable};
use uv_python::{Interpreter, VirtualEnvironment};
use uv_shell::escape_posix_for_single_quotes;
use uv_version::version;
use uv_warnings::warn_user_once;
use uv_warnings::{warn_ci_once, warn_user_once};
use crate::{Error, Prompt};
@ -135,6 +135,9 @@ pub(crate) fn create(
location.user_display(),
"--clear".green(),
);
warn_ci_once!(
"`uv venv` replaced an existing {name}; this behavior is deprecated. In the future, uv will require `--clear` or `UV_VENV_CLEAR=1` to replace an existing {name}.",
);
}
}
}

View File

@ -16,6 +16,8 @@ doctest = false
workspace = true
[dependencies]
uv-static = { workspace = true }
anstream = { workspace = true }
owo-colors = { workspace = true }
rustc-hash = { workspace = true }

View File

@ -7,6 +7,8 @@ pub use anstream;
#[doc(hidden)]
pub use owo_colors;
use rustc_hash::FxHashSet;
#[doc(hidden)]
pub use uv_static::EnvVars;
/// Whether user-facing warnings are enabled.
pub static ENABLED: AtomicBool = AtomicBool::new(false);
@ -56,3 +58,46 @@ macro_rules! warn_user_once {
}
}};
}
/// Create a warning for a visibility in a CI provider, if warnings are enabled. Only shows the
/// warning once in a given uv invocation, with uniqueness determined by the content of the message.
#[macro_export]
macro_rules! warn_ci_once {
($($arg:tt)*) => {{
use $crate::anstream::eprintln;
use $crate::owo_colors::OwoColorize;
if $crate::ENABLED.load(std::sync::atomic::Ordering::Relaxed) {
if let Ok(mut states) = $crate::WARNINGS.lock() {
if let Some(provider) = $crate::CIProvider::from_env() {
let message = provider.format(&format!("{}", format_args!($($arg)*)));
if states.insert(message.clone()) {
eprintln!("{message}");
}
}
}
}
}};
}
pub enum CIProvider {
GitHubActions,
}
impl CIProvider {
pub fn from_env() -> Option<Self> {
if std::env::var_os(EnvVars::GITHUB_ACTIONS).is_some() {
Some(Self::GitHubActions)
} else {
None
}
}
pub fn format(&self, message: &str) -> String {
match self {
Self::GitHubActions => {
format!("::warning ::{message}")
}
}
}
}