diff --git a/.changes/9.5.0.md b/.changes/9.5.0.md new file mode 100644 index 00000000..23fed13f --- /dev/null +++ b/.changes/9.5.0.md @@ -0,0 +1,13 @@ + +## 9.5.0 - 2024-10-08 + +### Changed + +- drop support to PHP 8.1 +- [#213](https://github.com/overtrue/phplint/issues/213) : Get application version from Composer Runtime API + +### Fixed + +- [#192](https://github.com/overtrue/phplint/issues/192) : The "-x" option does not exist. + +**Full Changelog**: [9.4.1...9.5.0](https://github.com/overtrue/phplint/compare/9.4.1...9.5.0) diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index a53624a7..86bfecf8 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -107,7 +107,7 @@ jobs: - # https://github.com/actions/download-artifact name: Retrieve PHPBench baseline results - uses: actions/download-artifact@v3 + uses: actions/download-artifact@v4.1.7 with: name: "PHPBench-Baseline" path: ".phpbench/" diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index f65daabe..fdc2356c 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -24,21 +24,21 @@ jobs: - # https://github.com/actions/checkout name: Checkout code uses: actions/checkout@v4 - - + - # https://github.com/docker/setup-qemu-action name: Set up QEMU - uses: docker/setup-qemu-action@v2 - - + uses: docker/setup-qemu-action@v3 + - # https://github.com/docker/setup-buildx-action name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 - - + uses: docker/setup-buildx-action@v3 + - # https://github.com/docker/login-action name: Login to DockerHub - uses: docker/login-action@v2 + uses: docker/login-action@v3 with: username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} - - + - # https://github.com/docker/build-push-action name: Build and push Docker images - uses: docker/build-push-action@v3 + uses: docker/build-push-action@v6 with: push: true tags: overtrue/phplint:${{ env.DOCKER_BUILD_TAG }} diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 54493471..d554b12f 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -16,11 +16,9 @@ jobs: matrix: operating-system: - - "ubuntu-20.04" - "ubuntu-22.04" php-version: - - "8.1" - "8.2" - "8.3" @@ -30,12 +28,11 @@ jobs: uses: actions/checkout@v4 - # https://github.com/shivammathur/setup-php - name: Setup PHP runtime for PHPUnit 10 + name: Setup PHP runtime uses: shivammathur/setup-php@v2 with: php-version: "${{ matrix.php-version }}" coverage: "none" - tools: phpunit:10.5 - # https://github.com/ramsey/composer-install name: Install Composer dependencies @@ -45,4 +42,4 @@ jobs: - # https://github.com/sebastianbergmann/phpunit/tree/10.5 name: Unit tests with PHPUnit 10 - run: phpunit --no-progress --testdox --do-not-cache-result + run: vendor/bin/phpunit --no-progress --testdox --do-not-cache-result diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 9312e41a..49c4f26e 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -49,19 +49,18 @@ jobs: composer-options: "--prefer-dist" - # https://github.com/llaville/box-manifest - name: Download BOX Manifest Artifact - run: | - curl -Ls https://github.com/llaville/box-manifest/releases/latest/download/box-manifest.phar -o /usr/local/bin/box-manifest - chmod +x /usr/local/bin/box-manifest + name: Download BOX Manifest Artifact + env: + BOX_MANIFEST_VERSION: "4.0.0" + run: | + curl -Ls "https://github.com/llaville/box-manifest/releases/download/$BOX_MANIFEST_VERSION/box-manifest.phar" -o /usr/local/bin/box-manifest + chmod +x /usr/local/bin/box-manifest - # https://github.com/llaville/box-manifest - name: Build Release Artifact - run: | - box-manifest manifest:build --ansi -vv -c box.json --output-file=sbom.json - box-manifest manifest:build --ansi -vv -c box.json --output-file=console.txt --format console - box-manifest manifest:stub --ansi -vv -c box.json --output-file=stub.php --resource console.txt --resource sbom.json - box compile --ansi -vv -c box.json.dist - box info --ansi ${{ github.workspace }}/bin/phplint.phar + name: Build Release Artifact + run: | + box-manifest make build stub configure -r console-table.txt -r plain.txt -r sbom.json --output-stub stub.php --output-conf box.json.dist -vvv --ansi + box compile -c box.json.dist -vvv --ansi - # https://github.com/softprops/action-gh-release name: Create Release from current tag diff --git a/.gitignore b/.gitignore index 1e07ad01..9db486fe 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,9 @@ composer.lock .php-cs-fixer.cache /vendor-bin/**/vendor .phpbench/ -site/ \ No newline at end of file +site/ +.box.manifests.bin +console-table.txt +plain.txt +sbom.json +stub.php diff --git a/.php-cs-fixer.release.php b/.php-cs-fixer.release.php deleted file mode 100644 index e0743c18..00000000 --- a/.php-cs-fixer.release.php +++ /dev/null @@ -1,18 +0,0 @@ -registerCustomFixers([ - new ApplicationVersionFixer(), - ]) - ->setRules([ - ApplicationVersionFixer::name() => true, - ]) - ->setFinder( - PhpCsFixer\Finder::create() - ->in([__DIR__.'/src/Console']) - ) -; diff --git a/CHANGELOG.md b/CHANGELOG.md index fb84b62a..a275aaad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,19 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html), and is generated by [Changie](https://github.com/miniscruff/changie). +## 9.5.0 - 2024-10-08 + +### Changed + +- drop support to PHP 8.1 +- [#213](https://github.com/overtrue/phplint/issues/213) : Get application version from Composer Runtime API + +### Fixed + +- [#192](https://github.com/overtrue/phplint/issues/192) : The "-x" option does not exist. + +**Full Changelog**: [9.4.1...9.5.0](https://github.com/overtrue/phplint/compare/9.4.1...9.5.0) + ## 9.4.1 - 2024-07-05 > [!NOTE] diff --git a/Dockerfile b/Dockerfile index d084dd07..22a9f6e5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,6 +7,11 @@ COPY entrypoint.sh /entrypoint.sh RUN chmod +x /entrypoint.sh RUN cp /usr/local/etc/php/php.ini-development /usr/local/etc/php/php.ini +# Default container directory where to mount your project source files +# GitLab uses $CI_PROJECT_DIR to identify where job runs on source files +# GitHub uses $GITHUB_WORKSPACE to identify where job runs on source files +RUN mkdir /workdir + # Create a group and user RUN addgroup appgroup && adduser appuser -D -G appgroup @@ -16,7 +21,7 @@ USER appuser # Install Composer v2 then overtrue/phplint package COPY --from=composer/composer:2-bin /composer /usr/bin/composer ENV COMPOSER_ALLOW_SUPERUSER 1 -RUN composer global require --no-progress overtrue/phplint 9.4.x-dev +RUN composer global require --no-progress overtrue/phplint 9.5.x-dev # Following recommendation at https://docs.github.com/en/actions/creating-actions/dockerfile-support-for-github-actions#workdir diff --git a/README.md b/README.md index 20a119a7..d2917e73 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,7 @@ | Version | Status | Requirements | |:--------|:------------------------------------------|:---------------| | **9.x** | **Active development** | **PHP >= 8.1** | +| 9.5 | Active support | PHP >= 8.2 | | 9.4 | Active support | PHP >= 8.1 | | 9.3 | Active support | PHP >= 8.1 | | 9.2 | Active support | PHP >= 8.1 | diff --git a/box.json b/box.json index c5d8c2d7..3abdddbb 100644 --- a/box.json +++ b/box.json @@ -10,6 +10,10 @@ "with this source code in the file LICENSE." ], "force-autodiscovery": true, + "dump-autoload": true, "exclude-dev-files": false, - "files": ["autoload.php", "phplint.php"] + "files": [ + "autoload.php", + "phplint.php" + ] } diff --git a/box.json.dist b/box.json.dist index 563e4c5f..b707158b 100644 --- a/box.json.dist +++ b/box.json.dist @@ -10,12 +10,28 @@ "with this source code in the file LICENSE." ], "force-autodiscovery": true, + "dump-autoload": true, "exclude-dev-files": false, - "files": ["autoload.php", "phplint.php"], - "stub": "stub.php", - "files-bin": ["sbom.json", "console.txt"], + "files": [ + "autoload.php", + "phplint.php" + ], + "files-bin": [ + "console-table.txt", + "plain.txt", + "sbom.json", + ".box.manifests.bin" + ], "map": [ - { "console.txt": ".box.manifests/console.txt" }, - { "sbom.json": ".box.manifests/sbom.json" } - ] + { + "console-table.txt": ".box.manifests/console-table.txt" + }, + { + "plain.txt": ".box.manifests/plain.txt" + }, + { + "sbom.json": ".box.manifests/sbom.json" + } + ], + "stub": "stub.php" } diff --git a/composer.json b/composer.json index 7d7b9cfa..65d39905 100644 --- a/composer.json +++ b/composer.json @@ -21,17 +21,18 @@ } ], "require": { - "php": "^8.1", + "php": "^8.2", "ext-dom": "*", "ext-json": "*", "ext-mbstring": "*", - "symfony/cache": "^6.4 || ^7.0", - "symfony/console": "^6.4 || ^7.0", - "symfony/event-dispatcher": "^6.4 || ^7.0", - "symfony/finder": "^6.4 || ^7.0", - "symfony/options-resolver": "^6.4 || ^7.0", - "symfony/process": "^6.4 || ^7.0", - "symfony/yaml": "^6.4 || ^7.0" + "composer-runtime-api": "^2.0", + "symfony/cache": "^7.0", + "symfony/console": "^7.0", + "symfony/event-dispatcher": "^7.0", + "symfony/finder": "^7.0", + "symfony/options-resolver": "^7.0", + "symfony/process": "^7.0", + "symfony/yaml": "^7.0" }, "require-dev": { "php-parallel-lint/php-console-highlighter": "^1.0", @@ -59,13 +60,10 @@ "pre-commit": [ "composer style:fix", "composer code:check" - ], - "pre-push": [ - "composer qa:check" ] }, "branch-alias": { - "dev-main": "9.4.x-dev" + "dev-main": "9.5.x-dev" } }, "scripts": { @@ -81,8 +79,6 @@ "@composer bin all install --ansi" ], "cghooks": "vendor/bin/cghooks", - "qa:check": "vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.release.php --using-cache=no --verbose --ansi --diff --dry-run", - "qa:fix": "vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.release.php --using-cache=no --verbose --ansi", "style:check": "vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.dist.php --using-cache=no --verbose --ansi --diff --dry-run", "style:fix": "vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.dist.php --using-cache=no --verbose --ansi", "tests:unit": "vendor/bin/phpunit --testsuite=cache,configuration,finder", @@ -94,8 +90,6 @@ "minimum-stability": "dev", "prefer-stable": true, "scripts-descriptions": { - "qa:check": "Run QA style checks before pushing new tag and releasing a new version (only dry run - no fixing!).", - "qa:fix": "Run QA style checks and fix violations.", "style:check": "Run style checks (only dry run - no fixing!).", "style:fix": "Run style checks and fix violations.", "tests:unit": "Run unit tests on following components: cache, configuration, finder", diff --git a/docs/installation.md b/docs/installation.md index d48af523..2bcd2f06 100644 --- a/docs/installation.md +++ b/docs/installation.md @@ -48,7 +48,7 @@ You can also install `phplint` locally to your project with [Phive][phive] and c ```xml - + ``` @@ -61,7 +61,7 @@ phive install --force-accept-unsigned You can install `phplint` with [Composer][composer] ```shell -composer global require overtrue/phplint +composer global require overtrue/phplint ^9.5 ``` If you cannot install it because of a dependency conflict, or you prefer to install it for your project, we recommend diff --git a/docs/usage/github-actions.md b/docs/usage/github-actions.md index f280c3bc..5dc09b4f 100644 --- a/docs/usage/github-actions.md +++ b/docs/usage/github-actions.md @@ -36,11 +36,9 @@ jobs: matrix: operating-system: - - "ubuntu-20.04" - "ubuntu-22.04" php-version: - - "8.1" - "8.2" - "8.3" diff --git a/entrypoint.sh b/entrypoint.sh index 9e10dbcb..2b4dea5e 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -3,12 +3,24 @@ [ "$APP_DEBUG" == 'true' ] && set -x set -e -composer_global_home="/home/$(id -u -n)/.composer" +if [ ! -z ${GITHUB_WORKSPACE} ]; then + APP_WORKSPACE=$GITHUB_WORKSPACE +elif [ ! -z ${CI_PROJECT_DIR} ]; then + APP_WORKSPACE=$CI_PROJECT_DIR +else + APP_WORKSPACE="/workdir" +fi + +COMPOSER_HOME="/home/$(id -u -n)/.composer" if [ "$APP_DEBUG" == 'true' ] then echo "> You will act as user: $(id -u -n)" - echo "> Path to Composer home dir: ${composer_global_home}" + echo "> Your project source directory : $(ls -al $APP_WORKSPACE)" fi -"${composer_global_home}/vendor/bin/phplint" $@ +if [ ! -z ${INPUT_PATH} ]; then + sh -c "cd $APP_WORKSPACE; $COMPOSER_HOME/vendor/bin/phplint ${INPUT_PATH} ${INPUT_OPTIONS}" +else + sh -c "cd $APP_WORKSPACE; $COMPOSER_HOME/vendor/bin/phplint $*" +fi diff --git a/src/Console/Application.php b/src/Console/Application.php index 6e64b5d4..341013b2 100644 --- a/src/Console/Application.php +++ b/src/Console/Application.php @@ -13,6 +13,8 @@ namespace Overtrue\PHPLint\Console; +use Composer\InstalledVersions; +use OutOfBoundsException; use Overtrue\PHPLint\Helper\DebugFormatterHelper; use Overtrue\PHPLint\Helper\ProcessHelper; use Overtrue\PHPLint\Output\ConsoleOutput; @@ -26,6 +28,7 @@ use function array_keys; use function in_array; +use function sprintf; use const STDOUT; @@ -36,11 +39,12 @@ final class Application extends BaseApplication { public const NAME = 'phplint'; - public const VERSION = '9.4.1'; + + private const PACKAGE_NAME = 'overtrue/phplint'; public function __construct() { - parent::__construct(self::NAME, self::VERSION); + parent::__construct(self::NAME, self::getPrettyVersion()); } public function run(InputInterface $input = null, OutputInterface $output = null): int @@ -69,4 +73,33 @@ protected function getCommandName(InputInterface $input): ?string $name = parent::getCommandName($input); return in_array($name, array_keys(parent::all())) ? $name : null; } + + private static function getPrettyVersion(): string + { + foreach (InstalledVersions::getAllRawData() as $installed) { + if (!isset($installed['versions'][self::PACKAGE_NAME])) { + continue; + } + + $version = $installed['versions'][self::PACKAGE_NAME]['pretty_version'] + ?? $installed['versions'][self::PACKAGE_NAME]['version'] + ?? 'dev' + ; + + $aliases = $installed['versions'][self::PACKAGE_NAME]['aliases'] ?? []; + + $reference = $installed['versions'][self::PACKAGE_NAME]['reference']; + if (null === $reference) { + return sprintf('%s', $aliases[0] ?? $version); + } + + return sprintf( + '%s@%s', + $aliases[0] ?? $version, + substr($reference, 0, 7) + ); + } + + throw new OutOfBoundsException(sprintf('Package "%s" is not installed', self::PACKAGE_NAME)); + } } diff --git a/vendor-bin/php-cs-fixer/src/ApplicationVersionFixer.php b/vendor-bin/php-cs-fixer/src/ApplicationVersionFixer.php deleted file mode 100644 index 3b1bf0a7..00000000 --- a/vendor-bin/php-cs-fixer/src/ApplicationVersionFixer.php +++ /dev/null @@ -1,118 +0,0 @@ -isAllTokenKindsFound([T_CLASS, T_CONSTANT_ENCAPSED_STRING]); - } - - /** - * @inheritDoc - */ - public function isRisky(): bool - { - return false; - } - - protected function applyFix(SplFileInfo $file, Tokens $tokens): void - { - foreach ($tokens as $index => $token) { - if (!$token->isGivenKind(T_CONSTANT_ENCAPSED_STRING)) { - continue; - } - if (!$this->isVersionConst($tokens, $index)) { - continue; - } - - $tag = @exec('git describe --tags --abbrev=0 2>&1'); - - if ($token->getContent() !== $tag) { - $tokens[$index] = new Token([$token->getId(), "'$tag'"]); - } - } - } - - private function isVersionConst(Tokens $tokens, int $index): bool - { - $prevTokenIndex = $tokens->getPrevMeaningfulToken($index); - if (!$tokens[$prevTokenIndex]->equals('=')) { - return false; - } - - $constantNamePosition = $tokens->getPrevMeaningfulToken($prevTokenIndex); - return $tokens[$constantNamePosition]->equals([T_STRING, 'VERSION']); - } - - /** - * @inheritDoc - */ - public function getDefinition(): FixerDefinitionInterface - { - return new FixerDefinition( - 'Application::VERSION constant value must match the current git tag.', - [] - ); - } - - /** - * @inheritDoc - */ - public function getName(): string - { - return self::name(); - } - - public static function name(): string - { - return 'OvertrueCsFixer/application_version'; - } - - /** - * @inheritDoc - */ - public function supports(SplFileInfo $file): bool - { - return $file->getBasename() === 'Application.php'; - } - - /** - * @inheritDoc - */ - public function getPriority(): int - { - return 0; - } -}