Skip to content

Commit

Permalink
Add compatibility with Composer v2.3
Browse files Browse the repository at this point in the history
- rewrite production autoload for compat with Composer v2.3
- refresh QA
  • Loading branch information
gmazzap committed Mar 30, 2022
1 parent ff31830 commit 6caeffe
Show file tree
Hide file tree
Showing 16 changed files with 150 additions and 103 deletions.
127 changes: 69 additions & 58 deletions .github/workflows/qa.yml
Original file line number Diff line number Diff line change
@@ -1,72 +1,83 @@
name: Quality Assurance
on: [push, pull_request]
jobs:

cross_version:
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, 'ci skip')"

strategy:
matrix:
php: [ '7.3', '7.4' ]
tools: [ 'composer:v2', 'composer:v1' ]
prefer: [ 'lowest', 'highest' ]
ignore-platform: [ '' ]
experimental: [ false ]
include:
- php: "8.0"
prefer: "highest"
ignore-platform: "--ignore-platform-reqs"
experimental: true
tools: "composer:v2"
- php: "8.0"
prefer: "highest"
ignore-platform: "--ignore-platform-reqs"
experimental: true
tools: "composer:v1"
on:
push:
pull_request:
workflow_dispatch:
inputs:
skip-jobs:
required: true
type: choice
default: 'Run all'
description: 'Choose jobs to run'
options:
- 'Run all'
- 'Run static QA only'
- 'Run static unit tests only'

continue-on-error: ${{ matrix.experimental }}
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

steps:
- name: Checkout
uses: actions/checkout@v2
jobs:
static-qa:
runs-on: ubuntu-latest
if: ${{ !contains(github.event.head_commit.message, 'skip qa') || github.event.inputs.skip-jobs == 'Run static unit tests only' }}
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
tools: ${{ matrix.tools }}
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 7.4
coverage: none
tools: cs2pr

- name: Check syntax error in sources
run: find ./src/ -type f -name '*.php' -print0 | xargs -0 -L 1 -P 4 -- php -l
- name: Install dependencies
uses: ramsey/composer-install@v2

- name: Install dependencies
uses: "ramsey/composer-install@v1"
with:
dependency-versions: ${{ matrix.prefer }}
composer-options: ${{ matrix.ignore-platform }}
- name: Check code styles
run: ./vendor/bin/phpcs -q --report=checkstyle | cs2pr

qa:
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, 'ci skip')"
- name: Check Psalm
run: ./vendor/bin/psalm --output-format=github --no-cache

steps:
- name: Checkout
uses: actions/checkout@v2
unit-tests:
runs-on: ubuntu-latest
if: ${{ !contains(github.event.head_commit.message, 'skip tests') || github.event.inputs.skip-jobs == 'Run static QA only' }}
strategy:
fail-fast: false
matrix:
php-ver: [ '7.3', '7.4', '8.0' ]
composer: [ 'composer:2.0', 'composer:2.1', 'composer:2.2', 'composer:2.3', 'composer:v1' ]
dependency-versions: [ 'lowest', 'highest' ]
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 7.4
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-ver }}
ini-values: zend.assertions=1, error_reporting=-1, display_errors=On
coverage: none
tools: cs2pr, ${{ matrix.composer }}

- name: Install dependencies
uses: "ramsey/composer-install@v1"
- name: Install parallel-lint
if: ${{ matrix.dependency-versions == 'highest' }}
run: composer require php-parallel-lint/php-parallel-lint:^1.3.1 --dev --no-update

- name: Check cross-version PHP compatibility
run: composer phpcompat
- name: Install dependencies
uses: ramsey/composer-install@v2
with:
dependency-versions: ${{ matrix.dependency-versions }}
composer-options: ${{ matrix.composer-options }}

- name: Check code style
run: composer cs
- name: Lint PHP sources
if: ${{ matrix.dependency-versions == 'highest' }}
run: ./vendor/bin/parallel-lint ./src/ --checkstyle | cs2pr

- name: Check Psalm
run: composer psalm
# TODO: Write tests...
#- name: Run unit tests
# run: ./vendor/bin/phpunit --no-coverage
18 changes: 10 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@
},
"require-dev": {
"composer/composer": "^2",
"inpsyde/php-coding-standards": "^1@dev",
"phpcompatibility/php-compatibility": "^9.3.0",
"vimeo/psalm": "^4.1.1"
"inpsyde/php-coding-standards": "^1",
"vimeo/psalm": "^4.22"
},
"autoload": {
"psr-4": {
Expand All @@ -37,13 +36,16 @@
"class": "Inpsyde\\VipComposer\\Plugin"
},
"scripts": {
"cs": "@php ./vendor/squizlabs/php_codesniffer/bin/phpcs",
"psalm": "@php ./vendor/vimeo/psalm/psalm --no-cache --show-info=false --output-format=compact --no-progress",
"phpcompat": "@php ./vendor/squizlabs/php_codesniffer/bin/phpcs -p . --standard=PHPCompatibility --ignore=*/vendor/* --extensions=php --basepath=./ --runtime-set testVersion 7.3-",
"phpcs": "@php ./vendor/squizlabs/php_codesniffer/bin/phpcs",
"psalm": "@php ./vendor/vimeo/psalm/psalm --no-cache --show-info=false --no-progress",
"qa": [
"@cs",
"@phpcompat",
"@phpcs",
"@psalm"
]
},
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
}
}
}
2 changes: 1 addition & 1 deletion phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<arg value="sp"/>
<arg name="colors"/>
<config name="testVersion" value="7.2-"/>
<config name="testVersion" value="7.3-"/>

