Skip to content

Commit d07cd98

Browse files
authored
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.
1 parent 8d9e79b commit d07cd98

File tree

4 files changed

+87
-47
lines changed

4 files changed

+87
-47
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ for building and testing PHP extensions on Windows.
3030
- `ts`: thread-safety (`nts` or `ts`)
3131
- `deps`: dependency libraries to install; for now, only
3232
[core dependencies](https://windows.php.net/downloads/php-sdk/deps/) are available
33+
- `cache`: whether to cache the PHP SDK, PHP and development pack
3334

3435
Note that for PHP versions 7.4 and below, `runs-on: windows-2022` will not work
3536
as the correct toolset is not available. For these versions, you should use

action.yml

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ inputs:
1414
description: "List of dependency libraries"
1515
required: false
1616
default: '@()'
17+
cache:
18+
description: "Whether the PHP-SDK should be cached"
19+
type: boolean
20+
required: false
21+
default: false
1722
outputs:
1823
toolset:
1924
description: "The required toolset version"
@@ -27,6 +32,24 @@ outputs:
2732
runs:
2833
using: "composite"
2934
steps:
35+
- name: Determine current PHP revision
36+
id: revision
37+
run: ${{github.action_path}}/determine-revision -version ${{inputs.version}}
38+
shell: powershell
39+
- name: Cache PHP SDK
40+
if: ${{inputs.cache == 'true'}}
41+
uses: actions/cache@v4
42+
with:
43+
path: php-sdk
44+
key: php-sdk-2.3.0
45+
- name: Cache PHP
46+
if: ${{inputs.cache == 'true'}}
47+
uses: actions/cache@v4
48+
with:
49+
path: |
50+
php-bin
51+
php-dev
52+
key: php-${{steps.revision.outputs.version}}-${{inputs.arch}}-${{inputs.ts}}
3053
- id: setup
31-
run: ${{github.action_path}}/run -version ${{inputs.version}} -arch ${{inputs.arch}} -ts ${{inputs.ts}} -deps ${{inputs.deps}}
54+
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}}
3255
shell: powershell

determine-revision.ps1

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
param (
2+
[Parameter(Mandatory)] [String] $version
3+
)
4+
5+
$ErrorActionPreference = "Stop"
6+
7+
$baseurl = "https://downloads.php.net/~windows/releases/archives"
8+
$releases = @{
9+
"7.0" = "7.0.33"
10+
"7.1" = "7.1.33"
11+
"7.2" = "7.2.34"
12+
"7.3" = "7.3.33"
13+
"7.4" = "7.4.33"
14+
"8.0" = "8.0.30"
15+
}
16+
$phpversion = $releases.$version
17+
if (-not $phpversion) {
18+
$baseurl = "https://downloads.php.net/~windows/releases"
19+
$url = "$baseurl/releases.json"
20+
$releases = Invoke-WebRequest $url | ConvertFrom-Json
21+
$phpversion = $releases.$version.version
22+
if (-not $phpversion) {
23+
$baseurl = "https://downloads.php.net/~windows/qa"
24+
$url = "$baseurl/releases.json"
25+
$releases = Invoke-WebRequest $url | ConvertFrom-Json
26+
$phpversion = $releases.$version.version
27+
if (-not $phpversion) {
28+
throw "unknown version"
29+
}
30+
}
31+
}
32+
33+
Write-Output "version=$phpversion" >> $Env:GITHUB_OUTPUT
34+
Write-Output "baseurl=$baseurl" >> $Env:GITHUB_OUTPUT

run.ps1

