forked from php/php-windows-builder
-
Notifications
You must be signed in to change notification settings - Fork 0
275 lines (232 loc) · 9.76 KB
/
php.yml
File metadata and controls
275 lines (232 loc) · 9.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
name: Build PHP
run-name: Build PHP ${{ inputs.php-version }}
on:
workflow_dispatch:
inputs:
php-version:
description: 'PHP versions to build (comma-separated)'
required: true
arch:
description: 'Architecture'
required: true
type: choice
options: ['x64', 'x86']
default: 'x64'
ts:
description: 'Thread safety'
required: true
type: choice
options: ['ts', 'nts', 'ts,nts']
default: 'ts,nts'
upload:
type: choice
options: ['true', 'false']
description: Upload artifacts to the downloads server
required: false
default: 'true'
do-release: # NEW
type: choice
options: ['true', 'false']
description: 'Make Release?'
required: false
default: 'true'
jobs:
generate-matrix:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
php-versions: ${{ steps.set-matrix.outputs.php-versions }}
steps:
- id: set-matrix
run: |
ARCH="${{ inputs.arch }}"
TS_INPUT="${{ inputs.ts }}"
PHP_VERSIONS="${{ inputs.php-version }}"
IFS=',' read -ra TS_VALUES <<< "$TS_INPUT"
IFS=',' read -ra PHP_VALUES <<< "$PHP_VERSIONS"
MATRIX_JSON="{\"include\":["
SEP=""
for PHP_VERSION in "${PHP_VALUES[@]}"; do
for TS in "${TS_VALUES[@]}"; do
MATRIX_JSON+="${SEP}{\"php-version\":\"$PHP_VERSION\",\"arch\":\"$ARCH\",\"ts\":\"$TS\"}"
SEP=","
done
done
MATRIX_JSON+="]}"
PHP_VERSIONS_JSON="["
SEP=""
for PHP_VERSION in "${PHP_VALUES[@]}"; do
PHP_VERSIONS_JSON+="${SEP}\"$PHP_VERSION\""
SEP=","
done
PHP_VERSIONS_JSON+="]"
echo "Generated matrix: $MATRIX_JSON"
echo "PHP versions: $PHP_VERSIONS_JSON"
echo "matrix=$MATRIX_JSON" >> $GITHUB_OUTPUT
echo "php-versions=$PHP_VERSIONS_JSON" >> $GITHUB_OUTPUT
create-releases:
if: ${{ inputs.do-release == 'true' }} # NEW
runs-on: ubuntu-latest
needs: generate-matrix
strategy:
matrix:
php-version: ${{ fromJson(needs.generate-matrix.outputs.php-versions) }}
steps:
- name: Create release for PHP ${{ matrix.php-version }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
VERSION="${{ matrix.php-version }}"
RELEASE_TAG="php-${VERSION}"
echo "Creating/checking release for PHP ${VERSION}"
if gh release view "${RELEASE_TAG}" -R ${{ github.repository }} >/dev/null 2>&1; then
echo "Release ${RELEASE_TAG} already exists, deleting it..."
gh release delete "${RELEASE_TAG}" -R ${{ github.repository }} --yes --cleanup-tag
fi
if git ls-remote --tags origin | grep -q "refs/tags/${RELEASE_TAG}$"; then
echo "Tag ${RELEASE_TAG} still exists, deleting it..."
gh api -X DELETE repos/${{ github.repository }}/git/refs/tags/${RELEASE_TAG} || true
fi
sleep 2
gh release create "${RELEASE_TAG}" \
--title "PHP ${VERSION}" \
--notes "Release of PHP version ${VERSION}" \
--repo ${{ github.repository }}
php:
needs: [generate-matrix]
runs-on: windows-2022
strategy:
matrix: ${{ fromJson(needs.generate-matrix.outputs.matrix) }}
steps:
- name: Checkout
uses: actions/checkout@v5
- name: Build
uses: ./php
with:
php-version: ${{ matrix.php-version }}
arch: ${{ matrix.arch }}
ts: ${{ matrix.ts }}
env:
PHP_BUILD_PROVIDER: "The PHP Group"
process-artifacts:
if: ${{ inputs.do-release == 'true' }} # NEW
runs-on: windows-2022
needs: [generate-matrix, php, create-releases]
strategy:
matrix:
php-version: ${{ fromJson(needs.generate-matrix.outputs.php-versions) }}
steps:
- name: Process and upload artifacts for PHP ${{ matrix.php-version }}
shell: pwsh
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
$phpVersion = "${{ matrix.php-version }}"
$releaseTag = "php-${phpVersion}"
$errorOccurred = $false
Write-Host "Processing artifacts for PHP version: ${phpVersion}"
Write-Host "Release tag: ${releaseTag}"
try {
$extractDir = "all_files"
New-Item -ItemType Directory -Force -Path $extractDir | Out-Null
Write-Host "Getting artifacts list..."
$artifactsJson = gh api repos/${{ github.repository }}/actions/runs/${{ github.run_id }}/artifacts
$artifacts = $artifactsJson | ConvertFrom-Json
Write-Host "Available artifacts:"
$artifacts.artifacts | ForEach-Object {
Write-Host "- $($_.name)"
}
$versionArtifacts = $artifacts.artifacts | Where-Object {
$_.name -like "artifacts-${phpVersion}-*"
}
if ($versionArtifacts.Count -eq 0) {
Write-Host "No artifacts found for PHP version ${phpVersion}. Skipping..."
exit 0
}
Write-Host "Found $($versionArtifacts.Count) artifacts for PHP ${phpVersion}"
foreach ($artifact in $versionArtifacts) {
Write-Host "Processing artifact: $($artifact.name)"
$headers = @{
"Authorization" = "Bearer ${{ secrets.GITHUB_TOKEN }}"
"Accept" = "application/vnd.github+json"
"X-GitHub-Api-Version" = "2022-11-28"
}
$downloadUrl = "https://api.github.com/repos/${{ github.repository }}/actions/artifacts/$($artifact.id)/zip"
$zipFileName = "$($artifact.name).zip"
Write-Host "Downloading from: ${downloadUrl}"
Invoke-WebRequest -Uri $downloadUrl -Headers $headers -OutFile $zipFileName
Write-Host "Extracting ${zipFileName}..."
Expand-Archive -Path $zipFileName -DestinationPath $extractDir -Force
Remove-Item $zipFileName -Force
}
$allFiles = Get-ChildItem -Path $extractDir -Filter "*.zip" | Where-Object {
$_.Name -like "php-*" -and $_.Name -like "*${phpVersion}*"
}
if ($allFiles.Count -eq 0) {
Write-Host "No PHP files found for version ${phpVersion}"
exit 0
}
Write-Host "Found $($allFiles.Count) PHP files for version ${phpVersion}:"
$allFiles | ForEach-Object { Write-Host "- $($_.Name)" }
Write-Host "Renaming files..."
$renamedFiles = @()
foreach ($file in $allFiles) {
$originalName = $file.Name
$newName = $originalName
$newName = $newName -replace '-SSE4\.2', ''
$newName = $newName.ToLower()
$newName = $newName -replace '-win32-', '-Win32-'
$newPath = Join-Path $extractDir $newName
if ($originalName -ne $newName) {
Rename-Item -Path $file.FullName -NewName $newName
Write-Host "Renamed: ${originalName} -> ${newName}"
} else {
Write-Host "No rename needed: ${originalName}"
}
$renamedFiles += Get-Item $newPath
}
Write-Host "Uploading $($renamedFiles.Count) files to release ${releaseTag}..."
foreach ($file in $renamedFiles) {
Write-Host "Uploading: $($file.Name)"
$maxRetries = 3
$retryCount = 0
$uploaded = $false
while (-not $uploaded -and $retryCount -lt $maxRetries) {
try {
gh release upload $releaseTag $file.FullName --repo ${{ github.repository }} --clobber
Write-Host "Successfully uploaded: $($file.Name)"
$uploaded = $true
}
catch {
$retryCount++
Write-Host "Upload attempt ${retryCount} failed for $($file.Name): $($_.Exception.Message)"
if ($retryCount -lt $maxRetries) {
Write-Host "Retrying in 5 seconds..."
Start-Sleep -Seconds 5
}
}
}
if (-not $uploaded) {
Write-Host "Failed to upload $($file.Name) after ${maxRetries} attempts"
throw "Failed to upload $($file.Name)"
}
}
Write-Host "All files uploaded successfully to release ${releaseTag}"
}
catch {
Write-Host "Error occurred: $($_.Exception.Message)"
Write-Host "Error details: $_"
$errorOccurred = $true
}
if ($errorOccurred) {
Write-Host "Error occurred, cleaning up release ${releaseTag}..."
try {
gh release delete $releaseTag -R ${{ github.repository }} --yes --cleanup-tag
Write-Host "Release ${releaseTag} deleted due to error"
}
catch {
Write-Host "Failed to delete release ${releaseTag}: $($_.Exception.Message)"
}
exit 1
}
Write-Host "Process completed successfully for PHP ${phpVersion}"