1010
1111jobs :
1212 test :
13- runs-on : ubuntu-latest
13+ name : Test (${{ matrix.os }}, ${{ matrix.php-version }}, ${{ matrix.ts }})
14+ runs-on : ${{ matrix.os }}
15+ strategy :
16+ fail-fast : false
17+ matrix :
18+ os : [ubuntu-22.04, ubuntu-22.04-arm, macos-14, windows-2022]
19+ php-version : ['8.1', '8.2', '8.3', '8.4']
20+ ts : [ts, nts]
1421 steps :
1522 - name : Checkout
1623 uses : actions/checkout@v4 # not pinning to commit since this is a GitHub action, which we trust
17- - name : Download crc_fast library release
24+
25+ - name : Set platform and architecture (Unix)
26+ if : runner.os != 'Windows'
27+ shell : bash
28+ run : |
29+ case "${{ matrix.os }}" in
30+ ubuntu-22.04)
31+ echo "PLATFORM=linux" >> $GITHUB_ENV
32+ echo "ARCH=x86_64" >> $GITHUB_ENV
33+ ;;
34+ ubuntu-22.04-arm)
35+ echo "PLATFORM=linux" >> $GITHUB_ENV
36+ echo "ARCH=aarch64" >> $GITHUB_ENV
37+ ;;
38+ macos-14)
39+ echo "PLATFORM=macos" >> $GITHUB_ENV
40+ echo "ARCH=aarch64" >> $GITHUB_ENV
41+ ;;
42+ esac
43+ echo "Platform: $PLATFORM, Architecture: $ARCH"
44+
45+ - name : Set platform and architecture (Windows)
46+ if : runner.os == 'Windows'
47+ shell : pwsh
48+ run : |
49+ switch ("${{ matrix.os }}") {
50+ "windows-2022" {
51+ echo "PLATFORM=windows" >> $env:GITHUB_ENV
52+ echo "ARCH=x86_64" >> $env:GITHUB_ENV
53+ }
54+ }
55+ Write-Host "Platform: $env:PLATFORM, Architecture: $env:ARCH"
56+
57+ - name : Download crc_fast library release (Unix)
58+ if : runner.os != 'Windows'
59+ shell : bash
1860 run : |
19- ARCH="x86_64"
20- PLATFORM="linux"
21-
2261 # Fetch the latest release version
2362 echo "Fetching latest crc_fast library release..."
24- LATEST_RELEASE=$(curl -sL https://api.github.com/repos/awesomized/crc-fast-rust/releases/latest | jq -r .tag_name)
63+ LATEST_RELEASE=$(curl -sL -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" https://api.github.com/repos/awesomized/crc-fast-rust/releases/latest | jq -r .tag_name)
2564
2665 if [ -z "$LATEST_RELEASE" ]; then
2766 echo "Error: Failed to fetch latest release version"
@@ -34,39 +73,180 @@ jobs:
3473 DOWNLOAD_URL="https://github.com/awesomized/crc-fast-rust/releases/download/${LATEST_RELEASE}/${ARTIFACT_NAME}"
3574
3675 echo "Downloading crc_fast library ${LATEST_RELEASE} for ${PLATFORM}-${ARCH}"
37- curl -sL -o crc-fast.tar.gz "${DOWNLOAD_URL}" || {
76+ curl -sL -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" - o crc-fast.tar.gz "${DOWNLOAD_URL}" || {
3877 echo "Error: Failed to download crc_fast library release ${LATEST_RELEASE} from ${DOWNLOAD_URL}"
3978 exit 1
4079 }
4180
4281 # Save version for next step
4382 echo "CRC_FAST_VERSION=${LATEST_RELEASE}" >> $GITHUB_ENV
44- - name : Extract crc_fast library
83+
84+ - name : Download crc_fast library release (Windows)
85+ if : runner.os == 'Windows'
86+ shell : pwsh
87+ run : |
88+ # Get the latest release information from GitHub API
89+ Write-Host "Fetching latest crc_fast library release..."
90+ $releaseUrl = "https://api.github.com/repos/awesomized/crc-fast-rust/releases/latest"
91+ $release = Invoke-RestMethod -Uri $releaseUrl -Headers @{
92+ "Accept" = "application/vnd.github+json"
93+ "User-Agent" = "GitHub-Actions"
94+ "Authorization" = "Bearer ${{ secrets.GITHUB_TOKEN }}"
95+ }
96+
97+ $version = $release.tag_name
98+
99+ if ([string]::IsNullOrEmpty($version)) {
100+ Write-Error "Error: Failed to fetch latest release version"
101+ exit 1
102+ }
103+
104+ Write-Host "Latest crc_fast library version: $version"
105+
106+ # Find the Windows artifact for the target architecture
107+ $artifactName = "crc-fast-$version-$env:PLATFORM-$env:ARCH.zip"
108+ $asset = $release.assets | Where-Object { $_.name -eq $artifactName }
109+
110+ if (-not $asset) {
111+ Write-Error "ERROR: Could not find artifact '$artifactName' in release $version"
112+ Write-Host "Available assets:"
113+ $release.assets | ForEach-Object { Write-Host " - $($_.name)" }
114+ exit 1
115+ }
116+
117+ $downloadUrl = $asset.browser_download_url
118+ Write-Host "Downloading from: $downloadUrl"
119+
120+ # Download the artifact
121+ $outputPath = "crc_fast_lib.zip"
122+ Invoke-WebRequest -Uri $downloadUrl -OutFile $outputPath -Headers @{
123+ "Accept" = "application/octet-stream"
124+ "User-Agent" = "GitHub-Actions"
125+ "Authorization" = "Bearer ${{ secrets.GITHUB_TOKEN }}"
126+ }
127+
128+ if (-not (Test-Path $outputPath)) {
129+ Write-Error "ERROR: Failed to download crc_fast library"
130+ exit 1
131+ }
132+
133+ Write-Host "Successfully downloaded crc_fast library ($([math]::Round((Get-Item $outputPath).Length / 1MB, 2)) MB)"
134+
135+ # Save version for next step
136+ echo "CRC_FAST_VERSION=$version" >> $env:GITHUB_ENV
137+
138+ - name : Extract crc_fast library (Unix)
139+ if : runner.os != 'Windows'
140+ shell : bash
45141 run : |
46142 tar -xzf crc-fast.tar.gz
47- EXTRACT_DIR="crc-fast-${CRC_FAST_VERSION}-linux-x86_64 "
143+ EXTRACT_DIR="crc-fast-${CRC_FAST_VERSION}-${PLATFORM}-${ARCH} "
48144
49- # Verify required files exist
145+ # Verify required header file exists
50146 if [ ! -f "${EXTRACT_DIR}/include/libcrc_fast.h" ]; then
51147 echo "Error: Required header file not found: ${EXTRACT_DIR}/include/libcrc_fast.h"
52148 exit 1
53149 fi
54- if [ ! -f "${EXTRACT_DIR}/lib/libcrc_fast.so" ]; then
55- echo "Error: Required library file not found: ${EXTRACT_DIR}/lib/libcrc_fast.so"
150+
151+ # Verify required library file exists (handle both .so for Linux and .dylib for macOS)
152+ if [ -f "${EXTRACT_DIR}/lib/libcrc_fast.so" ]; then
153+ LIB_FILE="${EXTRACT_DIR}/lib/libcrc_fast.so"
154+ elif [ -f "${EXTRACT_DIR}/lib/libcrc_fast.dylib" ]; then
155+ LIB_FILE="${EXTRACT_DIR}/lib/libcrc_fast.dylib"
156+ else
157+ echo "Error: Required library file not found: ${EXTRACT_DIR}/lib/libcrc_fast.so or ${EXTRACT_DIR}/lib/libcrc_fast.dylib"
56158 exit 1
57159 fi
58160
59161 # Copy files to expected locations
60162 mkdir -p lib include
61- cp "${EXTRACT_DIR}/lib/libcrc_fast.so " lib/
163+ cp "${LIB_FILE} " lib/
62164 cp "${EXTRACT_DIR}/include/libcrc_fast.h" include/
63165
64166 echo "Successfully extracted crc_fast library ${CRC_FAST_VERSION}"
167+
168+ - name : Extract crc_fast library (Windows)
169+ if : runner.os == 'Windows'
170+ shell : pwsh
171+ run : |
172+ $extractPath = "C:\crc_fast"
173+ $tempExtractPath = "C:\crc_fast_temp"
174+
175+ # Create temporary extraction directory
176+ New-Item -ItemType Directory -Force -Path $tempExtractPath | Out-Null
177+
178+ # Extract the zip file to temp location
179+ Write-Host "Extracting crc_fast library to temporary location"
180+ Expand-Archive -Path "crc_fast_lib.zip" -DestinationPath $tempExtractPath -Force
181+
182+ # Find the versioned subdirectory (e.g., crc-fast-1.7.0-windows-x86_64)
183+ $dirs = Get-ChildItem -Path $tempExtractPath -Directory
184+
185+ if ($dirs.Count -eq 0) {
186+ Write-Error "ERROR: No subdirectory found after extraction"
187+ exit 1
188+ } elseif ($dirs.Count -gt 1) {
189+ Write-Error "ERROR: Multiple subdirectories found after extraction. Expected only one."
190+ $dirs | ForEach-Object { Write-Host " $($_.FullName)" }
191+ exit 1
192+ }
193+
194+ $versionedDir = $dirs[0]
195+ Write-Host "Found versioned directory: $($versionedDir.Name)"
196+
197+ # Move contents from versioned directory to final location
198+ New-Item -ItemType Directory -Force -Path $extractPath | Out-Null
199+ Move-Item -Path "$($versionedDir.FullName)\*" -Destination $extractPath -Force
200+
201+ # Clean up temp directory
202+ Remove-Item -Recurse -Force $tempExtractPath
203+
204+ # Verify required header file exists
205+ if (-not (Test-Path "$extractPath\include\libcrc_fast.h")) {
206+ Write-Error "Error: Required header file not found: $extractPath\include\libcrc_fast.h"
207+ exit 1
208+ }
209+
210+ # Verify required library file exists
211+ if (-not (Test-Path "$extractPath\lib\crc_fast.lib")) {
212+ Write-Error "Error: Required library file not found: $extractPath\lib\crc_fast.lib"
213+ exit 1
214+ }
215+
216+ Write-Host "Successfully extracted crc_fast library $env:CRC_FAST_VERSION"
217+
218+ - name : Setup PHP (Unix)
219+ if : runner.os != 'Windows'
220+ uses : shivammathur/setup-php@v2
221+ with :
222+ php-version : ${{ matrix.php-version }}
223+ extensions : none
224+ tools : phpize, php-config
225+ ini-values : |
226+ zend.assertions=-1
227+ thread_safety=${{ matrix.ts == 'ts' && 'On' || 'Off' }}
228+
65229 - name : Phpize
230+ if : runner.os != 'Windows'
66231 run : phpize
232+
67233 - name : Configure
234+ if : runner.os != 'Windows'
68235 run : ./configure --with-crc-fast=.
236+
69237 - name : Make
238+ if : runner.os != 'Windows'
70239 run : make
71- - name : Test
72- run : make test
240+
241+ - name : Test (Unix)
242+ if : runner.os != 'Windows'
243+ run : NO_INTERACTION=1 make test
244+
245+ - name : Build and Test (Windows)
246+ if : runner.os == 'Windows'
247+ uses : php/php-windows-builder/extension@v1
248+ with :
249+ php-version : ${{ matrix.php-version }}
250+ arch : x64
251+ ts : ${{ matrix.ts }}
252+ args : --with-crc-fast=C:\crc_fast
0 commit comments