CI on Unix #14
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: "CI on Unix" | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| os: | |
| required: true | |
| description: Build target OS | |
| default: 'linux-x86_64' | |
| type: choice | |
| options: | |
| - 'linux-x86_64' | |
| - 'linux-aarch64' | |
| - 'linux-x86_64-glibc' | |
| - 'linux-aarch64-glibc' | |
| - 'macos-x86_64' | |
| - 'macos-aarch64' | |
| php-version: | |
| required: true | |
| description: PHP version to compile | |
| default: '8.4' | |
| type: choice | |
| options: | |
| - '8.4' | |
| - '8.3' | |
| - '8.2' | |
| - '8.1' | |
| extensions: | |
| description: Extensions to build (comma separated) | |
| required: true | |
| type: string | |
| shared-extensions: | |
| description: Shared extensions to build (optional, comma separated) | |
| type: string | |
| extra-libs: | |
| description: Extra libraries to build (optional, comma separated) | |
| type: string | |
| build-cli: | |
| description: Build cli binary | |
| default: true | |
| type: boolean | |
| build-micro: | |
| description: Build phpmicro binary | |
| type: boolean | |
| build-fpm: | |
| description: Build fpm binary | |
| type: boolean | |
| build-frankenphp: | |
| description: Build frankenphp binary (requires ZTS) | |
| type: boolean | |
| default: false | |
| enable-zts: | |
| description: Enable ZTS | |
| type: boolean | |
| default: false | |
| prefer-pre-built: | |
| description: Prefer pre-built binaries (reduce build time) | |
| type: boolean | |
| default: true | |
| with-suggested-libs: | |
| description: Build with suggested libs | |
| type: boolean | |
| default: false | |
| debug: | |
| description: Show full build logs | |
| type: boolean | |
| no-strip: | |
| description: Keep debug symbols for debugging | |
| type: boolean | |
| default: false | |
| workflow_call: | |
| inputs: | |
| os: | |
| required: true | |
| description: Build target OS | |
| default: 'linux-x86_64' | |
| type: string | |
| php-version: | |
| required: true | |
| description: PHP version to compile | |
| default: '8.4' | |
| type: string | |
| extensions: | |
| description: Extensions to build (comma separated) | |
| required: true | |
| type: string | |
| shared-extensions: | |
| description: Shared extensions to build (optional, comma separated) | |
| type: string | |
| extra-libs: | |
| description: Extra libraries to build (optional, comma separated) | |
| type: string | |
| build-cli: | |
| description: Build cli binary | |
| default: true | |
| type: boolean | |
| build-micro: | |
| description: Build phpmicro binary | |
| type: boolean | |
| build-fpm: | |
| description: Build fpm binary | |
| type: boolean | |
| build-frankenphp: | |
| description: Build frankenphp binary (requires ZTS) | |
| type: boolean | |
| default: false | |
| enable-zts: | |
| description: Enable ZTS | |
| type: boolean | |
| default: false | |
| prefer-pre-built: | |
| description: Prefer pre-built binaries (reduce build time) | |
| type: boolean | |
| default: true | |
| with-suggested-libs: | |
| description: Include suggested libs | |
| type: boolean | |
| default: false | |
| debug: | |
| description: Show full build logs | |
| type: boolean | |
| no-strip: | |
| description: Keep debug symbols for debugging | |
| type: boolean | |
| default: false | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| jobs: | |
| define-build: | |
| name: "Define Build Scripts" | |
| runs-on: ubuntu-latest | |
| outputs: | |
| run: ${{ steps.gendef.outputs.run }} | |
| download: ${{ steps.gendef.outputs.download }} | |
| build: ${{ steps.gendef.outputs.build }} | |
| steps: | |
| - name: "Checkout" | |
| uses: actions/checkout@v4 | |
| - name: "Define" | |
| id: gendef | |
| run: | | |
| case "${{ inputs.os }}" in | |
| linux-x86_64) | |
| DOWN_CMD="./bin/spc-alpine-docker download" | |
| BUILD_CMD="./bin/spc-alpine-docker build" | |
| RUNS_ON="ubuntu-latest" | |
| ;; | |
| linux-aarch64) | |
| DOWN_CMD="./bin/spc-alpine-docker download" | |
| BUILD_CMD="./bin/spc-alpine-docker build" | |
| RUNS_ON="ubuntu-24.04-arm" | |
| ;; | |
| linux-x86_64-glibc) | |
| DOWN_CMD="./bin/spc-gnu-docker download" | |
| BUILD_CMD="./bin/spc-gnu-docker build" | |
| RUNS_ON="ubuntu-22.04" | |
| ;; | |
| linux-aarch64-glibc) | |
| DOWN_CMD="./bin/spc-gnu-docker download" | |
| BUILD_CMD="./bin/spc-gnu-docker build" | |
| RUNS_ON="ubuntu-22.04-arm" | |
| ;; | |
| macos-x86_64) | |
| DOWN_CMD="composer update --no-dev --classmap-authoritative && ./bin/spc doctor --auto-fix && ./bin/spc download" | |
| BUILD_CMD="./bin/spc build" | |
| RUNS_ON="macos-15-intel" | |
| ;; | |
| macos-aarch64) | |
| DOWN_CMD="composer update --no-dev --classmap-authoritative && ./bin/spc doctor --auto-fix && ./bin/spc download" | |
| BUILD_CMD="./bin/spc build" | |
| RUNS_ON="macos-15" | |
| ;; | |
| esac | |
| STATIC_EXTS="${{ inputs.extensions }}" | |
| SHARED_EXTS="${{ inputs['shared-extensions'] }}" | |
| BUILD_FRANKENPHP="${{ inputs['build-frankenphp'] }}" | |
| ENABLE_ZTS="${{ inputs['enable-zts'] }}" | |
| ALL_EXTS="$STATIC_EXTS" | |
| if [ -n "$SHARED_EXTS" ]; then | |
| ALL_EXTS="$ALL_EXTS,$SHARED_EXTS" | |
| case "${{ inputs.os }}" in | |
| linux-x86_64|linux-aarch64) | |
| echo "Shared extensions (e.g. xdebug) require glibc/macOS targets. Use linux-*-glibc or macos-*." | |
| exit 1 | |
| ;; | |
| esac | |
| fi | |
| if [ "$BUILD_FRANKENPHP" = "true" ] && [ "$ENABLE_ZTS" != "true" ]; then | |
| echo "FrankenPHP build requires ZTS. Set enable-zts=true." | |
| exit 1 | |
| fi | |
| DOWN_CMD="$DOWN_CMD --with-php=${{ inputs.php-version }} --for-extensions=$ALL_EXTS --ignore-cache-sources=php-src" | |
| BUILD_CMD="$BUILD_CMD $STATIC_EXTS" | |
| if [ -n "$SHARED_EXTS" ]; then | |
| BUILD_CMD="$BUILD_CMD --build-shared=$SHARED_EXTS" | |
| fi | |
| if [ -n "${{ inputs.extra-libs }}" ]; then | |
| DOWN_CMD="$DOWN_CMD --for-libs=${{ inputs.extra-libs }}" | |
| BUILD_CMD="$BUILD_CMD --with-libs=${{ inputs.extra-libs }}" | |
| fi | |
| if [ ${{ inputs.debug }} == true ]; then | |
| DOWN_CMD="$DOWN_CMD --debug" | |
| BUILD_CMD="$BUILD_CMD --debug" | |
| fi | |
| if [ ${{ inputs.prefer-pre-built }} == true ]; then | |
| DOWN_CMD="$DOWN_CMD --prefer-pre-built" | |
| fi | |
| if [ ${{ inputs.with-suggested-libs }} == true ]; then | |
| BUILD_CMD="$BUILD_CMD --with-suggested-libs" | |
| fi | |
| if [ ${{ inputs.build-cli }} == true ]; then | |
| BUILD_CMD="$BUILD_CMD --build-cli" | |
| fi | |
| if [ ${{ inputs.build-micro }} == true ]; then | |
| BUILD_CMD="$BUILD_CMD --build-micro" | |
| fi | |
| if [ ${{ inputs.build-fpm }} == true ]; then | |
| BUILD_CMD="$BUILD_CMD --build-fpm" | |
| fi | |
| if [ "$BUILD_FRANKENPHP" = "true" ]; then | |
| BUILD_CMD="$BUILD_CMD --build-frankenphp" | |
| fi | |
| if [ "$ENABLE_ZTS" = "true" ]; then | |
| BUILD_CMD="$BUILD_CMD --enable-zts" | |
| fi | |
| echo 'download='"$DOWN_CMD" >> "$GITHUB_OUTPUT" | |
| echo 'build='"$BUILD_CMD" >> "$GITHUB_OUTPUT" | |
| echo 'run='"$RUNS_ON" >> "$GITHUB_OUTPUT" | |
| build: | |
| name: "Build ${{ inputs.version }} on ${{ inputs.os }}" | |
| runs-on: ${{ needs.define-build.outputs.run }} | |
| needs: define-build | |
| timeout-minutes: 240 | |
| steps: | |
| - name: "Checkout" | |
| uses: actions/checkout@v4 | |
| - name: "Setup PHP" | |
| uses: shivammathur/setup-php@v2 | |
| with: | |
| php-version: 8.4 | |
| tools: pecl, composer | |
| extensions: curl, openssl, mbstring | |
| ini-values: memory_limit=-1 | |
| env: | |
| phpts: nts | |
| - if: ${{ inputs['build-frankenphp'] == true }} | |
| name: "Install go-xcaddy for FrankenPHP" | |
| run: | | |
| case "${{ inputs.os }}" in | |
| linux-x86_64|linux-aarch64) | |
| ./bin/spc-alpine-docker install-pkg go-xcaddy | |
| ;; | |
| linux-x86_64-glibc|linux-aarch64-glibc) | |
| ./bin/spc-gnu-docker install-pkg go-xcaddy | |
| ;; | |
| macos-x86_64|macos-aarch64) | |
| composer update --no-dev --classmap-authoritative | |
| ./bin/spc doctor --auto-fix | |
| ./bin/spc install-pkg go-xcaddy | |
| ;; | |
| *) | |
| echo "Unsupported OS for go-xcaddy install: ${{ inputs.os }}" | |
| exit 1 | |
| ;; | |
| esac | |
| # Cache downloaded source | |
| - id: cache-download | |
| uses: actions/cache@v4 | |
| with: | |
| path: downloads | |
| key: php-dependencies-${{ inputs.os }} | |
| - name: "Download sources" | |
| run: ${{ needs.define-build.outputs.download }} | |
| - name: "Build PHP" | |
| run: ${{ needs.define-build.outputs.build }} | |
| # - name: Setup tmate session | |
| # if: ${{ failure() }} | |
| # uses: mxschmitt/action-tmate@v3 | |
| # Upload debug logs | |
| - if: ${{ inputs.debug && failure() }} | |
| name: "Upload build logs on failure" | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: spc-logs-${{ inputs.php-version }}-${{ inputs.os }} | |
| path: log/*.log | |
| # Upload cli executable | |
| - if: ${{ inputs.build-cli == true }} | |
| name: "Upload PHP cli SAPI" | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: php-cli-${{ inputs.php-version }}-${{ inputs.os }} | |
| path: buildroot/bin/php | |
| # Upload micro self-extracted executable | |
| - if: ${{ inputs.build-micro == true }} | |
| name: "Upload PHP micro SAPI" | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: php-micro-${{ inputs.php-version }}-${{ inputs.os }} | |
| path: buildroot/bin/micro.sfx | |
| # Upload fpm executable | |
| - if: ${{ inputs.build-fpm == true }} | |
| name: "Upload PHP fpm SAPI" | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: php-fpm-${{ inputs.php-version }}-${{ inputs.os }} | |
| path: buildroot/bin/php-fpm | |
| # Upload frankenphp executable | |
| - if: ${{ inputs['build-frankenphp'] == true }} | |
| name: "Upload FrankenPHP SAPI" | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: php-frankenphp-${{ inputs.php-version }}-${{ inputs.os }} | |
| path: buildroot/bin/frankenphp | |
| # Upload extensions metadata | |
| - if: ${{ inputs['shared-extensions'] != '' }} | |
| name: "Upload shared extensions" | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: php-shared-ext-${{ inputs.php-version }}-${{ inputs.os }} | |
| path: | | |
| buildroot/modules/*.so | |
| buildroot/modules/*.dylib | |
| - uses: actions/upload-artifact@v4 | |
| name: "Upload License Files" | |
| with: | |
| name: license-files-${{ inputs.php-version }}-${{ inputs.os }} | |
| path: buildroot/license/ | |
| - uses: actions/upload-artifact@v4 | |
| name: "Upload Build Metadata" | |
| with: | |
| name: build-meta-${{ inputs.php-version }}-${{ inputs.os }} | |
| path: | | |
| buildroot/build-extensions.json | |
| buildroot/build-libraries.json |