-
-
Notifications
You must be signed in to change notification settings - Fork 20
203 lines (176 loc) · 6.37 KB
/
build-php.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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
name: Build PHP
permissions:
contents: write
pull-requests: write
on:
schedule:
# This will run weekly on Sunday at 00:00 UTC.
- cron: '0 0 * * 0'
workflow_dispatch:
inputs:
php_version:
description: 'Select PHP version (optional)'
required: false
type: choice
options:
- '8.1'
- '8.2'
- '8.3'
- '8.4'
default: ''
operating_system:
description: 'Select operating system (optional)'
required: false
type: choice
options:
- 'ubuntu-latest'
- 'windows-latest'
- 'macos-13'
- 'macos-latest'
default: ''
enable_debug:
description: 'Enable debug mode'
required: false
type: choice
options:
- 'true'
- 'false'
default: 'false'
env:
GITHUB_TOKEN: ${{ secrets.PAT }}
jobs:
build:
name: ${{ matrix.version }} ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
version: ["8.1", "8.2", "8.3", "8.4"]
os: ["macos-13", "macos-latest", "windows-latest", "ubuntu-latest"]
include:
- version: ${{ inputs.php_version || matrix.version }}
os: ${{ inputs.operating_system || matrix.os }}
continue-on-error: true
steps:
- uses: actions/checkout@v4
- name: Download SPC
shell: bash
run: |
cd ..
git clone https://github.com/crazywhalecc/static-php-cli.git
cd static-php-cli
git checkout main
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'
run: echo "SPC_BUILD_ARCH=arm64" >> $GITHUB_ENV
- shell: bash
if: matrix.os == 'macos-13'
run: echo "SPC_BUILD_ARCH=x86" >> $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'
run: echo "SPC_BUILD_OS=linux" >> $GITHUB_ENV
- name: Setup system PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.2
tools: pecl, composer
extensions: curl, openssl, mbstring, sodium, tokenizer
ini-values: memory_limit=-1
# Cache composer dependencies
- id: cache-spc-composer-deps
uses: actions/cache@v4
with:
path: ../static-php-cli/vendor
key: composer-dependencies
- name: Install SPC Composer dependencies
if: steps.cache-spc-composer-deps.outputs.cache-hit != 'true'
run: |
cd ../static-php-cli
composer update --no-dev --classmap-authoritative
cd ../php-bin
- name: SPC doctor
run: |
cd ../static-php-cli
./bin/spc 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
# Cache downloaded source
- id: cache-spc-downloads
uses: actions/cache@v4
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/spc download --with-php=${{ matrix.version }} --for-extensions "${{ env.PHP_EXTENSIONS }}" --prefer-pre-built
cd ../php-bin
- name: Build PHP
run: |
cd ../static-php-cli
if [[ "${{ inputs.enable_debug }}" == "true" ]]; then
./bin/spc build --build-cli --debug "${{ env.PHP_EXTENSIONS }}"
else
./bin/spc build --build-cli "${{ env.PHP_EXTENSIONS }}"
fi
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: 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
- name: Create Pull Request
uses: peter-evans/create-pull-request@v7
with:
branch: update-php-${{ env.PHP_VERSION }}-${{ env.SPC_BUILD_OS }}-${{ env.SPC_BUILD_ARCH }}
title: "Update PHP ${{ env.PHP_VERSION }} build for ${{ env.SPC_BUILD_OS }} ${{ env.SPC_BUILD_ARCH }}"
commit-message: "build"
body: |
PHP: ${{ env.PHP_VERSION_FULL }}
Exts: ${{ env.PHP_EXTENSIONS }}
OS: ${{ env.SPC_BUILD_OS }}
Arch: ${{ env.SPC_BUILD_ARCH }}
base: main