Skip to content

Build Self-Hosted PHP Binary (common) #21

Build Self-Hosted PHP Binary (common)

Build Self-Hosted PHP Binary (common) #21

name: Build Self-Hosted PHP Binary (common)
on:
workflow_dispatch:
inputs:
add_extensions:
description: extensions to add (comma start if add)
type: string
default: ''
without_deploy:
type: boolean
default: false
jobs:
build-release-artifacts:
name: "Build ${{ matrix.php-version }} on ${{ matrix.operating-system }}"
runs-on: ${{ matrix.operating-system }}
strategy:
matrix:
php-version:
- "8.0"
- "8.1"
- "8.2"
- "8.3"
operating-system:
- "ubuntu-latest"
- "macos-latest"
- "debian-arm64-self-hosted"
- "macos-arm64-self-hosted"
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,phar,posix,redis,session,simplexml,soap,sockets,sqlite3,tokenizer,xmlwriter,xmlreader,zlib,zip
steps:
- name: "Checkout"
uses: "actions/checkout@v4"
- name: OS type
id: os-type
run: |
OS=""
if [ "${{ matrix.operating-system }}" = "ubuntu-latest" ]; then
OS="linux-x86_64"
elif [ "${{ matrix.operating-system }}" = "macos-latest" ]; then
OS="macos-x86_64"
elif [ "${{ matrix.operating-system }}" = "debian-arm64-self-hosted" ]; then
OS="linux-aarch64"
elif [ "${{ matrix.operating-system }}" = "macos-arm64-self-hosted" ]; then
OS="macos-aarch64"
fi
echo "OS=$OS" >> $GITHUB_ENV
- name: Download SPC bin artifact for self-hosted runners
uses: dawidd6/action-download-artifact@v2
with:
repo: static-php/static-php-cli-hosted
branch: master
workflow: build-spc-release.yml
name: "spc-${{ env.OS }}"
- name: Validate SPC bin
run: |
chmod +x spc
./spc --version
- id: cache-download
uses: actions/cache@v3
with:
path: downloads
key: php-${{ matrix.php-version }}-dependencies-for-common-extensions
# If there's no dependencies cache, fetch sources
- if: steps.cache-download.outputs.cache-hit != 'true'
name: "Download sources"
env:
GITHUB_TOKEN: ${{ secrets.S_GITHUB_TOKEN }}
run: ./spc download --with-php=${{ matrix.php-version }} --for-extensions=${{ matrix.extensions }}${{ inputs.add_extensions }}
- name: "Build library: ${{ matrix.library }}"
run: |
SPC_USE_SUDO=yes ./spc doctor --auto-fix
./spc build --build-cli --build-micro --build-fpm ${{ matrix.extensions }}${{ inputs.add_extensions }} --debug
PHPVER=$(cat source/php-src/main/php_version.h | grep "PHP_VERSION " | awk -F\" '{print $2}')
mkdir dist/
tar -czf dist/php-$PHPVER-cli-$OS.tar.gz -C buildroot/bin/ php
tar -czf dist/php-$PHPVER-micro-$OS.tar.gz -C buildroot/bin/ micro.sfx
tar -czf dist/php-$PHPVER-fpm-$OS.tar.gz -C buildroot/bin/ php-fpm
if [ "${{ matrix.php-version }}" == "8.3" ] && [ "${{ matrix.operating-system }}" == "ubuntu-latest" ]; then
cp -r buildroot/license dist/
cp buildroot/build-extensions.json dist/
cp buildroot/build-libraries.json dist/
fi
- if: inputs.without_deploy != true
name: Deploy to Zhamao Server
uses: easingthemes/ssh-deploy@main
env:
SSH_PRIVATE_KEY: ${{ secrets.DEPLOY_SERVER_SECRET_KEY }}
ARGS: "-rltgoDzvO"
SOURCE: "dist/"
REMOTE_HOST: ${{ secrets.DEPLOY_SERVER_HOST }}
REMOTE_PORT: ${{ secrets.DEPLOY_SERVER_PORT }}
REMOTE_USER: ${{ secrets.DEPLOY_SERVER_USER }}
TARGET: ${{ secrets.DEPLOY_SERVER_TARGET }}
- name: "Upload Artifact"
uses: actions/upload-artifact@v3
with:
name: php-${{ matrix.php-version }}-${{ env.OS }}
path: |
buildroot/bin/php
buildroot/bin/php-fpm
buildroot/bin/micro.sfx
if-no-files-found: error