Skip to content

Commit 1474b2f

Browse files
committed
Add workflow to test PHP builds from source repo and with custom library builds
1 parent 2ffcb9d commit 1474b2f

2 files changed

Lines changed: 162 additions & 9 deletions

File tree

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
name: Build PHP with custom library builds from winlibs/winlib-builder (source)
2+
run-name: Build PHP from source ${{ inputs.php-src-ref }}
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
php-src-repository:
7+
description: 'php-src repository to source builds and tests from'
8+
required: true
9+
php-src-ref:
10+
description: 'Branch, tag, or SHA in the php-src repository to source builds and tests from'
11+
required: true
12+
libs-build-runs:
13+
description: 'Comma-separated list of GitHub Actions run IDs from winlibs/winlib-builder'
14+
required: false
15+
16+
jobs:
17+
php:
18+
strategy:
19+
matrix:
20+
arch: [x64, x86]
21+
ts: [nts, ts]
22+
runs-on: windows-2022
23+
steps:
24+
- name: Checkout PHP source
25+
uses: actions/checkout@v6
26+
with:
27+
repository: ${{ inputs.php-src-repository }}
28+
ref: ${{ inputs.php-src-ref }}
29+
token: ${{ secrets.GITHUB_TOKEN }}
30+
31+
- name: Checkout
32+
uses: actions/checkout@v6
33+
with:
34+
path: builder
35+
36+
- name: Build
37+
uses: ./builder/php
38+
with:
39+
arch: ${{ matrix.arch }}
40+
ts: ${{ matrix.ts }}
41+
libs-build-runs: ${{ inputs.libs-build-runs }}
42+
github-token: ${{ secrets.GITHUB_TOKEN }}
43+
env:
44+
PHP_BUILD_PROVIDER: "The PHP Group"
45+
46+
artifacts:
47+
runs-on: ubuntu-latest
48+
needs: php
49+
outputs:
50+
artifact-id: ${{ steps.artifacts.outputs.artifact-id }}
51+
steps:
52+
- name: Upload artifacts
53+
uses: actions/upload-artifact/merge@v7
54+
id: artifacts
55+
with:
56+
name: artifacts
57+
delete-merged: true
58+
59+
tests:
60+
needs: artifacts
61+
strategy:
62+
matrix:
63+
arch: [x64, x86]
64+
ts: [nts, ts]
65+
opcache: [opcache, nocache]
66+
test-type: [php, ext]
67+
runs-on: windows-2022
68+
steps:
69+
- name: Checkout
70+
uses: actions/checkout@v6
71+
72+
- name: Download artifacts
73+
uses: actions/download-artifact@v8
74+
id: artifacts
75+
with:
76+
name: artifacts
77+
78+
- name: Get Cache Key
79+
id: cache-key
80+
run: |
81+
$artifactDirectory = $(pwd).Path
82+
$zip = Get-ChildItem -Path $artifactDirectory -Filter "php-*.zip" -File |
83+
Where-Object { $_.Name -match "^php-(.+?)-(?:nts-)?Win32-vs\d+-${{ matrix.arch }}\.zip$" } |
84+
Select-Object -First 1
85+
if ($null -eq $zip) {
86+
throw "Unable to determine PHP version from build artifacts in $artifactDirectory"
87+
}
88+
$phpVersion = [regex]::Match($zip.Name, '^php-(.+?)-(?:nts-)?Win32-vs\d+-').Groups[1].Value
89+
90+
$pv = $phpVersion
91+
if($phpVersion -ne 'master') {
92+
$pv = $phpVersion.Split('.')[0..1] -join '.'
93+
}
94+
$vsVersion = (Get-Content -Raw -Path (Join-Path $(pwd).Path '\php\BuildPhp\config\vs.json') | ConvertFrom-Json).php.$pv
95+
$packagesListUrl = "https://downloads.php.net/~windows/php-sdk/deps/series/packages-$pv-$vsVersion-${{ matrix.arch }}-staging.txt"
96+
Invoke-WebRequest -OutFile packages.txt -Uri $packagesListUrl
97+
Add-Content -Value "php-version=$phpVersion" -Path $env:GITHUB_OUTPUT
98+
Add-Content -Value "cache-key=deps-$pv-${{ matrix.arch }}-${{ inputs.libs-build-runs }}" -Path $env:GITHUB_OUTPUT
99+
Add-Content -Value "cache-dir=C:\deps-$pv-${{ matrix.arch }}" -Path $env:GITHUB_OUTPUT
100+
101+
- name: Cache Deps
102+
id: cache-deps
103+
uses: actions/cache@v5
104+
with:
105+
path: ${{ steps.cache-key.outputs.cache-dir }}
106+
key: ${{ steps.cache-key.outputs.cache-key }}-${{ hashFiles('packages.txt') }}
107+
108+
- name: Test PHP
109+
shell: pwsh
110+
continue-on-error: true
111+
env:
112+
DEPS_DIR: ${{ steps.cache-key.outputs.cache-dir }}
113+
DEPS_CACHE_HIT: ${{ steps.cache-deps.outputs.cache-hit }}
114+
LIBS_BUILD_RUNS: ${{ inputs.libs-build-runs }}
115+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
116+
run: |
117+
Import-Module (Join-Path $(pwd).Path '\php\BuildPhp') -Force
118+
Invoke-PhpTests -PhpVersion ${{ steps.cache-key.outputs.php-version }} `
119+
-Arch ${{matrix.arch}} `
120+
-Ts ${{matrix.ts}} `
121+
-Opcache ${{matrix.opcache}} `
122+
-TestType ${{matrix.test-type}} `
123+
-SourceRepository '${{ inputs.php-src-repository }}' `
124+
-SourceRef '${{ inputs.php-src-ref }}'
125+
126+
- name: Upload artifacts
127+
uses: actions/upload-artifact@v7
128+
continue-on-error: true
129+
with:
130+
name: test-results-${{matrix.arch}}-${{matrix.ts}}-${{matrix.opcache}}-${{matrix.test-type}}
131+
path: test-${{matrix.arch}}-${{matrix.ts}}-${{matrix.opcache}}-${{matrix.test-type}}.xml
132+
133+
smoke-tests:
134+
strategy:
135+
matrix:
136+
arch: [x64, x86]
137+
ts: [nts, ts]
138+
runs-on: windows-2022
139+
needs: [artifacts]
140+
steps:
141+
- name: Checkout
142+
uses: actions/checkout@v6
143+
144+
- name: Download artifacts
145+
uses: actions/download-artifact@v8
146+
with:
147+
name: artifacts
148+
path: artifacts
149+
150+
- name: Smoke test PHP builds
151+
shell: pwsh
152+
run: |
153+
Import-Module (Join-Path $(pwd).Path '\php\BuildPhp') -Force
154+
Invoke-PhpSmokeTests -ArtifactsDirectory (Join-Path $(pwd).Path 'artifacts') `
155+
-Arch ${{matrix.arch}} `
156+
-Ts ${{matrix.ts}}

