-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added basic tests and fixed upgraded dependency issue (#60)
* Added basic tests and fixed upgraded dependency issue * Fixed base branch detection after 4.3 stable branches * fixup! Added basic tests and fixed upgraded dependency issue * Make sonar happy
- Loading branch information
Showing
13 changed files
with
292 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
name: CI | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
- '[0-9]+.[0-9]+' | ||
pull_request: ~ | ||
|
||
jobs: | ||
cs-fix: | ||
name: Run code style check | ||
runs-on: "ubuntu-20.04" | ||
strategy: | ||
matrix: | ||
php: | ||
- '8.0' | ||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Setup PHP Action | ||
uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: ${{ matrix.php }} | ||
coverage: none | ||
extensions: 'pdo_sqlite, gd' | ||
tools: cs2pr | ||
|
||
- uses: "ramsey/composer-install@v1" | ||
with: | ||
dependency-versions: "highest" | ||
|
||
- name: Run code style check | ||
run: composer run-script check-cs -- --format=checkstyle | cs2pr | ||
|
||
tests: | ||
name: Tests | ||
runs-on: "ubuntu-20.04" | ||
timeout-minutes: 10 | ||
|
||
strategy: | ||
fail-fast: false | ||
matrix: | ||
php: | ||
- '7.3' | ||
- '7.4' | ||
- '8.0' | ||
- '8.1' | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Setup PHP Action | ||
uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: ${{ matrix.php }} | ||
coverage: none | ||
extensions: pdo_sqlite, gd | ||
tools: cs2pr | ||
|
||
- uses: "ramsey/composer-install@v1" | ||
with: | ||
dependency-versions: "highest" | ||
composer-options: "--prefer-dist --no-progress" | ||
|
||
- name: Setup problem matchers for PHPUnit | ||
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" | ||
|
||
- name: Run test suite | ||
run: composer run-script --timeout=600 test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
/vendor/ | ||
composer.lock | ||
.php_cs.cache | ||
.phpunit.result.cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?xml version="1.0"?> | ||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
backupGlobals="false" | ||
backupStaticAttributes="false" | ||
bootstrap="vendor/autoload.php" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
colors="true" | ||
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"> | ||
<coverage> | ||
<include> | ||
<directory>src</directory> | ||
</include> | ||
</coverage> | ||
<testsuites> | ||
<testsuite name="Tests"> | ||
<directory>tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,12 +6,12 @@ | |
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Ibexa\Platform\ContiniousIntegrationScripts\Command; | ||
namespace Ibexa\ContiniousIntegrationScripts\Command; | ||
|
||
use Cz\Git\GitException; | ||
use Cz\Git\GitRepository; | ||
use CzProject\GitPhp\Git; | ||
use CzProject\GitPhp\GitException; | ||
use Github\Client; | ||
use Ibexa\Platform\ContiniousIntegrationScripts\Helper\ComposerHelper; | ||
use Ibexa\ContiniousIntegrationScripts\Helper\ComposerLocalTokenProvider; | ||
use JsonException; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
|
@@ -31,26 +31,47 @@ class RunRegressionCommand extends Command | |
/** @var ?string */ | ||
private $token; | ||
|
||
/** @var \Github\Client */ | ||
private $githubClient; | ||
|
||
/** @var \CzProject\GitPhp\Git */ | ||
private $repository; | ||
|
||
/** @var \Ibexa\ContiniousIntegrationScripts\Helper\ComposerLocalTokenProvider */ | ||
private $tokenProvider; | ||
|
||
public function __construct() | ||
{ | ||
parent::__construct(); | ||
$this->githubClient = new Client(); | ||
$this->repository = new Git(); | ||
$this->tokenProvider = new ComposerLocalTokenProvider(); | ||
} | ||
|
||
protected function interact(InputInterface $input, OutputInterface $output): void | ||
{ | ||
$io = new SymfonyStyle($input, $output); | ||
|
||
if (!$input->getArgument('token')) { | ||
$input->setArgument('token', ComposerHelper::getGitHubToken()); | ||
$input->setArgument('token', $this->tokenProvider->getGitHubToken()); | ||
} | ||
|
||
if (!$input->getArgument('productVersion')) { | ||
$productVersion = $io->ask('Please enter the Ibexa DXP version', '4.1', static function (string $answer): string { | ||
if (preg_match('/^(\d+)\.(\d+)$/', $answer) === 0) { | ||
throw new \RuntimeException( | ||
sprintf( | ||
'Unrecognised version format: %s. Please use format X.Y instead, e.g. 3.3, 4.0, 4.1', | ||
$answer) | ||
); | ||
} | ||
$productVersion = $io->ask( | ||
'Please enter the Ibexa DXP version', | ||
'4.2', | ||
static function (string $answer): string { | ||
if (preg_match('/^(\d+)\.(\d+)$/', $answer) === 0) { | ||
throw new \RuntimeException( | ||
sprintf( | ||
'Unrecognised version format: %s. Please use format X.Y instead, e.g. 3.3, 4.2, 4.3', | ||
$answer) | ||
); | ||
} | ||
|
||
return $answer; | ||
}); | ||
return $answer; | ||
} | ||
); | ||
|
||
$input->setArgument('productVersion', $productVersion); | ||
} | ||
|
@@ -99,13 +120,13 @@ public function execute(InputInterface $input, OutputInterface $output): int | |
private function createRegressionPullRequest(string $productEdition, string $baseBranch, string $regressionBranchName, SymfonyStyle $io): void | ||
{ | ||
try { | ||
$repo = GitRepository::cloneRepository( | ||
$repo = $this->repository->cloneRepository( | ||
sprintf('[email protected]:%s/%s.git', self::REPO_OWNER, $productEdition), | ||
null, ['-b' => $baseBranch] | ||
); | ||
} catch (GitException $exception) { | ||
// fallback to HTTPS if SSH fails | ||
$repo = GitRepository::cloneRepository( | ||
$repo = $this->repository->cloneRepository( | ||
sprintf('https://github.com/%s/%s.git', self::REPO_OWNER, $productEdition), | ||
null, ['-b' => $baseBranch] | ||
); | ||
|
@@ -118,18 +139,19 @@ private function createRegressionPullRequest(string $productEdition, string $bas | |
|
||
$repo->addFile(LinkDependenciesCommand::DEPENDENCIES_FILE); | ||
$repo->commit(self::COMMIT_MESSAGE); | ||
$repo->push('origin', [$regressionBranchName, '-u']); | ||
$repo->push(['origin', $regressionBranchName]); | ||
|
||
$io->success(sprintf('Successfuly pushed to %s/%s a branch called: %s', self::REPO_OWNER, $productEdition, $regressionBranchName)); | ||
|
||
$client = new Client(); | ||
if ($this->token) { | ||
$client->authenticate($this->token, null, Client::AUTH_ACCESS_TOKEN); | ||
$this->githubClient->authenticate($this->token, null, Client::AUTH_ACCESS_TOKEN); | ||
} | ||
|
||
$this->waitUntilBranchExists($client, $productEdition, $regressionBranchName); | ||
$this->waitUntilBranchExists($productEdition, $regressionBranchName); | ||
|
||
$response = $client->pullRequests()->create(self::REPO_OWNER, $productEdition, | ||
$response = $this->githubClient->pullRequests()->create( | ||
self::REPO_OWNER, | ||
$productEdition, | ||
[ | ||
'title' => 'Run regression for IBX-XXXX', | ||
'base' => $baseBranch, | ||
|
@@ -181,13 +203,13 @@ private function validate(): void | |
} | ||
} | ||
|
||
private function waitUntilBranchExists(Client $client, string $productEdition, string $branchName): void | ||
private function waitUntilBranchExists(string $productEdition, string $branchName): void | ||
{ | ||
$counter = 0; | ||
$success = false; | ||
while ($counter < 5) { | ||
try { | ||
$client->repo()->branches(self::REPO_OWNER, $productEdition, $branchName); | ||
$this->githubClient->repo()->branches(self::REPO_OWNER, $productEdition, $branchName); | ||
$success = true; | ||
break; | ||
} catch (\RuntimeException $e) { | ||
|
@@ -203,6 +225,6 @@ private function waitUntilBranchExists(Client $client, string $productEdition, s | |
|
||
private function getBaseBranch(string $productVersion): string | ||
{ | ||
return $productVersion === "4.2" ? "master" : $productVersion; | ||
return $productVersion === '4.3' ? 'master' : $productVersion; | ||
} | ||
} |
Oops, something went wrong.