Skip to content

Commit

Permalink
Bundle PHP with builds
Browse files Browse the repository at this point in the history
  • Loading branch information
joecampo committed Mar 15, 2023
1 parent 70f600d commit dee0fff
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
/.reaol
/storage/*
/builds/logs
/packagers
.phpunit.result.cache
/database/database.sqlite
27 changes: 27 additions & 0 deletions app/Commands/Package.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace App\Commands;

use Illuminate\Support\Facades\Process;
use LaravelZero\Framework\Commands\Command;

class Package extends Command
{
protected $signature = 'package';

protected $description = 'Bundle PHP with release for each operating system.';

protected array $packagers = [
'macos' => '/packagers/macos-micro-cli.sfx',
'linux' => '/packagers/linux-micro-cli.sfx',
];

public function handle()
{
$build = base_path().'/builds/p3ol';

collect($this->packagers)->each(function (string $packager, string $os) use ($build) {
Process::run('cat '.base_path().$packager.' '.$build.' > '.base_path().'/builds/'.$os.'/p3ol');
});
}
}
23 changes: 23 additions & 0 deletions app/Updaters/GithubStrategy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace App\Updaters;

use LaravelZero\Framework\Components\Updater\Strategy\StrategyInterface;
use Phar;

class GithubStrategy extends \Humbug\SelfUpdate\Strategy\GithubStrategy implements StrategyInterface
{
protected function getDownloadUrl(array $package): string
{
$downloadUrl = parent::getDownloadUrl($package);

$downloadUrl = str_replace('releases/download', 'raw', $downloadUrl);

$os = match (true) {
str_contains(php_uname(), 'Darwin') => 'macos',
default => 'linux'
};

return $downloadUrl.'/builds/'.$os.'/'.basename(Phar::running());
}
}
Binary file added builds/linux/p3ol
Binary file not shown.
Binary file added builds/macos/p3ol
Binary file not shown.
1 change: 1 addition & 0 deletions config/commands.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
Illuminate\Console\Scheduling\ScheduleListCommand::class,
Illuminate\Console\Scheduling\ScheduleFinishCommand::class,
LaravelZero\Framework\Commands\StubPublishCommand::class,
Illuminate\Foundation\Console\VendorPublishCommand::class,
],

/*
Expand Down
20 changes: 20 additions & 0 deletions config/updater.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

use App\Updaters\GithubStrategy;

return [

/*
|--------------------------------------------------------------------------
| Self-updater Strategy
|--------------------------------------------------------------------------
|
| Here you may specify which update strategy class you wish to use when
| updating your application via the "self-update" command. This must
| be a class that implements the StrategyInterface from Humbug.
|
*/

'strategy' => GithubStrategy::class,

];
2 changes: 1 addition & 1 deletion install.sh → install-linux.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/sh
link="https://github.com/p3/p3ol-cli/raw/main/builds/p3ol"
link="https://github.com/p3/p3ol-cli/raw/main/builds/linux/p3ol"
curl --fail -OL "$link"
if [ $? -ne 0 ]; then
exit 1
Expand Down
8 changes: 8 additions & 0 deletions install-macos.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/sh
link="https://github.com/p3/p3ol-cli/raw/main/builds/macos/p3ol"
curl --fail -OL "$link"
if [ $? -ne 0 ]; then
exit 1
fi

chmod 744 p3ol

0 comments on commit dee0fff

Please sign in to comment.