Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
180 changes: 180 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,186 @@ jobs:
echo "Installed version: ${{ steps.setup.outputs.version }}"
echo "Cache hit: ${{ steps.setup.outputs.cache-hit }}"

test-task-cache-populate:
runs-on: ubuntu-latest
timeout-minutes: 10
env:
GITHUB_RUN_ID: task-cache-e2e-${{ github.run_id }}
GITHUB_RUN_ATTEMPT: "1"
steps:
- uses: taiki-e/checkout-action@7d1e50e93dc4fb3bba58f85018fadf77898aee8b # v1.4.2

# The fixture lives under $RUNNER_TEMP, outside the repository, and
# `working-directory` points the action (and with it the task cache
# path) at it. The task cache is independent of the dependency cache,
# so no lock file is needed and `run-install` stays off.
- name: Create test project
shell: bash
run: |
PROJECT="$RUNNER_TEMP/task-cache-project"
mkdir -p "$PROJECT"
echo '{"name":"task-cache-project","private":true}' > "$PROJECT/package.json"
echo "PROJECT=$PROJECT" >> "$GITHUB_ENV"

- name: Setup Vite+ with task cache
uses: ./
id: setup
with:
working-directory: ${{ runner.temp }}/task-cache-project
task-cache: true
run-install: false

# The post action saves the task cache once the job finishes, so the
# entry content a later run must find is written here. The key is
# scoped to this workflow run, so no earlier entry can share it.
- name: Write task cache content for the entry to save
shell: bash
run: |
mkdir -p "$PROJECT/node_modules/.vite/task-cache"
echo "populate-${{ github.run_id }}" > "$PROJECT/node_modules/.vite/task-cache/marker.txt"
echo "populate-${{ github.run_id }}" > "$PROJECT/node_modules/.vite/task-cache/from-populate.txt"

test-task-cache-hit:
needs: test-task-cache-populate
runs-on: ubuntu-latest
timeout-minutes: 10
env:
GITHUB_RUN_ID: task-cache-e2e-${{ github.run_id }}
GITHUB_RUN_ATTEMPT: "1"
steps:
- uses: taiki-e/checkout-action@7d1e50e93dc4fb3bba58f85018fadf77898aee8b # v1.4.2

- name: Create test project
shell: bash
run: |
PROJECT="$RUNNER_TEMP/task-cache-project"
mkdir -p "$PROJECT"
echo '{"name":"task-cache-project","private":true}' > "$PROJECT/package.json"
echo "PROJECT=$PROJECT" >> "$GITHUB_ENV"

# Same run-scoped key as the populate job, so the restore resolves the
# exact primary key of the entry that job saved.
- name: Setup Vite+ with the same task cache key
uses: ./
id: setup
with:
working-directory: ${{ runner.temp }}/task-cache-project
task-cache: true
run-install: false

- name: Verify the saved task cache entry is restored
shell: bash
env:
ACTUAL_HIT: ${{ steps.setup.outputs.task-cache-hit }}
run: |
if [ "$ACTUAL_HIT" != "true" ]; then
echo "::error::task-cache-hit was '$ACTUAL_HIT'; the populate job did not save a restorable task cache entry"
exit 1
fi
if [ "$(cat "$PROJECT/node_modules/.vite/task-cache/marker.txt" 2>/dev/null)" != "populate-${{ github.run_id }}" ]; then
echo "::error::the restored task cache does not contain the content saved by the populate job"
exit 1
fi
echo "OK: task cache hit restored the saved entry"

test-task-cache-refresh:
needs: test-task-cache-hit
runs-on: ubuntu-latest
timeout-minutes: 10
env:
GITHUB_RUN_ID: task-cache-e2e-${{ github.run_id }}
GITHUB_RUN_ATTEMPT: "2"
steps:
- uses: taiki-e/checkout-action@7d1e50e93dc4fb3bba58f85018fadf77898aee8b # v1.4.2

