diff --git a/.appveyor.yml b/.appveyor.yml deleted file mode 100644 index 49f57ea..0000000 --- a/.appveyor.yml +++ /dev/null @@ -1,59 +0,0 @@ -image: Visual Studio 2017 - -branches: - only: - - master - -version: "Build {build}" - -skip_tags: true - -skip_commits: - files: - - .github/ - - .vscode/ - - images/ - - src/ - - .gitignore - - CONTRIBUTING.md - - LICENSE - - README.md - -environment: - PsgKey: - secure: tlhLuUS6x8FcP159+X/EIBDlj9m+u5KCTTuqwzsiNHlPX6K4AolpaZcfAP4ClOdB - matrix: - - DOCKER_IMAGE: - - DOCKER_IMAGE: nanoserver - - DOCKER_IMAGE: windowsservercore - -cache: - - test\download-cache -> .appveyor.yml - - '%ProgramFiles%\WindowsPowerShell\Modules\VcRedist -> .appveyor.yml' - - '%ProgramFiles%\WindowsPowerShell\Modules\PSScriptAnalyzer -> .appveyor.yml' - - '%ProgramFiles%\WindowsPowerShell\Modules\Pester -> .appveyor.yml' - -build: off - -install: - - ps: | - if ($null -eq $Env:DOCKER_IMAGE -or $Env:DOCKER_IMAGE -eq '') { - .\test\setup.ps1 - } else { - & ".\test\Dockerfile.$Env:DOCKER_IMAGE.ps1" - } - -test_script: - - ps: | - if ($null -eq $Env:DOCKER_IMAGE -or $Env:DOCKER_IMAGE -eq '') { - $pesterResult = .\test\pester.ps1 - $failCount = $pesterResult.FailedCount - } else { - $volume="$($Env:APPVEYOR_BUILD_FOLDER):C:\App" - docker run --rm --volume $volume --workdir C:\App --env "PM_TEST_DOCKER=1" phpmanager/test powershell.exe 'Set-Location -LiteralPath C:\App; $pesterResult=.\test\pester.ps1; exit $pesterResult.FailedCount' - $failCount = $LASTEXITCODE - } - (New-Object 'System.Net.WebClient').UploadFile("https://ci.appveyor.com/api/testresults/nunit/$($env:APPVEYOR_JOB_ID)", (Resolve-Path -LiteralPath .\TestsResults.xml)) - if ($failCount -ne 0) { - throw "$failCount tests failed!" - } diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml index 0673526..d912376 100644 --- a/.github/workflows/publish-release.yml +++ b/.github/workflows/publish-release.yml @@ -12,7 +12,7 @@ jobs: runs-on: windows-latest steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v7 with: fetch-depth: 0 - name: Publish diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 55cb7ed..e30f8b5 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -19,9 +19,7 @@ jobs: Remove-Item -Force -Recurse -LiteralPath C:\tools\php } - name: Checkout - uses: actions/checkout@v1 - with: - fetch-depth: 1 + uses: actions/checkout@v7 - name: Setup shell: powershell run: .\test\setup.ps1 @@ -44,9 +42,7 @@ jobs: Remove-Item -Force -Recurse -LiteralPath C:\tools\php } - name: Checkout - uses: actions/checkout@v1 - with: - fetch-depth: 1 + uses: actions/checkout@v7 - name: Setup shell: pwsh run: .\test\setup.ps1 @@ -57,3 +53,29 @@ jobs: if ($pesterResult.FailedCount -ne 0) { throw "$($pesterResult.FailedCount) tests failed!" } + docker: + strategy: + matrix: + include: + - name: nanoserver + shell: pwsh.exe + - name: windowsservercore + shell: powershell.exe + fail-fast: false + name: Docker (${{ matrix.name }}) + # Windows containers need a base image matching the host kernel: see the FROM lines in test/Dockerfile.* + runs-on: windows-2022 + steps: + - name: Checkout + uses: actions/checkout@v7 + - name: Prepare files for Docker image + run: .\test\Prepare-Dockerfile.ps1 "${{ matrix.name }}" + - name: Build Docker image + run: docker build --tag phpmanager/test .\test\docker-build + - name: Test + run: | + docker run --rm --user ContainerAdministrator --volume "$($Env:GITHUB_WORKSPACE):C:\App" --workdir C:\App --env "PM_TEST_DOCKER=1" phpmanager/test ${{ matrix.shell }} -Command '$pesterResult = .\test\pester.ps1; if ($null -eq $pesterResult) { exit 1 }; exit $pesterResult.FailedCount' + $failCount = $LASTEXITCODE + if ($failCount -ne 0) { + throw "$failCount tests failed!" + } diff --git a/PhpManager/private/Edit-FolderInPath.ps1 b/PhpManager/private/Edit-FolderInPath.ps1 index dda60ac..2002cb8 100644 --- a/PhpManager/private/Edit-FolderInPath.ps1 +++ b/PhpManager/private/Edit-FolderInPath.ps1 @@ -71,7 +71,10 @@ } else { $originalPath = [System.Environment]::GetEnvironmentVariable('Path', $target) } - if ($null -eq $originalPath -or $originalPath -eq '') { + if ($null -eq $originalPath) { + $originalPath = '' + } + if ($originalPath -eq '') { $parts = @() } else { $parts = $originalPath.Split($pathSeparator) diff --git a/PhpManager/private/Set-EnvVar.ps1 b/PhpManager/private/Set-EnvVar.ps1 index 65c8c68..d9093c5 100644 --- a/PhpManager/private/Set-EnvVar.ps1 +++ b/PhpManager/private/Set-EnvVar.ps1 @@ -25,6 +25,7 @@ [ValidateLength(1, [int]::MaxValue)] [string] $Name, [Parameter(Mandatory = $true, Position = 1)] + [AllowEmptyString()] [string] $Value, [Parameter(Mandatory = $false, Position = 2)] [ValidateNotNull()] @@ -51,6 +52,9 @@ } $needDirectRegistryAccess = [System.Environment]::GetEnvironmentVariable[0].OverloadDefinitions.Count -lt 2 if ($User) { + if (-not(Test-Path -LiteralPath 'HKCU:\Environment')) { + New-Item -Path 'HKCU:\Environment' -Force | Out-Null + } if ($needDirectRegistryAccess) { New-ItemProperty -Path 'HKCU:\Environment' -Name $Name -Value $Value -PropertyType ExpandString -Force | Out-Null } else { diff --git a/README.md b/README.md index 882ad51..4d0ff30 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,3 @@ -[![AppVeyor Build Status](https://ci.appveyor.com/api/projects/status/github/mlocati/powershell-phpmanager?branch=master&svg=true)](https://ci.appveyor.com/project/mlocati/powershell-phpmanager) [![GitHub Actions Test Status](https://github.com/mlocati/powershell-phpmanager/actions/workflows/test.yml/badge.svg)](https://github.com/mlocati/powershell-phpmanager/actions?query=workflow:Test) [![PowerShell Gallery Download Count](https://img.shields.io/powershellgallery/dt/PhpManager?label=downloads%20from%20PSGallery)](https://www.powershellgallery.com/packages/PhpManager) [![Github Releases Download Count](https://img.shields.io/github/downloads/mlocati/powershell-phpmanager/total?label=downloads%20from%20GitHub)](https://github.com/mlocati/powershell-phpmanager/releases) diff --git a/test/Dockerfile.nanoserver b/test/Dockerfile.nanoserver index cb0f3e6..5b82c33 100644 --- a/test/Dockerfile.nanoserver +++ b/test/Dockerfile.nanoserver @@ -1,10 +1,13 @@ # escape=` -FROM mcr.microsoft.com/windows/nanoserver:10.0.14393.2007 +# Nano Server has no PowerShell: use the image published by the PowerShell team +FROM mcr.microsoft.com/powershell:lts-nanoserver-ltsc2022 -SHELL ["powershell", "-Command"] +USER ContainerAdministrator -COPY vcruntime140.dll C:/Windows/System32/ +SHELL ["pwsh", "-Command"] + +COPY *.dll C:/Windows/System32/ COPY setup-nodejs.ps1 C:/ RUN C:\setup-nodejs.ps1 diff --git a/test/Dockerfile.nanoserver.ps1 b/test/Dockerfile.nanoserver.ps1 deleted file mode 100644 index e08d2a5..0000000 --- a/test/Dockerfile.nanoserver.ps1 +++ /dev/null @@ -1,17 +0,0 @@ -$dockerBuildPath = Join-Path -Path $PSScriptRoot -ChildPath docker-build -if (-Not(Test-Path -LiteralPath $dockerBuildPath)) { - New-Item -ItemType Directory -Path $dockerBuildPath | Out-Null -} -$me = Get-Item -LiteralPath $PSCommandPath -try { - Copy-Item -LiteralPath "$($Env:SystemRoot)\System32\vcruntime140.dll" -Destination $dockerBuildPath - Copy-Item -LiteralPath (Join-Path -Path $PSScriptRoot -ChildPath setup-nodejs.ps1) -Destination $dockerBuildPath - Copy-Item -LiteralPath (Join-Path -Path $PSScriptRoot -ChildPath setup.ps1) -Destination $dockerBuildPath - Copy-Item -LiteralPath (Join-Path -Path $PSScriptRoot -ChildPath $me.BaseName) -Destination (Join-Path -Path $dockerBuildPath -ChildPath Dockerfile) - docker build --rm --force-rm --tag phpmanager/test $dockerBuildPath -} finally { - try { - Remove-Item -LiteralPath $dockerBuildPath -Recurse - } catch { - } -} diff --git a/test/Dockerfile.windowsservercore b/test/Dockerfile.windowsservercore index 21386aa..7c6ec4a 100644 --- a/test/Dockerfile.windowsservercore +++ b/test/Dockerfile.windowsservercore @@ -1,6 +1,6 @@ # escape=` -FROM mcr.microsoft.com/windows/servercore:10.0.14393.2007 +FROM mcr.microsoft.com/windows/servercore:ltsc2022 SHELL ["powershell", "-Command"] diff --git a/test/Dockerfile.windowsservercore.ps1 b/test/Dockerfile.windowsservercore.ps1 deleted file mode 100644 index b736214..0000000 --- a/test/Dockerfile.windowsservercore.ps1 +++ /dev/null @@ -1,18 +0,0 @@ -$dockerBuildPath = Join-Path -Path $PSScriptRoot -ChildPath docker-build -if (-Not(Test-Path -LiteralPath $dockerBuildPath)) { - New-Item -ItemType Directory -Path $dockerBuildPath | Out-Null -} -$me = Get-Item -LiteralPath $PSCommandPath -try { - Copy-Item -LiteralPath "$($Env:SystemRoot)\System32\vcruntime140.dll" -Destination $dockerBuildPath - Copy-Item -LiteralPath "$($Env:SystemRoot)\System32\vcomp140.dll" -Destination $dockerBuildPath - Copy-Item -LiteralPath (Join-Path -Path $PSScriptRoot -ChildPath setup-nodejs.ps1) -Destination $dockerBuildPath - Copy-Item -LiteralPath (Join-Path -Path $PSScriptRoot -ChildPath setup.ps1) -Destination $dockerBuildPath - Copy-Item -LiteralPath (Join-Path -Path $PSScriptRoot -ChildPath $me.BaseName) -Destination (Join-Path -Path $dockerBuildPath -ChildPath Dockerfile) - docker build --rm --force-rm --tag phpmanager/test $dockerBuildPath -} finally { - try { - Remove-Item -LiteralPath $dockerBuildPath -Recurse - } catch { - } -} diff --git a/test/Prepare-Dockerfile.ps1 b/test/Prepare-Dockerfile.ps1 new file mode 100644 index 0000000..72a9680 --- /dev/null +++ b/test/Prepare-Dockerfile.ps1 @@ -0,0 +1,12 @@ +param ([string] $DockerImage) + +$dockerBuildPath = Join-Path -Path $PSScriptRoot -ChildPath docker-build +if (-Not(Test-Path -LiteralPath $dockerBuildPath)) { + New-Item -ItemType Directory -Path $dockerBuildPath | Out-Null +} +Copy-Item -LiteralPath "$($Env:SystemRoot)\System32\vcruntime140.dll" -Destination $dockerBuildPath +Copy-Item -LiteralPath "$($Env:SystemRoot)\System32\vcruntime140_1.dll" -Destination $dockerBuildPath +Copy-Item -LiteralPath "$($Env:SystemRoot)\System32\vcomp140.dll" -Destination $dockerBuildPath +Copy-Item -LiteralPath (Join-Path -Path $PSScriptRoot -ChildPath setup-nodejs.ps1) -Destination $dockerBuildPath +Copy-Item -LiteralPath (Join-Path -Path $PSScriptRoot -ChildPath setup.ps1) -Destination $dockerBuildPath +Copy-Item -LiteralPath (Join-Path -Path $PSScriptRoot -ChildPath "Dockerfile.$DockerImage") -Destination (Join-Path -Path $dockerBuildPath -ChildPath Dockerfile) diff --git a/test/pester.ps1 b/test/pester.ps1 index 256e7a0..7743446 100644 --- a/test/pester.ps1 +++ b/test/pester.ps1 @@ -2,7 +2,7 @@ $Global:ProgressPreference = 'SilentlyContinue' -Import-Module -Name Pester -MinimumVersion 4.5 -MaximumVersion 4.9999.9999 +Import-Module -Name Pester -MinimumVersion 4.5 -MaximumVersion 4.9999.9999 -ErrorAction Stop New-Variable -Scope Global -Option ReadOnly -Name PHPMANAGER_MODULEPATH -Value (Split-Path -LiteralPath $PSScriptRoot | Join-Path -ChildPath PhpManager) -Force diff --git a/test/setup-nodejs.ps1 b/test/setup-nodejs.ps1 index bcffc50..8115544 100644 --- a/test/setup-nodejs.ps1 +++ b/test/setup-nodejs.ps1 @@ -11,5 +11,5 @@ Expand-Archive -LiteralPath C:\nodejs.zip -DestinationPath 'C:\Program Files' Remove-Item -LiteralPath C:\nodejs.zip Rename-Item -LiteralPath "C:\Program Files\node-v$version" -NewName 'C:\Program Files\NodeJS' $newPath = "$Env:Path;C:\Program Files\NodeJS" -setx.exe Path $newPath /m +[Environment]::SetEnvironmentVariable('Path', $newPath, 'Machine') $Env:Path = $newPath diff --git a/test/setup.ps1 b/test/setup.ps1 index e3c972d..a3b1994 100644 --- a/test/setup.ps1 +++ b/test/setup.ps1 @@ -1,7 +1,10 @@ -Write-Host "Setting up test dependencies" -$pcInfo = Get-ComputerInfo -Write-Host " - Windows installation type: $($pcInfo.WindowsInstallationType)" -Write-Host " - Windows version name: $($pcInfo.WindowsProductName)" +$ErrorActionPreference = 'Stop' + +Write-Host "Setting up test dependencies" +# Get-ComputerInfo is not available on Nano Server +$winInfo = Get-ItemProperty -LiteralPath 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion' +Write-Host " - Windows installation type: $($winInfo.InstallationType)" +Write-Host " - Windows version name: $($winInfo.ProductName)" Write-Host " - PowerShell edition: $($PSVersionTable.PSEdition)" Write-Host " - PowerShell version: $($PSVersionTable.PSVersion.ToString())" try { @@ -56,8 +59,11 @@ if (-Not($pester)) { } if (-Not($pester)) { Write-Host ' - installing Pester' - Install-Module -Name Pester -Force -SkipPublisherCheck -MinimumVersion '4.5' -MaximumVersion '4.9999.9999' + Install-Module -Name Pester -Force -SkipPublisherCheck -Scope AllUsers -MinimumVersion '4.5' -MaximumVersion '4.9999.9999' $pester = Get-Module -ListAvailable | Where-Object { $_.Name -eq 'Pester' -and $_.Version -ge '4.5' -and $_.Version -le '4.9999.9999' } + if (-Not($pester)) { + throw 'Failed to install Pester' + } } } Write-Host " - Pester version: $($pester.Version.ToString())" diff --git a/test/tests/Get-PhpVersionFromUrl.Tests.ps1 b/test/tests/Get-PhpVersionFromUrl.Tests.ps1 index 71b6f32..ab3db60 100644 --- a/test/tests/Get-PhpVersionFromUrl.Tests.ps1 +++ b/test/tests/Get-PhpVersionFromUrl.Tests.ps1 @@ -18,7 +18,7 @@ Describe 'Get-PhpVersionFromUrl' { } It 'parses a release candidate with build number' { $v = Get-PhpVersionFromUrl -Url 'php-8.6.0RC4-2-nts-Win32-vs18-x64.zip' -ReleaseState QA - $v.FullVersion | Should -BeExactly '8.6.0RC4' + $v.FullVersion | Should -BeExactly '8.6.0rc4' $v.Build | Should -Be 2 } It 'prefers higher build numbers of the same version' { diff --git a/test/tests/Install-Composer.Tests.ps1 b/test/tests/Install-Composer.Tests.ps1 index 0b8b005..a842c11 100644 --- a/test/tests/Install-Composer.Tests.ps1 +++ b/test/tests/Install-Composer.Tests.ps1 @@ -29,7 +29,7 @@ Remove-Item -LiteralPath $composerPath -Recurse -Force } try { - Install-Php -Version 7.1.0 -Architecture x64 -ThreadSafe $true -Path $phpPath + Install-Php -Version 8.0.0 -Architecture x64 -ThreadSafe $true -Path $phpPath Enable-PhpExtension -Extension curl,openssl -Path $phpPath Update-PhpCAInfo -Path $phpPath Install-Composer -Path $composerPath -PhpPath $phpPath -Scope User -NoAddToPath -NoCache diff --git a/test/tests/Install-Get-Update-Uninstall-Php.Tests.ps1 b/test/tests/Install-Get-Update-Uninstall-Php.Tests.ps1 index 659dbff..fd8e9c3 100644 --- a/test/tests/Install-Get-Update-Uninstall-Php.Tests.ps1 +++ b/test/tests/Install-Get-Update-Uninstall-Php.Tests.ps1 @@ -1,20 +1,20 @@ Describe 'Install-Get-Update-Uninstall-Php' { Mock -ModuleName PhpManager Get-PhpDownloadCache { return Join-Path -Path $Global:PHPMANAGER_TESTPATH -ChildPath download-cache } - $isNanoServer = (Get-ComputerInfo -Property WindowsInstallationType).WindowsInstallationType -eq 'Nano Server' + $isNanoServer = (Get-ItemProperty -LiteralPath 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion' -Name InstallationType).InstallationType -eq 'Nano Server' $phpPath = Join-Path -Path $Global:PHPMANAGER_TESTINSTALLS -ChildPath (New-Guid).Guid It 'should install/get/update/remove PHP' { if (Test-Path -LiteralPath $phpPath) { Remove-Item -LiteralPath $phpPath -Recurse -Force } try { - Install-Php -Version 7.1.0 -Architecture x64 -ThreadSafe $true -Path $phpPath + Install-Php -Version 8.0.0 -Architecture x64 -ThreadSafe $true -Path $phpPath $initialPhpVersion = Get-Php -Path $phpPath $initialPhpVersion | Should -Not -BeNullOrEmpty $initialPhpVersion.GetType().FullName | Should -BeExactly 'PhpVersionInstalled' $initialPhpVersion.Version | Should -BeOfType [string] - $initialPhpVersion.Version | Should -BeExactly '7.1.0' - $initialPhpVersion.MajorMinorVersion | Should -BeExactly '7.1' + $initialPhpVersion.Version | Should -BeExactly '8.0.0' + $initialPhpVersion.MajorMinorVersion | Should -BeExactly '8.0' $initialPhpVersion.ComparableVersion | Should -BeOfType [version] $initialPhpVersion.UnstabilityLevel | Should -BeNullOrEmpty $initialPhpVersion.UnstabilityVersion | Should -BeNullOrEmpty @@ -33,7 +33,7 @@ $updatedPhpVersion | Should -Not -BeNullOrEmpty $updatedPhpVersion.GetType().FullName | Should -BeExactly 'PhpVersionInstalled' $updatedPhpVersion.Version | Should -BeOfType [string] - $updatedPhpVersion.Version | Should -Match '^7\.1\.' + $updatedPhpVersion.Version | Should -Match '^8\.0\.' $updatedPhpVersion.ComparableVersion | Should -BeOfType [version] $updatedPhpVersion.ComparableVersion | Should -BeGreaterThan $initialPhpVersion.ComparableVersion $updatedPhpVersion.UnstabilityLevel | Should -BeNullOrEmpty @@ -177,13 +177,13 @@ Remove-Item -LiteralPath $phpPath -Recurse -Force } try { - Install-Php -Version 7.1.0 -Architecture x64 -ThreadSafe $true -Path $phpPath + Install-Php -Version 8.0.0 -Architecture x64 -ThreadSafe $true -Path $phpPath Get-PhpIniKey -Key display_errors -Path $phpPath | Should -BeNullOrEmpty Uninstall-Php -Path $phpPath - Install-Php -Version 7.1.0 -Architecture x64 -ThreadSafe $true -Path $phpPath -InitialPhpIni Development + Install-Php -Version 8.0.0 -Architecture x64 -ThreadSafe $true -Path $phpPath -InitialPhpIni Development Get-PhpIniKey -Key display_errors -Path $phpPath | Should -BeExactly 'On' Uninstall-Php -Path $phpPath - Install-Php -Version 7.1.0 -Architecture x64 -ThreadSafe $true -Path $phpPath -InitialPhpIni Production + Install-Php -Version 8.0.0 -Architecture x64 -ThreadSafe $true -Path $phpPath -InitialPhpIni Production Get-PhpIniKey -Key display_errors -Path $phpPath | Should -BeExactly 'Off' } finally { try {