1- name : Build Self-Hosted PHP Binary (Unix)
1+ name : " [v3] Build Self-Hosted PHP Binary (Unix)"
22
33on :
44 workflow_dispatch :
55 schedule :
66 - cron : " 0 1 */3 * *"
77
8+ env :
9+ GITHUB_TOKEN : ${{ secrets.S_GITHUB_TOKEN || secrets.GITHUB_TOKEN }}
10+
811jobs :
912 build-release-artifacts :
1013 name : " Build ${{ matrix.php-version }}-${{ matrix.combination }} on ${{ matrix.runner }}"
1316 fail-fast : false
1417 matrix :
1518 php-version :
16- # - "8.1"
1719 - " 8.2"
1820 - " 8.3"
1921 - " 8.4"
@@ -41,72 +43,76 @@ jobs:
4143 - { runner: "ubuntu-22.04-arm", combination: "minimal" }
4244 - { runner: "ubuntu-22.04-arm", combination: "bulk" }
4345 - { runner: "ubuntu-22.04-arm", combination: "common" }
46+
4447 steps :
4548 - name : " Process env string"
4649 id : process-env
4750 shell : bash
4851 run : |
4952 case "${{ matrix.combination }}" in
50- minimal)
53+ minimal)
5154 echo "EXTENSIONS=iconv,pcntl,posix,mbstring,filter,tokenizer,phar" >> "$GITHUB_OUTPUT"
5255 ;;
53- common)
56+ common)
5457 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"
55- echo "SUGGEST=--with-suggested-libs " >> "$GITHUB_OUTPUT"
58+ echo "SUGGEST=--with-suggests " >> "$GITHUB_OUTPUT"
5659 ;;
57- bulk|gnu-bulk)
60+ bulk|gnu-bulk)
5861 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"
59- echo "SUGGEST=--with-suggested-libs " >> "$GITHUB_OUTPUT"
62+ echo "SUGGEST=--with-suggests " >> "$GITHUB_OUTPUT"
6063 ;;
6164 esac
62-
65+
66+ echo "CMD=bin/spc" >> "$GITHUB_OUTPUT"
67+
6368 case "${{ matrix.runner }}" in
6469 ubuntu-latest)
6570 echo "OS=linux" >> "$GITHUB_OUTPUT"
6671 echo "ARCH=x86_64" >> "$GITHUB_OUTPUT"
67- echo "CMD=bin/spc-alpine-docker " >> "$GITHUB_OUTPUT"
72+ echo "UPX=--with-upx-pack " >> "$GITHUB_OUTPUT"
6873 ;;
6974 ubuntu-24.04-arm)
7075 echo "OS=linux" >> "$GITHUB_OUTPUT"
7176 echo "ARCH=aarch64" >> "$GITHUB_OUTPUT"
72- echo CMD="bin/spc-alpine-docker " >> "$GITHUB_OUTPUT"
77+ echo "UPX=--with-upx-pack " >> "$GITHUB_OUTPUT"
7378 ;;
7479 ubuntu-22.04)
7580 echo "OS=linux" >> "$GITHUB_OUTPUT"
7681 echo "ARCH=x86_64" >> "$GITHUB_OUTPUT"
77- echo CMD="bin/spc-gnu-docker " >> "$GITHUB_OUTPUT"
82+ echo "SPC_TARGET=native-native-gnu.2.17 " >> "$GITHUB_OUTPUT"
7883 ;;
7984 ubuntu-22.04-arm)
8085 echo "OS=linux" >> "$GITHUB_OUTPUT"
8186 echo "ARCH=aarch64" >> "$GITHUB_OUTPUT"
82- echo CMD="bin/spc-gnu-docker" >> "$GITHUB_OUTPUT"
83- ;;
84- windows-2019)
85- echo "OS=windows" >> "$GITHUB_OUTPUT"
86- echo "ARCH=x86_64" >> "$GITHUB_OUTPUT"
87- echo "CMD=bin/spc" >> "$GITHUB_OUTPUT"
87+ echo "SPC_TARGET=native-native-gnu.2.17" >> "$GITHUB_OUTPUT"
8888 ;;
8989 macos-15-intel)
9090 echo "OS=macos" >> "$GITHUB_OUTPUT"
9191 echo "ARCH=x86_64" >> "$GITHUB_OUTPUT"
92- echo "CMD=bin/spc" >> "$GITHUB_OUTPUT"
9392 ;;
9493 macos-15)
9594 echo "OS=macos" >> "$GITHUB_OUTPUT"
9695 echo "ARCH=aarch64" >> "$GITHUB_OUTPUT"
97- echo "CMD=bin/spc" >> "$GITHUB_OUTPUT"
9896 ;;
9997 esac
100-
98+
99+ - name : " Checkout current repository"
100+ if : github.repository == 'crazywhalecc/static-php-cli'
101+ uses : actions/checkout@v4
102+
101103 - name : " Checkout remote"
102104 if : github.repository != 'crazywhalecc/static-php-cli'
103105 uses : actions/checkout@v4
104106 with :
105107 repository : crazywhalecc/static-php-cli
106- ref : main
108+ ref : v3
109+
110+ - name : " Apply target env"
111+ if : ${{ steps.process-env.outputs.SPC_TARGET != '' }}
112+ shell : bash
113+ run : echo "SPC_TARGET=${{ steps.process-env.outputs.SPC_TARGET }}" >> "$GITHUB_ENV"
107114
108115 - name : " Setup PHP"
109- if : ${{ !startsWith(matrix.runner, 'ubuntu') }}
110116 uses : shivammathur/setup-php@v2
111117 with :
112118 php-version : 8.4
@@ -115,77 +121,79 @@ jobs:
115121 ini-values : memory_limit=-1
116122
117123 - name : " Cache composer packages"
118- id : composer-cache
119124 uses : actions/cache@v4
120125 with :
121126 path : vendor
122127 key : ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
123128 restore-keys : |
124129 ${{ runner.os }}-php
125130
126- # Cache downloaded source
127- - id : cache-download
131+ - name : " Cache downloaded artifacts"
128132 uses : actions/cache@v4
129133 with :
130134 path : downloads
131- key : pack-lib-dependencies -${{ matrix.combination }}-${{ matrix.php-version }}-${{ matrix.runner }}
135+ key : v3-php-bin -${{ matrix.combination }}-${{ matrix.php-version }}-${{ matrix.runner }}
132136
133137 - name : " Install Dependencies"
134- if : ${{ !startsWith(matrix.runner, 'ubuntu') }}
135138 run : composer update -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist --no-dev
136139
137- - run : ${{ steps.process-env.outputs.CMD }} doctor --auto-fix
140+ - name : " Run Build Tests (doctor)"
141+ run : ${{ steps.process-env.outputs.CMD }} doctor --auto-fix
138142
139- - name : " ACLOCAL"
140- run : |
141- autoconf --version
142- aclocal --print-ac-dir
143- echo $ACLOCAL_PATH
143+ - name : " Install UPX"
144+ if : ${{ steps.process-env.outputs.UPX != '' }}
145+ run : ${{ steps.process-env.outputs.CMD }} install-pkg upx
144146
145- # If there's no dependencies cache, fetch sources
146- - name : " Download sources"
147- env :
148- GITHUB_TOKEN : ${{ secrets.S_GITHUB_TOKEN }}
149- run : ${{ steps.process-env.outputs.CMD }} download --with-php=${{ matrix.php-version }} --for-extensions=${{ steps.process-env.outputs.EXTENSIONS }} --retry=5 --prefer-pre-built --ignore-cache-sources=php-src
147+ - name : " Build PHP"
148+ shell : bash
149+ run : |
150+ ${{ steps.process-env.outputs.CMD }} build \
151+ --build-cli \
152+ --build-micro \
153+ --build-fpm \
154+ "${{ steps.process-env.outputs.EXTENSIONS }}" \
155+ --debug \
156+ ${{ steps.process-env.outputs.UPX }} \
157+ ${{ steps.process-env.outputs.SUGGEST }} \
158+ --dl-with-php="${{ matrix.php-version }}" \
159+ --dl-retry=5 \
160+ --dl-prefer-binary \
161+ --dl-ignore-cache=php-src
150162
151- - name : " Build library: ${{ matrix.library }}"
163+ - name : " Pack PHP"
164+ shell : bash
152165 run : |
153- if [ "${{ steps.process-env.outputs.OS }}" = "linux" ] && [ "${{ steps.process-env.outputs.CMD }}" = "bin/spc-alpine-docker" ]; then
154- ${{ steps.process-env.outputs.CMD }} install-pkg upx
155- UPX=--with-upx-pack
156- fi
157-
158- ${{ steps.process-env.outputs.CMD }} build --build-cli --build-micro --build-fpm ${{ steps.process-env.outputs.EXTENSIONS }} --debug $UPX ${{ steps.process-env.outputs.SUGGEST }}
166+ mkdir -p tmp_dist dist
159167
160- # Copy out from buildroot, because docker build has different permission
161- mkdir -p tmp_dist/
162168 cp buildroot/bin/php tmp_dist/
163169 cp buildroot/bin/micro.sfx tmp_dist/
164170 cp buildroot/bin/php-fpm tmp_dist/
165171
166- PHPVER=$(cat source/php-src/main/php_version.h | grep "PHP_VERSION " | awk -F\" '{print $2}')
167-
168- if [ ! -d "dist" ]; then
169- mkdir dist/
172+ ${{ steps.process-env.outputs.CMD }} dev:info php --json --no-ansi > php-info.json
173+ PHPVER="$(php -r '$j = json_decode(file_get_contents("php-info.json"), true); echo $j["cache"]["source"]["info"]["version"] ?? "";')"
174+ if [ -z "$PHPVER" ]; then
175+ echo "Cannot resolve PHP version from dev:info php --json"
176+ exit 1
170177 fi
171178
172- sudo chmod -R 777 dist
173-
174- tar -czf dist/php-$PHPVER-cli-${{ steps.process-env.outputs.OS }}-${{ steps.process-env.outputs.ARCH }}.tar.gz -C tmp_dist/ php
175- tar -czf dist/php-$PHPVER-micro-${{ steps.process-env.outputs.OS }}-${{ steps.process-env.outputs.ARCH }}.tar.gz -C tmp_dist/ micro.sfx
176- tar -czf dist/php-$PHPVER-fpm-${{ steps.process-env.outputs.OS }}-${{ steps.process-env.outputs.ARCH }}.tar.gz -C tmp_dist/ php-fpm
177- if [ "${{ matrix.php-version }}" == "8.4" ] && [ "${{ matrix.runner }}" == "ubuntu-latest" ]; then
178- cp -r buildroot/license dist/
179- cp buildroot/build-extensions.json dist/
180- cp buildroot/build-libraries.json dist/
181- echo -e "# Note\n\nCurrent distribution uses extensions:\n\n${{ steps.process-env.outputs.EXTENSIONS }}\n\nUsing compile command:\n\n bin/spc build --build-cli --build-micro --build-fpm ${{ steps.process-env.outputs.EXTENSIONS }} --debug --with-upx-pack" > dist/README.txt
182- fi
183- if [ "${{ matrix.php-version }}" == "8.4" ] && [ "${{ matrix.runner }}" == "ubuntu-22.04" ]; then
184- cp -r buildroot/license dist/
185- cp buildroot/build-extensions.json dist/
186- cp buildroot/build-libraries.json dist/
187- echo -e "# Note\n\nCurrent distribution uses extensions:\n\n${{ steps.process-env.outputs.EXTENSIONS }}\n\nUsing compile command:\n\n bin/spc build --build-cli --build-micro --build-fpm ${{ steps.process-env.outputs.EXTENSIONS }} --debug --with-upx-pack" > dist/README.txt
188- fi
179+ chmod -R 755 tmp_dist
180+ sudo chmod -R 777 dist || true
181+
182+ tar -czf "dist/php-$PHPVER-cli-${{ steps.process-env.outputs.OS }}-${{ steps.process-env.outputs.ARCH }}.tar.gz" -C tmp_dist/ php
183+ tar -czf "dist/php-$PHPVER-micro-${{ steps.process-env.outputs.OS }}-${{ steps.process-env.outputs.ARCH }}.tar.gz" -C tmp_dist/ micro.sfx
184+ tar -czf "dist/php-$PHPVER-fpm-${{ steps.process-env.outputs.OS }}-${{ steps.process-env.outputs.ARCH }}.tar.gz" -C tmp_dist/ php-fpm
185+
186+ echo "PHPVER=$PHPVER" >> "$GITHUB_ENV"
187+ ls -la dist
188+
189+ - name : " Add build metadata"
190+ if : ${{ matrix.php-version == '8.4' && (matrix.runner == 'ubuntu-latest' || matrix.runner == 'ubuntu-22.04') }}
191+ shell : bash
192+ run : |
193+ cp -r buildroot/license dist/
194+ cp buildroot/build-extensions.json dist/
195+ cp buildroot/build-libraries.json dist/
196+ 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
189197
190198 - name : " Deploy to self-hosted OSS"
191199 uses : static-php/upload-s3-action@v1.0.0
@@ -194,15 +202,23 @@ jobs:
194202 aws_secret_access_key : ${{ secrets.AWS_SECRET_ACCESS_KEY }}
195203 aws_bucket : ${{ secrets.AWS_BUCKET }}
196204 source_dir : " dist/"
197- destination_dir : static- php-cli /${{ matrix.combination }}/
205+ destination_dir : v3/ php-bin /${{ matrix.combination }}/
198206 endpoint : ${{ secrets.AWS_ENDPOINT }}
199207
200208 - name : " Upload Artifact"
201209 uses : actions/upload-artifact@v4
202210 with :
203- name : php-${{ matrix.php-version }}-${{ matrix.combination }}-${{ steps.process-env.outputs.OS }}-${{ steps.process-env.outputs.ARCH }}
211+ name : php-${{ env.PHPVER }}-${{ matrix.combination }}-${{ steps.process-env.outputs.OS }}-${{ steps.process-env.outputs.ARCH }}
204212 path : |
205213 tmp_dist/php
206214 tmp_dist/php-fpm
207215 tmp_dist/micro.sfx
208216 if-no-files-found : error
217+
218+ - name : " Upload logs on failure"
219+ if : ${{ failure() }}
220+ uses : actions/upload-artifact@v4
221+ with :
222+ name : spc-logs-${{ matrix.php-version }}-${{ matrix.combination }}-${{ matrix.runner }}
223+ path : log/*.log
224+ if-no-files-found : ignore
0 commit comments