<rule ref="Inpsyde" />

Expand Down
4 changes: 0 additions & 4 deletions psalm.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
<?xml version="1.0"?>
<psalm
totallyTyped="true"
useDocblockPropertyTypes="true"
usePhpDocMethodsWithoutMagicCall="true"
strictBinaryOperands="true"
allowPhpStormGenerics="true"
allowCoercionFromStringToClassConst="true"
ignoreInternalFunctionFalseReturn="false"
ignoreInternalFunctionNullReturn="false"
hideExternalErrors="true"
Expand All @@ -26,6 +23,5 @@
<MissingClosureReturnType errorLevel="suppress" />
<UnresolvableInclude errorLevel="suppress" />
<UndefinedConstant errorLevel="suppress" />
<UnnecessaryVarAnnotation errorLevel="suppress" />
</issueHandlers>
</psalm>
10 changes: 8 additions & 2 deletions src/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,14 @@ protected function execute(InputInterface $input, OutputInterface $output)
{
try {
$this->resetComposer();
/** @var Composer $composer */
$composer = $this->getComposer(true);
/**
* @psalm-suppress DeprecatedMethod
* @var Composer $composer
*/
$composer = is_callable([$this, 'requireComposer'])
? $this->requireComposer()
: $this->getComposer(true);

$factory = new Factory($composer, $this->getIO());
$config = $factory->config();

Expand Down
1 change: 0 additions & 1 deletion src/Git/EnsureGitIgnore.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

final class EnsureGitIgnore
{

/**
* @param string $dir
* @return bool
Expand Down
1 change: 0 additions & 1 deletion src/Git/GitProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

class GitProcess
{

/**
* @var string
*/
Expand Down
3 changes: 3 additions & 0 deletions src/Git/MirrorCopier.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,9 @@ private function copyLinks(array $linksPaths): bool
$copied = 0;
foreach ($linksPaths as $link => $target) {
$real = realpath($link);
if (!$real) {
continue;
}
$targetParent = dirname($target);
$saveIn = "{$targetParent}/" . pathinfo($real, PATHINFO_FILENAME) . '.zip';
$git->cd($real)->exec("archive --format zip --output {$saveIn} master");
Expand Down
10 changes: 4 additions & 6 deletions src/Git/VipGit.php
Original file line number Diff line number Diff line change
Expand Up @@ -305,9 +305,7 @@ private function mergeAndPush(
$branches = explode($output, "\n") ?: [];
$currentBranch = '';
foreach ($branches as $branch) {
if (strpos(trim($branch), '* ')) {
$currentBranch = ltrim($branch, '* ');
}
strpos(trim($branch), '* ') and $currentBranch = ltrim($branch, '* ');
}

$commands = [];
Expand Down Expand Up @@ -481,8 +479,8 @@ private function fillMirrorVendor(MirrorCopier $copier, string $mirrorDir): bool
$vendorDir = $this->config->composerConfigValue('vendor-dir');
$vendorSource = $this->filesystem->normalizePath($vendorDir);
$targetPath = $this->directories->targetPath();
$subdir = $this->filesystem->findShortestPath($targetPath, $vendorSource, true);
$vendorTarget = "{$mirrorDir}/{$subdir}";
$subDir = $this->filesystem->findShortestPath($targetPath, $vendorSource, true);
$vendorTarget = "{$mirrorDir}/{$subDir}";
$this->filesystem->ensureDirectoryExists($vendorTarget);
$toCopy = $this->packages->noDevPackages();

Expand Down Expand Up @@ -552,7 +550,7 @@ static function (string $file) use (&$counts): void {
}
);

if ($total < 1) {
if (!$files) {
$this->nothingToDoMessage($push);

return 0;
Expand Down
3 changes: 1 addition & 2 deletions src/Task/EnsureGitKeep.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

final class EnsureGitKeep implements Task
{

/**
* @var VipDirectories
*/
Expand Down Expand Up @@ -76,7 +75,7 @@ private function ensureGitKeepFor(string $dir): void
}

$hasFiles = $this->haveFiles(0, $dir);
$hasGitKeep = file_exists(realpath($dir) . '/.gitkeep');
$hasGitKeep = file_exists((string)realpath($dir) . '/.gitkeep');

if (!$hasFiles && !$hasGitKeep) {
file_put_contents("{$dir}/.gitkeep", "\n");
Expand Down
1 change: 0 additions & 1 deletion src/Task/GenerateMuPluginsLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

final class GenerateMuPluginsLoader implements Task
{

/**
* @var VipDirectories
*/
Expand Down
Loading

0 comments on commit 6caeffe

Please sign in to comment.