diff --git a/.github/workflows/_test-integrations.yml b/.github/workflows/_test-integrations.yml index a9b9f102..08e59ff3 100644 --- a/.github/workflows/_test-integrations.yml +++ b/.github/workflows/_test-integrations.yml @@ -104,17 +104,56 @@ jobs: - uses: actions/checkout@v4 with: submodules: recursive - - name: Install Ghostscript - run: choco install ghostscript --version 10.03.1 -y - name: Set up php ${{ matrix.php-version }} uses: shivammathur/setup-php@v2 - env: - phpts: zts with: - php-version: ${{ matrix.php-version }} + php-version: '${{ matrix.php-version }}' extensions: curl, fileinfo, json, imagick - - name: Install Ghostscript - run: choco install ghostscript -y + + + - name: Install Ghostscript and Patch Imagick Policy + shell: powershell + run: | + $gsVersion = "10.03.1" + $gsVersionCompact = $gsVersion.Replace('.', '') + $installerUrl = "https://github.com/ArtifexSoftware/ghostpdl-downloads/releases/download/gs$gsVersionCompact/gs${gsVersionCompact}w64.exe" + $downloadPath = "$env:TEMP\gs_installer.exe" + $extractDir = "C:\gs" + + Write-Host "Downloading and Extracting Ghostscript..." + Invoke-WebRequest -Uri $installerUrl -OutFile $downloadPath + 7z x $downloadPath -o"$extractDir" -y | Out-Null + + $binDir = (Get-ChildItem -Path $extractDir -Recurse -Filter "gswin64c.exe").Directory.FullName + $libDir = (Get-ChildItem -Path $extractDir -Recurse -Filter "gs_init.ps").Directory.FullName + $dllPath = (Get-ChildItem -Path $extractDir -Recurse -Filter "gsdll64.dll").FullName + $resourceDir = (Get-ChildItem -Path $extractDir -Recurse -Filter "Init" | Where-Object {$_.Parent.Name -eq "Resource"}).Parent.FullName + + Write-Host "Creating gs.exe for generic shell commands..." + Copy-Item -Path "$binDir\gswin64c.exe" -Destination "$binDir\gs.exe" + + Write-Host "Writing Registry Keys for PHP Imagick..." + $registryPath = "HKLM:\SOFTWARE\GPL Ghostscript\$gsVersion" + New-Item -Path $registryPath -Force | Out-Null + New-ItemProperty -Path $registryPath -Name "GS_DLL" -Value $dllPath -PropertyType String -Force | Out-Null + + $gsLibStr = "$libDir;$resourceDir\Init;$resourceDir\Font" + New-ItemProperty -Path $registryPath -Name "GS_LIB" -Value $gsLibStr -PropertyType String -Force | Out-Null + + Write-Host "Adding Ghostscript to GITHUB_ENV and GITHUB_PATH..." + Add-Content -Path $env:GITHUB_ENV -Value "GS_PROG=$binDir\gs.exe" + Add-Content -Path $env:GITHUB_PATH -Value $binDir + Add-Content -Path $env:GITHUB_PATH -Value $libDir + + Write-Host "Patching ImageMagick policy.xml on Windows..." + $policyFiles = Get-ChildItem -Path C:\tools\php -Filter policy.xml -Recurse -ErrorAction SilentlyContinue + + foreach ($file in $policyFiles) { + Write-Host "Patching PDF rights in: $($file.FullName)" + $content = Get-Content $file.FullName + $content = $content -replace 'rights="none" pattern="PDF"', 'rights="read|write" pattern="PDF"' + Set-Content -Path $file.FullName -Value $content + } - uses: ramsey/composer-install@v2 - name: Unit testing with phpunit run: | diff --git a/.github/workflows/_test-units.yml b/.github/workflows/_test-units.yml index befbc73e..e5525c79 100644 --- a/.github/workflows/_test-units.yml +++ b/.github/workflows/_test-units.yml @@ -181,20 +181,55 @@ jobs: - uses: actions/checkout@v4 with: submodules: recursive - - name: Install Ghostscript - run: choco install ghostscript --version 10.04.0 -y - - name: Create Ghostscript alias - run: | - New-Item -ItemType SymbolicLink -Path "C:\Windows\gs.exe" -Target "C:\Program Files\gs\gs10.04.0\bin\gswin64c.exe" - New-Item -ItemType SymbolicLink -Path "C:\Windows\gs" -Target "C:\Program Files\gs\gs10.04.0\bin\gswin64c.exe" - shell: powershell + - name: Set up php ${{ matrix.php-version }} uses: shivammathur/setup-php@v2 - env: - phpts: zts with: - php-version: ${{ matrix.php-version }} + php-version: '${{ matrix.php-version }}' extensions: curl, fileinfo, json, imagick + - name: Install Ghostscript and Patch Imagick Policy + shell: powershell + run: | + $gsVersion = "10.03.1" + $gsVersionCompact = $gsVersion.Replace('.', '') + $installerUrl = "https://github.com/ArtifexSoftware/ghostpdl-downloads/releases/download/gs$gsVersionCompact/gs${gsVersionCompact}w64.exe" + $downloadPath = "$env:TEMP\gs_installer.exe" + $extractDir = "C:\gs" + + Write-Host "Downloading and Extracting Ghostscript..." + Invoke-WebRequest -Uri $installerUrl -OutFile $downloadPath + 7z x $downloadPath -o"$extractDir" -y | Out-Null + + $binDir = (Get-ChildItem -Path $extractDir -Recurse -Filter "gswin64c.exe").Directory.FullName + $libDir = (Get-ChildItem -Path $extractDir -Recurse -Filter "gs_init.ps").Directory.FullName + $dllPath = (Get-ChildItem -Path $extractDir -Recurse -Filter "gsdll64.dll").FullName + $resourceDir = (Get-ChildItem -Path $extractDir -Recurse -Filter "Init" | Where-Object {$_.Parent.Name -eq "Resource"}).Parent.FullName + + Write-Host "Creating gs.exe for generic shell commands..." + Copy-Item -Path "$binDir\gswin64c.exe" -Destination "$binDir\gs.exe" + + Write-Host "Writing Registry Keys for PHP Imagick..." + $registryPath = "HKLM:\SOFTWARE\GPL Ghostscript\$gsVersion" + New-Item -Path $registryPath -Force | Out-Null + New-ItemProperty -Path $registryPath -Name "GS_DLL" -Value $dllPath -PropertyType String -Force | Out-Null + + $gsLibStr = "$libDir;$resourceDir\Init;$resourceDir\Font" + New-ItemProperty -Path $registryPath -Name "GS_LIB" -Value $gsLibStr -PropertyType String -Force | Out-Null + + Write-Host "Adding Ghostscript to GITHUB_ENV and GITHUB_PATH..." + Add-Content -Path $env:GITHUB_ENV -Value "GS_PROG=$binDir\gs.exe" + Add-Content -Path $env:GITHUB_PATH -Value $binDir + Add-Content -Path $env:GITHUB_PATH -Value $libDir + + Write-Host "Patching ImageMagick policy.xml on Windows..." + $policyFiles = Get-ChildItem -Path C:\tools\php -Filter policy.xml -Recurse -ErrorAction SilentlyContinue + + foreach ($file in $policyFiles) { + Write-Host "Patching PDF rights in: $($file.FullName)" + $content = Get-Content $file.FullName + $content = $content -replace 'rights="none" pattern="PDF"', 'rights="read|write" pattern="PDF"' + Set-Content -Path $file.FullName -Value $content + } - uses: ramsey/composer-install@v3 - name: Unit testing with phpunit env: