-
Notifications
You must be signed in to change notification settings - Fork 0
376 lines (327 loc) · 12.3 KB
/
Copy pathbuild-php.yml
File metadata and controls
376 lines (327 loc) · 12.3 KB
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
name: Build PHP
on:
workflow_dispatch:
inputs:
php_version:
description: 'PHP version to build (X.Y.Z, or X.Y to resolve to the latest patch)'
required: true
default: '8.4'
type: string
extensions:
description: 'Extensions to include (comma-separated)'
required: true
default: 'curl,filter,openssl,pcntl,phar,posix,readline,zlib'
type: string
create_release:
description: 'Create a GitHub release with the binaries'
required: true
default: true
type: boolean
debug:
description: 'Enable debug output'
required: false
default: false
type: boolean
env:
SPC_VERSION: '2.8.5'
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
jobs:
# Resolve a minor version (e.g. 8.4) to the latest patch version (e.g. 8.4.20)
# so all artifact names and the release tag include the full X.Y.Z.
resolve-version:
name: Resolve PHP version
runs-on: ubuntu-latest
outputs:
php_version: ${{ steps.resolve.outputs.php_version }}
steps:
- name: Resolve to latest patch version
id: resolve
env:
INPUT_PHP_VERSION: ${{ inputs.php_version }}
run: |
input="$INPUT_PHP_VERSION"
if [[ "$input" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
resolved="$input"
elif [[ "$input" =~ ^[0-9]+\.[0-9]+$ ]]; then
resolved=$(curl -fsSL "https://www.php.net/releases/?json&version=$input" | jq -er .version)
else
echo "Invalid PHP version: $input (expected X.Y or X.Y.Z)" >&2
exit 1
fi
echo "Resolved PHP version: $resolved"
echo "php_version=$resolved" >> "$GITHUB_OUTPUT"
# Linux x86_64 build using Docker
build-linux-amd64:
name: Linux x86_64
needs: resolve-version
runs-on: ubuntu-latest
steps:
- name: Clone static-php-cli
run: |
git clone --depth 1 --branch ${{ env.SPC_VERSION }} https://github.com/crazywhalecc/static-php-cli.git spc
- name: Build PHP in Docker
run: |
cd spc
SPC_USE_ARCH=x86_64 ./bin/spc-alpine-docker download \
--with-php=${{ needs.resolve-version.outputs.php_version }} \
--for-extensions=${{ inputs.extensions }} \
--prefer-pre-built \
${{ inputs.debug && '--debug' || '' }}
SPC_USE_ARCH=x86_64 ./bin/spc-alpine-docker build \
${{ inputs.extensions }} \
--build-cli \
${{ inputs.debug && '--debug' || '' }}
- name: Upload artifact
uses: actions/upload-artifact@v7
with:
name: php-${{ needs.resolve-version.outputs.php_version }}-linux-amd64
path: spc/buildroot/bin/php
retention-days: 1
# Linux ARM64 build using native ARM runner
build-linux-arm64:
name: Linux ARM64
needs: resolve-version
runs-on: ubuntu-24.04-arm
steps:
- name: Clone static-php-cli
run: |
git clone --depth 1 --branch ${{ env.SPC_VERSION }} https://github.com/crazywhalecc/static-php-cli.git spc
- name: Build PHP in Docker
run: |
cd spc
SPC_USE_ARCH=aarch64 ./bin/spc-alpine-docker download \
--with-php=${{ needs.resolve-version.outputs.php_version }} \
--for-extensions=${{ inputs.extensions }} \
--prefer-pre-built \
${{ inputs.debug && '--debug' || '' }}
SPC_USE_ARCH=aarch64 ./bin/spc-alpine-docker build \
${{ inputs.extensions }} \
--build-cli \
${{ inputs.debug && '--debug' || '' }}
- name: Upload artifact
uses: actions/upload-artifact@v7
with:
name: php-${{ needs.resolve-version.outputs.php_version }}-linux-arm64
path: spc/buildroot/bin/php
retention-days: 1
# macOS ARM64 (Apple Silicon) build
build-macos-arm64:
name: macOS ARM64
needs: resolve-version
runs-on: macos-15
steps:
- name: Clone static-php-cli
run: |
git clone --depth 1 --branch ${{ env.SPC_VERSION }} https://github.com/crazywhalecc/static-php-cli.git spc
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.4'
tools: composer
extensions: curl, openssl, mbstring
- name: Install dependencies
run: |
cd spc
composer install --no-dev --classmap-authoritative
- name: Setup build environment
run: |
cd spc
./bin/spc doctor --auto-fix
- name: Download sources
run: |
cd spc
./bin/spc download \
--with-php=${{ needs.resolve-version.outputs.php_version }} \
--for-extensions=${{ inputs.extensions }} \
--prefer-pre-built \
${{ inputs.debug && '--debug' || '' }}
- name: Build PHP
run: |
cd spc
./bin/spc build \
${{ inputs.extensions }} \
--build-cli \
${{ inputs.debug && '--debug' || '' }}
- name: Upload artifact
uses: actions/upload-artifact@v7
with:
name: php-${{ needs.resolve-version.outputs.php_version }}-darwin-arm64
path: spc/buildroot/bin/php
retention-days: 1
# macOS x86_64 (Intel) build
build-macos-amd64:
name: macOS x86_64
needs: resolve-version
runs-on: macos-15-intel
steps:
- name: Clone static-php-cli
run: |
git clone --depth 1 --branch ${{ env.SPC_VERSION }} https://github.com/crazywhalecc/static-php-cli.git spc
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.4'
tools: composer
extensions: curl, openssl, mbstring
- name: Install dependencies
run: |
cd spc
composer install --no-dev --classmap-authoritative
- name: Setup build environment
run: |
cd spc
./bin/spc doctor --auto-fix
- name: Download sources
run: |
cd spc
./bin/spc download \
--with-php=${{ needs.resolve-version.outputs.php_version }} \
--for-extensions=${{ inputs.extensions }} \
--prefer-pre-built \
${{ inputs.debug && '--debug' || '' }}
- name: Build PHP
run: |
cd spc
./bin/spc build \
${{ inputs.extensions }} \
--build-cli \
${{ inputs.debug && '--debug' || '' }}
- name: Upload artifact
uses: actions/upload-artifact@v7
with:
name: php-${{ needs.resolve-version.outputs.php_version }}-darwin-amd64
path: spc/buildroot/bin/php
retention-days: 1
# Windows x64 build
build-windows-amd64:
name: Windows x64
needs: resolve-version
# Not windows-latest or windows-2025: those images now ship Visual Studio
# 2026, and static-php-cli only looks for 2022 or 2019, so its doctor check
# fails before anything is built.
runs-on: windows-2022
steps:
- name: Check out repository code
uses: actions/checkout@v7
- name: Clone static-php-cli
run: |
git clone --depth 1 --branch ${{ env.SPC_VERSION }} https://github.com/crazywhalecc/static-php-cli.git spc
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.4'
tools: composer
extensions: curl, openssl, mbstring
- name: Install dependencies
run: |
cd spc
composer install --no-dev --classmap-authoritative
# Schannel cannot use a CA file and the Windows certificate store
# together, which the CLI needs. This must run before the download step,
# which reads the dependencies it changes.
- name: Build curl against OpenSSL, not Schannel
run: php scripts/patch-spc-windows-curl.php spc
- name: Setup build environment
run: |
cd spc
./bin/spc doctor
# Note: Windows doesn't support pcntl and posix extensions.
# readline uses libedit in static-php-cli, which requires ncurses (not supported on Windows).
- name: Download sources
run: |
cd spc
$extensions = "${{ inputs.extensions }}" -replace 'pcntl,?' -replace 'posix,?' -replace 'readline,?' -replace ',,',','
$extensions = $extensions.Trim(',')
./bin/spc download --with-php=${{ needs.resolve-version.outputs.php_version }} --for-extensions="$extensions" --prefer-pre-built ${{ inputs.debug && '--debug' || '' }}
- name: Build PHP
run: |
cd spc
$extensions = "${{ inputs.extensions }}" -replace 'pcntl,?' -replace 'posix,?' -replace 'readline,?' -replace ',,',','
$extensions = $extensions.Trim(',')
./bin/spc build "$extensions" --build-cli ${{ inputs.debug && '--debug' || '' }}
# The CLI depends on the SSL backend: only OpenSSL can use a CA file and
# the Windows certificate store together.
- name: Check the SSL backend
run: |
$curl = & ./spc/buildroot/bin/php.exe -n -r "echo curl_version()['ssl_version'];"
$openssl = & ./spc/buildroot/bin/php.exe -n -r "echo OPENSSL_VERSION_TEXT;"
Write-Host "curl: $curl"
Write-Host "openssl extension: $openssl"
if ($curl -notlike 'OpenSSL/*') {
throw "expected curl to be built against OpenSSL, got '$curl'"
}
- name: Upload artifact
uses: actions/upload-artifact@v7
with:
name: php-${{ needs.resolve-version.outputs.php_version }}-windows-amd64
path: spc/buildroot/bin/php.exe
retention-days: 1
# Create GitHub release with all binaries
create-release:
name: Create Release
needs:
- resolve-version
- build-linux-amd64
- build-linux-arm64
- build-macos-arm64
- build-macos-amd64
- build-windows-amd64
runs-on: ubuntu-latest
if: ${{ inputs.create_release }}
permissions:
contents: write
env:
PHP_VERSION: ${{ needs.resolve-version.outputs.php_version }}
steps:
- name: Download all artifacts
uses: actions/download-artifact@v8
with:
path: artifacts
- name: Prepare release assets
run: |
mkdir -p release
# Linux x86_64
cp artifacts/php-${PHP_VERSION}-linux-amd64/php \
release/php-${PHP_VERSION}-linux-amd64
chmod +x release/php-${PHP_VERSION}-linux-amd64
# Linux ARM64
cp artifacts/php-${PHP_VERSION}-linux-arm64/php \
release/php-${PHP_VERSION}-linux-arm64
chmod +x release/php-${PHP_VERSION}-linux-arm64
# macOS ARM64
cp artifacts/php-${PHP_VERSION}-darwin-arm64/php \
release/php-${PHP_VERSION}-darwin-arm64
chmod +x release/php-${PHP_VERSION}-darwin-arm64
# macOS x86_64
cp artifacts/php-${PHP_VERSION}-darwin-amd64/php \
release/php-${PHP_VERSION}-darwin-amd64
chmod +x release/php-${PHP_VERSION}-darwin-amd64
# Windows x64
cp artifacts/php-${PHP_VERSION}-windows-amd64/php.exe \
release/php-${PHP_VERSION}-windows-amd64.exe
# Generate checksums
cd release
sha256sum * > SHA256SUMS.txt
cat SHA256SUMS.txt
- name: Create GitHub Release
uses: softprops/action-gh-release@v3
with:
tag_name: php-${{ env.PHP_VERSION }}
name: PHP ${{ env.PHP_VERSION }}
body: |
PHP ${{ env.PHP_VERSION }} static binaries for the Upsun CLI.
## Included Extensions
${{ inputs.extensions }}
Note: `pcntl`, `posix`, and `readline` are not available on Windows.
## Build Details
- Built with [static-php-cli](https://github.com/crazywhalecc/static-php-cli) v${{ env.SPC_VERSION }}
- All binaries are statically linked (no external dependencies)
- Linux builds use musl libc for maximum portability
## Verification
Download `SHA256SUMS.txt` and verify:
```bash
sha256sum -c SHA256SUMS.txt
```
files: release/*
fail_on_unmatched_files: true
overwrite_files: true