-
-
Notifications
You must be signed in to change notification settings - Fork 77
262 lines (223 loc) · 10.1 KB
/
Copy pathbuild-php.yml
File metadata and controls
262 lines (223 loc) · 10.1 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
name: Build PHP
# Required repository secrets (same names as nativephp-php-bin-mobile):
# R2_ACCESS_KEY_ID - Cloudflare R2 access key
# R2_SECRET_ACCESS_KEY - Cloudflare R2 secret key
permissions:
contents: read
on:
workflow_dispatch:
env:
SPC_VERSION: 2.8.5
# Each branch uploads to its own directory: main/, feature-x/, etc.
R2_PREFIX: ${{ format('{0}/', github.ref_name) }}
R2_ENDPOINT: https://713f4e1d515cf082921cdf5122bf1739.r2.cloudflarestorage.com
R2_BUCKET: nativephplibs
jobs:
build:
name: ${{ matrix.version }} ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
version: ["8.3", "8.4", "8.5"]
os: [ "macos-15-intel", "macos-latest", "windows-latest", "ubuntu-latest", "ubuntu-24.04-arm" ]
continue-on-error: true
steps:
- uses: actions/checkout@v6
- name: Set SPC binary name
shell: bash
run: echo "SPC_BINARY=spc" >> $GITHUB_ENV
- name: Set SPC URL for macos-15-intel
shell: bash
if: matrix.os == 'macos-15-intel'
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.3
tools: pecl, composer
extensions: curl, openssl, mbstring, sodium, tokenizer, filter
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
- name: Read PHP libraries from file
id: read-libs
shell: bash
run: |
LIBRARIES=$(php -r "echo trim(file_get_contents('php-libraries.txt'));")
LIBRARIES_HASH=$(php -r "echo md5(getenv('LIBRARIES'));")
echo "PHP_LIBS=$LIBRARIES" >> $GITHUB_ENV
# Cache downloaded source
- id: cache-spc-downloads
uses: actions/cache@v5
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
cd ../php-bin
- name: Build PHP
run: |
cd ../static-php-cli
./bin/${{ env.SPC_BINARY }} build --build-cli "${{ env.PHP_EXTENSIONS }}" --with-libs="${{ env.PHP_LIBS }}" --debug
cd ../php-bin
- name: Get built PHP version
shell: bash
run: |
if [[ "${{ matrix.os }}" == "windows-latest" ]]; then
PHP_VERSION_FULL=$(../static-php-cli/buildroot/bin/php.exe -r "echo PHP_VERSION;")
else
PHP_VERSION_FULL=$(../static-php-cli/buildroot/bin/php -r "echo PHP_VERSION;")
fi
echo "PHP_VERSION_FULL=$PHP_VERSION_FULL" >> $GITHUB_ENV
- 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/php.exe" -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/php tmp-bin/
cd tmp-bin
zip ../bin/${{ env.SPC_BUILD_OS }}/${{ env.SPC_BUILD_ARCH }}/php-${{ env.PHP_VERSION }}.zip php
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
# Upload the built zip (and a sha256 sidecar) to R2 instead of committing
# it to git. Mirrors nativephp-php-bin-mobile/.github/workflows/build.yml:
# same `aws s3 cp` tooling, R2_* secrets, endpoint and --cache-control.
# `shell: bash` runs under Git Bash on the windows-latest matrix leg too.
- name: Upload to R2
shell: bash
env:
AWS_ACCESS_KEY_ID: ${{ secrets.R2_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.R2_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: auto
run: |
ZIP="bin/${SPC_BUILD_OS}/${SPC_BUILD_ARCH}/php-${PHP_VERSION}.zip"
DEST="${R2_PREFIX}desktop/${SPC_BUILD_OS}/${SPC_BUILD_ARCH}/php-${PHP_VERSION}.zip"
# Compute the checksum and upload it as a sidecar first.
if command -v sha256sum >/dev/null 2>&1; then
SHA=$(sha256sum "$ZIP" | awk '{print $1}')
else
SHA=$(shasum -a 256 "$ZIP" | awk '{print $1}')
fi
echo "$SHA $(basename "$ZIP")" > "$ZIP.sha256"
echo "Uploading $ZIP -> ${DEST} (sha256=$SHA)"
aws s3 cp "$ZIP" "s3://${R2_BUCKET}/${DEST}" \
--endpoint-url "$R2_ENDPOINT" \
--cache-control "public, max-age=31536000, immutable"
aws s3 cp "$ZIP.sha256" "s3://${R2_BUCKET}/${DEST}.sha256" \
--endpoint-url "$R2_ENDPOINT" \
--content-type "text/plain" \
--cache-control "public, max-age=31536000, immutable"
# Regenerate the branch manifest from everything currently in R2. Runs after
# all build jobs; safe because it lists the whole bucket prefix, so it always
# reflects every platform/version actually uploaded (mac, linux, win).
manifest:
needs: build
# Run even if some matrix legs failed, so the manifest still reflects the
# binaries that DID upload. Skip only on cancellation. The generator lists
# the live bucket, so it never references a missing object.
if: always() && needs.build.result != 'cancelled'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Generate and upload versions.json
shell: bash
env:
AWS_ACCESS_KEY_ID: ${{ secrets.R2_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.R2_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: auto
BUCKET: ${{ env.R2_BUCKET }}
BASE_URL: https://bin.nativephp.com
run: |
chmod +x .github/scripts/generate-versions-json.sh
.github/scripts/generate-versions-json.sh > versions.json
echo "versions.json:"
cat versions.json
# Manifest LAST, after every binary it references is already in R2.
aws s3 cp versions.json "s3://${R2_BUCKET}/${R2_PREFIX}desktop/versions.json" \
--endpoint-url "$R2_ENDPOINT" \
--content-type "application/json" \
--cache-control "no-cache, no-store"