Skip to content

Commit

Permalink
DQA-8654: Align project information endpoint with new Envs structure (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
joaocsilva authored Feb 2, 2024
1 parent 49d5b9b commit d0884c5
Show file tree
Hide file tree
Showing 13 changed files with 19,903 additions and 62 deletions.
2 changes: 1 addition & 1 deletion src/Mock.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ final class Mock
*
* @var string
*/
private static string $defaultTag = '0.0.2';
private static string $defaultTag = '0.0.3';

/**
* The directory to download the mock to.
Expand Down
34 changes: 26 additions & 8 deletions src/TaskRunner/Commands/ComponentCheckCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -431,14 +431,11 @@ protected function validateComponent(array $package)
// Check if the module is allowed for this profile.
if (!$allowedInProject && !empty($allowedProfiles)) {
$allowedProfiles = array_map('trim', explode(',', $allowedProfiles));
// Load the project from the website.
$project = Website::projectInformation($projectId);
if (array_key_exists('profile', $project)) {
if (in_array($project['profile'], $allowedProfiles)) {
$allowedInProject = true;
$message = "The package $packageName is authorised for the profile {$project['profile']}";
$messageType = 'Packages authorised:';
}
$profile = $this->getProjectProfile($projectId);
if (in_array($profile, $allowedProfiles)) {
$allowedInProject = true;
$message = "The package $packageName is authorised for the profile $profile";
$messageType = 'Packages authorised:';
}
}

Expand Down Expand Up @@ -858,4 +855,25 @@ private function getFailedOrPassed(bool $value): string
return $value ? 'failed' : 'passed';
}

/**
* Load given project from website and return the profile in the production env.
*
* @param string $projectId
* The project to use in the endpoint.
*/
private function getProjectProfile(string $projectId): string
{
// Load the project from the website.
$project = Website::projectInformation($projectId);
// Get the profile from the production environment.
if (!empty($project['environments'])) {
foreach ($project['environments'] as $env) {
if (!empty($env['profile']) && $env['type'] === 'Production') {
return $env['profile'];
}
}
}
return '';
}

}
17 changes: 12 additions & 5 deletions src/TaskRunner/Commands/DockerCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function dockerRefreshConfiguration(): int

$websiteRequirements = $this->getWebsiteRequirements();
$requirementsServiceImage = $this->getServicesVersionsFromRequirements($websiteRequirements['defaults']);
$projectInfo = $this->getWebsiteProjectInformation($projectId);
$projectInfo = $this->getProjectPhpFromWebsite($projectId);

$requirements = array_merge($requirementsServiceImage, $projectInfo);

