Skip to content

Commit 56d83c1

Browse files
authored
Build self-contained executables (#60)
1 parent 48956f0 commit 56d83c1

File tree

5 files changed

+234
-3
lines changed

5 files changed

+234
-3
lines changed

.github/workflows/test.yml

Lines changed: 130 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,135 @@ jobs:
7777

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