Build PHP #7
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 PHP | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| on: | |
| schedule: | |
| # This will run weekly on Sunday at 00:00 UTC. | |
| - cron: "0 0 * * 0" | |
| workflow_dispatch: | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.PAT }} | |
| SPC_VERSION: 2.5.2 | |
| jobs: | |
| build: | |
| name: ${{ matrix.version }} ${{ matrix.os }} | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| matrix: | |
| version: ["8.3", "8.4"] | |
| os: | |
| [ | |
| "macos-13", | |
| "macos-latest", | |
| "windows-latest", | |
| "ubuntu-latest", | |
| "ubuntu-24.04-arm", | |
| ] | |
| continue-on-error: true | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set SPC binary name | |
| shell: bash | |
| run: echo "SPC_BINARY=spc" >> $GITHUB_ENV | |
| - name: Set SPC URL for macos-13 | |
| shell: bash | |
| if: matrix.os == 'macos-13' | |
| run: echo "SPC_URL=https://github.com/crazywhalecc/static-php-cli/releases/download/${{ env.SPC_VERSION }}/spc-macos-x86_64.tar.gz" >> $GITHUB_ENV | |
| - name: Set SPC URL for macos-latest | |
| shell: bash | |
| if: matrix.os == 'macos-latest' | |
| run: echo "SPC_URL=https://github.com/crazywhalecc/static-php-cli/releases/download/${{ env.SPC_VERSION }}/spc-macos-aarch64.tar.gz" >> $GITHUB_ENV | |
| - name: Set SPC URL for ubuntu-latest and ubuntu-24.04 | |
| shell: bash | |
| if: matrix.os == 'ubuntu-latest' | |
| run: echo "SPC_URL=https://github.com/crazywhalecc/static-php-cli/releases/download/${{ env.SPC_VERSION }}/spc-linux-x86_64.tar.gz" >> $GITHUB_ENV | |
| - name: Set SPC URL for ubuntu-24.04-arm | |
| shell: bash | |
| if: matrix.os == 'ubuntu-24.04-arm' | |
| run: echo "SPC_URL=https://github.com/crazywhalecc/static-php-cli/releases/download/${{ env.SPC_VERSION }}/spc-linux-aarch64.tar.gz" >> $GITHUB_ENV | |
| - name: Set SPC URL for windows-latest | |
| shell: bash | |
| if: matrix.os == 'windows-latest' | |
| run: | | |
| echo "SPC_URL=https://github.com/crazywhalecc/static-php-cli/releases/download/${{ env.SPC_VERSION }}/spc-windows-x64.exe" >> $GITHUB_ENV | |
| echo "SPC_BINARY=spc.exe" >> $GITHUB_ENV | |
| - name: Download SPC | |
| shell: bash | |
| run: | | |
| cd .. | |
| if [[ "${{ matrix.os }}" == "windows-latest" ]]; then | |
| curl -fsSL -o ${{ env.SPC_BINARY }} ${{ env.SPC_URL }} | |
| else | |
| curl -fsSL -o ${{ env.SPC_BINARY }}.tar.gz ${{ env.SPC_URL }} | |
| tar -xzf ${{ env.SPC_BINARY }}.tar.gz | |
| fi | |
| chmod +x ${{ env.SPC_BINARY }} | |
| [ ! -d static-php-cli/bin ] && mkdir -p static-php-cli/bin | |
| mv ${{ env.SPC_BINARY }} static-php-cli/bin/ | |
| - name: Create php-bin directory | |
| shell: bash | |
| run: | | |
| cd .. | |
| [ ! -d php-bin ] && mkdir -p php-bin | |
| cd php-bin | |
| - shell: bash | |
| run: | | |
| PHP_VERSION=$(echo "${{ matrix.version }}" | cut -d. -f1,2) | |
| echo "PHP_VERSION=$PHP_VERSION" >> $GITHUB_ENV | |
| - shell: bash | |
| run: echo "SPC_BUILD_ARCH=x64" >> $GITHUB_ENV | |
| - shell: bash | |
| if: matrix.os == 'macos-latest' || matrix.os == 'ubuntu-24.04-arm' | |
| run: echo "SPC_BUILD_ARCH=arm64" >> $GITHUB_ENV | |
| - shell: bash | |
| if: contains(matrix.os, 'macos') | |
| run: | | |
| brew install automake gzip | |
| echo "SPC_BUILD_OS=mac" >> $GITHUB_ENV | |
| - shell: bash | |
| if: matrix.os == 'windows-latest' | |
| run: echo "SPC_BUILD_OS=win" >> $GITHUB_ENV | |
| - shell: bash | |
| if: matrix.os == 'ubuntu-latest' || matrix.os == 'ubuntu-24.04-arm' | |
| run: echo "SPC_BUILD_OS=linux" >> $GITHUB_ENV | |
| - name: Setup system PHP | |
| uses: shivammathur/setup-php@v2 | |
| with: | |
| php-version: 8.2 | |
| tools: pecl, composer | |
| extensions: curl, openssl, mbstring, sodium, tokenizer | |
| ini-values: memory_limit=-1 | |
| - name: SPC doctor | |
| run: | | |
| cd ../static-php-cli | |
| ./bin/${{ env.SPC_BINARY }} doctor | |
| cd ../php-bin | |
| - name: Read PHP extensions from file | |
| id: read-extensions | |
| shell: bash | |
| run: | | |
| EXTENSIONS=$(php -r "echo trim(file_get_contents('php-extensions.txt'));") | |
| EXT_HASH=$(php -r "echo md5(getenv('EXTENSIONS'));") | |
| echo "PHP_EXTENSIONS=$EXTENSIONS" >> $GITHUB_ENV | |
| echo "PHP_EXT_HASH=$EXT_HASH" >> $GITHUB_ENV | |
| # Cache downloaded source | |
| - id: cache-spc-downloads | |
| uses: actions/cache@v4 | |
| with: | |
| path: ../static-php-cli/downloads | |
| key: spc-downloads-${{ env.PHP_EXT_HASH }} | |
| - name: Download PHP extension sources | |
| if: steps.cache-spc-downloads.outputs.cache-hit != 'true' | |
| run: | | |
| cd ../static-php-cli | |
| ./bin/${{ env.SPC_BINARY }} download --with-php=${{ matrix.version }} --for-extensions "${{ env.PHP_EXTENSIONS }}" --prefer-pre-built --retry=3 | |
| cd ../php-bin | |
| - name: Copy icon file for Windows builds | |
| if: matrix.os == 'windows-latest' | |
| shell: bash | |
| run: | | |
| cp assets/icon.ico ../static-php-cli/ | |
| - name: Build PHP (non-Windows) | |
| if: matrix.os != 'windows-latest' | |
| run: | | |
| cd ../static-php-cli | |
| ./bin/${{ env.SPC_BINARY }} build --build-micro "${{ env.PHP_EXTENSIONS }}" --debug | |
| cd ../php-bin | |
| - name: Build PHP (Windows with custom icon) | |
| if: matrix.os == 'windows-latest' | |
| run: | | |
| cd ../static-php-cli | |
| ./bin/${{ env.SPC_BINARY }} build --build-micro "${{ env.PHP_EXTENSIONS }}" --debug --with-micro-logo=icon.ico | |
| cd ../php-bin | |
| - name: Get built PHP version | |
| shell: bash | |
| run: | | |
| cd ../static-php-cli | |
| PHP_VERSION_FULL=$(./bin/${{ env.SPC_BINARY }} dev:php-version) | |
| echo "PHP_VERSION_FULL=$PHP_VERSION_FULL" >> $GITHUB_ENV | |
| cd ../php-bin | |
| - name: Create bin directories | |
| shell: bash | |
| run: | | |
| mkdir -p bin/${{ env.SPC_BUILD_OS }}/${{ env.SPC_BUILD_ARCH }} | |
| mkdir -p license-files | |
| mkdir -p build-meta | |
| - name: Zip PHP binary, copy metadata | |
| shell: bash | |
| run: | | |
| if [[ "${{ matrix.os }}" == "windows-latest" ]]; then | |
| powershell Compress-Archive -Path "../static-php-cli/buildroot/bin/micro.sfx" -DestinationPath "bin/${{ env.SPC_BUILD_OS }}/${{ env.SPC_BUILD_ARCH }}/php-${{ env.PHP_VERSION }}.zip" -Force | |
| else | |
| rm -f bin/${{ env.SPC_BUILD_OS }}/${{ env.SPC_BUILD_ARCH }}/php-${{ env.PHP_VERSION }}.zip | |
| mkdir -p tmp-bin | |
| cp ../static-php-cli/buildroot/bin/micro.sfx tmp-bin/ | |
| cd tmp-bin | |
| zip ../bin/${{ env.SPC_BUILD_OS }}/${{ env.SPC_BUILD_ARCH }}/php-${{ env.PHP_VERSION }}.zip micro.sfx | |
| cd .. | |
| rm -rf tmp-bin | |
| fi | |
| cp ../static-php-cli/buildroot/license/* license-files/ | |
| cp ../static-php-cli/buildroot/build-extensions.json build-meta/build-extensions-${{ env.SPC_BUILD_OS }}.json | |
| cp ../static-php-cli/buildroot/build-libraries.json build-meta/build-libraries-${{ env.SPC_BUILD_OS }}.json | |
| - name: Create Pull Request | |
| uses: peter-evans/create-pull-request@v7 | |
| with: | |
| branch: update-php-${{ env.PHP_VERSION }}-${{ env.SPC_BUILD_OS }}-${{ env.SPC_BUILD_ARCH }} | |
| title: "Update PHP ${{ env.PHP_VERSION }} build for ${{ env.SPC_BUILD_OS }} ${{ env.SPC_BUILD_ARCH }}" | |
| commit-message: "build" | |
| body: | | |
| PHP: ${{ env.PHP_VERSION_FULL }} | |
| Exts: ${{ env.PHP_EXTENSIONS }} | |
| OS: ${{ env.SPC_BUILD_OS }} | |
| Arch: ${{ env.SPC_BUILD_ARCH }} | |
| base: main |