Build Self-Hosted PHP Binary (Windows) #30
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: Build Self-Hosted PHP Binary (Windows) | |
on: | |
workflow_dispatch: | |
jobs: | |
build-release-artifacts: | |
name: "Build ${{ matrix.php-version }}-${{ matrix.combination }} on ${{ matrix.runner }}" | |
runs-on: ${{ matrix.runner }} | |
strategy: | |
fail-fast: false | |
matrix: | |
php-version: | |
- "8.0" | |
- "8.1" | |
- "8.2" | |
- "8.3" | |
runner: | |
- "windows-latest" | |
combination: | |
- spc-min | |
- spc-max | |
steps: | |
- name: "Process env string" | |
id: process-env | |
run: | | |
switch ("${{ matrix.combination }}") { | |
"spc-min" { | |
Add-Content -Path $env:GITHUB_OUTPUT -Value "EXTENSIONS=ctype,fileinfo,mbstring,tokenizer,phar" | |
Add-Content -Path $env:GITHUB_OUTPUT -Value "DEPLOY_TARGET=${{ secrets.DEPLOY_SERVER_TARGET_WINDOWS_SPC_MIN }}" | |
} | |
"spc-max" { | |
Add-Content -Path $env:GITHUB_OUTPUT -Value "EXTENSIONS=amqp,apcu,bcmath,bz2,calendar,ctype,curl,dba,dom,ds,exif,ffi,fileinfo,filter,ftp,gd,iconv,libxml,mbregex,mbstring,mysqli,mysqlnd,opcache,openssl,pdo,pdo_mysql,pdo_sqlite,pdo_sqlsrv,phar,rar,session,shmop,simdjson,simplexml,soap,sockets,sqlite3,sqlsrv,ssh2,swow,sysvshm,tokenizer,xml,xmlreader,xmlwriter,yac,yaml,zip,zlib" | |
Add-Content -Path $env:GITHUB_OUTPUT -Value "DEPLOY_TARGET=${{ secrets.DEPLOY_SERVER_TARGET_WINDOWS_SPC_MAX }}" | |
} | |
} | |
switch ("${{ matrix.runner }}") { | |
"windows-latest" { | |
Add-Content -Path $env:GITHUB_OUTPUT -Value "OS=windows" | |
Add-Content -Path $env:GITHUB_OUTPUT -Value "ARCH=x86_64" | |
Add-Content -Path $env:GITHUB_OUTPUT -Value "CMD=bin/spc" | |
} | |
} | |
- name: "Checkout remote" | |
if: github.repository != 'crazywhalecc/static-php-cli' | |
uses: actions/checkout@v4 | |
with: | |
repository: crazywhalecc/static-php-cli | |
ref: pre-built-libs | |
- name: "Setup PHP" | |
uses: shivammathur/setup-php@v2 | |
with: | |
php-version: 8.2 | |
tools: pecl, composer | |
extensions: curl, openssl, mbstring | |
ini-values: memory_limit=-1 | |
- name: "Cache composer packages" | |
id: composer-cache | |
uses: actions/cache@v4 | |
with: | |
path: vendor | |
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }} | |
restore-keys: | | |
${{ runner.os }}-php | |
# Cache downloaded source | |
- id: cache-download | |
uses: actions/cache@v4 | |
with: | |
path: downloads | |
key: pack-lib-dependencies-${{ matrix.combination }}-${{ matrix.php-version }}-${{ matrix.runner }} | |
- name: "Install Dependencies" | |
run: composer update -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist --no-dev | |
- name: "Validate SPC powershell script" | |
run: ${{ steps.process-env.outputs.CMD }} --version | |
- name: "Run Build Tests (doctor)" | |
run: ${{ steps.process-env.outputs.CMD }} doctor --auto-fix | |
# If there's no dependencies cache, fetch sources | |
- name: "Download sources" | |
env: | |
GITHUB_TOKEN: ${{ secrets.S_GITHUB_TOKEN }} | |
run: ${{ steps.process-env.outputs.CMD }} download --with-php=${{ matrix.php-version }} --for-extensions="${{ steps.process-env.outputs.EXTENSIONS }}" --retry=5 --prefer-pre-built | |
- name: "Build extensions: ${{ steps.process-env.outputs.EXTENSIONS }}" | |
run: | | |
${{ steps.process-env.outputs.CMD }} doctor --auto-fix | |
${{ steps.process-env.outputs.CMD }} install-pkg upx | |
${{ steps.process-env.outputs.CMD }} build --build-cli --build-micro "${{ steps.process-env.outputs.EXTENSIONS }}" --debug | |
$PHPVER = ${{ steps.process-env.outputs.CMD }} dev:php-ver | |
New-Item -ItemType Directory -Force -Path dist | |
Compress-Archive -Path "buildroot\bin\php.exe" -DestinationPath "dist\php-$PHPVER-cli-win.zip" | |
Compress-Archive -Path "buildroot\bin\micro.sfx" -DestinationPath "dist\php-$PHPVER-micro-win.zip" | |
ls dist | |
echo ("PHPVER=" + $PHPVER) >> $env:GITHUB_ENV | |
- name: "Deploy cli to Zhamao Server" | |
uses: garygrossgarten/github-action-scp@release | |
with: | |
local: "dist/php-${{ env.PHPVER }}-cli-win.zip" | |
remote: /usr/share/nginx/dl.static-php.dev/static-php-cli/windows/ | |
host: ${{ secrets.DEPLOY_SERVER_HOST }} | |
username: ${{ secrets.DEPLOY_SERVER_USER }} | |
privateKey: ${{ secrets.DEPLOY_SERVER_SECRET_KEY }} | |
- name: "Deploy cli to Zhamao Server" | |
uses: garygrossgarten/github-action-scp@release | |
with: | |
local: "dist/php-${{ env.PHPVER }}-micro-win.zip" | |
remote: /usr/share/nginx/dl.static-php.dev/static-php-cli/windows/ | |
host: ${{ secrets.DEPLOY_SERVER_HOST }} | |
username: ${{ secrets.DEPLOY_SERVER_USER }} | |
privateKey: ${{ secrets.DEPLOY_SERVER_SECRET_KEY }} | |
- name: "Upload Artifact" | |
uses: actions/upload-artifact@v4 | |
with: | |
name: php-${{ matrix.php-version }}-windows | |
path: | | |
buildroot/bin/php.exe | |
buildroot/bin/micro.sfx | |
if-no-files-found: error | |