Skip to content

Commit

Permalink
Close #8: Implement caching (#14)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
cmb69 authored Sep 30, 2024
1 parent 8d9e79b commit d07cd98
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 47 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 24 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -27,6 +32,24 @@ outputs:
runs:
using: "composite"
steps:
- 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}} -arch ${{inputs.arch}} -ts ${{inputs.ts}} -deps ${{inputs.deps}}
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 changes: 34 additions & 0 deletions determine-revision.ps1
Original file line number Diff line number Diff line change
@@ -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 changes: 28 additions & 46 deletions run.ps1
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit d07cd98

Please sign in to comment.