Skip to content

Commit 439d00d

Browse files
committed
github workflow for building multi platform binaries
1 parent 2ef2bab commit 439d00d

File tree

2 files changed

+83
-26
lines changed

2 files changed

+83
-26
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
name: Build Release Binaries
2+
3+
on:
4+
push:
5+
tags:
6+
- "*"
7+
8+
jobs:
9+
build:
10+
name: Build Binary (${{ matrix.os }})
11+
runs-on: ${{ matrix.os }}
12+
strategy:
13+
fail-fast: false
14+
matrix:
15+
include:
16+
- os: ubuntu-latest
17+
arch: x64-linux
18+
spc_suffix: linux-x86_64.tar.gz
19+
- os: macos-latest
20+
arch: x64-darwin
21+
spc_suffix: macos-x86_64.tar.gz
22+
- os: macos-14
23+
arch: arm64-darwin
24+
spc_suffix: macos-aarch64.tar.gz
25+
- os: windows-latest
26+
arch: x64-win32
27+
spc_suffix: windows-x86_64.zip
28+
steps:
29+
- name: Checkout code
30+
uses: actions/checkout@v4
31+
32+
- name: Setup PHP
33+
uses: shivammathur/setup-php@v2
34+
with:
35+
php-version: "8.2"
36+
extensions: bcmath,calendar,ctype,curl,dba,dom,exif,fileinfo,filter,iconv,mbregex,mbstring,openssl,pcntl,pdo_mysql,pdo_sqlite,pdo,phar,posix,readline,session,simplexml,sockets,sodium,sqlite3,tokenizer,xml,xmlreader,xmlwriter,zip,zlib
37+
38+
- name: Get the version
39+
id: get_version
40+
run: echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
41+
42+
- name: Install dependencies
43+
run: |
44+
composer install --prefer-dist --no-progress --no-dev
45+
46+
- name: Install SPC
47+
run: |
48+
mkdir -p bin
49+
wget "https://github.com/crazywhalecc/static-php-cli/releases/latest/download/spc-${{ matrix.spc_suffix }}"
50+
tar xzf "spc-${{ matrix.spc_suffix }}"
51+
chmod +x ./spc
52+
./spc --version
53+
54+
- name: Build binary
55+
run: |
56+
php php-parser compile-binary --arch=${{ matrix.arch }}
57+
58+
- name: Upload binary as artifact
59+
uses: actions/upload-artifact@v4
60+
with:
61+
name: php-parser-${{ env.VERSION }}-${{ matrix.arch }}
62+
path: bin/php-parser-${{ env.VERSION }}-${{ matrix.arch }}
63+
64+
- name: Create Release
65+
uses: softprops/action-gh-release@v1
66+
if: startsWith(github.ref, 'refs/tags/')
67+
with:
68+
files: |
69+
bin/php-parser-${{ env.VERSION }}-${{ matrix.arch }}
70+
env:
71+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

app/Commands/CompileBinaryCommand.php

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,30 @@
66
use Illuminate\Support\Facades\Process;
77
use LaravelZero\Framework\Commands\Command;
88

9-
use function Laravel\Prompts\confirm;
109
use function Laravel\Prompts\info;
1110

1211
class CompileBinaryCommand extends Command
1312
{
14-
protected $signature = 'compile-binary';
13+
protected $signature = 'compile-binary {--arch=}';
1514

1615
protected $description = 'Compile the binary for the current version';
1716

1817
public function handle(): void
1918
{
19+
set_time_limit(300);
20+
2021
$version = File::json(base_path('composer.json'))['version'];
2122

2223
info("Compiling binary for version {$version}");
2324

24-
$destination = base_path('bin/php-parser-' . $version);
25+
$destination = base_path(
26+
sprintf('bin/php-parser-%s-%s', $version, $this->option('arch'))
27+
);
2528

26-
if (File::exists($destination)) {
27-
if (!confirm('The binary already exists. Do you want to overwrite it?', false)) {
28-
return;
29-
}
30-
} else {
31-
confirm('Continue?', true);
29+
if (file_exists(base_path('.env'))) {
30+
exec('mv ' . base_path('.env') . ' ' . base_path('.env.bak'));
3231
}
3332

34-
exec('mv ' . base_path('.env') . ' ' . base_path('.env.bak'));
35-
3633
file_put_contents(base_path('.env'), '');
3734

3835
exec('composer install --no-dev');
@@ -79,26 +76,15 @@ public function handle(): void
7976
sprintf('%s build --build-micro --build-cli "%s"', $spc, $extensions),
8077
sprintf('%s micro:combine %s -O %s', $spc, base_path('builds/php-parser'), $destination),
8178
])->each(function (string $command) {
82-
Process::run($command, function (string $type, string $output) {
79+
Process::timeout(300)->run($command, function (string $type, string $output) {
8380
echo $output;
8481
});
8582
});
8683

87-
exec('mv ' . base_path('.env.bak') . ' ' . base_path('.env'));
88-
exec('composer install');
84+
if (file_exists(base_path('.env.bak'))) {
85+
exec('mv ' . base_path('.env.bak') . ' ' . base_path('.env'));
86+
}
8987

9088
info("Binary compiled successfully at {$destination}");
91-
92-
// if [[ $(git status --porcelain) ]]; then
93-
// git add builds/php-parser
94-
// git commit -m "Release $version"
95-
// git push
96-
// fi
97-
98-
// git push
99-
// git tag -a $version -m "$version"
100-
// git push --tags
101-
// echo "\n"
102-
// $this->line("https://github.com/laravel/vs-code-php-parser/releases");
10389
}
10490
}

0 commit comments

Comments
 (0)