Skip to content

Commit

Permalink
Pass editions from CLI (#71)
Browse files Browse the repository at this point in the history
* Added the possibility to specify editions as input argument

* Upgraded Fixer and PHPStan
  • Loading branch information
mnocon authored May 15, 2023
1 parent ce896c6 commit 220126c
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 49 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
composer.lock
.php_cs.cache
.phpunit.result.cache
.php-cs-fixer.cache
dependencies.json
dependencies.txt
27 changes: 27 additions & 0 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

use Ibexa\CodeStyle\PhpCsFixer\InternalConfigFactory;

$configFactory = new InternalConfigFactory();
$configFactory->withRules([
'declare_strict_types' => false,
]);

return $configFactory
->buildConfig()
->setFinder(
PhpCsFixer\Finder::create()
->in(
array_filter([
__DIR__ . '/src',
__DIR__ . '/tests',
], 'is_dir')
)
->files()->name('*.php')
);
11 changes: 0 additions & 11 deletions .php_cs

This file was deleted.

11 changes: 8 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,21 @@
"bin/ci"
],
"require-dev": {
"ezsystems/ezplatform-code-style": "^1.0@dev",
"phpstan/phpstan": "~0.12",
"ibexa/code-style": "^1.0",
"phpstan/phpstan": "^1.8",
"phpunit/phpunit": "^9.5",
"mikey179/vfsstream": "^1.6"
},
"scripts": {
"phpstan": "phpstan analyse -c phpstan.neon",
"phpstan-baseline": "phpstan analyse -c phpstan.neon --generate-baseline",
"fix-cs": "php-cs-fixer fix -v --show-progress=estimating",
"fix-cs": "php-cs-fixer fix --config=.php-cs-fixer.php -v --show-progress=dots",
"check-cs": "@fix-cs --dry-run",
"test": "phpunit -c phpunit.xml"
},
"config": {
"allow-plugins": {
"php-http/discovery": false
}
}
}
18 changes: 4 additions & 14 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -1,22 +1,12 @@
parameters:
ignoreErrors:
-
message: "#^Offset 'head' does not exist on array\\|string\\.$#"
count: 2
message: "#^Offset 'base' does not exist on array\\|string\\.$#"
count: 3
path: src/Command/LinkDependenciesCommand.php

-
message: "#^Property Ibexa\\\\Platform\\\\ContiniousIntegrationScripts\\\\Command\\\\LinkDependenciesCommand\\:\\:\\$token \\(string\\|null\\) does not accept array\\<string\\>\\|string\\|null\\.$#"
count: 1
message: "#^Offset 'head' does not exist on array\\|string\\.$#"
count: 4
path: src/Command/LinkDependenciesCommand.php

-
message: "#^Parameter \\#1 \\$productVersion of method Ibexa\\\\Platform\\\\ContiniousIntegrationScripts\\\\Command\\\\RunRegressionCommand\\:\\:mapProductVersionToPageBuilder\\(\\) expects string, array\\<string\\>\\|string\\|null given\\.$#"
count: 1
path: src/Command/RunRegressionCommand.php

-
message: "#^Property Ibexa\\\\Platform\\\\ContiniousIntegrationScripts\\\\Command\\\\RunRegressionCommand\\:\\:\\$token \\(string\\|null\\) does not accept array\\<string\\>\\|string\\|null\\.$#"
count: 1
path: src/Command/RunRegressionCommand.php

11 changes: 6 additions & 5 deletions src/Command/LinkDependenciesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class LinkDependenciesCommand extends Command
*/
private $tokenProvider;

public function __construct($outputDirectory = null, ComposerLocalTokenProvider $tokenProvider = null)
public function __construct(string $outputDirectory = null, ComposerLocalTokenProvider $tokenProvider = null)
{
parent::__construct();
$this->serializer = new Serializer([new ObjectNormalizer()], [new JsonEncoder()]);
Expand Down Expand Up @@ -175,9 +175,10 @@ private function analyzeDependencies(array $pullRequestUrls): Dependencies
private function getRecipesEndpointUrl(string $owner, string $repository, int $prNumber): string
{
return sprintf(
'https://api.github.com/repos/%s/%s/contents/index.json?ref=flex/pull-%d',
$owner,
$repository,
$prNumber);
'https://api.github.com/repos/%s/%s/contents/index.json?ref=flex/pull-%d',
$owner,
$repository,
$prNumber
);
}
}
49 changes: 33 additions & 16 deletions src/Command/RunRegressionCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ static function (string $answer): string {
throw new \RuntimeException(
sprintf(
'Unrecognised version format: %s. Please use format X.Y instead, e.g. 3.3, 4.4, 4.5',
$answer)
$answer
)
);
}

Expand All @@ -79,17 +80,7 @@ static function (string $answer): string {
if (!$input->getArgument('productEditions')) {
$productEditions = $io->ask('Please enter the Ibexa DXP edition(s)', 'oss', static function (string $answer): array {
$editions = explode(',', $answer);
foreach ($editions as $edition) {
if (!in_array($edition, self::PRODUCT_EDITIONS)) {
throw new \RuntimeException(
sprintf(
'Unrecognised edition: %s. Please choose one of: %s',
$edition,
implode(',', self::PRODUCT_EDITIONS)
)
);
}
}
self::validateEditions($editions);

return $editions;
});
Expand All @@ -105,6 +96,11 @@ public function execute(InputInterface $input, OutputInterface $output): int
$productVersion = $input->getArgument('productVersion');
$productEditions = $input->getArgument('productEditions');

if (!is_array($productEditions)) {
$productEditions = explode(',', $productEditions);
$this->validateEditions($productEditions);
}

$this->validate();

$regressionBranchName = uniqid('tmp_regression_', true);
Expand All @@ -122,13 +118,15 @@ private function createRegressionPullRequest(string $productEdition, string $bas
try {
$repo = $this->repository->cloneRepository(
sprintf('[email protected]:%s/%s.git', self::REPO_OWNER, $productEdition),
null, ['-b' => $baseBranch]
null,
['-b' => $baseBranch]
);
} catch (GitException $exception) {
// fallback to HTTPS if SSH fails
$repo = $this->repository->cloneRepository(
sprintf('https://github.com/%s/%s.git', self::REPO_OWNER, $productEdition),
null, ['-b' => $baseBranch]
null,
['-b' => $baseBranch]
);
}

Expand Down Expand Up @@ -158,7 +156,8 @@ private function createRegressionPullRequest(string $productEdition, string $bas
'head' => $regressionBranchName,
'body' => 'Please add your description here.',
'draft' => 'true',
]);
]
);

$io->success(sprintf('Created PR, please see: %s', $response['_links']['html']['href']));

Expand Down Expand Up @@ -223,7 +222,7 @@ private function waitUntilBranchExists(string $productEdition, string $branchNam
}
}

private function getBaseBranch($productEdition, string $productVersion): string
private function getBaseBranch(string $productEdition, string $productVersion): string
{
try {
$this->githubClient->repo()->branches(self::REPO_OWNER, $productEdition, $productVersion);
Expand All @@ -233,4 +232,22 @@ private function getBaseBranch($productEdition, string $productVersion): string
return 'master';
}
}

/**
* @param iterable<string> $editions
*/
private static function validateEditions(iterable $editions): void
{
foreach ($editions as $edition) {
if (!in_array($edition, self::PRODUCT_EDITIONS)) {
throw new \RuntimeException(
sprintf(
'Unrecognised edition: %s. Please choose one of: %s',
$edition,
implode(',', self::PRODUCT_EDITIONS)
)
);
}
}
}
}

0 comments on commit 220126c

Please sign in to comment.