diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 80f073a..21bb211 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -28,3 +28,18 @@ jobs: - uses: ramsey/composer-install@v3 - run: vendor/bin/phpstan analyse --error-format=github + + box: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v5 + with: + fetch-depth: 0 + + - uses: shivammathur/setup-php@v2 + with: + php-version: '8.4' + coverage: none + tools: box:4 + + - run: box validate diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3f0fe1b..655f03b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -54,31 +54,29 @@ jobs: files: coverage-unit.xml flags: unit - bin: - runs-on: ubuntu-latest - env: - GOFLAGS: '-mod=mod' + phar: + runs-on: ubuntu-24.04 + outputs: + php-version: ${{ steps.setup-php.outputs.php-version }} steps: - uses: actions/checkout@v5 + with: + fetch-depth: 0 - uses: shivammathur/setup-php@v2 + id: setup-php with: php-version: '8.4' coverage: none + tools: box:4 - uses: ramsey/composer-install@v3 with: - composer-options: '--no-dev --prefer-dist' + composer-options: --no-dev --prefer-dist - - name: Add bin into PATH - run: echo "${WORKSPACE}/bin" >> "$GITHUB_PATH" - env: - WORKSPACE: ${{ github.workspace }} + - run: box compile - - uses: actions/setup-go@v6 + - uses: actions/upload-artifact@v4 with: - go-version-file: 'go.mod' - - - name: Print php-matrix binary path - run: go test -count=1 -v ./internal - - - run: go test -count=1 ./... + name: php-matrix.phar + path: phar/php-matrix + if-no-files-found: error diff --git a/.gitignore b/.gitignore index f273821..0efb0b6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,8 @@ +# Composer /vendor/ + +# Pest /coverage*.xml + +# Box +/phar/ diff --git a/Makefile b/Makefile index 78353c9..39bbc62 100644 --- a/Makefile +++ b/Makefile @@ -10,6 +10,12 @@ vendor: bin: vendor +phar: vendor + box compile + box verify phar/php-matrix + box info phar/php-matrix + php phar/php-matrix --version + test-%: % PATH="$(shell pwd)/$*:$(shell echo $$PATH)" \ go test -count=1 ./... diff --git a/README.md b/README.md index ebf885f..912163b 100644 --- a/README.md +++ b/README.md @@ -95,20 +95,7 @@ Available sources: ## Installation -### Composer Global - -```bash -composer global require typisttech/php-matrix -php-matrix --help -``` - -### Composer Project - -```bash -composer create-project typisttech/php-matrix -cd php-matrix -./bin/php-matrix --help -``` +TODO! ## Credits diff --git a/bin/php-matrix b/bin/php-matrix index 5550ca7..2afd634 100755 --- a/bin/php-matrix +++ b/bin/php-matrix @@ -3,9 +3,19 @@ declare(strict_types=1); -use TypistTech\PhpMatrix\Console\Application; +namespace TypistTech\PhpMatrix; -include $_composer_autoload_path ?? __DIR__.'/../vendor/autoload.php'; +use TypistTech\PhpMatrix\Console\Runner; +use function in_array; +use const PHP_EOL; +use const PHP_SAPI; -Application::make() - ->run(); +// Taken from https://box-project.github.io/box/faq/#what-is-the-canonical-way-to-write-a-cli-entry-file +if (!in_array(PHP_SAPI, ['micro', 'cli', 'phpdbg', 'embed'], true)) { + echo PHP_EOL . 'This app may only be invoked from a command line, got "' . PHP_SAPI . '"' . PHP_EOL; + exit(1); +} + +include $_composer_autoload_path ?? __DIR__ . '/../vendor/autoload.php'; + +Runner::run(); diff --git a/box.json b/box.json new file mode 100644 index 0000000..fa88d86 --- /dev/null +++ b/box.json @@ -0,0 +1,10 @@ +{ + "output": "phar/php-matrix", + "check-requirements": false, + "files-bin": [ + "data/all-versions.json" + ], + "datetime": "datetime", + "datetime-format": "Y-m-d", + "git-tag": "git-tag" +} diff --git a/composer.json b/composer.json index 2a4545c..b6140ef 100644 --- a/composer.json +++ b/composer.json @@ -64,6 +64,7 @@ }, "scripts": { "lint": [ + "box validate", "pint --test", "phpstan analyse" ], diff --git a/src/Console/Application.php b/src/Console/Application.php index 135f11c..a935eba 100644 --- a/src/Console/Application.php +++ b/src/Console/Application.php @@ -4,25 +4,107 @@ namespace TypistTech\PhpMatrix\Console; -use Composer\InstalledVersions; -use Symfony\Component\Console\Application as ConsoleApplication; +use Symfony\Component\Console\Application as SymfonyConsoleApplication; +use Symfony\Component\Console\Helper\FormatterHelper; -class Application +class Application extends SymfonyConsoleApplication { - private const string NAME = 'php-matrix'; + private const BANNER = << < + |_| |_| |_|_| |_| |_|\__,_|\__|_| |_/_/\_\ + BANNER; - public static function make(): ConsoleApplication + public const BUILD_TIMESTAMP = '@datetime@'; + + public function getLongVersion(): string { - $app = new ConsoleApplication( - self::NAME, - InstalledVersions::getPrettyVersion('typisttech/php-matrix') ?? 'unknown', + $longVersion = self::BANNER; + $longVersion .= PHP_EOL.PHP_EOL; + + $app = sprintf( + '%-15s %s %s', + $this->getName(), + $this->getVersion(), + self::BUILD_TIMESTAMP, + ); + $longVersion .= $app; + + $githubUrl = sprintf( + 'https://github.com/typisttech/php-matrix/releases/tag/%1$s', + $this->getVersion(), + ); + // https://github.com/box-project/box/blob/b0123f358f2a32488c92e09bf56f16d185e4e3cb/src/Configuration/Configuration.php#L2116 + if ((bool) preg_match('/^(?.+)-\d+-g(?[a-f0-9]{7})$/', $this->getVersion(), $matches)) { + // Not on a tag. + $githubUrl = sprintf( + 'https://github.com/typisttech/php-matrix/compare/%1$s...%2$s', + $matches['tag'], + $matches['hash'], + ); + } + $longVersion .= PHP_EOL.$githubUrl; + + $longVersion .= PHP_EOL.PHP_EOL.'PHP:'; + + $phpVersion = sprintf( + '%-15s %s', + 'Version', + PHP_VERSION, + ); + $longVersion .= PHP_EOL.$phpVersion; + + $phpSapi = sprintf( + '%-15s %s', + 'SAPI', + PHP_SAPI, + ); + $longVersion .= PHP_EOL.$phpSapi; + + $longVersion .= PHP_EOL.PHP_EOL.'Support Composer SemVer:'; + + $supportBlock = (new FormatterHelper) + ->formatBlock( + [ + 'If you find this tool useful, please consider supporting its development.', + 'Every contribution counts, regardless how big or small.', + 'I am eternally grateful to all sponsors who fund my open source journey.', + ], + 'question', + true, + ); + $longVersion .= PHP_EOL.$supportBlock; + + $sponsorUrl = sprintf( + '%1$-15s %2$s', + 'GitHub Sponsor', + 'https://github.com/sponsors/tangrufus', ); + $longVersion .= PHP_EOL.PHP_EOL.$sponsorUrl; + + $longVersion .= PHP_EOL.PHP_EOL.'Hire Tang Rufus:'; - $app->addCommands([ - new ComposerCommand, - new ConstraintCommand, - ]); + $hireBlock = (new FormatterHelper) + ->formatBlock( + [ + 'I am looking for my next role, freelance or full-time.', + 'If you find this tool useful, I can build you more weird stuffs like this.', + "Let's talk if you are hiring PHP / Ruby / Go developers.", + ], + 'error', + true, + ); + $longVersion .= PHP_EOL.$hireBlock; + + $sponsorUrl = sprintf( + '%1$-15s %2$s', + 'Contact', + 'https://typist.tech/contact/', + ); + $longVersion .= PHP_EOL.PHP_EOL.$sponsorUrl; - return $app; + return $longVersion; } } diff --git a/src/Console/Runner.php b/src/Console/Runner.php new file mode 100644 index 0000000..7910df1 --- /dev/null +++ b/src/Console/Runner.php @@ -0,0 +1,24 @@ +addCommands([ + new ComposerCommand, + new ConstraintCommand, + ]); + + return $app->run(); + } +}