Lines changed: 28 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
param (
22
[Parameter(Mandatory)] [String] $version,
3+
[Parameter(Mandatory)] [String] $revision,
4+
[Parameter(Mandatory)] [String] $baseurl,
35
[Parameter(Mandatory)] [String] $arch,
46
[Parameter(Mandatory)] [String] $ts,
57
[Parameter(Mandatory)] [AllowEmptyCollection()] [Array] $deps
@@ -45,60 +47,40 @@ if (-not $toolset) {
4547
throw "toolset not available"
4648
}
4749

48-
Write-Output "Install PHP SDK ..."
50+
if (-not (Test-Path "php-sdk")) {
51+
Write-Output "Install PHP SDK ..."
4952

50-
$temp = New-TemporaryFile | Rename-Item -NewName {$_.Name + ".zip"} -PassThru
51-
$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"
52-
Invoke-WebRequest $url -OutFile $temp
53-
Expand-Archive $temp -DestinationPath "."
54-
Rename-Item "php-sdk-binary-tools-php-sdk-2.3.0" "php-sdk"
55-
56-
$baseurl = "https://downloads.php.net/~windows/releases/archives"
57-
$releases = @{
58-
"7.0" = "7.0.33"
59-
"7.1" = "7.1.33"
60-
"7.2" = "7.2.34"
61-
"7.3" = "7.3.33"
62-
"7.4" = "7.4.33"
63-
"8.0" = "8.0.30"
64-
}
65-
$phpversion = $releases.$version
66-
if (-not $phpversion) {
67-
$baseurl = "https://downloads.php.net/~windows/releases"
68-
$url = "$baseurl/releases.json"
69-
$releases = Invoke-WebRequest $url | ConvertFrom-Json
70-
$phpversion = $releases.$version.version
71-
if (-not $phpversion) {
72-
$baseurl = "https://downloads.php.net/~windows/qa"
73-
$url = "$baseurl/releases.json"
74-
$releases = Invoke-WebRequest $url | ConvertFrom-Json
75-
$phpversion = $releases.$version.version
76-
if (-not $phpversion) {
77-
throw "unknown version"
78-
}
79-
}
53+
$temp = New-TemporaryFile | Rename-Item -NewName {$_.Name + ".zip"} -PassThru
54+
$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"
55+
Invoke-WebRequest $url -OutFile $temp
56+
Expand-Archive $temp -DestinationPath "."
57+
Rename-Item "php-sdk-binary-tools-php-sdk-2.3.0" "php-sdk"
8058
}
8159

8260
$tspart = if ($ts -eq "nts") {"nts-Win32"} else {"Win32"}
8361

84-
Write-Output "Install PHP $phpversion ..."
62+
if (-not (Test-path "php-bin")) {
63+
Write-Output "Install PHP $revision ..."
8564

86-
$temp = New-TemporaryFile | Rename-Item -NewName {$_.Name + ".zip"} -PassThru
87-
$fname = "php-$phpversion-$tspart-$vs-$arch.zip"
88-
$url = "$baseurl/$fname"
89-
Write-Output "Downloading $url ..."
90-
Invoke-WebRequest $url -OutFile $temp
91-
Expand-Archive $temp "php-bin"
65+
$temp = New-TemporaryFile | Rename-Item -NewName {$_.Name + ".zip"} -PassThru
66+
$fname = "php-$revision-$tspart-$vs-$arch.zip"
67+
$url = "$baseurl/$fname"
68+
Write-Output "Downloading $url ..."
69+
Invoke-WebRequest $url -OutFile $temp
70+
Expand-Archive $temp "php-bin"
71+
}
9272

93-
Write-Output "Install development pack ..."
73+
if (-not (Test-Path "php-dev")) {
74+
Write-Output "Install development pack ..."
9475

95-
$temp = New-TemporaryFile | Rename-Item -NewName {$_.Name + ".zip"} -PassThru
96-
$fname = "php-devel-pack-$phpversion-$tspart-$vs-$arch.zip"
97-
$url = "$baseurl/$fname"
98-
Write-Output "Downloading $url ..."
99-
Invoke-WebRequest $url -OutFile $temp
100-
Expand-Archive $temp "."
101-
Rename-Item "php-$phpversion-devel-$vs-$arch" "php-dev"
76+
$temp = New-TemporaryFile | Rename-Item -NewName {$_.Name + ".zip"} -PassThru
77+
$fname = "php-devel-pack-$revision-$tspart-$vs-$arch.zip"
78+
$url = "$baseurl/$fname"
79+
Write-Output "Downloading $url ..."
80+
Invoke-WebRequest $url -OutFile $temp
81+
Expand-Archive $temp "."
82+
Rename-Item "php-$revision-devel-$vs-$arch" "php-dev"
83+
}
10284

10385
if ($deps.Count -gt 0) {
10486
$baseurl = "https://downloads.php.net/~windows/php-sdk/deps"

0 commit comments

Comments
 (0)