php/action.yml

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ branding:
88

99
inputs:
1010
php-version:
11-
description: PHP version to build
12-
required: true
11+
description: PHP version to build, skip this to build from the current source directory
12+
required: false
1313
arch:
1414
description: Architecture to build
1515
required: true
@@ -27,22 +27,19 @@ inputs:
2727
runs:
2828
using: composite
2929
steps:
30-
- name: Checkout
31-
uses: actions/checkout@v6
32-
3330
- name: Build PHP
3431
shell: pwsh
3532
env:
3633
LIBS_BUILD_RUNS: ${{ inputs.libs-build-runs }}
3734
GITHUB_TOKEN: ${{ inputs.github-token }}
3835
run: |
3936
Import-Module ${{ github.action_path }}\BuildPhp -Force
40-
Invoke-PhpBuild -PhpVersion ${{inputs.php-version}} `
41-
-Arch ${{inputs.arch}} `
42-
-Ts ${{inputs.ts}}
37+
Invoke-PhpBuild -PhpVersion '${{ inputs.php-version }}' `
38+
-Arch '${{ inputs.arch }}' `
39+
-Ts '${{ inputs.ts }}'
4340
4441
- name: Upload artifacts
4542
uses: actions/upload-artifact@v7
4643
with:
47-
name: artifacts-${{inputs.php-version}}-${{inputs.arch}}-${{inputs.ts}}
44+
name: artifacts-${{ inputs.php-version || 'source' }}-${{inputs.arch}}-${{inputs.ts}}
4845
path: artifacts/*

0 commit comments

Comments
 (0)