mirror of
https://github.com/astral-sh/setup-uv.git
synced 2025-12-17 18:07:43 +00:00
Compare commits
7 Commits
v5.0.0
...
macos-pyth
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6a26ee8850 | ||
|
|
03fe035094 | ||
|
|
887a942a15 | ||
|
|
d174a24c07 | ||
|
|
12c852e6ba | ||
|
|
180f8b4439 | ||
|
|
e3fb95a689 |
14
.github/workflows/test.yml
vendored
14
.github/workflows/test.yml
vendored
@@ -167,3 +167,17 @@ jobs:
|
||||
exit 1
|
||||
fi
|
||||
shell: bash
|
||||
test-macos-python-version:
|
||||
runs-on: macos-latest
|
||||
steps:
|
||||
- run: |
|
||||
/Applications/Xcode_15.4.app/Contents/Developer/usr/bin/python3 --version
|
||||
- name: Install uv
|
||||
uses: astral-sh/setup-uv@v5
|
||||
with:
|
||||
python-version: 3.9
|
||||
- run: |
|
||||
echo "$UV_PYTHON"
|
||||
python --version
|
||||
uv python list
|
||||
shell: bash
|
||||
|
||||
51
README.md
51
README.md
@@ -34,7 +34,7 @@ Set up your GitHub Actions workflow with a specific version of [uv](https://docs
|
||||
|
||||
```yaml
|
||||
- name: Install the latest version of uv
|
||||
uses: astral-sh/setup-uv@v4
|
||||
uses: astral-sh/setup-uv@v5
|
||||
with:
|
||||
version: "latest"
|
||||
```
|
||||
@@ -46,7 +46,7 @@ For an example workflow, see
|
||||
|
||||
```yaml
|
||||
- name: Install a specific version of uv
|
||||
uses: astral-sh/setup-uv@v4
|
||||
uses: astral-sh/setup-uv@v5
|
||||
with:
|
||||
version: "0.4.4"
|
||||
```
|
||||
@@ -58,14 +58,14 @@ to install the latest version that satisfies the range.
|
||||
|
||||
```yaml
|
||||
- name: Install a semver range of uv
|
||||
uses: astral-sh/setup-uv@v4
|
||||
uses: astral-sh/setup-uv@v5
|
||||
with:
|
||||
version: ">=0.4.0"
|
||||
```
|
||||
|
||||
```yaml
|
||||
- name: Pinning a minor version of uv
|
||||
uses: astral-sh/setup-uv@v4
|
||||
uses: astral-sh/setup-uv@v5
|
||||
with:
|
||||
version: "0.4.x"
|
||||
```
|
||||
@@ -82,7 +82,7 @@ This will override any python version specifications in `pyproject.toml` and `.p
|
||||
|
||||
```yaml
|
||||
- name: Install the latest version of uv and set the python version to 3.13t
|
||||
uses: astral-sh/setup-uv@v4
|
||||
uses: astral-sh/setup-uv@v5
|
||||
with:
|
||||
python-version: 3.13t
|
||||
- run: uv pip install --python=3.13t pip
|
||||
@@ -100,7 +100,7 @@ jobs:
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Install the latest version of uv and set the python version
|
||||
uses: astral-sh/setup-uv@v4
|
||||
uses: astral-sh/setup-uv@v5
|
||||
with:
|
||||
python-version: ${{ matrix.python-version }}
|
||||
- name: Test with python ${{ matrix.python-version }}
|
||||
@@ -115,7 +115,7 @@ are automatically verified by this action. The sha256 hashes can be found on the
|
||||
|
||||
```yaml
|
||||
- name: Install a specific version and validate the checksum
|
||||
uses: astral-sh/setup-uv@v4
|
||||
uses: astral-sh/setup-uv@v5
|
||||
with:
|
||||
version: "0.3.1"
|
||||
checksum: "e11b01402ab645392c7ad6044db63d37e4fd1e745e015306993b07695ea5f9f8"
|
||||
@@ -136,7 +136,7 @@ You can optionally define a custom cache key suffix.
|
||||
```yaml
|
||||
- name: Enable caching and define a custom cache key suffix
|
||||
id: setup-uv
|
||||
uses: astral-sh/setup-uv@v4
|
||||
uses: astral-sh/setup-uv@v5
|
||||
with:
|
||||
enable-cache: true
|
||||
cache-suffix: "optional-suffix"
|
||||
@@ -168,7 +168,7 @@ changes. If you use relative paths, they are relative to the repository root.
|
||||
|
||||
```yaml
|
||||
- name: Define a cache dependency glob
|
||||
uses: astral-sh/setup-uv@v4
|
||||
uses: astral-sh/setup-uv@v5
|
||||
with:
|
||||
enable-cache: true
|
||||
cache-dependency-glob: "**/pyproject.toml"
|
||||
@@ -176,7 +176,7 @@ changes. If you use relative paths, they are relative to the repository root.
|
||||
|
||||
```yaml
|
||||
- name: Define a list of cache dependency globs
|
||||
uses: astral-sh/setup-uv@v4
|
||||
uses: astral-sh/setup-uv@v5
|
||||
with:
|
||||
enable-cache: true
|
||||
cache-dependency-glob: |
|
||||
@@ -186,7 +186,7 @@ changes. If you use relative paths, they are relative to the repository root.
|
||||
|
||||
```yaml
|
||||
- name: Define an absolute cache dependency glob
|
||||
uses: astral-sh/setup-uv@v4
|
||||
uses: astral-sh/setup-uv@v5
|
||||
with:
|
||||
enable-cache: true
|
||||
cache-dependency-glob: "/tmp/my-folder/requirements*.txt"
|
||||
@@ -194,7 +194,7 @@ changes. If you use relative paths, they are relative to the repository root.
|
||||
|
||||
```yaml
|
||||
- name: Never invalidate the cache
|
||||
uses: astral-sh/setup-uv@v4
|
||||
uses: astral-sh/setup-uv@v5
|
||||
with:
|
||||
enable-cache: true
|
||||
cache-dependency-glob: ""
|
||||
@@ -209,7 +209,7 @@ It defaults to `setup-uv-cache` in the `TMP` dir, `D:\a\_temp\uv-tool-dir` on Wi
|
||||
|
||||
```yaml
|
||||
- name: Define a custom uv cache path
|
||||
uses: astral-sh/setup-uv@v4
|
||||
uses: astral-sh/setup-uv@v5
|
||||
with:
|
||||
cache-local-path: "/path/to/cache"
|
||||
```
|
||||
@@ -228,7 +228,7 @@ input.
|
||||
|
||||
```yaml
|
||||
- name: Don't prune the cache before saving it
|
||||
uses: astral-sh/setup-uv@v4
|
||||
uses: astral-sh/setup-uv@v5
|
||||
with:
|
||||
enable-cache: true
|
||||
prune-cache: false
|
||||
@@ -241,7 +241,7 @@ If you want to ignore this, set the `ignore-nothing-to-cache` input to `true`.
|
||||
|
||||
```yaml
|
||||
- name: Ignore nothing to cache
|
||||
uses: astral-sh/setup-uv@v4
|
||||
uses: astral-sh/setup-uv@v5
|
||||
with:
|
||||
enable-cache: true
|
||||
ignore-nothing-to-cache: true
|
||||
@@ -259,7 +259,7 @@ are not sufficient, you can provide a custom GitHub token with the necessary per
|
||||
|
||||
```yaml
|
||||
- name: Install the latest version of uv with a custom GitHub token
|
||||
uses: astral-sh/setup-uv@v4
|
||||
uses: astral-sh/setup-uv@v5
|
||||
with:
|
||||
github-token: ${{ secrets.CUSTOM_GITHUB_TOKEN }}
|
||||
```
|
||||
@@ -277,7 +277,7 @@ input:
|
||||
|
||||
```yaml
|
||||
- name: Install the latest version of uv with a custom tool dir
|
||||
uses: astral-sh/setup-uv@v4
|
||||
uses: astral-sh/setup-uv@v5
|
||||
with:
|
||||
tool-dir: "/path/to/tool/dir"
|
||||
```
|
||||
@@ -296,7 +296,7 @@ If you want to change this behaviour (especially on self-hosted runners) you can
|
||||
|
||||
```yaml
|
||||
- name: Install the latest version of uv with a custom tool bin dir
|
||||
uses: astral-sh/setup-uv@v4
|
||||
uses: astral-sh/setup-uv@v5
|
||||
with:
|
||||
tool-bin-dir: "/path/to/tool-bin/dir"
|
||||
```
|
||||
@@ -312,7 +312,7 @@ This action supports expanding the `~` character to the user's home directory fo
|
||||
|
||||
```yaml
|
||||
- name: Expand the tilde character
|
||||
uses: astral-sh/setup-uv@v4
|
||||
uses: astral-sh/setup-uv@v5
|
||||
with:
|
||||
cache-local-path: "~/path/to/cache"
|
||||
tool-dir: "~/path/to/tool/dir"
|
||||
@@ -334,21 +334,22 @@ by name (`uv`).
|
||||
|
||||
### Do I still need `actions/setup-python` alongside `setup-uv`?
|
||||
|
||||
No. This action is modelled as a drop-in replacement for `actions/setup-python` when using uv. With
|
||||
`setup-uv`, you can install a specific version of Python using `uv python install` rather than
|
||||
With `setup-uv`, you can install a specific version of Python using `uv python install` rather than
|
||||
relying on `actions/setup-python`.
|
||||
|
||||
Using `actions/setup-python` can be faster, because GitHub caches the Python versions alongside the runner.
|
||||
|
||||
For example:
|
||||
|
||||
```yaml
|
||||
- name: Checkout the repository
|
||||
uses: actions/checkout@main
|
||||
- name: Install the latest version of uv
|
||||
uses: astral-sh/setup-uv@v4
|
||||
uses: astral-sh/setup-uv@v5
|
||||
with:
|
||||
enable-cache: true
|
||||
- name: Test
|
||||
run: uv run --frozen pytest
|
||||
run: uv run --frozen pytest # Uses the Python version automatically installed by uv
|
||||
```
|
||||
|
||||
To install a specific version of Python, use
|
||||
@@ -356,7 +357,7 @@ To install a specific version of Python, use
|
||||
|
||||
```yaml
|
||||
- name: Install the latest version of uv
|
||||
uses: astral-sh/setup-uv@v4
|
||||
uses: astral-sh/setup-uv@v5
|
||||
with:
|
||||
enable-cache: true
|
||||
- name: Install Python 3.12
|
||||
@@ -375,7 +376,7 @@ output:
|
||||
uses: actions/checkout@main
|
||||
- name: Install the default version of uv
|
||||
id: setup-uv
|
||||
uses: astral-sh/setup-uv@v4
|
||||
uses: astral-sh/setup-uv@v5
|
||||
- name: Print the installed version
|
||||
run: echo "Installed uv version is ${{ steps.setup-uv.outputs.uv-version }}"
|
||||
```
|
||||
|
||||
14
dist/save-cache/index.js
generated
vendored
14
dist/save-cache/index.js
generated
vendored
@@ -91465,9 +91465,9 @@ const exec = __importStar(__nccwpck_require__(5236));
|
||||
exports.STATE_CACHE_KEY = "cache-key";
|
||||
exports.STATE_CACHE_MATCHED_KEY = "cache-matched-key";
|
||||
const CACHE_VERSION = "1";
|
||||
function restoreCache(version) {
|
||||
function restoreCache() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const cacheKey = yield computeKeys(version);
|
||||
const cacheKey = yield computeKeys();
|
||||
let matchedKey;
|
||||
core.info(`Trying to restore uv cache from GitHub Actions cache with key: ${cacheKey}`);
|
||||
try {
|
||||
@@ -91483,22 +91483,22 @@ function restoreCache(version) {
|
||||
handleMatchResult(matchedKey, cacheKey);
|
||||
});
|
||||
}
|
||||
function computeKeys(version) {
|
||||
function computeKeys() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
let cacheDependencyPathHash = "-";
|
||||
if (inputs_1.cacheDependencyGlob !== "") {
|
||||
core.info(`Searching files using cache dependency glob: ${inputs_1.cacheDependencyGlob.split("\n").join(",")}`);
|
||||
cacheDependencyPathHash += yield (0, hash_files_1.hashFiles)(inputs_1.cacheDependencyGlob, true);
|
||||
if (cacheDependencyPathHash === "-") {
|
||||
throw new Error(`No file matched to [${inputs_1.cacheDependencyGlob.split("\n").join(",")}], make sure you have checked out the target repository and configured the cache-dependency-glob input correctly.`);
|
||||
core.warning(`No file matched to [${inputs_1.cacheDependencyGlob.split("\n").join(",")}]. The cache will never get invalidated. Make sure you have checked out the target repository and configured the cache-dependency-glob input correctly.`);
|
||||
}
|
||||
}
|
||||
else {
|
||||
cacheDependencyPathHash += "no-dependency-glob";
|
||||
if (cacheDependencyPathHash === "-") {
|
||||
cacheDependencyPathHash = "-no-dependency-glob";
|
||||
}
|
||||
const suffix = inputs_1.cacheSuffix ? `-${inputs_1.cacheSuffix}` : "";
|
||||
const pythonVersion = yield getPythonVersion();
|
||||
return `setup-uv-${CACHE_VERSION}-${(0, platforms_1.getArch)()}-${(0, platforms_1.getPlatform)()}-${version}-${pythonVersion}${cacheDependencyPathHash}${suffix}`;
|
||||
return `setup-uv-${CACHE_VERSION}-${(0, platforms_1.getArch)()}-${(0, platforms_1.getPlatform)()}-${pythonVersion}${cacheDependencyPathHash}${suffix}`;
|
||||
});
|
||||
}
|
||||
function getPythonVersion() {
|
||||
|
||||
18
dist/setup/index.js
generated
vendored
18
dist/setup/index.js
generated
vendored
@@ -96548,9 +96548,9 @@ const exec = __importStar(__nccwpck_require__(5236));
|
||||
exports.STATE_CACHE_KEY = "cache-key";
|
||||
exports.STATE_CACHE_MATCHED_KEY = "cache-matched-key";
|
||||
const CACHE_VERSION = "1";
|
||||
function restoreCache(version) {
|
||||
function restoreCache() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const cacheKey = yield computeKeys(version);
|
||||
const cacheKey = yield computeKeys();
|
||||
let matchedKey;
|
||||
core.info(`Trying to restore uv cache from GitHub Actions cache with key: ${cacheKey}`);
|
||||
try {
|
||||
@@ -96566,22 +96566,22 @@ function restoreCache(version) {
|
||||
handleMatchResult(matchedKey, cacheKey);
|
||||
});
|
||||
}
|
||||
function computeKeys(version) {
|
||||
function computeKeys() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
let cacheDependencyPathHash = "-";
|
||||
if (inputs_1.cacheDependencyGlob !== "") {
|
||||
core.info(`Searching files using cache dependency glob: ${inputs_1.cacheDependencyGlob.split("\n").join(",")}`);
|
||||
cacheDependencyPathHash += yield (0, hash_files_1.hashFiles)(inputs_1.cacheDependencyGlob, true);
|
||||
if (cacheDependencyPathHash === "-") {
|
||||
throw new Error(`No file matched to [${inputs_1.cacheDependencyGlob.split("\n").join(",")}], make sure you have checked out the target repository and configured the cache-dependency-glob input correctly.`);
|
||||
core.warning(`No file matched to [${inputs_1.cacheDependencyGlob.split("\n").join(",")}]. The cache will never get invalidated. Make sure you have checked out the target repository and configured the cache-dependency-glob input correctly.`);
|
||||
}
|
||||
}
|
||||
else {
|
||||
cacheDependencyPathHash += "no-dependency-glob";
|
||||
if (cacheDependencyPathHash === "-") {
|
||||
cacheDependencyPathHash = "-no-dependency-glob";
|
||||
}
|
||||
const suffix = inputs_1.cacheSuffix ? `-${inputs_1.cacheSuffix}` : "";
|
||||
const pythonVersion = yield getPythonVersion();
|
||||
return `setup-uv-${CACHE_VERSION}-${(0, platforms_1.getArch)()}-${(0, platforms_1.getPlatform)()}-${version}-${pythonVersion}${cacheDependencyPathHash}${suffix}`;
|
||||
return `setup-uv-${CACHE_VERSION}-${(0, platforms_1.getArch)()}-${(0, platforms_1.getPlatform)()}-${pythonVersion}${cacheDependencyPathHash}${suffix}`;
|
||||
});
|
||||
}
|
||||
function getPythonVersion() {
|
||||
@@ -99274,7 +99274,7 @@ function run() {
|
||||
core.setOutput("uv-version", setupResult.version);
|
||||
core.info(`Successfully installed uv version ${setupResult.version}`);
|
||||
if (inputs_1.enableCache) {
|
||||
yield (0, restore_cache_1.restoreCache)(setupResult.version);
|
||||
yield (0, restore_cache_1.restoreCache)();
|
||||
}
|
||||
process.exit(0);
|
||||
}
|
||||
@@ -99349,7 +99349,7 @@ function setupPython() {
|
||||
venvBinPath = ".venv/Scripts";
|
||||
}
|
||||
core.addPath(venvBinPath);
|
||||
core.exportVariable("VIRTUAL_ENV", venvBinPath);
|
||||
core.exportVariable("VIRTUAL_ENV", ".venv");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
17
src/cache/restore-cache.ts
vendored
17
src/cache/restore-cache.ts
vendored
@@ -14,8 +14,8 @@ export const STATE_CACHE_KEY = "cache-key";
|
||||
export const STATE_CACHE_MATCHED_KEY = "cache-matched-key";
|
||||
const CACHE_VERSION = "1";
|
||||
|
||||
export async function restoreCache(version: string): Promise<void> {
|
||||
const cacheKey = await computeKeys(version);
|
||||
export async function restoreCache(): Promise<void> {
|
||||
const cacheKey = await computeKeys();
|
||||
|
||||
let matchedKey: string | undefined;
|
||||
core.info(
|
||||
@@ -35,7 +35,7 @@ export async function restoreCache(version: string): Promise<void> {
|
||||
handleMatchResult(matchedKey, cacheKey);
|
||||
}
|
||||
|
||||
async function computeKeys(version: string): Promise<string> {
|
||||
async function computeKeys(): Promise<string> {
|
||||
let cacheDependencyPathHash = "-";
|
||||
if (cacheDependencyGlob !== "") {
|
||||
core.info(
|
||||
@@ -43,16 +43,17 @@ async function computeKeys(version: string): Promise<string> {
|
||||
);
|
||||
cacheDependencyPathHash += await hashFiles(cacheDependencyGlob, true);
|
||||
if (cacheDependencyPathHash === "-") {
|
||||
throw new Error(
|
||||
`No file matched to [${cacheDependencyGlob.split("\n").join(",")}], make sure you have checked out the target repository and configured the cache-dependency-glob input correctly.`,
|
||||
core.warning(
|
||||
`No file matched to [${cacheDependencyGlob.split("\n").join(",")}]. The cache will never get invalidated. Make sure you have checked out the target repository and configured the cache-dependency-glob input correctly.`,
|
||||
);
|
||||
}
|
||||
} else {
|
||||
cacheDependencyPathHash += "no-dependency-glob";
|
||||
}
|
||||
if (cacheDependencyPathHash === "-") {
|
||||
cacheDependencyPathHash = "-no-dependency-glob";
|
||||
}
|
||||
const suffix = cacheSuffix ? `-${cacheSuffix}` : "";
|
||||
const pythonVersion = await getPythonVersion();
|
||||
return `setup-uv-${CACHE_VERSION}-${getArch()}-${getPlatform()}-${version}-${pythonVersion}${cacheDependencyPathHash}${suffix}`;
|
||||
return `setup-uv-${CACHE_VERSION}-${getArch()}-${getPlatform()}-${pythonVersion}${cacheDependencyPathHash}${suffix}`;
|
||||
}
|
||||
|
||||
async function getPythonVersion(): Promise<string> {
|
||||
|
||||
@@ -55,7 +55,7 @@ async function run(): Promise<void> {
|
||||
core.info(`Successfully installed uv version ${setupResult.version}`);
|
||||
|
||||
if (enableCache) {
|
||||
await restoreCache(setupResult.version);
|
||||
await restoreCache();
|
||||
}
|
||||
process.exit(0);
|
||||
} catch (err) {
|
||||
@@ -143,7 +143,7 @@ async function setupPython(): Promise<void> {
|
||||
venvBinPath = ".venv/Scripts";
|
||||
}
|
||||
core.addPath(venvBinPath);
|
||||
core.exportVariable("VIRTUAL_ENV", venvBinPath);
|
||||
core.exportVariable("VIRTUAL_ENV", ".venv");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user