diff --git a/.github/workflows/chocolatey_publish.yml b/.github/workflows/chocolatey_publish.yml new file mode 100644 index 0000000..0ee4e1c --- /dev/null +++ b/.github/workflows/chocolatey_publish.yml @@ -0,0 +1,23 @@ +name: Publish chocolatey package + +on: + release: + types: [published] + +jobs: + publish: + runs-on: windows-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Install Chocolatey-AU + shell: pwsh + run: Install-Module Chocolatey-AU -Force -Scope CurrentUser + + - name: Run update.ps1 + shell: pwsh + env: + CHOCO_API_KEY: ${{ secrets.CHOCO_API_KEY }} + working-directory: ./php-pvm + run: .\update.ps1 \ No newline at end of file diff --git a/LICENSE b/LICENSE index 3fdbef4..8e055c9 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2021 Harry Bayliss +Copyright (c) 2025 Harry Bayliss Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 5259eac..92684d6 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,20 @@ This utility changes that. ## Installation +### Chocolatey + +If you want to install pvm without configuring any settings and setting PATH variables, then you can install pvm via [Chocolatey](https://community.chocolatey.org/packages/php-pvm). + +Ensure that [Chocolatey](https://chocolatey.org/) is installed on your system. + +You can easily install PVM using Chocolatey. Run the following command in a command prompt or PowerShell with administrative rights: + +```shell +choco install php-pvm +``` + +### Manual + Download the latest pvm version from the releases page (1.0-alpha-1, it's currently a pre-release). Create the folder `%UserProfile%\.pvm\bin` (e.g. `C:\Users\Harry\.pvm\bin`) and drop the pvm exe in there. Add the folder to your PATH. diff --git a/php-pvm/php-pvm.nuspec b/php-pvm/php-pvm.nuspec new file mode 100644 index 0000000..96609b1 --- /dev/null +++ b/php-pvm/php-pvm.nuspec @@ -0,0 +1,28 @@ + + + + + php-pvm + 1.2.1 + https://github.com/tschogge/php-pvm + + + pvm + hjbdev,Lotti,ENG3PLabs,oldreposcrapyard,goodjun,OliverWich,EbouBaker + Tschogge + https://github.com/hjbdev/pvm + https://github.com/hjbdev/pvm + https://github.com/hjbdev/pvm + https://github.com/hjbdev/pvm/blob/master/LICENSE + true + https://github.com/hjbdev/pvm/discussions + https://github.com/hjbdev/pvm/discussions + pvm php php-version php-version-manager manager phpversion phpversionmanager + A PHP version manager + A PHP version manager to simply install different PHP versions and easily switch between them. Similar to nvm. Use pvm in the terminal after installation to get started. Repo: https://github.com/hjbdev/pvm + + + + + + diff --git a/php-pvm/tools/chocolateyinstall.ps1 b/php-pvm/tools/chocolateyinstall.ps1 new file mode 100644 index 0000000..66bcc1f --- /dev/null +++ b/php-pvm/tools/chocolateyinstall.ps1 @@ -0,0 +1,36 @@ +$ErrorActionPreference = 'Stop' +$toolName = 'pvm' +$userDataPath = [Environment]::GetFolderPath('UserProfile') +$targetPath = "$userDataPath\.$toolName\bin" +$url64 = 'https://github.com/hjbdev/pvm/releases/download/1.2.0/pvm.exe' +$checksum64 = 'A764F8C2EE58EE4A5B026EEEDEFC044F1C4E3802CA96E4E8D00AF3E6504E831F' + + +if (!(Test-Path $targetPath)) { + New-Item -ItemType Directory -Path $targetPath -Force + Write-Host "Created directory $targetPath" +} + +Install-ChocolateyPath -Path $targetPath -PathType 'Machine' +Write-Host "Added $targetPath to the system PATH" + +$tempFile = "$env:TEMP\pvm.exe" +$packageArgs = @{ + packageName = $env:ChocolateyPackageName + fileType = 'EXE' + url64bit = $url64 + softwareName = "$toolName*" + checksum64 = $checksum64 + checksumType64 = 'sha256' + file = $tempFile +} + +Get-ChocolateyWebFile @packageArgs + +Copy-Item -Path $tempFile -Destination "$targetPath\$toolName.exe" -Force +Write-Host "Copied $toolName.exe to $targetPath" + +if (!(Test-Path "$targetPath\$toolName.exe")) { + Write-Error "Failed to copy pvm.exe to $targetPath" + exit 1 +} \ No newline at end of file diff --git a/php-pvm/tools/chocolateyuninstall.ps1 b/php-pvm/tools/chocolateyuninstall.ps1 new file mode 100644 index 0000000..0689027 --- /dev/null +++ b/php-pvm/tools/chocolateyuninstall.ps1 @@ -0,0 +1,17 @@ +$ErrorActionPreference = 'Stop' +$toolName = "pvm" +$userDataPath = [Environment]::GetFolderPath('UserProfile') +$targetPath = "$userDataPath\.$toolName" + +if (Test-Path $targetPath) { + Remove-Item $targetPath -Force -Recurse + Write-Host "Removed the directory and all its contents from $targetPath" +} + +Uninstall-ChocolateyPath -Path "$targetPath\bin" -PathType "Machine" +Write-Host "Removed $targetPath\bin from the system PATH" + +if (Test-Path "$targetPath\$toolName.exe") { + Write-Host "Failed to remove $targetPath\$toolName.exe" + exit 1 +} \ No newline at end of file diff --git a/php-pvm/update.ps1 b/php-pvm/update.ps1 new file mode 100644 index 0000000..288052c --- /dev/null +++ b/php-pvm/update.ps1 @@ -0,0 +1,37 @@ +Import-Module Chocolatey-AU + +function global:au_BeforeUpdate { + $Latest.Checksum64 = Get-RemoteChecksum $Latest.URL64 +} + +function global:au_GetLatest { + $latestRelease = Invoke-RestMethod -UseBasicParsing -Uri 'https://api.github.com/repos/hjbdev/pvm/releases/latest' + + return @{ + URL64 = $latestRelease.assets.browser_download_url + Version = $latestRelease.tag_name + ChecksumType64 = 'sha256' + Description = 'A PHP version manager to simply install different PHP versions and easily switch between them. Similar to nvm. Use pvm in the terminal after installation to get started. Repo: https://github.com/hjbdev/pvm' + } +} + +function global:au_SearchReplace { + @{ + ".\tools\chocolateyInstall.ps1" = @{ + "(^[$]url64\s*=\s*)('.*')" = "`$1'$($Latest.URL64)'" + "(^[$]checksum64\s*=\s*)('.*')" = "`$1'$($Latest.Checksum64)'" + "(^\s*checksumType64\s*=\s*)('.*')" = "`$1'$($Latest.ChecksumType64)'" + } + + "php-pvm.nuspec" = @{ + "(\).*?(\)" = "`${1}$($Latest.Version)`$2" + } + + } +} + +function global:au_AfterUpdate ($Package) { + choco push $Package.NuspecPath --api-key=$Env:CHOCO_API_KEY +} + +update -ChecksumFor none -NoReadme \ No newline at end of file