diff --git a/.docker/php/Dockerfile b/.docker/php/Dockerfile index 856a489..2e197e3 100644 --- a/.docker/php/Dockerfile +++ b/.docker/php/Dockerfile @@ -8,6 +8,7 @@ ENV COMPOSER_NO_INTERACTION 1 ENV COMPOSER_VERSION 2.7.6 ENV DEBIAN_FRONTEND noninteractive ENV DOCKER_PHP_DEPS \ + gnupg \ libxml2-dev \ libzip-dev \ unzip @@ -26,6 +27,15 @@ RUN set -xe; \ curl -sS https://getcomposer.org/installer | php -- --filename=composer --install-dir=/usr/local/bin --version=${COMPOSER_VERSION} > /dev/null 2>&1 && \ chmod +x /usr/local/bin/composer +# Install PHIVE +RUN set -xe; \ + curl -sSL -o phive.phar https://phar.io/releases/phive.phar && \ + curl -sSL -o phive.phar.asc https://phar.io/releases/phive.phar.asc && \ + gpg --keyserver hkps://keys.openpgp.org --recv-keys 0x9D8A98B29B2D5D79 && \ + gpg --verify phive.phar.asc phive.phar && \ + chmod +x phive.phar && \ + mv phive.phar /usr/local/bin/phive + WORKDIR /app COPY composer.* ./ diff --git a/.editorconfig b/.editorconfig index c675e7d..94549ef 100644 --- a/.editorconfig +++ b/.editorconfig @@ -27,3 +27,6 @@ indent_size = 4 [composer.json] indent_style = space indent_size = 4 + +[.phive/trust-gpg-keys.txt] +insert_final_newline = false diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..017f52c --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,68 @@ +name: Release + +on: + release: + types: [ created ] + +# See https://stackoverflow.com/a/72408109 +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +jobs: + build-phar: + runs-on: ubuntu-latest + name: Build PHAR + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: 8.2 + ini-values: phar.readonly=0 + tools: composer + coverage: none + + - name: Install Composer dependencies + uses: ramsey/composer-install@v3 + with: + composer-options: '--no-dev' + + - name: Build PHAR + run: composer build + + # Smoke test. + # It is recommended ot have some sorts of tests for your PHAR. + #- name: Ensure the PHAR works + # run: pcsf-baseline.phar --version + + # The following section is done only for releases + - name: Import GPG key + if: github.event_name == 'release' + uses: crazy-max/ghaction-import-gpg@v5 + with: + gpg_private_key: ${{ secrets.GPG_KEY_83F9945BC33EC39E9710206C8B4927076BA50A83 }} + passphrase: "${{ secrets.GPG_KEY_83F9945BC33EC39E9710206C8B4927076BA50A83_PASSPHRASE }}" + + - name: Sign the PHAR + if: github.event_name == 'release' + run: | + gpg --local-user 83F9945BC33EC39E9710206C8B4927076BA50A83 \ + --batch \ + --yes \ + --passphrase="${{ secrets.GPG_KEY_83F9945BC33EC39E9710206C8B4927076BA50A83_PASSPHRASE }}" \ + --detach-sign \ + --output pcsf-baseline.phar.asc \ + pcsf-baseline.phar + + - name: Upload PHAR to the release + uses: softprops/action-gh-release@v2 + with: + token: ${{ secrets.GITHUB_TOKEN }} + files: | + pcsf-baseline.phar + pcsf-baseline.phar.asc diff --git a/.gitignore b/.gitignore index 6ec1b85..667073a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ .idea /.phpunit.cache/ +/tools/ /vendor/ /.php-cs-fixer.cache +pcsf-baseline.phar diff --git a/.phive/phars.xml b/.phive/phars.xml new file mode 100644 index 0000000..d45413c --- /dev/null +++ b/.phive/phars.xml @@ -0,0 +1,4 @@ + + + + diff --git a/.phive/trust-gpg-keys.txt b/.phive/trust-gpg-keys.txt new file mode 100644 index 0000000..687581e --- /dev/null +++ b/.phive/trust-gpg-keys.txt @@ -0,0 +1 @@ +2DF45277AEF09A2F \ No newline at end of file diff --git a/README.md b/README.md index c77aa37..5d313da 100644 --- a/README.md +++ b/README.md @@ -17,20 +17,31 @@ So, it's some work around till baseline will be implemented in the PHP CS Fixer. ```shell composer require --dev aeliot/php-cs-fixer-baseline ``` -2. Extract `Finder` from the config of PHP CS Fixer to the separate file. +2. Extract `Finder` from the config of PHP CS Fixer to the separate file. It expects `.php-cs-fixer-finder.php` at the root of the project. 3. Add filtering of files detected by Finder ```php + use Aeliot\PhpCsFixerBaseline\Service\FilterFactory; + $finder->filter((new FilterFactory())->createFilter(__DIR__ . '/.php-cs-fixer-baseline.json', $config)); ``` 4. Generate baseline. Just call script without options when all config files uses default names. ```shell - vendor/bin/pcsf-baseline + vendor/bin/pcsf-baseline ``` See options of it below. You can see how it is configured in this project. +### Autoload classes from PHAR + +If you use this project as PHAR file, you need to require autoloader of it to use provided filter. +Do it in the main config file of PHP CS Fixer (`.php-cs-fixer.dist.php`) +```php +Phar::loadPhar('/path/to/pcsf-baseline.phar', 'pcsf-baseline.phar'); +require_once 'phar://pcsf-baseline.phar/vendor/autoload.php'; +``` + ### Options of baseline generator | Short name | Long name | Description | Default value | @@ -39,5 +50,5 @@ You can see how it is configured in this project. | c | config | Name of config file | .php-cs-fixer.dist.php | | f | finder | Name of file with definition of Finder | .php-cs-fixer-finder.php | -Path to files can be absolute or related or omitted at all. It the last case it is expected that files +Path to files can be absolute or related or omitted at all. It the last case it is expected that files in the root directory of project. diff --git a/bin/pcsf-baseline b/bin/pcsf-baseline index 869753d..7c10816 100644 --- a/bin/pcsf-baseline +++ b/bin/pcsf-baseline @@ -1,10 +1,16 @@ #!/usr/bin/env php