Skip to content

Commit a4e91bb

Browse files
committed
Build self-contained executables
1 parent 1319186 commit a4e91bb

File tree

5 files changed

+233
-2
lines changed

5 files changed

+233
-2
lines changed

.github/workflows/test.yml

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,132 @@ jobs:
8080
name: php-matrix.phar
8181
path: phar/php-matrix
8282
if-no-files-found: error
83+
84+
build:
85+
needs: phar
86+
strategy:
87+
matrix:
88+
include:
89+
- runs-on: ubuntu-24.04-arm
90+
variant: linux_arm64
91+
spc-variant: linux-aarch64
92+
- runs-on: ubuntu-24.04
93+
variant: linux_amd64
94+
spc-variant: linux-x86_64
95+
- runs-on: macos-15
96+
variant: darwin_arm64
97+
spc-variant: macos-aarch64
98+
- runs-on: macos-15-intel
99+
variant: darwin_amd64
100+
spc-variant: macos-x86_64
101+
runs-on: ${{ matrix.runs-on }}
102+
steps:
103+
- uses: actions/checkout@v5
104+
with:
105+
sparse-checkout: craft.yml
106+
sparse-checkout-cone-mode: false
107+
108+
- name: Install spc
109+
run: |
110+
gh release download --repo crazywhalecc/static-php-cli --pattern "${PATTERN}" --output spc.tar.gz && \
111+
mkdir -p /tmp/spc && \
112+
tar -xvf spc.tar.gz --directory /tmp/spc && \
113+
echo "/tmp/spc" >> "$GITHUB_PATH"
114+
env:
115+
PATTERN: spc-${{ matrix.spc-variant }}.tar.gz
116+
GH_TOKEN: ${{ github.token }}
117+
118+
- uses: actions/download-artifact@v5
119+
with:
120+
name: php-matrix.phar
121+
path: phar
122+
123+
- name: Restore cached micro.sfx
124+
id: restore-micro-sfx
125+
uses: actions/cache/restore@v4
126+
with:
127+
path: buildroot/bin/micro.sfx
128+
key: micro-sfx-${{ runner.os }}-${{ runner.arch }}-${{ needs.phar.outputs.php-version }}-${{ hashFiles('craft.yml') }}
129+
130+
- name: Build micro.sfx
131+
if: steps.restore-micro-sfx.outputs.cache-hit != 'true'
132+
run: spc craft
133+
env:
134+
GITHUB_TOKEN: ${{ github.token }} # Not a typo.
135+
136+
- name: Cache micro.sfx
137+
id: cache-micro-sfx
138+
if: steps.restore-micro-sfx.outputs.cache-hit != 'true'
139+
uses: actions/cache/save@v4
140+
with:
141+
path: buildroot/bin/micro.sfx
142+
key: ${{ steps.restore-micro-sfx.outputs.cache-primary-key }}
143+
144+
- run: mkdir -p out
145+
- run: spc micro:combine phar/php-matrix --output out/php-matrix
146+
147+
- uses: actions/upload-artifact@v4
148+
with:
149+
name: php-matrix_${{ matrix.variant }}
150+
path: out/php-matrix
151+
if-no-files-found: error
152+
153+
e2e:
154+
needs: build
155+
strategy:
156+
matrix:
157+
include:
158+
- runs-on: ubuntu-24.04-arm
159+
variant: linux_arm64
160+
- runs-on: ubuntu-24.04
161+
variant: linux_amd64
162+
- runs-on: macos-15
163+
variant: darwin_arm64
164+
- runs-on: macos-15-intel
165+
variant: darwin_amd64
166+
runs-on: ${{ matrix.runs-on }}
167+
env:
168+
GOFLAGS: '-mod=mod'
169+
steps:
170+
- uses: actions/checkout@v5
171+
172+
- uses: actions/setup-go@v6
173+
with:
174+
go-version-file: 'go.mod'
175+
176+
- run: echo OS="$(go env GOOS)" >> $GITHUB_ENV
177+
- run: echo ARCH="$(go env GOARCH)" >> $GITHUB_ENV
178+
179+
- uses: actions/download-artifact@v5
180+
with:
181+
name: php-matrix_${{ matrix.variant }}
182+
path: out
183+
184+
- name: Grant php-matrix binary execute permission
185+
run: chmod +x out/php-matrix
186+
187+
- name: Add php-matrix binary into PATH
188+
run: echo "${WORKSPACE}/out" >> "$GITHUB_PATH"
189+
env:
190+
WORKSPACE: ${{ github.workspace }}
191+
192+
- name: Print php-matrix binary path
193+
run: go test -count=1 -v ./internal
194+
195+
- run: go test -count=1 ./...
196+
197+
merge:
198+
needs:
199+
- build
200+
- e2e
201+
runs-on: ubuntu-24.04
202+
steps:
203+
- name: Merge binary artifacts
204+
uses: actions/upload-artifact/merge@v4
205+
with:
206+
name: binaries
207+
pattern: |
208+
php-matrix_darwin_*
209+
php-matrix_linux_*
210+
separate-directories: true
211+
delete-merged: true

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,11 @@
66

77
# Box
88
/phar/
9+
10+
# Static PHP CLI (spc)
11+
/buildroot/
12+
/downloads/
13+
/log/
14+
/out/
15+
/pkgroot/
16+
/source/

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@
3131
"composer-runtime-api": "^2.2",
3232
"composer/semver": "^3.4",
3333
"guzzlehttp/guzzle": "^7.10",
34-
"symfony/console": "^7.3"
34+
"symfony/console": "^7.3",
35+
"symfony/polyfill-iconv": "^1.33"
3536
},
3637
"require-dev": {
3738
"mockery/mockery": "^1.6",

composer.lock

Lines changed: 85 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

craft.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
php-version: 8.4
2+
extensions:
3+
- phar
4+
- filter # For Symfony CompleteCommand
5+
- curl # For guzzlehttp/guzzle
6+
sapi:
7+
- micro
8+
download-options:
9+
prefer-pre-built: true

0 commit comments

Comments
 (0)