Skip to content

Commit

Permalink
Expand TILDE (~) in path inputs (#160)
Browse files Browse the repository at this point in the history
Closes: #159
  • Loading branch information
eifinger authored Nov 23, 2024
1 parent 7c23811 commit caf0cab
Show file tree
Hide file tree
Showing 8 changed files with 410 additions and 21 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/test-cache.yml
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,49 @@ jobs:
CACHE_HIT: ${{ steps.restore.outputs.cache-hit }}
- run: uv sync
working-directory: __tests__/fixtures/uv-project

prepare-tilde-expansion-tests:
runs-on: selfhosted-ubuntu-arm64
steps:
- name: Create cache directory
run: mkdir -p ~/uv-cache
shell: bash
- name: Create cache dependency glob file
run: touch ~/uv-cache.glob
shell: bash

test-tilde-expansion-cache-local-path:
needs: prepare-tilde-expansion-tests
runs-on: selfhosted-ubuntu-arm64
steps:
- uses: actions/checkout@v4
- name: Setup with cache
uses: ./
with:
enable-cache: true
cache-local-path: ~/uv-cache/cache-local-path

test-tilde-expansion-cache-dependency-glob:
needs: prepare-tilde-expansion-tests
runs-on: selfhosted-ubuntu-arm64
steps:
- uses: actions/checkout@v4
- name: Setup with cache
uses: ./
with:
enable-cache: true
cache-local-path: ~/uv-cache/cache-dependency-glob
cache-dependency-glob: "~/uv-cache.glob"

cleanup-tilde-expansion-tests:
needs:
- test-tilde-expansion-cache-local-path
- test-tilde-expansion-cache-dependency-glob
runs-on: selfhosted-ubuntu-arm64
steps:
- name: Remove cache directory
run: rm -rf ~/uv-cache
shell: bash
- name: Remove cache dependency glob file
run: rm -f ~/uv-cache.glob
shell: bash
21 changes: 21 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,24 @@ jobs:
uses: ./
- run: uv tool install ruff
- run: ruff --version

test-tilde-expansion-tool-dirs:
runs-on: selfhosted-ubuntu-arm64
steps:
- uses: actions/checkout@v4
- name: Setup with cache
uses: ./
with:
tool-bin-dir: "~/tool-bin-dir"
tool-dir: "~/tool-dir"
- name: "Check if tool dirs are expanded"
run: |
if ! echo "$PATH" | grep -q "/home/ubuntu/tool-bin-dir"; then
echo "PATH does not contain /home/ubuntu/tool-bin-dir: $PATH"
exit 1
fi
if [ "$UV_TOOL_DIR" != "/home/ubuntu/tool-dir" ]; then
echo "UV_TOOL_DIR does not contain /home/ubuntu/tool-dir: $UV_TOOL_DIR"
exit 1
fi
30 changes: 29 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Set up your GitHub Actions workflow with a specific version of [uv](https://docs
- [GitHub authentication token](#github-authentication-token)
- [UV_TOOL_DIR](#uv_tool_dir)
- [UV_TOOL_BIN_DIR](#uv_tool_bin_dir)
- [Tilde Expansion](#tilde-expansion)
- [How it works](#how-it-works)
- [FAQ](#faq)

Expand Down Expand Up @@ -120,7 +121,7 @@ use it in subsequent steps. For example, to use the cache in the above case:

If you want to control when the cache is invalidated, specify a glob pattern with the
`cache-dependency-glob` input. The cache will be invalidated if any file matching the glob pattern
changes. The glob matches files relative to the repository root.
changes. If you use relative paths, the glob matches files relative to the repository root.

> [!NOTE]
>
Expand All @@ -144,6 +145,14 @@ changes. The glob matches files relative to the repository root.
**/pyproject.toml
```

```yaml
- name: Define an absolute cache dependency glob
uses: astral-sh/setup-uv@v3
with:
enable-cache: true
cache-dependency-glob: "/tmp/my-folder/requirements*.txt"
```

```yaml
- name: Never invalidate the cache
uses: astral-sh/setup-uv@v3
Expand Down Expand Up @@ -240,6 +249,25 @@ If you want to change this behaviour (especially on self-hosted runners) you can
tool-bin-dir: "/path/to/tool-bin/dir"
```

### Tilde Expansion

This action supports expanding the `~` character to the user's home directory for the following inputs:

- `cache-local-path`
- `tool-dir`
- `tool-bin-dir`
- `cache-dependency-glob`

```yaml
- name: Expand the tilde character
uses: astral-sh/setup-uv@v3
with:
cache-local-path: "~/path/to/cache"
tool-dir: "~/path/to/tool/dir"
tool-bin-dir: "~/path/to/tool-bin/dir"
cache-dependency-glob: "~/my-cache-buster"
```

## How it works

This action downloads uv from the uv repo's official
Expand Down
140 changes: 135 additions & 5 deletions dist/save-cache/index.js

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

Loading

0 comments on commit caf0cab

Please sign in to comment.