Skip to content

Build PHP 8.3.26,8.4.13 #35

Build PHP 8.3.26,8.4.13

Build PHP 8.3.26,8.4.13 #35

Workflow file for this run

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@v4
- name: Build
uses: ./php
with:
php-version: ${{ matrix.php-version }}
arch: ${{ matrix.arch }}
ts: ${{ matrix.ts }}
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}"