Skip to content

Commit ec4c691

Browse files
authored
new inputs activate-environment and working-directory (#381)
venv activation was implicit when python-version was supplied. This now only happens when activate-environment is true. working-directory controls where we work and thus also where the .venv will be created Closes: #351 Closes: #271 Closes: #251 Closes: #211
1 parent aa12905 commit ec4c691

File tree

9 files changed

+203
-179
lines changed

9 files changed

+203
-179
lines changed

.github/workflows/test.yml

+20-8
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ jobs:
115115
id: setup-uv
116116
uses: ./
117117
with:
118-
pyproject-file: "__tests__/fixtures/pyproject-toml-project/pyproject.toml"
118+
working-directory: "__tests__/fixtures/pyproject-toml-project"
119119
- name: Correct version gets installed
120120
run: |
121121
if [ "$(uv --version)" != "uv 0.5.14" ]; then
@@ -131,9 +131,8 @@ jobs:
131131
id: setup-uv
132132
uses: ./
133133
with:
134-
pyproject-file: "__tests__/fixtures/malformed-pyproject-toml-project/pyproject.toml"
135-
- run: uv sync
136-
working-directory: __tests__/fixtures/uv-project
134+
working-directory: "__tests__/fixtures/malformed-pyproject-toml-project"
135+
- run: uv --help
137136

138137
test-uv-file-version:
139138
runs-on: ubuntu-latest
@@ -143,8 +142,7 @@ jobs:
143142
id: setup-uv
144143
uses: ./
145144
with:
146-
pyproject-file: "__tests__/fixtures/uv-toml-project/pyproject.toml"
147-
uv-file: "__tests__/fixtures/uv-toml-project/uv.toml"
145+
working-directory: "__tests__/fixtures/uv-toml-project"
148146
- name: Correct version gets installed
149147
run: |
150148
if [ "$(uv --version)" != "uv 0.5.15" ]; then
@@ -229,7 +227,7 @@ jobs:
229227
fi
230228
231229
test-python-version:
232-
runs-on: ubuntu-latest
230+
runs-on: ${{ matrix.os }}
233231
strategy:
234232
matrix:
235233
os: [ubuntu-latest, macos-latest, windows-latest]
@@ -246,8 +244,21 @@ jobs:
246244
exit 1
247245
fi
248246
shell: bash
247+
248+
test-activate-environment:
249+
runs-on: ${{ matrix.os }}
250+
strategy:
251+
matrix:
252+
os: [ ubuntu-latest, macos-latest, windows-latest ]
253+
steps:
254+
- uses: actions/checkout@v4
255+
- name: Install latest version
256+
uses: ./
257+
with:
258+
python-version: 3.13.1t
259+
activate-environment: true
249260
- name: Verify packages can be installed
250-
run: uv pip install --python=3.13.1t pip
261+
run: uv pip install pip
251262
shell: bash
252263
- name: Verify python version is correct
253264
run: |
@@ -508,6 +519,7 @@ jobs:
508519
- test-tool-install
509520
- test-tilde-expansion-tool-dirs
510521
- test-python-version
522+
- test-activate-environment
511523
- test-musl
512524
- test-restore-cache
513525
- test-restore-cache-requirements-txt

README.md

+32-26
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ Set up your GitHub Actions workflow with a specific version of [uv](https://docs
1515
- [Install the latest version](#install-the-latest-version)
1616
- [Install a specific version](#install-a-specific-version)
1717
- [Install a version by supplying a semver range or pep440 specifier](#install-a-version-by-supplying-a-semver-range-or-pep440-specifier)
18-
- [Install a required-version](#install-a-required-version)
1918
- [Python version](#python-version)
19+
- [Activate environment](#activate-environment)
20+
- [Working directory](#working-directory)
2021
- [Validate checksum](#validate-checksum)
2122
- [Enable Caching](#enable-caching)
2223
- [Cache dependency glob](#cache-dependency-glob)
@@ -90,32 +91,9 @@ to install the latest version that satisfies the range.
9091
version: ">=0.4.25,<0.5"
9192
```
9293

93-
### Install a required-version
94-
95-
You can specify a [required-version](https://docs.astral.sh/uv/reference/settings/#required-version)
96-
in either a `uv.toml` or `pyproject.toml` file:
97-
98-
```yaml
99-
- name: Install required-version defined in uv.toml
100-
uses: astral-sh/setup-uv@v5
101-
with:
102-
uv-file: "path/to/uv.toml"
103-
```
104-
105-
```yaml
106-
- name: Install required-version defined in pyproject.toml
107-
uses: astral-sh/setup-uv@v5
108-
with:
109-
pyproject-file: "path/to/pyproject.toml"
110-
```
111-
11294
### Python version
11395

114-
You can use the input `python-version` to
115-
116-
- set the environment variable `UV_PYTHON` for the rest of your workflow
117-
- create a new virtual environment with the specified python version
118-
- activate the virtual environment for the rest of your workflow
96+
You can use the input `python-version` to set the environment variable `UV_PYTHON` for the rest of your workflow
11997

12098
This will override any python version specifications in `pyproject.toml` and `.python-version`
12199

@@ -146,6 +124,34 @@ jobs:
146124
run: uv run --frozen pytest
147125
```
148126

127+
### Activate environment
128+
129+
You can set `activate-environment` to `true` to automatically activate a venv.
130+
This allows directly using it in later steps:
131+
132+
```yaml
133+
- name: Install the latest version of uv and activate the environment
134+
uses: astral-sh/setup-uv@v5
135+
with:
136+
activate-environment: true
137+
- run: uv pip install pip
138+
```
139+
140+
### Working directory
141+
142+
You can set the working directory with the `working-directory` input.
143+
This controls where we look for `pyproject.toml`, `uv.toml` and `.python-version` files
144+
which are used to determine the version of uv and python to install.
145+
146+
It also controls where [the venv gets created](#activate-environment).
147+
148+
```yaml
149+
- name: Install uv based on the config files in the working-directory
150+
uses: astral-sh/setup-uv@v5
151+
with:
152+
working-directory: my/subproject/dir
153+
```
154+
149155
### Validate checksum
150156

151157
You can specify a checksum to validate the downloaded executable. Checksums up to the default version
@@ -383,7 +389,7 @@ This action downloads uv from the uv repo's official
383389
[GitHub Actions Toolkit](https://github.com/actions/toolkit) to cache it as a tool to speed up
384390
consecutive runs on self-hosted runners.
385391

386-
The installed version of uv is then added to the runner PATH, enabling subsequent steps to invoke it
392+
The installed version of uv is then added to the runner PATH, enabling later steps to invoke it
387393
by name (`uv`).
388394

389395
## FAQ

action.yml

+6-6
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ inputs:
66
version:
77
description: "The version of uv to install e.g., `0.5.0` Defaults to the version in pyproject.toml or 'latest'."
88
default: ""
9-
pyproject-file:
10-
description: "Path to a pyproject.toml"
11-
default: ""
12-
uv-file:
13-
description: "Path to a uv.toml"
14-
default: ""
159
python-version:
1610
description: "The version of Python to set UV_PYTHON to"
1711
required: false
12+
activate-environment:
13+
description: "Use uv venv to activate a venv ready to be used by later steps. "
14+
default: "false"
15+
working-directory:
16+
description: "The directory to execute all commands in and look for files such as pyproject.toml"
17+
default: ${{ github.workspace }}
1818
checksum:
1919
description: "The checksum of the uv version to install"
2020
required: false

dist/save-cache/index.js

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)