Skip to content
Merged
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
234 changes: 234 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,237 @@ jobs:
- name: Verify installation
run: vp --version

test-reuse-installed-version:
# Reproduces https://github.com/voidzero-dev/setup-vp/issues/145. Two setup
# steps share an installation, as jobs on a persistent runner would.
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
layout: [home, split]
version: ["0.3.0", "0.3.3"]
include:
- os: ubuntu-latest
layout: xdg
version: "0.3.0"
- os: ubuntu-latest
layout: xdg
version: "0.3.3"
runs-on: ${{ matrix.os }}
timeout-minutes: 10
env:
VP_PR_VERSION: ""
REUSE_LAYOUT: ${{ matrix.layout }}
REUSE_VERSION: ${{ matrix.version }}
steps:
- uses: taiki-e/checkout-action@7d1e50e93dc4fb3bba58f85018fadf77898aee8b # v1.4.2

- name: Prepare project and record CLI downloads
shell: bash
run: |
mkdir -p "$RUNNER_TEMP/reuse-project"
printf '{"name":"reuse-project","private":true,"devDependencies":{"vite-plus":"%s"}}\n' "$REUSE_VERSION" > "$RUNNER_TEMP/reuse-project/package.json"
reuse_root="$RUNNER_TEMP/setup-vp-reuse"
# The Windows installer passes this path to cmd.exe for mklink.
if [ "$RUNNER_OS" = "Windows" ]; then reuse_root="$(cygpath -w "$reuse_root")"; fi
{
case "$REUSE_LAYOUT" in
home)
echo "VP_HOME=$reuse_root"
echo "SETUP_VP_REUSE_DATA=$reuse_root"
;;
split)
echo "VP_HOME="
echo "VP_DATA_DIR=$reuse_root"
echo "VP_BIN_DIR=$reuse_root-bin"
echo "VP_CACHE_DIR=$reuse_root-cache"
echo "SETUP_VP_REUSE_DATA=$reuse_root"
;;
xdg)
echo "VP_HOME="
echo "XDG_DATA_HOME=$reuse_root-xdg"
echo "SETUP_VP_REUSE_DATA=$reuse_root-xdg/vite-plus"
;;
esac
} >> "$GITHUB_ENV"
bash test/record-cli-downloads.sh

- name: Setup Vite+ for the first time
id: first-setup
uses: ./
with:
working-directory: ${{ runner.temp }}/reuse-project
node-version: "22.23.1"
run-install: false
cache: false

- name: Check the first installation and start recording reuse
shell: bash
working-directory: ${{ runner.temp }}/reuse-project
env:
INSTALLED_VERSION: ${{ steps.first-setup.outputs.version }}
run: |
test "$INSTALLED_VERSION" = "$REUSE_VERSION"
binary=vp
if [ "$RUNNER_OS" = "Windows" ]; then binary=vp.exe; fi
test -x "$SETUP_VP_REUSE_DATA/current/bin/$binary"
test -f "$SETUP_VP_REUSE_DATA/$REUSE_VERSION/node_modules/vite-plus/package.json"
test "$(node --version)" = "v22.23.1"
# Check that the recorder sees real downloads before relying on it.
# Windows downloads through PowerShell; file snapshots cover that path.
if [ "$RUNNER_OS" != "Windows" ]; then test -s "$SETUP_VP_REUSE_DOWNLOADS"; fi
echo "CLI downloads during the first setup:"
cat "$SETUP_VP_REUSE_DOWNLOADS"
node "$GITHUB_WORKSPACE/test/reuse-installation-snapshot.mjs" "$SETUP_VP_REUSE_DATA/current" > "$RUNNER_TEMP/reuse-before.json"
: > "$SETUP_VP_REUSE_DOWNLOADS"

- name: Setup the same Vite+ version again
id: second-setup
uses: ./
with:
working-directory: ${{ runner.temp }}/reuse-project
node-version: "22.23.1"
run-install: false
cache: false

- name: Verify the second setup reuses the installation
shell: bash
working-directory: ${{ runner.temp }}/reuse-project
env:
INSTALLED_VERSION: ${{ steps.second-setup.outputs.version }}
run: |
test "$INSTALLED_VERSION" = "$REUSE_VERSION"
test "$(node --version)" = "v22.23.1"
failed=0
if [ -s "$SETUP_VP_REUSE_DOWNLOADS" ]; then
echo "::error::The second setup downloaded the installed Vite+ version again (issue #145)."
cat "$SETUP_VP_REUSE_DOWNLOADS"
failed=1
fi
node "$GITHUB_WORKSPACE/test/reuse-installation-snapshot.mjs" "$SETUP_VP_REUSE_DATA/current" > "$RUNNER_TEMP/reuse-after.json"
if ! cmp -s "$RUNNER_TEMP/reuse-before.json" "$RUNNER_TEMP/reuse-after.json"; then
echo "::error::The second setup changed the installed version tree (issue #145)."
diff -u "$RUNNER_TEMP/reuse-before.json" "$RUNNER_TEMP/reuse-after.json" || true
failed=1
fi
exit "$failed"

test-reuse-installation-integrity:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
timeout-minutes: 10
env:
VP_PR_VERSION: ""
steps:
- uses: taiki-e/checkout-action@7d1e50e93dc4fb3bba58f85018fadf77898aee8b # v1.4.2

