Skip to content

Commit

Permalink
DQA-9541: Add command to update latest mock tag (#780)
Browse files Browse the repository at this point in the history
  • Loading branch information
joaocsilva authored Jun 11, 2024
1 parent 9756040 commit 28414a2
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 11 deletions.
1 change: 0 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
version: '2'
services:
web:
image: registry.fpfis.eu/fpfis/httpd-php:8.1-ci
Expand Down
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.6';
private static string $defaultTag = '0.0.7';

/**
* The directory to download the mock to.
Expand Down
42 changes: 42 additions & 0 deletions src/TaskRunner/Commands/ReleaseCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,47 @@ public function toolkitVersionWrite(ConsoleIO $io, string $version)
return $this->collectionBuilder()->addTaskList($tasks);
}

/**
* Write the latest tag from toolkit-mock to the Mock class.
*
* @command toolkit:update-mock-default-tag
*
* @hidden
*/
public function toolkitUpdateDefaultMockTag(ConsoleIO $io)
{
if (empty($token = getenv('GITLAB_API_TOKEN'))) {
$io->error('Missing env var GITLAB_API_TOKEN.');
return ResultData::EXITCODE_ERROR;
}
$mockFile = 'src/Mock.php';
if (!file_exists($mockFile)) {
$io->error("Could not find the file $mockFile.");
return ResultData::EXITCODE_ERROR;
}

$api = 'https://git.fpfis.tech.ec.europa.eu/api/v4';
$url = $api . '/projects/4046/repository/tags';
$context = stream_context_create(['http' => ['header' => "Authorization: Bearer $token"]]);
$latestTag = file_get_contents($url, false, $context);
if (empty($latestTag)) {
$io->error('Failed to get response from GitLab.');
return ResultData::EXITCODE_ERROR;
}
$latestTag = json_decode($latestTag, true);
$latestTag = $latestTag[0]['name'] ?? false;
if (empty($latestTag)) {
$io->error('Failed read the latest tag.');
return ResultData::EXITCODE_ERROR;
}

$task = $this->taskReplaceInFile($mockFile)
->regex("#\\\$defaultTag = '[^']*'#")
->to("\\\$defaultTag = '" . $latestTag . "'");

return $this->collectionBuilder()->addTask($task);
}

/**
* Write the release changelog to the CHANGELOG.md file.
*
Expand Down Expand Up @@ -165,6 +206,7 @@ public function toolkitPrepareRelease(string $version)
$this->taskExec($runnerBin)->args(['toolkit:changelog-write', $version]),
$this->taskExec($runnerBin)->arg('toolkit:generate-commands-list'),
$this->taskExec($runnerBin)->arg('toolkit:generate-documentation'),
$this->taskExec($runnerBin)->arg('toolkit:update-mock-default-tag'),
]);
}

Expand Down
14 changes: 7 additions & 7 deletions tests/fixtures/commands/component-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -382,13 +382,13 @@
- file: composer.lock
content: |
{ "packages": [ { "name": "drupal/pipeline", "type": "drupal-module", "version": "1.0.0" } ] }
- file: .toolkit-mock/0.0.6/api/v1/project/ec-europa/toolkit/information.json
- file: .toolkit-mock/0.0.7/api/v1/project/ec-europa/toolkit/information.json
content: |
[ { "name":"toolkit", "type": "Openeuropa", "environments": [{ "profile": "minimal", "type": "Production" }] }]
- file: .toolkit-mock/0.0.6/api/v1/toolkit-requirements.json
- file: .toolkit-mock/0.0.7/api/v1/toolkit-requirements.json
content: |
{ "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.6/api/v1/package-reviews.json
- file: .toolkit-mock/0.0.7/api/v1/package-reviews.json
content: |
[ {
"type": "drupal-module",
Expand Down Expand Up @@ -423,13 +423,13 @@
- file: composer.lock
content: |
{ "packages": [ { "name": "drupal/pipeline", "type": "drupal-module", "version": "1.0.0" } ] }
- file: .toolkit-mock/0.0.6/api/v1/project/ec-europa/toolkit/information.json
- file: .toolkit-mock/0.0.7/api/v1/project/ec-europa/toolkit/information.json
content: |
[ { "name": "toolkit", "type": "Openeuropa", "environments": [{ "profile":"minimal", "type":"Production" }] } ]
- file: .toolkit-mock/0.0.6/api/v1/toolkit-requirements.json
- file: .toolkit-mock/0.0.7/api/v1/toolkit-requirements.json
content: |
{ "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.6/api/v1/package-reviews.json
- file: .toolkit-mock/0.0.7/api/v1/package-reviews.json
content: |
[ {
"type": "drupal-module",
Expand Down Expand Up @@ -463,7 +463,7 @@
- file: composer.lock
content: |
{ "packages": [ { "name": "ec-europa/toolkit" } ] }
- file: .toolkit-mock/0.0.6/api/v1/package-reviews.json
- file: .toolkit-mock/0.0.7/api/v1/package-reviews.json
content: |
[ {
"type": "drupal-module",
Expand Down
4 changes: 2 additions & 2 deletions tests/fixtures/commands/notifications.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
- CI=false
- QA_WEBSITE_URL=http://ec-behat.com
resources:
- file: .toolkit-mock/0.0.6/api/v1/notifications.json
- file: .toolkit-mock/0.0.7/api/v1/notifications.json
content: |
[{
"title": "Notification title 1",
Expand Down Expand Up @@ -44,7 +44,7 @@
- CI=false
- QA_WEBSITE_URL=http://ec-behat.com
resources:
- file: .toolkit-mock/0.0.6/api/v1/notifications.json
- file: .toolkit-mock/0.0.7/api/v1/notifications.json
content: |
[{
"title": "Notification title 1",
Expand Down
3 changes: 3 additions & 0 deletions tests/fixtures/commands/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,6 @@
[Simulator] Simulating Exec('./vendor/bin/run')
->arg('toolkit:generate-documentation')
[Simulator] Running ./vendor/bin/run 'toolkit:generate-documentation'
[Simulator] Simulating Exec('./vendor/bin/run')
->arg('toolkit:update-mock-default-tag')
[Simulator] Running ./vendor/bin/run 'toolkit:update-mock-default-tag'

0 comments on commit 28414a2

Please sign in to comment.