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
96 changes: 48 additions & 48 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -419,14 +419,21 @@ jobs:
- name: Test upgrade (bash)
shell: bash
run: |
# Helper to read the installed CLI version from package.json
get_cli_version() {
node -p "require(require('path').resolve(process.env.USERPROFILE || process.env.HOME, '.vite-plus', 'current', 'node_modules', 'vite-plus', 'package.json')).version"
# Resolve `current` (symlink on Unix, junction on Windows) and return
# the install dir basename — "local-dev-<timestamp>" for the dev
# build, "<version>" for a downloaded release. Node's realpathSync
# handles symlinks and junctions uniformly.
get_current_dirname() {
node -p "require('path').basename(require('fs').realpathSync(require('path').resolve(process.env.USERPROFILE || process.env.HOME, '.vite-plus', 'current')))"
}

# Save initial (dev build) version
INITIAL_VERSION=$(get_cli_version)
echo "Initial version: $INITIAL_VERSION"
# Assert on the `current` target dir, not the version: right after a
# release commit on main, the dev build's version equals npm latest,
# so `vp upgrade --force` succeeds but the version is unchanged.
# The dir flip (dev → release → dev) is the real signal that the
# download/extract/swap and rollback flows ran end-to-end.
INITIAL_DIR=$(get_current_dirname)
echo "Initial install dir: $INITIAL_DIR"

# --check queries npm registry and prints update status
vp upgrade --check
Expand All @@ -438,24 +445,22 @@ jobs:

ls -la ~/.vite-plus/

# Verify version changed after update
UPDATED_VERSION=$(get_cli_version)
echo "Updated version: $UPDATED_VERSION"
if [ "$UPDATED_VERSION" == "$INITIAL_VERSION" ]; then
echo "Error: version should have changed after upgrade (still $INITIAL_VERSION)"
UPDATED_DIR=$(get_current_dirname)
echo "Updated install dir: $UPDATED_DIR"
if [ "$UPDATED_DIR" == "$INITIAL_DIR" ]; then
echo "Error: current install dir should have changed after upgrade (still $INITIAL_DIR)"
exit 1
fi

# rollback to the previous version
# rollback to the previous install
vp upgrade --rollback
vp --version
vp env doctor

# Verify version restored after rollback
ROLLBACK_VERSION=$(get_cli_version)
echo "Rollback version: $ROLLBACK_VERSION"
if [ "$ROLLBACK_VERSION" != "$INITIAL_VERSION" ]; then
echo "Error: version should have been restored after rollback (expected $INITIAL_VERSION, got $ROLLBACK_VERSION)"
ROLLBACK_DIR=$(get_current_dirname)
echo "Rollback install dir: $ROLLBACK_DIR"
if [ "$ROLLBACK_DIR" != "$INITIAL_DIR" ]; then
echo "Error: current install dir should have been restored after rollback (expected $INITIAL_DIR, got $ROLLBACK_DIR)"
exit 1
fi

Expand All @@ -467,14 +472,13 @@ jobs:
. (Join-Path $vpHome 'env.ps1')
Get-ChildItem $vpHome

# Helper to read the installed CLI version from package.json
function Get-CliVersion {
node -p "require(require('path').resolve(process.env.USERPROFILE || process.env.HOME, '.vite-plus', 'current', 'node_modules', 'vite-plus', 'package.json')).version"
# See bash block above for why we assert on the install dir basename.
function Get-CurrentDirname {
node -p "require('path').basename(require('fs').realpathSync(require('path').resolve(process.env.USERPROFILE || process.env.HOME, '.vite-plus', 'current')))"
}

# Save initial (dev build) version
$initialVersion = Get-CliVersion
Write-Host "Initial version: $initialVersion"
$initialDir = Get-CurrentDirname
Write-Host "Initial install dir: $initialDir"

# --check queries npm registry and prints update status
vp upgrade --check
Expand All @@ -486,34 +490,32 @@ jobs:

Get-ChildItem $vpHome

# Verify version changed after update
$updatedVersion = Get-CliVersion
Write-Host "Updated version: $updatedVersion"
if ($updatedVersion -eq $initialVersion) {
Write-Error "Error: version should have changed after upgrade (still $initialVersion)"
$updatedDir = Get-CurrentDirname
Write-Host "Updated install dir: $updatedDir"
if ($updatedDir -eq $initialDir) {
Write-Error "Error: current install dir should have changed after upgrade (still $initialDir)"
exit 1
}

# rollback to the previous version
# rollback to the previous install
vp upgrade --rollback
vp --version
vp env doctor

# Verify version restored after rollback
$rollbackVersion = Get-CliVersion
Write-Host "Rollback version: $rollbackVersion"
if ($rollbackVersion -ne $initialVersion) {
Write-Error "Error: version should have been restored after rollback (expected $initialVersion, got $rollbackVersion)"
$rollbackDir = Get-CurrentDirname
Write-Host "Rollback install dir: $rollbackDir"
if ($rollbackDir -ne $initialDir) {
Write-Error "Error: current install dir should have been restored after rollback (expected $initialDir, got $rollbackDir)"
exit 1
}

- name: Test upgrade (cmd)
if: ${{ matrix.os == 'windows-latest' }}
shell: cmd
run: |
REM Save initial (dev build) version
for /f "usebackq delims=" %%v in (`node -p "require(require('path').resolve(process.env.USERPROFILE, '.vite-plus', 'current', 'node_modules', 'vite-plus', 'package.json')).version"`) do set INITIAL_VERSION=%%v
echo Initial version: %INITIAL_VERSION%
REM See bash block above for why we assert on the install dir basename.
for /f "usebackq delims=" %%v in (`node -p "require('path').basename(require('fs').realpathSync(require('path').resolve(process.env.USERPROFILE, '.vite-plus', 'current')))"`) do set INITIAL_DIR=%%v
echo Initial install dir: %INITIAL_DIR%

REM --check queries npm registry and prints update status
vp upgrade --check
Expand All @@ -525,24 +527,22 @@ jobs:

dir "%USERPROFILE%\.vite-plus\"

REM Verify version changed after update
for /f "usebackq delims=" %%v in (`node -p "require(require('path').resolve(process.env.USERPROFILE, '.vite-plus', 'current', 'node_modules', 'vite-plus', 'package.json')).version"`) do set UPDATED_VERSION=%%v
echo Updated version: %UPDATED_VERSION%
if "%UPDATED_VERSION%"=="%INITIAL_VERSION%" (
echo Error: version should have changed after upgrade, still %INITIAL_VERSION%
for /f "usebackq delims=" %%v in (`node -p "require('path').basename(require('fs').realpathSync(require('path').resolve(process.env.USERPROFILE, '.vite-plus', 'current')))"`) do set UPDATED_DIR=%%v
echo Updated install dir: %UPDATED_DIR%
if "%UPDATED_DIR%"=="%INITIAL_DIR%" (
echo Error: current install dir should have changed after upgrade, still %INITIAL_DIR%
exit /b 1
)

REM rollback to the previous version
REM rollback to the previous install
vp upgrade --rollback
vp --version
vp env doctor

REM Verify version restored after rollback
for /f "usebackq delims=" %%v in (`node -p "require(require('path').resolve(process.env.USERPROFILE, '.vite-plus', 'current', 'node_modules', 'vite-plus', 'package.json')).version"`) do set ROLLBACK_VERSION=%%v
echo Rollback version: %ROLLBACK_VERSION%
if not "%ROLLBACK_VERSION%"=="%INITIAL_VERSION%" (
echo Error: version should have been restored after rollback, expected %INITIAL_VERSION%, got %ROLLBACK_VERSION%
for /f "usebackq delims=" %%v in (`node -p "require('path').basename(require('fs').realpathSync(require('path').resolve(process.env.USERPROFILE, '.vite-plus', 'current')))"`) do set ROLLBACK_DIR=%%v
echo Rollback install dir: %ROLLBACK_DIR%
if not "%ROLLBACK_DIR%"=="%INITIAL_DIR%" (
echo Error: current install dir should have been restored after rollback, expected %INITIAL_DIR%, got %ROLLBACK_DIR%
exit /b 1
)

Expand Down
4 changes: 2 additions & 2 deletions packages/cli/snap-tests-global/command-upgrade-check/snap.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
> vp upgrade --check # check for updates without installing
> vp upgrade --check --tag alpha # alpha tag avoids release-day flake (dev version equals npm latest right after a release, hiding the Update-available branch)
info: checking for updates...
info: found vite-plus@<semver> (current: <semver>)
info: found vite-plus@<semver>
Update available: <semver> → <semver>
Run `vp upgrade` to update.
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{
"ignoredPlatforms": ["win32", { "os": "linux", "libc": "musl" }],
"commands": ["vp upgrade --check # check for updates without installing"]
"commands": [
"vp upgrade --check --tag alpha # alpha tag avoids release-day flake (dev version equals npm latest right after a release, hiding the Update-available branch)"
]
Comment thread
fengmk2 marked this conversation as resolved.
}
Loading