Skip to content

Commit aeb4649

Browse files
authored
Set tool(-bin) dir and add to PATH (#87)
Fixes: #83 Fixes: #60
1 parent dbb680f commit aeb4649

File tree

7 files changed

+229
-19
lines changed

7 files changed

+229
-19
lines changed

.github/workflows/test.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,21 @@ jobs:
105105
- name: Install default version
106106
uses: ./
107107
- run: uvx ruff --version
108+
test-tool-install:
109+
runs-on: ${{ matrix.os }}
110+
strategy:
111+
matrix:
112+
os:
113+
[
114+
ubuntu-latest,
115+
macos-latest,
116+
macos-14,
117+
windows-latest,
118+
oracle-aarch64,
119+
]
120+
steps:
121+
- uses: actions/checkout@v4
122+
- name: Install default version
123+
uses: ./
124+
- run: uv tool install ruff
125+
- run: ruff --version

README.md

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,14 @@ Set up your GitHub Actions workflow with a specific version of [uv](https://docs
1313
- [Usage](#usage)
1414
- [Install the latest version (default)](#install-the-latest-version-default)
1515
- [Install a specific version](#install-a-specific-version)
16+
- [Install a version by supplying a semver range](#install-a-version-by-supplying-a-semver-range)
1617
- [Validate checksum](#validate-checksum)
1718
- [Enable Caching](#enable-caching)
1819
- [Cache dependency glob](#cache-dependency-glob)
1920
- [Local cache path](#local-cache-path)
2021
- [GitHub authentication token](#github-authentication-token)
22+
- [UV_TOOL_DIR](#uv_tool_dir)
23+
- [UV_TOOL_BIN_DIR](#uv_tool_bin_dir)
2124
- [How it works](#how-it-works)
2225
- [FAQ](#faq)
2326

@@ -151,8 +154,10 @@ changes. The glob matches files relative to the repository root.
151154

152155
### Local cache path
153156

154-
This action controls where uv stores its cache on the runner's filesystem. You can change the
155-
default (`/tmp/setup-uv-cache`) by specifying the path with the `cache-local-path` input.
157+
This action controls where uv stores its cache on the runner's filesystem by setting `UV_CACHE_DIR`.
158+
It defaults to `setup-uv-cache` in the `TMP` dir, `D:\a\_temp\uv-tool-dir` on Windows and
159+
`/tmp/setup-uv-cache` on Linux/macOS. You can change the default by specifying the path with the
160+
`cache-local-path` input.
156161

157162
```yaml
158163
- name: Define a custom uv cache path
@@ -178,6 +183,43 @@ are not sufficient, you can provide a custom GitHub token with the necessary per
178183
github-token: ${{ secrets.CUSTOM_GITHUB_TOKEN }}
179184
```
180185

186+
### UV_TOOL_DIR
187+
188+
On Windows `UV_TOOL_DIR` is set to `uv-tool-dir` in the `TMP` dir (e.g. `D:\a\_temp\uv-tool-dir`).
189+
On GitHub hosted runners this is on the much faster `D:` drive.
190+
191+
On all other platforms the tool environments are placed in the
192+
[default location](https://docs.astral.sh/uv/concepts/tools/#tools-directory).
193+
194+
If you want to change this behaviour (especially on self-hosted runners) you can use the `tool-dir`
195+
input:
196+
197+
```yaml
198+
- name: Install the latest version of uv with a custom tool dir
199+
uses: astral-sh/setup-uv@v3
200+
with:
201+
tool-dir: "/path/to/tool/dir"
202+
```
203+
204+
### UV_TOOL_BIN_DIR
205+
206+
On Windows `UV_TOOL_BIN_DIR` is set to `uv-tool-bin-dir` in the `TMP` dir (e.g.
207+
`D:\a\_temp\uv-tool-bin-dir`). On GitHub hosted runners this is on the much faster `D:` drive. This
208+
path is also automatically added to the PATH.
209+
210+
On all other platforms the tool binaries get installed to the
211+
[default location](https://docs.astral.sh/uv/concepts/tools/#the-bin-directory).
212+
213+
If you want to change this behaviour (especially on self-hosted runners) you can use the
214+
`tool-bin-dir` input:
215+
216+
```yaml
217+
- name: Install the latest version of uv with a custom tool bin dir
218+
uses: astral-sh/setup-uv@v3
219+
with:
220+
tool-bin-dir: "/path/to/tool-bin/dir"
221+
```
222+
181223
## How it works
182224

183225
This action downloads uv from the uv repo's official

action.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ inputs:
2929
cache-local-path:
3030
description: "Local path to store the cache."
3131
default: ""
32+
tool-dir:
33+
description: "Custom path to set UV_TOOL_DIR to."
34+
required: false
35+
tool-bin-dir:
36+
description: "Custom path to set UV_TOOL_BIN_DIR to."
37+
required: false
3238
outputs:
3339
uv-version:
3440
description: "The installed uv version. Useful when using latest."

dist/save-cache/index.js

Lines changed: 31 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/setup/index.js

Lines changed: 61 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/setup-uv.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import {
1818
checkSum,
1919
enableCache,
2020
githubToken,
21+
toolBinDir,
22+
toolDir,
2123
version,
2224
} from "./utils/inputs";
2325

@@ -41,6 +43,8 @@ async function run(): Promise<void> {
4143
);
4244

4345
addUvToPath(setupResult.uvDir);
46+
addToolBinToPath();
47+
setToolDir();
4448
core.setOutput("uv-version", setupResult.version);
4549
core.info(`Successfully installed uv version ${setupResult.version}`);
4650

@@ -102,6 +106,33 @@ function addUvToPath(cachedPath: string): void {
102106
core.info(`Added ${cachedPath} to the path`);
103107
}
104108

109+
function addToolBinToPath(): void {
110+
if (toolBinDir !== undefined) {
111+
core.exportVariable("UV_TOOL_BIN_DIR", toolBinDir);
112+
core.info(`Set UV_TOOL_BIN_DIR to ${toolBinDir}`);
113+
core.addPath(toolBinDir);
114+
core.info(`Added ${toolBinDir} to the path`);
115+
} else {
116+
if (process.env.XDG_BIN_HOME !== undefined) {
117+
core.addPath(process.env.XDG_BIN_HOME);
118+
core.info(`Added ${process.env.XDG_BIN_HOME} to the path`);
119+
} else if (process.env.XDG_DATA_HOME !== undefined) {
120+
core.addPath(`${process.env.XDG_DATA_HOME}/../bin`);
121+
core.info(`Added ${process.env.XDG_DATA_HOME}/../bin to the path`);
122+
} else {
123+
core.addPath(`${process.env.HOME}/.local/bin`);
124+
core.info(`Added ${process.env.HOME}/.local/bin to the path`);
125+
}
126+
}
127+
}
128+
129+
function setToolDir(): void {
130+
if (toolDir !== undefined) {
131+
core.exportVariable("UV_TOOL_DIR", toolDir);
132+
core.info(`Set UV_TOOL_DIR to ${toolDir}`);
133+
}
134+
}
135+
105136
function setCacheDir(cacheLocalPath: string): void {
106137
core.exportVariable("UV_CACHE_DIR", cacheLocalPath);
107138
core.info(`Set UV_CACHE_DIR to ${cacheLocalPath}`);

src/utils/inputs.ts

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,42 @@ export const checkSum = core.getInput("checksum");
66
export const enableCache = core.getInput("enable-cache") === "true";
77
export const cacheSuffix = core.getInput("cache-suffix") || "";
88
export const cacheLocalPath = getCacheLocalPath();
9-
export const githubToken = core.getInput("github-token");
109
export const cacheDependencyGlob = core.getInput("cache-dependency-glob");
10+
export const toolBinDir = getToolBinDir();
11+
export const toolDir = getToolDir();
12+
export const githubToken = core.getInput("github-token");
13+
14+
function getToolBinDir(): string | undefined {
15+
const toolBinDirInput = core.getInput("tool-bin-dir");
16+
if (toolBinDirInput !== "") {
17+
return toolBinDirInput;
18+
}
19+
if (process.platform === "win32") {
20+
if (process.env.RUNNER_TEMP !== undefined) {
21+
return `${process.env.RUNNER_TEMP}${path.sep}uv-tool-bin-dir`;
22+
}
23+
throw Error(
24+
"Could not determine UV_TOOL_BIN_DIR. Please make sure RUNNER_TEMP is set or provide the tool-bin-dir input",
25+
);
26+
}
27+
return undefined;
28+
}
29+
30+
function getToolDir(): string | undefined {
31+
const toolDirInput = core.getInput("tool-dir");
32+
if (toolDirInput !== "") {
33+
return toolDirInput;
34+
}
35+
if (process.platform === "win32") {
36+
if (process.env.RUNNER_TEMP !== undefined) {
37+
return `${process.env.RUNNER_TEMP}${path.sep}uv-tool-dir`;
38+
}
39+
throw Error(
40+
"Could not determine UV_TOOL_DIR. Please make sure RUNNER_TEMP is set or provide the tool-dir input",
41+
);
42+
}
43+
return undefined;
44+
}
1145

1246
function getCacheLocalPath(): string {
1347
const cacheLocalPathInput = core.getInput("cache-local-path");
@@ -17,8 +51,7 @@ function getCacheLocalPath(): string {
1751
if (process.env.RUNNER_TEMP !== undefined) {
1852
return `${process.env.RUNNER_TEMP}${path.sep}setup-uv-cache`;
1953
}
20-
if (process.platform === "win32") {
21-
return "D:\\a\\_temp\\setup-uv-cache";
22-
}
23-
return "/tmp/setup-uv-cache";
54+
throw Error(
55+
"Could not determine UV_CACHE_DIR. Please make sure RUNNER_TEMP is set or provide the cache-local-path input",
56+
);
2457
}

0 commit comments

Comments
 (0)