- name: Create test project
shell: bash
run: |
PROJECT="$RUNNER_TEMP/task-cache-project"
mkdir -p "$PROJECT"
echo '{"name":"task-cache-project","private":true}' > "$PROJECT/package.json"
echo "PROJECT=$PROJECT" >> "$GITHUB_ENV"

# A new attempt means a new primary key, so the restore resolves through
# the `vite-task-Linux-x64-` restore keys to the entry saved earlier in
# this run. That entry is stale for this attempt, and the job replaces
# its contents below the way `vp run` task results would.
- name: Setup Vite+ with a new task cache attempt
uses: ./
id: setup
with:
working-directory: ${{ runner.temp }}/task-cache-project
task-cache: true
run-install: false

- name: Verify the restore keys resolve the earlier entry
shell: bash
env:
ACTUAL_HIT: ${{ steps.setup.outputs.task-cache-hit }}
run: |
if [ "$ACTUAL_HIT" != "true" ]; then
echo "::error::task-cache-hit was '$ACTUAL_HIT'; the restore keys did not resolve the entry saved earlier in this run"
exit 1
fi
echo "OK: restore keys resolved an earlier task cache entry"

# The post action saves the task cache after the job finishes. Replacing
# the restored (stale) content makes the saved entry differ from it; the
# save must happen because the primary key no longer matches.
- name: Change the task cache contents
shell: bash
run: |
rm -rf "$PROJECT/node_modules/.vite/task-cache"
mkdir -p "$PROJECT/node_modules/.vite/task-cache"
echo "refresh-${{ github.run_id }}" > "$PROJECT/node_modules/.vite/task-cache/marker.txt"

test-task-cache-updated:
needs: test-task-cache-refresh
runs-on: ubuntu-latest
timeout-minutes: 10
env:
GITHUB_RUN_ID: task-cache-e2e-${{ github.run_id }}
GITHUB_RUN_ATTEMPT: "2"
steps:
- uses: taiki-e/checkout-action@7d1e50e93dc4fb3bba58f85018fadf77898aee8b # v1.4.2

- name: Create test project
shell: bash
run: |
PROJECT="$RUNNER_TEMP/task-cache-project"
mkdir -p "$PROJECT"
echo '{"name":"task-cache-project","private":true}' > "$PROJECT/package.json"
echo "PROJECT=$PROJECT" >> "$GITHUB_ENV"

# Same attempt as the refresh job, so the restore resolves the exact
# primary key of the entry that job saved with the updated content.
- name: Setup Vite+ with the refreshed task cache key
uses: ./
id: setup
with:
working-directory: ${{ runner.temp }}/task-cache-project
task-cache: true
run-install: false

- name: Verify the updated task cache entry replaced the stale one
shell: bash
env:
ACTUAL_HIT: ${{ steps.setup.outputs.task-cache-hit }}
run: |
if [ "$ACTUAL_HIT" != "true" ]; then
echo "::error::task-cache-hit was '$ACTUAL_HIT'; the refresh job did not save a restorable task cache entry"
exit 1
fi
if [ "$(cat "$PROJECT/node_modules/.vite/task-cache/marker.txt" 2>/dev/null)" != "refresh-${{ github.run_id }}" ]; then
echo "::error::the restored task cache is stale: the updated content saved by the refresh job is missing"
exit 1
fi
if [ -e "$PROJECT/node_modules/.vite/task-cache/from-populate.txt" ]; then
echo "::error::stale content from the populate entry survived the refresh save"
exit 1
fi
echo "OK: a later run restores the updated task cache, not the stale entry"

