Skip to content

Commit 40cb4fe

Browse files
committed
Build .phar with GitHub Actions
1 parent 2399a35 commit 40cb4fe

File tree

3 files changed

+55
-4
lines changed

3 files changed

+55
-4
lines changed

.github/workflows/ci.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,45 @@ jobs:
4747
# run: |
4848
# wget http://psvcg.coreteks.org/php-semver-checker-git.phar
4949
# php php-semver-checker-git.phar suggest -vvv
50+
51+
phar:
52+
runs-on: ubuntu-latest
53+
name: Build PHAR
54+
if: startsWith(github.ref, 'refs/tags/')
55+
56+
steps:
57+
- name: Checkout code
58+
uses: actions/checkout@v3
59+
with:
60+
fetch-depth: 0
61+
62+
- name: Setup PHP
63+
uses: shivammathur/setup-php@v2
64+
with:
65+
php-version: 8.4
66+
tools: composer:v2
67+
68+
- name: Install dependencies
69+
run: composer install --prefer-dist --no-interaction --no-progress
70+
71+
- name: Install Box
72+
run: |
73+
wget https://github.com/box-project/box/releases/latest/download/box.phar
74+
chmod +x box.phar
75+
sudo mv box.phar /usr/local/bin/box
76+
77+
- name: Build PHAR
78+
run: box compile
79+
80+
- name: Upload PHAR artifact
81+
uses: actions/upload-artifact@v5
82+
with:
83+
name: php-semver-checker-phar
84+
path: php-semver-checker.phar
85+
86+
- name: Create Release
87+
uses: softprops/action-gh-release@v1
88+
with:
89+
files: php-semver-checker.phar
90+
env:
91+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

box.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"alias": "php-semver-checker.phar",
3-
"compactors": ["Herrera\\Box\\Compactor\\Php"],
4-
"compression": "GZ",
3+
"compactors": ["KevinGH\\Box\\Compactor\\Php"],
4+
"compression": "BZ2",
55
"directories": ["src"],
66
"files": ["LICENSE"],
77
"finder": [
@@ -11,7 +11,7 @@
1111
"in": "vendor"
1212
}
1313
],
14-
"git-version": "package_version",
14+
"git-tag": "package_version",
1515
"main": "bin/php-semver-checker",
1616
"output": "php-semver-checker.phar",
1717
"stub": true

src/PHPSemVerChecker/Console/Application.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
use PHPSemVerChecker\Console\Command\CompareCommand;
77
use Symfony\Component\Console\Application as SymfonyApplication;
8+
use Symfony\Component\Console\Command\HelpCommand;
9+
use Symfony\Component\Console\Command\ListCommand;
810

911
class Application extends SymfonyApplication
1012
{
@@ -39,7 +41,14 @@ public function getHelp(): string
3941
*/
4042
protected function getDefaultCommands(): array
4143
{
42-
$commands = parent::getDefaultCommands();
44+
// When running from PHAR, manually build command list without completion command
45+
// as it tries to use DirectoryIterator which doesn't work in PHAR context
46+
if (\Phar::running()) {
47+
$commands = [new HelpCommand(), new ListCommand()];
48+
} else {
49+
$commands = parent::getDefaultCommands();
50+
}
51+
4352
$commands[] = $this->add(new CompareCommand());
4453
return $commands;
4554
}

0 commit comments

Comments
 (0)