Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 48 additions & 29 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,35 +14,54 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4 # not pinning to commit since this is a GitHub action, which we trust
- name: Checkout crc_fast library
uses: actions/checkout@v4 # not pinning to commit since this is a GitHub action, which we trust
with:
repository: awesomized/crc-fast-rust
path: lib-crc-fast
- id: cache-cargo
name: Cache Rust Cargo toolchain
uses: actions/cache@v4 # not pinning to commit since this is a GitHub action, which we trust
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}-release
- if: ${{ steps.cache-cargo.outputs.cache-hit != 'true' }}
name: Install Rust toolchain
uses: actions-rs/toolchain@v1 # not pinning to commit since this is an archived GitHub action, which we trust
with:
profile: minimal
toolchain: stable
override: true
- name: Build crc_fast library
run: cd lib-crc-fast && cargo build --release
- name: Copy shared library
run: mkdir lib && cp lib-crc-fast/target/release/libcrc_fast.so lib/
- name: Copy C/C++ header
run: mkdir include && cp lib-crc-fast/libcrc_fast.h include/
- name: Download crc_fast library release
run: |
ARCH="x86_64"
PLATFORM="linux"

# Fetch the latest release version
echo "Fetching latest crc_fast library release..."
LATEST_RELEASE=$(curl -sL https://api.github.com/repos/awesomized/crc-fast-rust/releases/latest | jq -r .tag_name)

if [ -z "$LATEST_RELEASE" ]; then
echo "Error: Failed to fetch latest release version"
exit 1
fi

echo "Latest release: ${LATEST_RELEASE}"

ARTIFACT_NAME="crc-fast-${LATEST_RELEASE}-${PLATFORM}-${ARCH}.tar.gz"
DOWNLOAD_URL="https://github.com/awesomized/crc-fast-rust/releases/download/${LATEST_RELEASE}/${ARTIFACT_NAME}"

echo "Downloading crc_fast library ${LATEST_RELEASE} for ${PLATFORM}-${ARCH}"
curl -sL -o crc-fast.tar.gz "${DOWNLOAD_URL}" || {
echo "Error: Failed to download crc_fast library release ${LATEST_RELEASE} from ${DOWNLOAD_URL}"
exit 1
}

# Save version for next step
echo "CRC_FAST_VERSION=${LATEST_RELEASE}" >> $GITHUB_ENV
- name: Extract crc_fast library
run: |
tar -xzf crc-fast.tar.gz
EXTRACT_DIR="crc-fast-${CRC_FAST_VERSION}-linux-x86_64"

# Verify required files exist
if [ ! -f "${EXTRACT_DIR}/include/libcrc_fast.h" ]; then
echo "Error: Required header file not found: ${EXTRACT_DIR}/include/libcrc_fast.h"
exit 1
fi
if [ ! -f "${EXTRACT_DIR}/lib/libcrc_fast.so" ]; then
echo "Error: Required library file not found: ${EXTRACT_DIR}/lib/libcrc_fast.so"
exit 1
fi

# Copy files to expected locations
mkdir -p lib include
cp "${EXTRACT_DIR}/lib/libcrc_fast.so" lib/
cp "${EXTRACT_DIR}/include/libcrc_fast.h" include/

echo "Successfully extracted crc_fast library ${CRC_FAST_VERSION}"
- name: Phpize
run: phpize
- name: Configure
Expand Down
264 changes: 264 additions & 0 deletions .github/workflows/windows-release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,264 @@
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 }}"
echo "Full event context:"
echo '${{ toJson(github.event.workflow_run) }}'

- 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, arm64'
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 }}"

# Check if architecture is supported
if ($phpArch -eq "x86") {
echo "ERROR: 32-bit x86 builds are not supported"
echo "The crc_fast library does not provide 32-bit Windows releases"
echo "Supported architectures: x64, arm64"
exit 1
}

$libArch = switch ($phpArch) {
"x64" { "x86_64" }
"arm64" { "aarch64" }
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

- name: Upload DLL artifact
uses: actions/upload-artifact@v4
with:
name: php_crc_fast-${{ matrix.php-version }}-${{ matrix.arch }}-${{ matrix.ts }}
path: |
${{ matrix.arch }}/${{ matrix.ts == 'ts' && 'Release_TS' || 'Release' }}/php_crc_fast.dll
if-no-files-found: error

release:
runs-on: ubuntu-latest
needs: [check-trigger, build]
if: needs.check-trigger.outputs.should_run == 'true'
steps:
- name: Download all DLL artifacts
uses: actions/download-artifact@v4
with:
path: artifacts
pattern: php_crc_fast-*
merge-multiple: false

- name: Create draft release with DLL uploads
uses: php/php-windows-builder/release@v1
with:
release: ${{ needs.check-trigger.outputs.tag_name }}
token: ${{ secrets.GITHUB_TOKEN }}
draft: true
artifacts: artifacts/**/*.dll
Loading
Loading