Skip to content

Automate builds #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 108 additions & 0 deletions .github/workflows/build-php.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
name: Build latest PHP versions for each arch

on:
schedule:
# This will run weekly on Sunday at 00:00 UTC.
- cron: '0 0 * * 0'
workflow_dispatch:

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

jobs:
build:
name: Build latest PHP ${{ matrix.version }} for ${{ matrix.os }}
runs-on: ${{ matrix.os }}

strategy:
matrix:
version: ["8.1", "8.2.22", "8.3.10"]
os: ["macos-13", "macos-latest", "windows-latest", "ubuntu-latest"]

steps:
- uses: actions/checkout@v3

- name: Download SPC
run: |
cd ..
git clone https://github.com/crazywhalecc/static-php-cli.git
cd static-php-cli
git checkout $(git describe --tags `git rev-list --tags --max-count=1`)
cd ../php-bin

- run: echo "SPC_BUILD_ARCH=x64" >> $GITHUB_ENV

- if: matrix.os = 'macos-latest'
run: echo "SPC_BUILD_ARCH=arm64" >> $GITHUB_ENV

- if: matrix.os = 'macos-13'
run: echo "SPC_BUILD_ARCH=x86" >> $GITHUB_ENV

- if: matrix.os = 'macos-latest' || matrix.os = 'macos-13'
run: |
brew install automake gzip
echo "SPC_BUILD_OS=mac" >> $GITHUB_ENV

- if: matrix.os = 'windows-latest'
run: echo "SPC_BUILD_OS=win" >> $GITHUB_ENV

- if: matrix.os = 'ubuntu-latest'
run: echo "SPC_BUILD_OS=linux" >> $GITHUB_ENV

- name: "Setup PHP"
uses: shivammathur/setup-php@v2
with:
php-version: 8.1
tools: pecl, composer
extensions: curl, openssl, mbstring, tokenizer
ini-values: memory_limit=-1

# Cache composer dependencies
- id: cache-composer-deps
uses: actions/cache@v3
with:
path: vendor
key: composer-dependencies

# If there's no Composer cache, install dependencies
- if: steps.cache-composer-deps.outputs.cache-hit != 'true'
run: |
cd static-php-cli
composer update --no-dev --classmap-authoritative
cd ../php-bin

# Cache downloaded source
- id: cache-download
uses: actions/cache@v3
with:
path: ../static-php-cli/downloads
key: php-${{ matrix.version }}

- name: Read PHP extensions from file
id: read-extensions
run: |
EXTENSIONS=$(php -r "echo trim(file_get_contents('php-extensions.txt'));")
echo "PHP_EXTENSIONS=$EXTENSIONS" >> $GITHUB_ENV

# If there's no dependencies cache, fetch sources, with or without debug
- if: steps.cache-download.outputs.cache-hit != 'true'
run: ../static-php-cli/bin/spc download --with-php=${{ matrix.version }} --for-extensions "${{ env.PHP_EXTENSIONS }}" --prefer-pre-built

# Run build command
- run: ../static-php-cli/bin/spc build --build-cli "${{ env.PHP_EXTENSIONS }}"

# Zip the binaries, license, and metadata files
- name: Zip PHP binary, copy metadata
run: |
zip bin/${{ env.SPC_BUILD_OS }}/${{ env.SPC_BUILD_ARCH }}/php-${{ matrix.version }}.zip ../static-php-cli/buildroot/bin/php
cp ../static-php-cli/buildroot/license/* license-files/
cp ../static-php-cli/buildroot/build-*.json build-meta/

# Commit and push the zipped files back to the repository
- name: Commit and Push files
run: |
git config --global user.name 'GitHub Actions'
git config --global user.email '[email protected]'
git add .
git commit -m "Add PHP ${{ matrix.version }} build for ${{ env.SPC_BUILD_OS }} ${{ env.SPC_BUILD_ARCH }}"
git push origin
24 changes: 4 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,15 @@ npm -i @nativephp/php-bin --save-dev
> You should install this package as a `dev` dependency, in most cases, and simply copy what you need from it to the
relevant parts of your application. This will save you distributing all of the PHP binaries with every installation.

## Creating new binaries
## Building

NativePHP uses [`static-php-cli`](https://static-php.dev) to build minimal, statically-linked, self-contained PHP
executables for each platform.

You need to build separately for each PHP version:
They are automatically built weekly to get the latest versions of PHP near enough as soon as they become available.

### PHP 8.2
```shell
bin/spc download --clean
bin/spc download --with-php=8.2 --for-extensions "bcmath,ctype,curl,dom,fileinfo,filter,mbstring,openssl,pdo,pdo_sqlite,session,simplexml,sockets,sqlite3,tokenizer,xml,zlib"
```

### PHP 8.3
```shell
bin/spc download --clean
bin/spc download --with-php=8.3 --for-extensions "bcmath,ctype,curl,dom,fileinfo,filter,mbstring,openssl,pdo,pdo_sqlite,session,simplexml,sockets,sqlite3,tokenizer,xml,zlib"
```

### Build
```shell
bin/spc build --build-cli --build-embed "bcmath,ctype,curl,dom,fileinfo,filter,mbstring,openssl,pdo,pdo_sqlite,session,simplexml,sockets,sqlite3,tokenizer,xml,zlib"
```

You need to build these on the relevant platform to compile binaries for that platform.
[Check here](https://github.com/NativePHP/php-bin/blob/automate-builds/php-extensions.txt) for the definitive list of
extensions that are compiled in.

## Issues

Expand Down
Empty file added build-meta/.gitkeep
Empty file.
1 change: 1 addition & 0 deletions php-extensions.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bcmath,ctype,curl,dom,fileinfo,filter,gd,mbstring,opcache,openssl,pdo,pdo_sqlite,phar,session,simplexml,sockets,sqlite3,tokenizer,xml,zip,zlib