- name: Prepare an isolated global installation and project
run: node test/reuse-installation-integrity.mjs prepare

- name: Install Vite+
uses: ./
with:
version: "0.3.3"
run-install: false
cache: false

- name: Remove the active native binding and reproduce the CLI failure
run: node test/reuse-installation-integrity.mjs remove-binding

- name: Repair the incomplete installation
uses: ./
with:
version: "0.3.3"
run-install: false
cache: false

- name: Check that JavaScript CLI commands work again
run: node test/reuse-installation-integrity.mjs verify-repair

- name: Check combined and per-manager installer overrides on an existing installation
if: runner.os == 'Linux'
run: node test/reuse-installation-integrity.mjs manager-overrides

test-reuse-restored-prepare:
runs-on: ubuntu-latest
timeout-minutes: 10
env:
VP_PR_VERSION: ""
steps:
- uses: taiki-e/checkout-action@7d1e50e93dc4fb3bba58f85018fadf77898aee8b # v1.4.2
- name: Select the installation directory and record downloads
run: |
echo "VP_HOME=$RUNNER_TEMP/setup-vp-restored" >> "$GITHUB_ENV"
bash test/record-cli-downloads.sh
- name: Install from the user's version-file inputs
uses: ./
with:
working-directory: test/reuse-project
version-file: package.json
node-version-file: package.json
cache: false
run-install: false
- name: Save the complete installation
run: |
test -s "$SETUP_VP_REUSE_DOWNLOADS"
test ! -e "$VP_HOME/bin/corepack"
node test/reuse-installation-snapshot.mjs "$VP_HOME/current" > "$RUNNER_TEMP/reuse-before.json"
# Preserve symlinks, permissions, and nanosecond timestamps across jobs.
tar --format=posix -czf "$RUNNER_TEMP/reuse-installation.tar.gz" -C "$VP_HOME" .
- uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
with:
name: reuse-installation
path: |
${{ runner.temp }}/reuse-installation.tar.gz
${{ runner.temp }}/reuse-before.json
compression-level: 0
retention-days: 1

test-reuse-restored-version:
needs: test-reuse-restored-prepare
runs-on: ubuntu-latest
timeout-minutes: 10
env:
VP_PR_VERSION: ""
steps:
- uses: taiki-e/checkout-action@7d1e50e93dc4fb3bba58f85018fadf77898aee8b # v1.4.2
- uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4
with:
name: reuse-installation
path: ${{ runner.temp }}
- name: Restore the installation on a fresh runner
run: |
export VP_HOME="$RUNNER_TEMP/setup-vp-restored"
echo "VP_HOME=$VP_HOME" >> "$GITHUB_ENV"
test ! -e "$VP_HOME"
mkdir -p "$VP_HOME"
tar -xzf "$RUNNER_TEMP/reuse-installation.tar.gz" -C "$VP_HOME"
node test/reuse-installation-snapshot.mjs "$VP_HOME/current" > "$RUNNER_TEMP/reuse-restored.json"
cmp "$RUNNER_TEMP/reuse-before.json" "$RUNNER_TEMP/reuse-restored.json"
bash test/record-cli-downloads.sh
- name: Reuse the restored installation
id: setup
uses: ./
with:
working-directory: test/reuse-project
version-file: package.json
node-version-file: package.json
cache: false
run-install: false
- name: Verify versions and zero installation work
env:
INSTALLED_VERSION: ${{ steps.setup.outputs.version }}
run: |
test "$INSTALLED_VERSION" = "0.3.3"
test "$(node --version)" = "v22.23.1"
cat "$SETUP_VP_REUSE_DOWNLOADS"
test ! -s "$SETUP_VP_REUSE_DOWNLOADS"
node test/reuse-installation-snapshot.mjs "$VP_HOME/current" > "$RUNNER_TEMP/reuse-after.json"
diff -u "$RUNNER_TEMP/reuse-before.json" "$RUNNER_TEMP/reuse-after.json"

test-preview-build:
# End-to-end coverage for the commit-pinned install path: resolve the
# newest pkg.pr.new preview build (0.0.0-commit.<sha>) from the registry
Expand Down Expand Up @@ -80,6 +311,9 @@ jobs:
run-install: false
cache: false

- name: Verify shim PATH order in a subsequent step
run: node test/verify-vp-path.mjs

- name: Verify installation
shell: bash
run: |
Expand Down
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,19 @@ Separate package-manager modes require Vite+ 0.3.1+. Any explicit configuration,

## Caching

### Reuse an installed version

On runners that retain the Vite+ installation, the GitHub Action reuses an
active exact version when its files and shims pass the reuse checks and Node.js
and package-manager management are enabled. This applies to versions that support
`VP_DUMP_DIRS` (`0.3.0` and later). The action still applies requested management
opt-outs, sets up Node.js, and runs the remaining steps.

The action runs the installer when it needs to change versions or repair the
installation. It also runs the installer for dist-tags such as `latest`, version
ranges, preview builds, and older releases. Reuse works with `cache: false` and
does not restore an installation onto a fresh runner.

### Dependency Cache

When `cache: true` is set, the action additionally caches project dependencies by auto-detecting your lock file:
Expand Down
Loading