test-vp-exec:
strategy:
fail-fast: false
Expand Down
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ GitHub Action, GitLab CI/CD remote template, and Azure Pipelines step template t
- Install Vite+ globally via official install scripts
- GitHub Action: optionally set up a specific Node.js version via `vp env use`
- GitHub Action: cache project dependencies with auto-detection of lock files
- GitHub Action: save task caches to GitHub Actions Cache
- Optionally run `vp install` after setup
- Optionally wrap `vp install` with [Socket Firewall Free (`sfw`)](https://docs.socket.dev/docs/socket-firewall-free) to block malicious dependencies
- Support for all major package managers (npm, pnpm, yarn, bun)
Expand Down Expand Up @@ -98,6 +99,20 @@ steps:
run-install: true
```

### With Task Caching

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what I'm supposed to test here, is it just trying to save and restore using the setup-vp action vs the regualr cache action?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At minimum, we need to verify cache hit, and then the cache stale logic after changes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright. I also notice that the normal cache has an option to not save to cache. Do we want the equivalent added to task cache?


This will save the Vite+ task cache to GitHub Actions with a specific key. This only saves the task cache; other caches (from Vite builds, for example) that happen to be included in the `node_modules/.vite` folder is not included.

At the end, the cache is written back to GitHub in the action's post step. The task cache is independent of the dependency cache, so `task-cache` saves on its own; set `task-cache-save: false` to restore without saving.

```yaml
steps:
- uses: actions/checkout@v6
- uses: voidzero-dev/setup-vp@v1.17.0
with:
task-cache: true
```

### Specific Version

```yaml
Expand Down Expand Up @@ -346,6 +361,8 @@ jobs:
| `cache` | Enable caching of project dependencies | No | `false` |
| `cache-save` | Save the dependency cache in the post action. Has no effect when `cache` is `false` | No | `true` |
| `cache-dependency-path` | Path to lock file for cache key generation | No | Auto-detected |
| `task-cache` | Save the Vite+ task cache to GitHub Actions Cache and restore it from a previous run | No | `false` |
| `task-cache-save` | Save the task cache in the post action. Has no effect when `task-cache` is `false` | No | `true` |
| `registry-url` | Optional registry to set up for auth. Sets the registry in `.npmrc` and reads auth from `NODE_AUTH_TOKEN` | No | |
| `scope` | Optional scope for scoped registries. Falls back to repo owner for GitHub Packages | No | |

Expand Down Expand Up @@ -433,6 +450,8 @@ For example, this workflow restores caches on every run but saves them only from

Disabling cache saving doesn't change the `cache-hit` output, which continues to report whether the action restored a matching cache.

The task cache has its own switch: `task-cache-save` controls it independently of `cache` and `cache-save`, so `task-cache: true` alone restores and saves the task cache. Set `task-cache-save: false` to restore it without saving, mirroring the table above for the task cache.

## GitLab CI/CD

setup-vp also provides a GitLab CI/CD remote template hosted from this GitHub repository. Because this repository is not a GitLab CI/CD component project, GitLab users should load it with `include:remote` instead of `include:component`.
Expand Down
10 changes: 10 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ inputs:
description: "Enable caching of project dependencies"
required: false
default: "false"
task-cache:
description: "Enable task caching via GitHub Actions. Restores node_modules/.vite/task-cache from a previous run and saves it again in the post action (see task-cache-save). Independent of cache."
required: false
default: "false"
Comment on lines +44 to +47

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Document the new task-cache interface

The new input and output are absent from the public interface documentation: the Inputs table at README.md:329-344, Outputs table at README.md:350-355, and Caching section at README.md:357-375 still describe only dependency caching. Since the repository's marketplace README is how users discover and configure this action, the feature is effectively hidden and users cannot learn its cache path/key behavior or consume task-cache-hit; add the new input, output, and usage details there.

Useful? React with 👍 / 👎.

task-cache-save:
description: "Whether to save the task cache in the post action. Has no effect when task-cache is false."
required: false
default: "true"
cache-save:
description: "Whether to save the dependency cache in the post action. Has no effect when cache is false."
required: false
Expand All @@ -60,6 +68,8 @@ outputs:
description: "The installed version of Vite+"
cache-hit:
description: "Boolean indicating if cache was restored"
task-cache-hit:
description: "Boolean indicating if task cache was restored"

runs:
using: node24
Expand Down
Loading
Loading