Close #8: Implement caching (#14)

For now we cache only the PHP SDK, the PHP binaries and the development
packs.  This already greatly improves the setup performance (it might
easily safe a minute or two, in case of cache hits).  To be able to use
the current PHP revision as part of the cache key, we factor out
determine-revision.ps1.  We create a separate cache for the PHP-SDK
since this likely rarely changes, and since the cached variant is
apparently much faster than fetching a GH release of the PHP-SDK.

Since clients may not want to use the cache, possibly because they have
already a lot of other files in their caches, we explicitly require
clients to opt-in via the `cache` input parameter.
This commit is contained in:
Christoph M. Becker
2024-09-30 12:58:39 +02:00
committed by GitHub
parent 8d9e79bdbc
commit d07cd9875f
4 changed files with 88 additions and 48 deletions

View File

@@ -30,6 +30,7 @@ for building and testing PHP extensions on Windows.
- `ts`: thread-safety (`nts` or `ts`)
- `deps`: dependency libraries to install; for now, only
[core dependencies](https://windows.php.net/downloads/php-sdk/deps/) are available
- `cache`: whether to cache the PHP SDK, PHP and development pack
Note that for PHP versions 7.4 and below, `runs-on: windows-2022` will not work
as the correct toolset is not available. For these versions, you should use

View File

@@ -14,6 +14,11 @@ inputs:
description: "List of dependency libraries"
required: false
default: '@()'
cache:
description: "Whether the PHP-SDK should be cached"
type: boolean
required: false
default: false
outputs:
toolset:
description: "The required toolset version"
@@ -27,6 +32,24 @@ outputs:
runs:
using: "composite"
steps:
- id: setup
run: ${{github.action_path}}/run -version ${{inputs.version}} -arch ${{inputs.arch}} -ts ${{inputs.ts}} -deps ${{inputs.deps}}
- name: Determine current PHP revision
id: revision
run: ${{github.action_path}}/determine-revision -version ${{inputs.version}}
shell: powershell
- name: Cache PHP SDK
if: ${{inputs.cache == 'true'}}
uses: actions/cache@v4
with:
path: php-sdk
key: php-sdk-2.3.0
- name: Cache PHP
if: ${{inputs.cache == 'true'}}
uses: actions/cache@v4
with:
path: |
php-bin
php-dev
key: php-${{steps.revision.outputs.version}}-${{inputs.arch}}-${{inputs.ts}}
- id: setup
run: ${{github.action_path}}/run -version ${{inputs.version}} -revision ${{steps.revision.outputs.version}} -baseurl ${{steps.revision.outputs.baseurl}} -arch ${{inputs.arch}} -ts ${{inputs.ts}} -deps ${{inputs.deps}}
shell: powershell

34
determine-revision.ps1 Normal file
View File

@@ -0,0 +1,34 @@
param (
[Parameter(Mandatory)] [String] $version
)
$ErrorActionPreference = "Stop"
$baseurl = "https://downloads.php.net/~windows/releases/archives"
$releases = @{
"7.0" = "7.0.33"
"7.1" = "7.1.33"
"7.2" = "7.2.34"
"7.3" = "7.3.33"
"7.4" = "7.4.33"
"8.0" = "8.0.30"
}
$phpversion = $releases.$version
if (-not $phpversion) {
$baseurl = "https://downloads.php.net/~windows/releases"
$url = "$baseurl/releases.json"
$releases = Invoke-WebRequest $url | ConvertFrom-Json
$phpversion = $releases.$version.version
if (-not $phpversion) {
$baseurl = "https://downloads.php.net/~windows/qa"
$url = "$baseurl/releases.json"
$releases = Invoke-WebRequest $url | ConvertFrom-Json
$phpversion = $releases.$version.version
if (-not $phpversion) {
throw "unknown version"
}
}
}
Write-Output "version=$phpversion" >> $Env:GITHUB_OUTPUT
Write-Output "baseurl=$baseurl" >> $Env:GITHUB_OUTPUT

74
run.ps1
View File

@@ -1,5 +1,7 @@
param (
[Parameter(Mandatory)] [String] $version,
[Parameter(Mandatory)] [String] $revision,
[Parameter(Mandatory)] [String] $baseurl,
[Parameter(Mandatory)] [String] $arch,
[Parameter(Mandatory)] [String] $ts,
[Parameter(Mandatory)] [AllowEmptyCollection()] [Array] $deps
@@ -45,60 +47,40 @@ if (-not $toolset) {
throw "toolset not available"
}
Write-Output "Install PHP SDK ..."
if (-not (Test-Path "php-sdk")) {
Write-Output "Install PHP SDK ..."
$temp = New-TemporaryFile | Rename-Item -NewName {$_.Name + ".zip"} -PassThru
$url = "https://github.com/php/php-sdk-binary-tools/releases/download/php-sdk-2.3.0/php-sdk-binary-tools-php-sdk-2.3.0.zip"
Invoke-WebRequest $url -OutFile $temp
Expand-Archive $temp -DestinationPath "."
Rename-Item "php-sdk-binary-tools-php-sdk-2.3.0" "php-sdk"
$baseurl = "https://downloads.php.net/~windows/releases/archives"
$releases = @{
"7.0" = "7.0.33"
"7.1" = "7.1.33"
"7.2" = "7.2.34"
"7.3" = "7.3.33"
"7.4" = "7.4.33"
"8.0" = "8.0.30"
}
$phpversion = $releases.$version
if (-not $phpversion) {
$baseurl = "https://downloads.php.net/~windows/releases"
$url = "$baseurl/releases.json"
$releases = Invoke-WebRequest $url | ConvertFrom-Json
$phpversion = $releases.$version.version
if (-not $phpversion) {
$baseurl = "https://downloads.php.net/~windows/qa"
$url = "$baseurl/releases.json"
$releases = Invoke-WebRequest $url | ConvertFrom-Json
$phpversion = $releases.$version.version
if (-not $phpversion) {
throw "unknown version"
}
}
$temp = New-TemporaryFile | Rename-Item -NewName {$_.Name + ".zip"} -PassThru
$url = "https://github.com/php/php-sdk-binary-tools/releases/download/php-sdk-2.3.0/php-sdk-binary-tools-php-sdk-2.3.0.zip"
Invoke-WebRequest $url -OutFile $temp
Expand-Archive $temp -DestinationPath "."
Rename-Item "php-sdk-binary-tools-php-sdk-2.3.0" "php-sdk"
}
$tspart = if ($ts -eq "nts") {"nts-Win32"} else {"Win32"}
Write-Output "Install PHP $phpversion ..."
if (-not (Test-path "php-bin")) {
Write-Output "Install PHP $revision ..."
$temp = New-TemporaryFile | Rename-Item -NewName {$_.Name + ".zip"} -PassThru
$fname = "php-$phpversion-$tspart-$vs-$arch.zip"
$url = "$baseurl/$fname"
Write-Output "Downloading $url ..."
Invoke-WebRequest $url -OutFile $temp
Expand-Archive $temp "php-bin"
$temp = New-TemporaryFile | Rename-Item -NewName {$_.Name + ".zip"} -PassThru
$fname = "php-$revision-$tspart-$vs-$arch.zip"
$url = "$baseurl/$fname"
Write-Output "Downloading $url ..."
Invoke-WebRequest $url -OutFile $temp
Expand-Archive $temp "php-bin"
}
Write-Output "Install development pack ..."
if (-not (Test-Path "php-dev")) {
Write-Output "Install development pack ..."
$temp = New-TemporaryFile | Rename-Item -NewName {$_.Name + ".zip"} -PassThru
$fname = "php-devel-pack-$phpversion-$tspart-$vs-$arch.zip"
$url = "$baseurl/$fname"
Write-Output "Downloading $url ..."
Invoke-WebRequest $url -OutFile $temp
Expand-Archive $temp "."
Rename-Item "php-$phpversion-devel-$vs-$arch" "php-dev"
$temp = New-TemporaryFile | Rename-Item -NewName {$_.Name + ".zip"} -PassThru
$fname = "php-devel-pack-$revision-$tspart-$vs-$arch.zip"
$url = "$baseurl/$fname"
Write-Output "Downloading $url ..."
Invoke-WebRequest $url -OutFile $temp
Expand-Archive $temp "."
Rename-Item "php-$revision-devel-$vs-$arch" "php-dev"
}
if ($deps.Count -gt 0) {
$baseurl = "https://downloads.php.net/~windows/php-sdk/deps"