$ErrorActionPreference = 'Stop' # Persist fixed-version tools outside checkout, which Actions cleans between jobs. $identity = python -c "import hashlib, sys; print(hashlib.sha256((sys.executable + sys.version).encode()).hexdigest()[:16])" if ($LASTEXITCODE -ne 0) { throw 'Cannot identify packaging Python.' } $root = Join-Path $env:LOCALAPPDATA "Cutdex/ci-tools/python-$identity-pefile-2024.8.26-vpk-1.2.161" $python = Join-Path $root 'python/Scripts/python.exe' $vpk = Join-Path $root 'vpk/vpk.exe' $mutex = [Threading.Mutex]::new($false, "Local\CutdexPackageTools-$identity") $locked = $false try { try { $locked = $mutex.WaitOne([TimeSpan]::FromMinutes(10)) } catch [Threading.AbandonedMutexException] { $locked = $true } if (-not $locked) { throw 'Timed out waiting for packaging tools setup.' } if (-not (Test-Path -LiteralPath $python)) { python -m venv (Join-Path $root 'python') if ($LASTEXITCODE -ne 0) { throw 'Packaging environment setup failed.' } } $pefileVersion = & $python -c "import importlib.metadata; print(next((d.version for d in importlib.metadata.distributions() if d.metadata['Name'].lower() == 'pefile'), 'missing'))" if ($LASTEXITCODE -ne 0) { throw 'Cached packaging Python failed.' } if ($pefileVersion -ne '2024.8.26') { & $python -m pip install pefile==2024.8.26 if ($LASTEXITCODE -ne 0) { throw 'Packaging dependency installation failed.' } } if (-not (Test-Path -LiteralPath $vpk)) { dotnet tool install vpk --version 1.2.161 --tool-path (Join-Path $root 'vpk') if ($LASTEXITCODE -ne 0) { throw 'Velopack tool installation failed.' } } $help = & $vpk --legacyConsole --skip-updates --help 2>&1 if ($LASTEXITCODE -ne 0 -or ($help -join "`n") -notmatch '(?