-
Notifications
You must be signed in to change notification settings - Fork 44
187 lines (167 loc) · 8.09 KB
/
build-php-unix.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
name: Build Self-Hosted PHP Binary (Unix)
on:
workflow_dispatch:
jobs:
build-release-artifacts:
name: "Build ${{ matrix.php-version }}-${{ matrix.combination }} on ${{ matrix.runner }}"
runs-on: ${{ matrix.runner }}
strategy:
fail-fast: false
matrix:
php-version:
- "8.1"
- "8.2"
- "8.3"
- "8.4"
runner:
- "ubuntu-latest"
- "macos-13"
- "ubuntu-20.04"
- "macos-14"
combination:
- minimal
- bulk
- common
steps:
- name: "Process env string"
id: process-env
shell: bash
run: |
case "${{ matrix.combination }}" in
minimal)
echo "EXTENSIONS=pcntl,posix,mbstring,tokenizer,phar" >> "$GITHUB_OUTPUT"
echo "DEPLOY_TARGET=${{ secrets.DEPLOY_SERVER_TARGET_MINIMAL }}" >> "$GITHUB_OUTPUT"
;;
common)
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,phar,posix,redis,session,simplexml,soap,sockets,sqlite3,tokenizer,xmlwriter,xmlreader,zlib,zip" >> "$GITHUB_OUTPUT"
echo "DEPLOY_TARGET=${{ secrets.DEPLOY_SERVER_TARGET }}" >> "$GITHUB_OUTPUT"
;;
bulk)
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,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"
echo "DEPLOY_TARGET=${{ secrets.DEPLOY_SERVER_TARGET_BULK }}" >> "$GITHUB_OUTPUT"
;;
esac
case "${{ matrix.runner }}" in
ubuntu-latest)
echo "OS=linux" >> "$GITHUB_OUTPUT"
echo "ARCH=x86_64" >> "$GITHUB_OUTPUT"
echo "CMD=bin/spc-alpine-docker" >> "$GITHUB_OUTPUT"
;;
ubuntu-20.04)
echo "OS=linux" >> "$GITHUB_OUTPUT"
echo "ARCH=aarch64" >> "$GITHUB_OUTPUT"
echo CMD="SPC_USE_ARCH=aarch64 bin/spc-alpine-docker" >> "$GITHUB_OUTPUT"
;;
windows-2019)
echo "OS=windows" >> "$GITHUB_OUTPUT"
echo "ARCH=x86_64" >> "$GITHUB_OUTPUT"
echo "CMD=bin/spc" >> "$GITHUB_OUTPUT"
;;
macos-13)
echo "OS=macos" >> "$GITHUB_OUTPUT"
echo "ARCH=x86_64" >> "$GITHUB_OUTPUT"
echo "CMD=bin/spc" >> "$GITHUB_OUTPUT"
;;
macos-14)
echo "OS=macos" >> "$GITHUB_OUTPUT"
echo "ARCH=aarch64" >> "$GITHUB_OUTPUT"
echo "CMD=bin/spc" >> "$GITHUB_OUTPUT"
;;
esac
- name: "Checkout remote"
if: github.repository != 'crazywhalecc/static-php-cli'
uses: actions/checkout@v4
with:
repository: crazywhalecc/static-php-cli
ref: main
- name: "Setup PHP"
if: matrix.runner != 'ubuntu-20.04'
uses: shivammathur/setup-php@v2
with:
php-version: 8.2
tools: pecl, composer
extensions: curl, openssl, mbstring
ini-values: memory_limit=-1
- name: "Cache composer packages"
id: composer-cache
uses: actions/cache@v4
with:
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-php
# Cache downloaded source
- id: cache-download
uses: actions/cache@v4
with:
path: downloads
key: pack-lib-dependencies-${{ matrix.combination }}-${{ matrix.php-version }}-${{ matrix.runner }}
- name: "Install Dependencies"
if: matrix.runner != 'ubuntu-20.04'
run: composer update -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist --no-dev
- run: ${{ steps.process-env.outputs.CMD }} doctor --auto-fix
# If there's no dependencies cache, fetch sources
- name: "Download sources"
env:
GITHUB_TOKEN: ${{ secrets.S_GITHUB_TOKEN }}
run: ${{ steps.process-env.outputs.CMD }} download --with-php=${{ matrix.php-version }} --for-extensions=${{ steps.process-env.outputs.EXTENSIONS }} --retry=5 --prefer-pre-built
- name: "Build library: ${{ matrix.library }}"
run: |
if [ "${{ steps.process-env.outputs.OS }}" = "linux" ]; then
${{ steps.process-env.outputs.CMD }} install-pkg upx
if [ "${{ steps.process-env.outputs.ARCH }}" = "x86_64" ]; then
UPX=--with-upx-pack
fi
fi
${{ steps.process-env.outputs.CMD }} build --build-cli --build-micro --build-fpm ${{ steps.process-env.outputs.EXTENSIONS }} --debug $UPX
# Copy out from buildroot, because docker build has different permission
mkdir -p tmp_dist/
cp buildroot/bin/php tmp_dist/
cp buildroot/bin/micro.sfx tmp_dist/
cp buildroot/bin/php-fpm tmp_dist/
# UPX outside for linux-aarch64
if [ "${{ steps.process-env.outputs.OS }}-${{ steps.process-env.outputs.ARCH }}" = "linux-aarch64" ]; then
mkdir -p upx-x86_64
cd upx-x86_64
curl -#fSL -o upx.txz https://github.com/upx/upx/releases/download/v4.2.4/upx-4.2.4-amd64_linux.tar.xz
tar -xf upx.txz --strip-components 1
./upx --best ../tmp_dist/php
./upx --best ../tmp_dist/micro.sfx
SFX_SIZE=$(readelf -l ../tmp_dist/micro.sfx | awk '/LOAD|GNU_STACK/ {getline; print $1, $2, $3, $4, $6, $7}' | sed -n '2p' | awk '{print $1}')
head -c $(printf "%d" $SFX_SIZE) ../tmp_dist/micro.sfx > ../tmp_dist/micro.sfx.new
mv ../tmp_dist/micro.sfx.new ../tmp_dist/micro.sfx
./upx --best ../tmp_dist/php-fpm
cd ..
fi
PHPVER=$(cat source/php-src/main/php_version.h | grep "PHP_VERSION " | awk -F\" '{print $2}')
if [ ! -d "dist" ]; then
mkdir dist/
fi
sudo chmod -R 777 dist
tar -czf dist/php-$PHPVER-cli-${{ steps.process-env.outputs.OS }}-${{ steps.process-env.outputs.ARCH }}.tar.gz -C tmp_dist/ php
tar -czf dist/php-$PHPVER-micro-${{ steps.process-env.outputs.OS }}-${{ steps.process-env.outputs.ARCH }}.tar.gz -C tmp_dist/ micro.sfx
tar -czf dist/php-$PHPVER-fpm-${{ steps.process-env.outputs.OS }}-${{ steps.process-env.outputs.ARCH }}.tar.gz -C tmp_dist/ php-fpm
if [ "${{ matrix.php-version }}" == "8.4" ] && [ "${{ matrix.runner }}" == "ubuntu-latest" ]; then
cp -r buildroot/license dist/
cp buildroot/build-extensions.json dist/
cp buildroot/build-libraries.json dist/
echo "# 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
fi
- name: "Deploy to self-hosted OSS"
uses: static-php/[email protected]
with:
aws_key_id: ${{ secrets.AWS_KEY_ID }}
aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws_bucket: ${{ secrets.AWS_BUCKET }}
source_dir: "dist/"
destination_dir: static-php-cli/${{ matrix.combination }}/
endpoint: ${{ secrets.AWS_ENDPOINT }}
- name: "Upload Artifact"
uses: actions/upload-artifact@v4
with:
name: php-${{ matrix.php-version }}-${{ matrix.combination }}-${{ steps.process-env.outputs.OS }}-${{ steps.process-env.outputs.ARCH }}
path: |
tmp_dist/php
tmp_dist/php-fpm
tmp_dist/micro.sfx
if-no-files-found: error