Skip to content

Commit

Permalink
Add tool bin dir to PATH on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
eifinger committed Sep 18, 2024
1 parent 8205eab commit e35ed48
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 5 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,21 @@ jobs:
- name: Install default version
uses: ./
- run: uvx ruff --version
test-tool-install:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os:
[
ubuntu-latest,
macos-latest,
macos-14,
windows-latest,
oracle-aarch64,
]
steps:
- uses: actions/checkout@v4
- name: Install default version
uses: ./
- run: uv tool install ruff
- run: ruff --version
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ Set up your GitHub Actions workflow with a specific version of [uv](https://docs
- [Usage](#usage)
- [Install the latest version (default)](#install-the-latest-version-default)
- [Install a specific version](#install-a-specific-version)
- [Install a version by supplying a semver range](#install-a-version-by-supplying-a-semver-range)
- [Validate checksum](#validate-checksum)
- [Enable Caching](#enable-caching)
- [Cache dependency glob](#cache-dependency-glob)
- [Local cache path](#local-cache-path)
- [GitHub authentication token](#github-authentication-token)
- [UV_TOOL_BIN_DIR](#uv_tool_bin_dir)
- [How it works](#how-it-works)
- [FAQ](#faq)

Expand Down Expand Up @@ -178,6 +180,23 @@ are not sufficient, you can provide a custom GitHub token with the necessary per
github-token: ${{ secrets.CUSTOM_GITHUB_TOKEN }}
```

### UV_TOOL_BIN_DIR

On Windows `UV_TOOL_BIN_DIR` is set to the `TMP` dir.
On GitHub hosted runners this is on the much faster `D:` drive.
This path is also automatically added to the PATH.

On all other platforms the tool binaries get installed to the [default location](https://docs.astral.sh/uv/concepts/tools/#the-bin-directory).

If you want to change this behaviour (especially on self-hosted runners) you can use the `tool-bin-dir` input:

```yaml
- name: Install the latest version of uv with a custom tool bin dir
uses: astral-sh/setup-uv@v3
with:
tool-bin-dir: "/path/to/tool/bin"
```

## How it works

This action downloads uv from the uv repo's official
Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ inputs:
cache-local-path:
description: "Local path to store the cache."
default: ""
tool-bin-dir:
description: "Custom path to set UV_TOOL_BIN_DIR to."
required: false
outputs:
uv-version:
description: "The installed uv version. Useful when using latest."
Expand Down
15 changes: 13 additions & 2 deletions dist/save-cache/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 22 additions & 2 deletions dist/setup/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions src/setup-uv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
checkSum,
enableCache,
githubToken,
toolBinDir,
version,
} from "./utils/inputs";

Expand All @@ -41,6 +42,7 @@ async function run(): Promise<void> {
);

addUvToPath(setupResult.uvDir);
addToolBinToPath();
core.setOutput("uv-version", setupResult.version);
core.info(`Successfully installed uv version ${setupResult.version}`);

Expand Down Expand Up @@ -102,6 +104,15 @@ function addUvToPath(cachedPath: string): void {
core.info(`Added ${cachedPath} to the path`);
}

function addToolBinToPath(): void {
if (toolBinDir !== undefined) {
core.exportVariable("UV_TOOL_BIN_DIR", toolBinDir);
core.info(`Set UV_TOOL_BIN_DIR to ${toolBinDir}`);
core.addPath(toolBinDir);
core.info(`Added ${toolBinDir} to the path`);
}
}

function setCacheDir(cacheLocalPath: string): void {
core.exportVariable("UV_CACHE_DIR", cacheLocalPath);
core.info(`Set UV_CACHE_DIR to ${cacheLocalPath}`);
Expand Down
14 changes: 13 additions & 1 deletion src/utils/inputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,20 @@ export const checkSum = core.getInput("checksum");
export const enableCache = core.getInput("enable-cache") === "true";
export const cacheSuffix = core.getInput("cache-suffix") || "";
export const cacheLocalPath = getCacheLocalPath();
export const githubToken = core.getInput("github-token");
export const cacheDependencyGlob = core.getInput("cache-dependency-glob");
export const toolBinDir = getToolBinDir();
export const githubToken = core.getInput("github-token");

function getToolBinDir(): string | undefined {
const toolBinDirInput = core.getInput("tool-bin-dir");
if (toolBinDirInput !== "") {
return toolBinDirInput;
}
if (process.platform === "win32") {
return "D:\\a\\_temp\\uv-tool-bin-dir";
}
return undefined;
}

function getCacheLocalPath(): string {
const cacheLocalPathInput = core.getInput("cache-local-path");
Expand Down

0 comments on commit e35ed48

Please sign in to comment.