Skip to content

[v3] Build Self-Hosted PHP Binary (Unix) #1

[v3] Build Self-Hosted PHP Binary (Unix)

[v3] Build Self-Hosted PHP Binary (Unix) #1

name: "[v3] Build Self-Hosted PHP Binary (Unix)"
on:
workflow_dispatch:
schedule:
- cron: "0 1 */3 * *"
env:
GITHUB_TOKEN: ${{ secrets.S_GITHUB_TOKEN || secrets.GITHUB_TOKEN }}
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.2"
- "8.3"
- "8.4"
- "8.5"
runner:
- "ubuntu-latest"
- "macos-15-intel"
- "ubuntu-24.04-arm"
- "macos-15"
- "ubuntu-22.04"
- "ubuntu-22.04-arm"
combination:
- minimal
- bulk
- common
- gnu-bulk
exclude:
- { runner: "ubuntu-latest", combination: "gnu-bulk" }
- { runner: "ubuntu-24.04-arm", combination: "gnu-bulk" }
- { runner: "macos-15-intel", combination: "gnu-bulk" }
- { runner: "macos-15", combination: "gnu-bulk" }
- { runner: "ubuntu-22.04", combination: "minimal" }
- { runner: "ubuntu-22.04", combination: "bulk" }
- { runner: "ubuntu-22.04", combination: "common" }
- { runner: "ubuntu-22.04-arm", combination: "minimal" }
- { runner: "ubuntu-22.04-arm", combination: "bulk" }
- { runner: "ubuntu-22.04-arm", combination: "common" }
steps:
- name: "Process env string"
id: process-env
shell: bash
run: |
case "${{ matrix.combination }}" in
minimal)
echo "EXTENSIONS=iconv,pcntl,posix,mbstring,filter,tokenizer,phar" >> "$GITHUB_OUTPUT"
;;
common)
echo "EXTENSIONS=bcmath,bz2,calendar,ctype,curl,dom,exif,fileinfo,filter,ftp,gd,gmp,iconv,xml,mbstring,mbregex,mysqlnd,openssl,pcntl,pdo,pdo_mysql,pdo_sqlite,pdo_pgsql,pgsql,phar,posix,redis,session,simplexml,soap,sockets,sqlite3,tokenizer,xmlwriter,xmlreader,zlib,zip" >> "$GITHUB_OUTPUT"
echo "SUGGEST=--with-suggests" >> "$GITHUB_OUTPUT"
;;
bulk|gnu-bulk)
echo "EXTENSIONS=apcu,bcmath,bz2,calendar,ctype,curl,dba,dom,event,exif,fileinfo,filter,ftp,gd,gmp,iconv,imagick,imap,intl,mbregex,mbstring,mysqli,mysqlnd,opcache,openssl,opentelemetry,pcntl,pdo,pdo_mysql,pgsql,phar,posix,protobuf,readline,redis,session,shmop,simplexml,soap,sockets,sodium,sqlite3,swoole,swoole-hook-mysql,swoole-hook-pgsql,swoole-hook-sqlite,sysvmsg,sysvsem,sysvshm,tokenizer,xml,xmlreader,xmlwriter,xsl,zip,zlib" >> "$GITHUB_OUTPUT"
echo "SUGGEST=--with-suggests" >> "$GITHUB_OUTPUT"
;;
esac
echo "CMD=bin/spc" >> "$GITHUB_OUTPUT"
case "${{ matrix.runner }}" in
ubuntu-latest)
echo "OS=linux" >> "$GITHUB_OUTPUT"
echo "ARCH=x86_64" >> "$GITHUB_OUTPUT"
echo "UPX=--with-upx-pack" >> "$GITHUB_OUTPUT"
;;
ubuntu-24.04-arm)
echo "OS=linux" >> "$GITHUB_OUTPUT"
echo "ARCH=aarch64" >> "$GITHUB_OUTPUT"
echo "UPX=--with-upx-pack" >> "$GITHUB_OUTPUT"
;;
ubuntu-22.04)
echo "OS=linux" >> "$GITHUB_OUTPUT"
echo "ARCH=x86_64" >> "$GITHUB_OUTPUT"
echo "SPC_TARGET=native-native-gnu.2.17" >> "$GITHUB_OUTPUT"
;;
ubuntu-22.04-arm)
echo "OS=linux" >> "$GITHUB_OUTPUT"
echo "ARCH=aarch64" >> "$GITHUB_OUTPUT"
echo "SPC_TARGET=native-native-gnu.2.17" >> "$GITHUB_OUTPUT"
;;
macos-15-intel)
echo "OS=macos" >> "$GITHUB_OUTPUT"
echo "ARCH=x86_64" >> "$GITHUB_OUTPUT"
;;
macos-15)
echo "OS=macos" >> "$GITHUB_OUTPUT"
echo "ARCH=aarch64" >> "$GITHUB_OUTPUT"
;;
esac
- name: "Checkout current repository"
if: github.repository == 'crazywhalecc/static-php-cli'
uses: actions/checkout@v4
- name: "Checkout remote"
if: github.repository != 'crazywhalecc/static-php-cli'
uses: actions/checkout@v4
with:
repository: crazywhalecc/static-php-cli
ref: v3
- name: "Apply target env"
if: ${{ steps.process-env.outputs.SPC_TARGET != '' }}
shell: bash
run: echo "SPC_TARGET=${{ steps.process-env.outputs.SPC_TARGET }}" >> "$GITHUB_ENV"
- name: "Setup PHP"
uses: shivammathur/setup-php@v2
with:
php-version: 8.4
tools: pecl, composer
extensions: curl, openssl, mbstring, filter
ini-values: memory_limit=-1
- name: "Cache composer packages"
uses: actions/cache@v4
with:
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-php
- name: "Cache downloaded artifacts"
uses: actions/cache@v4
with:
path: downloads
key: v3-php-bin-${{ 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: "Run Build Tests (doctor)"
run: ${{ steps.process-env.outputs.CMD }} doctor --auto-fix
- name: "Install UPX"
if: ${{ steps.process-env.outputs.UPX != '' }}
run: ${{ steps.process-env.outputs.CMD }} install-pkg upx
- name: "Build PHP"
shell: bash
run: |
${{ steps.process-env.outputs.CMD }} build \
--build-cli \
--build-micro \
--build-fpm \
"${{ steps.process-env.outputs.EXTENSIONS }}" \
--debug \
${{ steps.process-env.outputs.UPX }} \
${{ steps.process-env.outputs.SUGGEST }} \
--dl-with-php="${{ matrix.php-version }}" \
--dl-retry=5 \
--dl-prefer-binary \
--dl-ignore-cache=php-src
- name: "Pack PHP"
shell: bash
run: |
mkdir -p tmp_dist dist
cp buildroot/bin/php tmp_dist/
cp buildroot/bin/micro.sfx tmp_dist/
cp buildroot/bin/php-fpm tmp_dist/
${{ steps.process-env.outputs.CMD }} dev:info php --json --no-ansi > php-info.json
PHPVER="$(php -r '$j = json_decode(file_get_contents("php-info.json"), true); echo $j["cache"]["source"]["info"]["version"] ?? "";')"
if [ -z "$PHPVER" ]; then
echo "Cannot resolve PHP version from dev:info php --json"
exit 1
fi
chmod -R 755 tmp_dist
sudo chmod -R 777 dist || true
tar -czf "dist/php-$PHPVER-cli-${{ steps.process-env.outputs.OS }}-${{ steps.process-env.outputs.ARCH }}.tar.gz" -C tmp_dist/ php
tar -czf "dist/php-$PHPVER-micro-${{ steps.process-env.outputs.OS }}-${{ steps.process-env.outputs.ARCH }}.tar.gz" -C tmp_dist/ micro.sfx
tar -czf "dist/php-$PHPVER-fpm-${{ steps.process-env.outputs.OS }}-${{ steps.process-env.outputs.ARCH }}.tar.gz" -C tmp_dist/ php-fpm
echo "PHPVER=$PHPVER" >> "$GITHUB_ENV"
ls -la dist
- name: "Add build metadata"
if: ${{ matrix.php-version == '8.4' && (matrix.runner == 'ubuntu-latest' || matrix.runner == 'ubuntu-22.04') }}
shell: bash
run: |
cp -r buildroot/license dist/
cp buildroot/build-manifest.json dist/
echo -e "# Note\n\nCurrent distribution uses extensions:\n\n${{ steps.process-env.outputs.EXTENSIONS }}\n\nUsing compile command:\n\n ${{ steps.process-env.outputs.CMD }} build --build-cli --build-micro --build-fpm \"${{ steps.process-env.outputs.EXTENSIONS }}\" --debug ${{ steps.process-env.outputs.UPX }} ${{ steps.process-env.outputs.SUGGEST }} --dl-with-php=\"${{ matrix.php-version }}\" --dl-retry=5 --dl-prefer-binary --dl-ignore-cache=php-src\n\nSPC_TARGET:\n\n ${SPC_TARGET:-default}" > dist/README.txt
- name: "Deploy to self-hosted OSS"
uses: static-php/upload-s3-action@v1.0.0
with:
aws_key_id: ${{ secrets.AWS_KEY_ID }}
aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws_bucket: ${{ secrets.AWS_BUCKET }}
source_dir: "dist/"
destination_dir: v3/php-bin/${{ matrix.combination }}/
endpoint: ${{ secrets.AWS_ENDPOINT }}
- name: "Upload Artifact"
uses: actions/upload-artifact@v4
with:
name: php-${{ env.PHPVER }}-${{ matrix.combination }}-${{ steps.process-env.outputs.OS }}-${{ steps.process-env.outputs.ARCH }}
path: |
tmp_dist/php
tmp_dist/php-fpm
tmp_dist/micro.sfx
if-no-files-found: error
- name: "Upload logs on failure"
if: ${{ failure() }}
uses: actions/upload-artifact@v4
with:
name: spc-logs-${{ matrix.php-version }}-${{ matrix.combination }}-${{ matrix.runner }}
path: log/*.log
if-no-files-found: ignore