Windows Release #14
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Windows Release | |
| on: | |
| workflow_dispatch: | |
| # used when called manually. | |
| workflow_run: | |
| workflows: ["Tests"] | |
| types: [completed] | |
| permissions: | |
| contents: write # For creating releases and uploading assets | |
| actions: read # For downloading artifacts from build job | |
| jobs: | |
| # Check if this workflow should run (only on successful test runs triggered by version tags) | |
| check-trigger: | |
| runs-on: ubuntu-latest | |
| if: github.event.workflow_run.conclusion == 'success' || github.event_name == 'workflow_dispatch' | |
| outputs: | |
| should_run: ${{ steps.check.outputs.should_run }} | |
| tag_name: ${{ steps.check.outputs.tag_name }} | |
| steps: | |
| - name: Debug workflow_run event | |
| run: | | |
| echo "Event name: ${{ github.event.workflow_run.event }}" | |
| echo "Head branch: ${{ github.event.workflow_run.head_branch }}" | |
| echo "Head SHA: ${{ github.event.workflow_run.head_sha }}" | |
| echo "Conclusion: ${{ github.event.workflow_run.conclusion }}" | |
| - name: Check if triggered by version tag | |
| id: check | |
| run: | | |
| # The head_branch contains the tag name directly (e.g., "0.0.1"), not "refs/tags/0.0.1" | |
| # when the workflow is triggered by a tag push | |
| HEAD_BRANCH="${{ github.event.workflow_run.head_branch }}" | |
| EVENT_TYPE="${{ github.event.workflow_run.event }}" | |
| echo "Event type: ${EVENT_TYPE}" | |
| echo "Head branch: ${HEAD_BRANCH}" | |
| # Check if this was triggered by a push event and the branch name looks like a version tag | |
| if [[ "${EVENT_TYPE}" == "push" ]] && [[ "${HEAD_BRANCH}" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then | |
| echo "Valid version tag detected: ${HEAD_BRANCH}" | |
| echo "should_run=true" >> $GITHUB_OUTPUT | |
| echo "tag_name=${HEAD_BRANCH}" >> $GITHUB_OUTPUT | |
| else | |
| echo "Not a valid version tag push. Event: ${EVENT_TYPE}, Branch: ${HEAD_BRANCH}" | |
| echo "should_run=false" >> $GITHUB_OUTPUT | |
| fi | |
| get-extension-matrix: | |
| runs-on: ubuntu-latest | |
| needs: check-trigger | |
| if: needs.check-trigger.outputs.should_run == 'true' | |
| outputs: | |
| matrix: ${{ steps.extension-matrix.outputs.matrix }} | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ needs.check-trigger.outputs.tag_name }} | |
| - name: Debug - Show composer.json | |
| run: | | |
| echo "=== composer.json contents ===" | |
| cat composer.json | |
| echo "" | |
| echo "=== PHP version requirement ===" | |
| grep -A 1 '"require"' composer.json | |
| - name: Generate extension build matrix | |
| id: extension-matrix | |
| uses: php/php-windows-builder/extension-matrix@v1 | |
| with: | |
| arch-list: 'x64' | |
| php-version-list: "8.1, 8.2, 8.3, 8.4" # reading from composer.json doesn't seem to work? | |
| build: | |
| runs-on: windows-2022 | |
| needs: [check-trigger, get-extension-matrix] | |
| strategy: | |
| fail-fast: false | |
| matrix: ${{ fromJson(needs.get-extension-matrix.outputs.matrix) }} | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ needs.check-trigger.outputs.tag_name }} | |
| - name: Map PHP architecture to library architecture | |
| id: map-arch | |
| shell: pwsh | |
| run: | | |
| $phpArch = "${{ matrix.arch }}" | |
| $libArch = switch ($phpArch) { | |
| "x64" { "x86_64" } | |
| default { "x86_64" } | |
| } | |
| echo "lib_arch=$libArch" >> $env:GITHUB_OUTPUT | |
| echo "Mapped PHP arch '$phpArch' to library arch '$libArch'" | |
| - name: Download crc_fast Windows library release | |
| shell: pwsh | |
| run: | | |
| $libArch = "${{ steps.map-arch.outputs.lib_arch }}" | |
| # Get the latest release information from GitHub API | |
| $releaseUrl = "https://api.github.com/repos/awesomized/crc-fast-rust/releases/latest" | |
| $release = Invoke-RestMethod -Uri $releaseUrl -Headers @{ | |
| "Accept" = "application/vnd.github+json" | |
| "User-Agent" = "GitHub-Actions" | |
| } | |
| $version = $release.tag_name | |
| echo "Latest crc_fast library version: $version" | |
| # Find the Windows artifact for the target architecture | |
| $artifactName = "crc-fast-$version-windows-$libArch.zip" | |
| $asset = $release.assets | Where-Object { $_.name -eq $artifactName } | |
| if (-not $asset) { | |
| echo "ERROR: Could not find artifact '$artifactName' in release $version" | |
| echo "Available assets:" | |
| $release.assets | ForEach-Object { echo " - $($_.name)" } | |
| exit 1 | |
| } | |
| $downloadUrl = $asset.browser_download_url | |
| echo "Downloading from: $downloadUrl" | |
| # Download the artifact | |
| $outputPath = "crc_fast_lib.zip" | |
| Invoke-WebRequest -Uri $downloadUrl -OutFile $outputPath -Headers @{ | |
| "Accept" = "application/octet-stream" | |
| "User-Agent" = "GitHub-Actions" | |
| } | |
| if (-not (Test-Path $outputPath)) { | |
| echo "ERROR: Failed to download crc_fast library" | |
| exit 1 | |
| } | |
| echo "Successfully downloaded crc_fast library ($([math]::Round((Get-Item $outputPath).Length / 1MB, 2)) MB)" | |
| - name: Extract crc_fast library files | |
| shell: pwsh | |
| run: | | |
| $extractPath = "C:\crc_fast" | |
| $tempExtractPath = "C:\crc_fast_temp" | |
| # Create temporary extraction directory | |
| New-Item -ItemType Directory -Force -Path $tempExtractPath | Out-Null | |
| # Extract the zip file to temp location | |
| echo "Extracting crc_fast library to temporary location" | |
| Expand-Archive -Path "crc_fast_lib.zip" -DestinationPath $tempExtractPath -Force | |
| # Find the versioned subdirectory (e.g., crc-fast-1.7.0-windows-x86_64) | |
| $dirs = Get-ChildItem -Path $tempExtractPath -Directory | |
| if ($dirs.Count -eq 0) { | |
| echo "ERROR: No subdirectory found after extraction" | |
| exit 1 | |
| } elseif ($dirs.Count -gt 1) { | |
| echo "ERROR: Multiple subdirectories found after extraction. Expected only one." | |
| $dirs | ForEach-Object { echo " $($_.FullName)" } | |
| exit 1 | |
| } | |
| $versionedDir = $dirs[0] | |
| echo "Found versioned directory: $($versionedDir.Name)" | |
| # Move contents from versioned directory to final location | |
| New-Item -ItemType Directory -Force -Path $extractPath | Out-Null | |
| Move-Item -Path "$($versionedDir.FullName)\*" -Destination $extractPath -Force | |
| # Clean up temp directory | |
| Remove-Item -Recurse -Force $tempExtractPath | |
| # List extracted contents for debugging | |
| echo "Final directory structure:" | |
| Get-ChildItem -Recurse $extractPath | ForEach-Object { echo " $($_.FullName)" } | |
| - name: Verify required library files | |
| shell: pwsh | |
| run: | | |
| $extractPath = "C:\crc_fast" | |
| $requiredFiles = @( | |
| "include\libcrc_fast.h", | |
| "lib\crc_fast.lib" | |
| ) | |
| $missingFiles = @() | |
| foreach ($file in $requiredFiles) { | |
| $fullPath = Join-Path $extractPath $file | |
| if (-not (Test-Path $fullPath)) { | |
| $missingFiles += $file | |
| echo "MISSING: $file" | |
| } else { | |
| echo "FOUND: $file" | |
| } | |
| } | |
| if ($missingFiles.Count -gt 0) { | |
| echo "" | |
| echo "ERROR: Required library files not found after extraction:" | |
| $missingFiles | ForEach-Object { echo " - $_" } | |
| echo "" | |
| echo "Directory structure:" | |
| Get-ChildItem -Recurse $extractPath | ForEach-Object { echo " $($_.FullName)" } | |
| exit 1 | |
| } | |
| echo "" | |
| echo "All required library files verified successfully" | |
| - name: Build extension with php-windows-builder | |
| uses: php/php-windows-builder/extension@v1 | |
| with: | |
| php-version: ${{ matrix.php-version }} | |
| arch: ${{ matrix.arch }} | |
| ts: ${{ matrix.ts }} | |
| args: --with-crc-fast=C:\crc_fast | |
| release: | |
| runs-on: ubuntu-latest | |
| needs: [check-trigger, build] | |
| if: needs.check-trigger.outputs.should_run == 'true' | |
| steps: | |
| - name: Create draft release with artifacts | |
| uses: php/php-windows-builder/release@v1 | |
| with: | |
| release: ${{ needs.check-trigger.outputs.tag_name }} | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| draft: true |