Expand Down Expand Up @@ -127,17 +127,24 @@ private function getServicesImagesFromDockerCompose(array $dcContent): array
* @return array|string[]
* @throws \Exception
*/
private function getWebsiteProjectInformation(string $projectId): array
private function getProjectPhpFromWebsite(string $projectId): array
{
$data = Website::projectInformation($projectId);
if (!$data) {
$this->writeln('Failed to connect to the endpoint. Required env var QA_API_AUTH_TOKEN.');
return [];
}

return [
'php_version' => $data['php_version'],
];
// Get the php version from the production environment.
if (!empty($data['environments'])) {
foreach ($data['environments'] as $env) {
if (!empty($data['php_version']) && $env['type'] === 'Production') {
return ['php_version' => $data['php_version']];
}
}
}

return [];
}

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/Features/Commands/DockerCommandsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function testDockerCommands(string $command, array $config = [], array $r

// Run command.
$result = $this->runCommand($command);

$this->debugExpectations($result['output'], $expectations);
// Assert expectations.
foreach ($expectations as $expectation) {
$this->assertDynamic($result['output'], $expectation);
Expand Down Expand Up @@ -95,10 +95,10 @@ public function testDockerCommandsComposeContent(string $command, array $config,

// Run command.
$this->runCommand($command, false);

// Assert expectations.
foreach ($expectations as $expectation) {
$content = file_get_contents($this->getSandboxFilepath($expectation['file']));
$this->debugExpectations($content, [$expectation]);
$this->assertDynamic($content, $expectation);
}
}
Expand Down
25 changes: 12 additions & 13 deletions tests/fixtures/commands/component-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
Website not installed, using config/sync/core.extension.yml file.
Config file not found at config/sync/core.extension.yml.
Package dropsolid_purge is mandatory and is not present on the project.
Package oe_dashboard_agent is mandatory and is not present on the project.
Checking Recommended components.
================================
Expand Down Expand Up @@ -363,13 +362,13 @@
- file: composer.lock
content: |
{ "packages": [ { "name": "drupal/pipeline", "type": "drupal-module", "version": "1.0.0" } ] }
- file: .toolkit-mock/0.0.2/api/v1/project/ec-europa/toolkit/information.json
- file: .toolkit-mock/0.0.3/api/v1/project/ec-europa/toolkit/information.json
content: |
[ { "type": "Drupal 9" ,"profile": "minimal" } ]
- file: .toolkit-mock/0.0.2/api/v1/toolkit-requirements.json
[ { "name":"toolkit", "type": "Openeuropa", "environments": [{ "profile": "minimal", "type": "Production" }] }]
- file: .toolkit-mock/0.0.3/api/v1/toolkit-requirements.json
content: |
{ "php_version":"8.0", "toolkit": "^3.7.2|^9.11|^10.1", "drupal": "^7.96|^9.5.8|^10.0.9", "vendor_list": [ "drupal" ] }
- file: .toolkit-mock/0.0.2/api/v1/package-reviews.json
{ "php_version":"8.1", "toolkit": "^3.7.2|^9.14|^10.4", "drupal": "^7.96|^10.1.4|^10.0.11", "vendor_list": [ "drupal" ] }
- file: .toolkit-mock/0.0.3/api/v1/package-reviews.json
content: |
[ {
"type": "drupal-module",
Expand All @@ -384,7 +383,7 @@
"status": "rejected",
"restricted_use": "1",
"allowed_profiles": "minimal",
"allowed_project_types": "Drupal 9",
"allowed_project_types": "Openeuropa",
"mandatory": "0",
"mandatory_date": false,
"core": "8.x",
Expand All @@ -394,7 +393,7 @@
"dev_component": "false"
} ]
expectations:
- string_contains: The package drupal/pipeline is authorised for the type of project Drupal 9
- string_contains: The package drupal/pipeline is authorised for the type of project Openeuropa

- command: 'toolkit:component-check'
configuration: [ ]
Expand All @@ -404,13 +403,13 @@
- file: composer.lock
content: |
{ "packages": [ { "name": "drupal/pipeline", "type": "drupal-module", "version": "1.0.0" } ] }
- file: .toolkit-mock/0.0.2/api/v1/project/ec-europa/toolkit/information.json
- file: .toolkit-mock/0.0.3/api/v1/project/ec-europa/toolkit/information.json
content: |
[ { "type": "Drupal 9" ,"profile": "minimal" } ]
- file: .toolkit-mock/0.0.2/api/v1/toolkit-requirements.json
[ { "name": "toolkit", "type": "Openeuropa", "environments": [{ "profile":"minimal", "type":"Production" }] } ]
- file: .toolkit-mock/0.0.3/api/v1/toolkit-requirements.json
content: |
{ "php_version":"8.0", "toolkit": "^3.7.2|^9.11|^10.1", "drupal": "^7.96|^9.5.8|^10.0.9", "vendor_list": [ "drupal" ] }
- file: .toolkit-mock/0.0.2/api/v1/package-reviews.json
{ "php_version": "8.1", "toolkit": "^3.7.2|^9.14|^10.4", "drupal": "^7.96|^10.1.4|^10.0.11", "vendor_list": [ "drupal" ] }
- file: .toolkit-mock/0.0.3/api/v1/package-reviews.json
content: |
[ {
"type": "drupal-module",
Expand Down
10 changes: 5 additions & 5 deletions tests/fixtures/commands/docker-compose-content.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
env_file:
- .env
mysql:
image: 'percona/percona-server:5.7'
image: 'percona/percona-server:8.0'
command: '--innodb-log-file_size=2G --max-allowed-packet=1G --innodb-buffer-pool-size=512M --wait-timeout=31536000'
environment:
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
Expand Down Expand Up @@ -60,7 +60,7 @@
version: '2'
services:
mysql:
image: 'percona/percona-server:5.7'
image: 'percona/percona-server:8.0'
command: '--innodb-log-file_size=2G --max-allowed-packet=1G --innodb-buffer-pool-size=512M --wait-timeout=31536000'
environment:
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
Expand Down Expand Up @@ -128,7 +128,7 @@
env_file:
- .env
mysql:
image: 'percona/percona-server:5.7'
image: 'percona/percona-server:8.0'
command: '--innodb-log-file_size=2G --max-allowed-packet=1G --innodb-buffer-pool-size=512M --wait-timeout=31536000'
environment:
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
Expand Down Expand Up @@ -179,7 +179,7 @@
env_file:
- .env
mysql:
image: 'percona/percona-server:5.7'
image: 'percona/percona-server:8.0'
command: '--innodb-log-file_size=2G --max-allowed-packet=1G --innodb-buffer-pool-size=512M --wait-timeout=31536000'
environment:
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
Expand Down Expand Up @@ -281,7 +281,7 @@
env_file:
- .env
mysql:
image: 'percona/percona-server:5.7'
image: 'percona/percona-server:8.0'
command: '--innodb-log-file_size=2G --max-allowed-packet=1G --innodb-buffer-pool-size=512M --wait-timeout=31536000'
environment:
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/commands/drupal.yml
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@
configuration: []
tokens: ~
resources:
- from: sample-composer.lock
- from: sample-d9-composer.lock
to: composer.lock
expectations:
- contains: |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
},
{
"name": "drupal/core",
"version": "9.5.11",
"version": "10.0.12",
"source": {
"type": "git",
"url": "https://github.com/drupal/core.git",
Expand Down Expand Up @@ -239,7 +239,7 @@
},
{
"name": "drupal/core-composer-scaffold",
"version": "9.5.11",
"version": "10.0.12",
"source": {
"type": "git",
"url": "https://github.com/drupal/core-composer-scaffold.git",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"packages": [
{
"name": "drupal/core",
"version": "9.5.11",
"version": "10.0.12",
"source": {
"type": "git",
"url": "https://github.com/drupal/core.git",
Expand Down
14 changes: 7 additions & 7 deletions tests/fixtures/samples/sample-composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit d0884c5

Please sign in to comment.