5
0
mirror of https://github.com/astral-sh/setup-uv.git synced 2025-12-17 11:05:59 +00:00

Compare commits

..

5 Commits

Author SHA1 Message Date
Kevin Stillhammer
6a26ee8850 Debug macos python version 2024-12-26 17:04:56 +01:00
Jinzhe Zeng
03fe035094 docs: bump astral-sh/setup-uv to v5 (#205) 2024-12-23 22:16:27 +01:00
Kevin Stillhammer
887a942a15 Set VIRTUAL_ENV to .venv instead of .venv/bin (#210)
Closes: #209
2024-12-23 17:45:21 +01:00
Kevin Stillhammer
d174a24c07 Align use of actions/setup-python with uv docu (#207)
Closes: #197
2024-12-22 11:13:40 +00:00
Kevin Stillhammer
12c852e6ba Remove uv version from cache key (#206)
This approach was copied from setup-rye but uv now has the capability to
determine if a cache version is compatible. By removing it we will less
frequently invalidate the cache and thus save bandwidth

Closes: #203
2024-12-22 12:12:29 +01:00
6 changed files with 56 additions and 41 deletions

View File

@@ -167,3 +167,17 @@ jobs:
exit 1 exit 1
fi fi
shell: bash 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

View File

@@ -34,7 +34,7 @@ Set up your GitHub Actions workflow with a specific version of [uv](https://docs
```yaml ```yaml
- name: Install the latest version of uv - name: Install the latest version of uv
uses: astral-sh/setup-uv@v4 uses: astral-sh/setup-uv@v5
with: with:
version: "latest" version: "latest"
``` ```
@@ -46,7 +46,7 @@ For an example workflow, see
```yaml ```yaml
- name: Install a specific version of uv - name: Install a specific version of uv
uses: astral-sh/setup-uv@v4 uses: astral-sh/setup-uv@v5
with: with:
version: "0.4.4" version: "0.4.4"
``` ```
@@ -58,14 +58,14 @@ to install the latest version that satisfies the range.
```yaml ```yaml
- name: Install a semver range of uv - name: Install a semver range of uv
uses: astral-sh/setup-uv@v4 uses: astral-sh/setup-uv@v5
with: with:
version: ">=0.4.0" version: ">=0.4.0"
``` ```
```yaml ```yaml
- name: Pinning a minor version of uv - name: Pinning a minor version of uv
uses: astral-sh/setup-uv@v4 uses: astral-sh/setup-uv@v5
with: with:
version: "0.4.x" version: "0.4.x"
``` ```
@@ -82,7 +82,7 @@ This will override any python version specifications in `pyproject.toml` and `.p
```yaml ```yaml
- name: Install the latest version of uv and set the python version to 3.13t - 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: with:
python-version: 3.13t python-version: 3.13t
- run: uv pip install --python=3.13t pip - run: uv pip install --python=3.13t pip
@@ -100,7 +100,7 @@ jobs:
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- name: Install the latest version of uv and set the python version - 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: with:
python-version: ${{ matrix.python-version }} python-version: ${{ matrix.python-version }}
- name: Test with python ${{ 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 ```yaml
- name: Install a specific version and validate the checksum - name: Install a specific version and validate the checksum
uses: astral-sh/setup-uv@v4 uses: astral-sh/setup-uv@v5
with: with:
version: "0.3.1" version: "0.3.1"
checksum: "e11b01402ab645392c7ad6044db63d37e4fd1e745e015306993b07695ea5f9f8" checksum: "e11b01402ab645392c7ad6044db63d37e4fd1e745e015306993b07695ea5f9f8"
@@ -136,7 +136,7 @@ You can optionally define a custom cache key suffix.
```yaml ```yaml
- name: Enable caching and define a custom cache key suffix - name: Enable caching and define a custom cache key suffix
id: setup-uv id: setup-uv
uses: astral-sh/setup-uv@v4 uses: astral-sh/setup-uv@v5
with: with:
enable-cache: true enable-cache: true
cache-suffix: "optional-suffix" cache-suffix: "optional-suffix"
@@ -168,7 +168,7 @@ changes. If you use relative paths, they are relative to the repository root.
```yaml ```yaml
- name: Define a cache dependency glob - name: Define a cache dependency glob
uses: astral-sh/setup-uv@v4 uses: astral-sh/setup-uv@v5
with: with:
enable-cache: true enable-cache: true
cache-dependency-glob: "**/pyproject.toml" cache-dependency-glob: "**/pyproject.toml"
@@ -176,7 +176,7 @@ changes. If you use relative paths, they are relative to the repository root.
```yaml ```yaml
- name: Define a list of cache dependency globs - name: Define a list of cache dependency globs
uses: astral-sh/setup-uv@v4 uses: astral-sh/setup-uv@v5
with: with:
enable-cache: true enable-cache: true
cache-dependency-glob: | cache-dependency-glob: |
@@ -186,7 +186,7 @@ changes. If you use relative paths, they are relative to the repository root.
```yaml ```yaml
- name: Define an absolute cache dependency glob - name: Define an absolute cache dependency glob
uses: astral-sh/setup-uv@v4 uses: astral-sh/setup-uv@v5
with: with:
enable-cache: true enable-cache: true
cache-dependency-glob: "/tmp/my-folder/requirements*.txt" 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 ```yaml
- name: Never invalidate the cache - name: Never invalidate the cache
uses: astral-sh/setup-uv@v4 uses: astral-sh/setup-uv@v5
with: with:
enable-cache: true enable-cache: true
cache-dependency-glob: "" 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 ```yaml
- name: Define a custom uv cache path - name: Define a custom uv cache path
uses: astral-sh/setup-uv@v4 uses: astral-sh/setup-uv@v5
with: with:
cache-local-path: "/path/to/cache" cache-local-path: "/path/to/cache"
``` ```
@@ -228,7 +228,7 @@ input.
```yaml ```yaml
- name: Don't prune the cache before saving it - name: Don't prune the cache before saving it
uses: astral-sh/setup-uv@v4 uses: astral-sh/setup-uv@v5
with: with:
enable-cache: true enable-cache: true
prune-cache: false prune-cache: false
@@ -241,7 +241,7 @@ If you want to ignore this, set the `ignore-nothing-to-cache` input to `true`.
```yaml ```yaml
- name: Ignore nothing to cache - name: Ignore nothing to cache
uses: astral-sh/setup-uv@v4 uses: astral-sh/setup-uv@v5
with: with:
enable-cache: true enable-cache: true
ignore-nothing-to-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 ```yaml
- name: Install the latest version of uv with a custom GitHub token - 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: with:
github-token: ${{ secrets.CUSTOM_GITHUB_TOKEN }} github-token: ${{ secrets.CUSTOM_GITHUB_TOKEN }}
``` ```
@@ -277,7 +277,7 @@ input:
```yaml ```yaml
- name: Install the latest version of uv with a custom tool dir - 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: with:
tool-dir: "/path/to/tool/dir" 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 ```yaml
- name: Install the latest version of uv with a custom tool bin dir - 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: with:
tool-bin-dir: "/path/to/tool-bin/dir" 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 ```yaml
- name: Expand the tilde character - name: Expand the tilde character
uses: astral-sh/setup-uv@v4 uses: astral-sh/setup-uv@v5
with: with:
cache-local-path: "~/path/to/cache" cache-local-path: "~/path/to/cache"
tool-dir: "~/path/to/tool/dir" tool-dir: "~/path/to/tool/dir"
@@ -334,21 +334,22 @@ by name (`uv`).
### Do I still need `actions/setup-python` alongside `setup-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 With `setup-uv`, you can install a specific version of Python using `uv python install` rather than
`setup-uv`, you can install a specific version of Python using `uv python install` rather than
relying on `actions/setup-python`. relying on `actions/setup-python`.
Using `actions/setup-python` can be faster, because GitHub caches the Python versions alongside the runner.
For example: For example:
```yaml ```yaml
- name: Checkout the repository - name: Checkout the repository
uses: actions/checkout@main uses: actions/checkout@main
- name: Install the latest version of uv - name: Install the latest version of uv
uses: astral-sh/setup-uv@v4 uses: astral-sh/setup-uv@v5
with: with:
enable-cache: true enable-cache: true
- name: Test - 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 To install a specific version of Python, use
@@ -356,7 +357,7 @@ To install a specific version of Python, use
```yaml ```yaml
- name: Install the latest version of uv - name: Install the latest version of uv
uses: astral-sh/setup-uv@v4 uses: astral-sh/setup-uv@v5
with: with:
enable-cache: true enable-cache: true
- name: Install Python 3.12 - name: Install Python 3.12
@@ -375,7 +376,7 @@ output:
uses: actions/checkout@main uses: actions/checkout@main
- name: Install the default version of uv - name: Install the default version of uv
id: setup-uv id: setup-uv
uses: astral-sh/setup-uv@v4 uses: astral-sh/setup-uv@v5
- name: Print the installed version - name: Print the installed version
run: echo "Installed uv version is ${{ steps.setup-uv.outputs.uv-version }}" run: echo "Installed uv version is ${{ steps.setup-uv.outputs.uv-version }}"
``` ```

8
dist/save-cache/index.js generated vendored
View File

@@ -91465,9 +91465,9 @@ const exec = __importStar(__nccwpck_require__(5236));
exports.STATE_CACHE_KEY = "cache-key"; exports.STATE_CACHE_KEY = "cache-key";
exports.STATE_CACHE_MATCHED_KEY = "cache-matched-key"; exports.STATE_CACHE_MATCHED_KEY = "cache-matched-key";
const CACHE_VERSION = "1"; const CACHE_VERSION = "1";
function restoreCache(version) { function restoreCache() {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
const cacheKey = yield computeKeys(version); const cacheKey = yield computeKeys();
let matchedKey; let matchedKey;
core.info(`Trying to restore uv cache from GitHub Actions cache with key: ${cacheKey}`); core.info(`Trying to restore uv cache from GitHub Actions cache with key: ${cacheKey}`);
try { try {
@@ -91483,7 +91483,7 @@ function restoreCache(version) {
handleMatchResult(matchedKey, cacheKey); handleMatchResult(matchedKey, cacheKey);
}); });
} }
function computeKeys(version) { function computeKeys() {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
let cacheDependencyPathHash = "-"; let cacheDependencyPathHash = "-";
if (inputs_1.cacheDependencyGlob !== "") { if (inputs_1.cacheDependencyGlob !== "") {
@@ -91498,7 +91498,7 @@ function computeKeys(version) {
} }
const suffix = inputs_1.cacheSuffix ? `-${inputs_1.cacheSuffix}` : ""; const suffix = inputs_1.cacheSuffix ? `-${inputs_1.cacheSuffix}` : "";
const pythonVersion = yield getPythonVersion(); 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() { function getPythonVersion() {

12
dist/setup/index.js generated vendored
View File

@@ -96548,9 +96548,9 @@ const exec = __importStar(__nccwpck_require__(5236));
exports.STATE_CACHE_KEY = "cache-key"; exports.STATE_CACHE_KEY = "cache-key";
exports.STATE_CACHE_MATCHED_KEY = "cache-matched-key"; exports.STATE_CACHE_MATCHED_KEY = "cache-matched-key";
const CACHE_VERSION = "1"; const CACHE_VERSION = "1";
function restoreCache(version) { function restoreCache() {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
const cacheKey = yield computeKeys(version); const cacheKey = yield computeKeys();
let matchedKey; let matchedKey;
core.info(`Trying to restore uv cache from GitHub Actions cache with key: ${cacheKey}`); core.info(`Trying to restore uv cache from GitHub Actions cache with key: ${cacheKey}`);
try { try {
@@ -96566,7 +96566,7 @@ function restoreCache(version) {
handleMatchResult(matchedKey, cacheKey); handleMatchResult(matchedKey, cacheKey);
}); });
} }
function computeKeys(version) { function computeKeys() {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
let cacheDependencyPathHash = "-"; let cacheDependencyPathHash = "-";
if (inputs_1.cacheDependencyGlob !== "") { if (inputs_1.cacheDependencyGlob !== "") {
@@ -96581,7 +96581,7 @@ function computeKeys(version) {
} }
const suffix = inputs_1.cacheSuffix ? `-${inputs_1.cacheSuffix}` : ""; const suffix = inputs_1.cacheSuffix ? `-${inputs_1.cacheSuffix}` : "";
const pythonVersion = yield getPythonVersion(); 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() { function getPythonVersion() {
@@ -99274,7 +99274,7 @@ function run() {
core.setOutput("uv-version", setupResult.version); core.setOutput("uv-version", setupResult.version);
core.info(`Successfully installed uv version ${setupResult.version}`); core.info(`Successfully installed uv version ${setupResult.version}`);
if (inputs_1.enableCache) { if (inputs_1.enableCache) {
yield (0, restore_cache_1.restoreCache)(setupResult.version); yield (0, restore_cache_1.restoreCache)();
} }
process.exit(0); process.exit(0);
} }
@@ -99349,7 +99349,7 @@ function setupPython() {
venvBinPath = ".venv/Scripts"; venvBinPath = ".venv/Scripts";
} }
core.addPath(venvBinPath); core.addPath(venvBinPath);
core.exportVariable("VIRTUAL_ENV", venvBinPath); core.exportVariable("VIRTUAL_ENV", ".venv");
} }
}); });
} }

View File

@@ -14,8 +14,8 @@ export const STATE_CACHE_KEY = "cache-key";
export const STATE_CACHE_MATCHED_KEY = "cache-matched-key"; export const STATE_CACHE_MATCHED_KEY = "cache-matched-key";
const CACHE_VERSION = "1"; const CACHE_VERSION = "1";
export async function restoreCache(version: string): Promise<void> { export async function restoreCache(): Promise<void> {
const cacheKey = await computeKeys(version); const cacheKey = await computeKeys();
let matchedKey: string | undefined; let matchedKey: string | undefined;
core.info( core.info(
@@ -35,7 +35,7 @@ export async function restoreCache(version: string): Promise<void> {
handleMatchResult(matchedKey, cacheKey); handleMatchResult(matchedKey, cacheKey);
} }
async function computeKeys(version: string): Promise<string> { async function computeKeys(): Promise<string> {
let cacheDependencyPathHash = "-"; let cacheDependencyPathHash = "-";
if (cacheDependencyGlob !== "") { if (cacheDependencyGlob !== "") {
core.info( core.info(
@@ -53,7 +53,7 @@ async function computeKeys(version: string): Promise<string> {
} }
const suffix = cacheSuffix ? `-${cacheSuffix}` : ""; const suffix = cacheSuffix ? `-${cacheSuffix}` : "";
const pythonVersion = await getPythonVersion(); 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> { async function getPythonVersion(): Promise<string> {

View File

@@ -55,7 +55,7 @@ async function run(): Promise<void> {
core.info(`Successfully installed uv version ${setupResult.version}`); core.info(`Successfully installed uv version ${setupResult.version}`);
if (enableCache) { if (enableCache) {
await restoreCache(setupResult.version); await restoreCache();
} }
process.exit(0); process.exit(0);
} catch (err) { } catch (err) {
@@ -143,7 +143,7 @@ async function setupPython(): Promise<void> {
venvBinPath = ".venv/Scripts"; venvBinPath = ".venv/Scripts";
} }
core.addPath(venvBinPath); core.addPath(venvBinPath);
core.exportVariable("VIRTUAL_ENV", venvBinPath); core.exportVariable("VIRTUAL_ENV", ".venv");
} }
} }