以缓存友好方式在 GitHub Actions 中使用 uvx

Simon Willison's Blog 工具

摘要

Simon Willison 分享了一种以缓存友好的方式在 GitHub Actions 中使用 uvx 的方法,通过设置环境变量并将其纳入缓存键,以避免重复下载 PyPI。

暂无内容
查看原文
查看缓存全文

缓存时间: 2026/07/14 04:12

# TIL:在 GitHub Actions 中以缓存友好方式使用 uvx 来源:https://simonwillison.net/2026/Jul/14/uvx-github-actions-cache/ TIL (https://simonwillison.net/elsewhere/til/)在 GitHub Actions 中以缓存友好方式使用 uvx (https://til.simonwillison.net/github-actions/uvx-github-actions-cache)—— 我经常想在 GitHub Actions 中通过 `uvx name-of-tool` 快速运行某个 Python 工具,但又不希望每次工作流运行时都向 PyPI 发起网络请求。我希望工具在首次获取后,后续运行能复用 GitHub Actions 缓存。 我终于找到了一个能兼容缓存的方案,用于在 GitHub Actions 工作流中使用 `uvx tool-name`,而且我很喜欢这个方案。 诀窍在于:在工作流开始时设置环境变量 `UV_EXCLUDE_NEWER: "2026-07-12"`,并将其作为 GitHub Actions 缓存键的一部分。这样一来,所有 `uvx tool-name` 命令都会解析为该日期下的最新版本;如果需要升级工具,只需把日期往后推就能刷新缓存。 我的目标是在 GitHub Actions 中使用 Python 工具,同时避免每次运行工作流时都去 PyPI 下载工具及其依赖的新副本。 **更新**:`astral-sh/setup-uv` 仓库已有一个现有 issue (https://github.com/astral-sh/setup-uv/issues/745),请求他们把默认行为改为缓存而非清除 PyPI 的 wheel。

相似文章

将你的 GitHub CI 迁移至 Hugging Face Jobs

Hugging Face Blog

本文提供了一份逐步指南,教你如何将 GitHub Actions CI 迁移到 Hugging Face Jobs 上运行,从而为类似 Trackio 的项目启用基于 GPU 的测试套件,并将 CPU CI 时间缩短 30%。