Skip to content

Commit 28414a2

Browse files
authored
DQA-9541: Add command to update latest mock tag (#780)
1 parent 9756040 commit 28414a2

File tree

6 files changed

+55
-11
lines changed

6 files changed

+55
-11
lines changed

docker-compose.yml

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
version: '2'
21
services:
32
web:
43
image: registry.fpfis.eu/fpfis/httpd-php:8.1-ci

src/Mock.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ final class Mock
1717
*
1818
* @var string
1919
*/
20-
private static string $defaultTag = '0.0.6';
20+
private static string $defaultTag = '0.0.7';
2121

2222
/**
2323
* The directory to download the mock to.

src/TaskRunner/Commands/ReleaseCommands.php

+42
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,47 @@ public function toolkitVersionWrite(ConsoleIO $io, string $version)
8383
return $this->collectionBuilder()->addTaskList($tasks);
8484
}
8585

86+
/**
87+
* Write the latest tag from toolkit-mock to the Mock class.
88+
*
89+
* @command toolkit:update-mock-default-tag
90+
*
91+
* @hidden
92+
*/
93+
public function toolkitUpdateDefaultMockTag(ConsoleIO $io)
94+
{
95+
if (empty($token = getenv('GITLAB_API_TOKEN'))) {
96+
$io->error('Missing env var GITLAB_API_TOKEN.');
97+
return ResultData::EXITCODE_ERROR;
98+
}
99+
$mockFile = 'src/Mock.php';
100+
if (!file_exists($mockFile)) {
101+
$io->error("Could not find the file $mockFile.");
102+
return ResultData::EXITCODE_ERROR;
103+
}
104+
105+
$api = 'https://git.fpfis.tech.ec.europa.eu/api/v4';
106+
$url = $api . '/projects/4046/repository/tags';
107+
$context = stream_context_create(['http' => ['header' => "Authorization: Bearer $token"]]);
108+
$latestTag = file_get_contents($url, false, $context);
109+
if (empty($latestTag)) {
110+
$io->error('Failed to get response from GitLab.');
111+
return ResultData::EXITCODE_ERROR;
112+
}
113+
$latestTag = json_decode($latestTag, true);
114+
$latestTag = $latestTag[0]['name'] ?? false;
115+
if (empty($latestTag)) {
116+
$io->error('Failed read the latest tag.');
117+
return ResultData::EXITCODE_ERROR;
118+
}
119+
120+
$task = $this->taskReplaceInFile($mockFile)
121+
->regex("#\\\$defaultTag = '[^']*'#")
122+
->to("\\\$defaultTag = '" . $latestTag . "'");
123+
124+
return $this->collectionBuilder()->addTask($task);
125+
}
126+
86127
/**
87128
* Write the release changelog to the CHANGELOG.md file.
88129
*
@@ -165,6 +206,7 @@ public function toolkitPrepareRelease(string $version)
165206
$this->taskExec($runnerBin)->args(['toolkit:changelog-write', $version]),
166207
$this->taskExec($runnerBin)->arg('toolkit:generate-commands-list'),
167208
$this->taskExec($runnerBin)->arg('toolkit:generate-documentation'),
209+
$this->taskExec($runnerBin)->arg('toolkit:update-mock-default-tag'),
168210
]);
169211
}
170212

tests/fixtures/commands/component-check.yml

+7-7
Original file line numberDiff line numberDiff line change
@@ -382,13 +382,13 @@
382382
- file: composer.lock
383383
content: |
384384
{ "packages": [ { "name": "drupal/pipeline", "type": "drupal-module", "version": "1.0.0" } ] }
385-
- file: .toolkit-mock/0.0.6/api/v1/project/ec-europa/toolkit/information.json
385+
- file: .toolkit-mock/0.0.7/api/v1/project/ec-europa/toolkit/information.json
386386
content: |
387387
[ { "name":"toolkit", "type": "Openeuropa", "environments": [{ "profile": "minimal", "type": "Production" }] }]
388-
- file: .toolkit-mock/0.0.6/api/v1/toolkit-requirements.json
388+
- file: .toolkit-mock/0.0.7/api/v1/toolkit-requirements.json
389389
content: |
390390
{ "php_version":"8.1", "toolkit": "^3.7.2|^9.14|^10.4", "drupal": "^7.96|^10.1.4|^10.0.11", "vendor_list": [ "drupal" ] }
391-
- file: .toolkit-mock/0.0.6/api/v1/package-reviews.json
391+
- file: .toolkit-mock/0.0.7/api/v1/package-reviews.json
392392
content: |
393393
[ {
394394
"type": "drupal-module",
@@ -423,13 +423,13 @@
423423
- file: composer.lock
424424
content: |
425425
{ "packages": [ { "name": "drupal/pipeline", "type": "drupal-module", "version": "1.0.0" } ] }
426-
- file: .toolkit-mock/0.0.6/api/v1/project/ec-europa/toolkit/information.json
426+
- file: .toolkit-mock/0.0.7/api/v1/project/ec-europa/toolkit/information.json
427427
content: |
428428
[ { "name": "toolkit", "type": "Openeuropa", "environments": [{ "profile":"minimal", "type":"Production" }] } ]
429-
- file: .toolkit-mock/0.0.6/api/v1/toolkit-requirements.json
429+
- file: .toolkit-mock/0.0.7/api/v1/toolkit-requirements.json
430430
content: |
431431
{ "php_version": "8.1", "toolkit": "^3.7.2|^9.14|^10.4", "drupal": "^7.96|^10.1.4|^10.0.11", "vendor_list": [ "drupal" ] }
432-
- file: .toolkit-mock/0.0.6/api/v1/package-reviews.json
432+
- file: .toolkit-mock/0.0.7/api/v1/package-reviews.json
433433
content: |
434434
[ {
435435
"type": "drupal-module",
@@ -463,7 +463,7 @@
463463
- file: composer.lock
464464
content: |
465465
{ "packages": [ { "name": "ec-europa/toolkit" } ] }
466-
- file: .toolkit-mock/0.0.6/api/v1/package-reviews.json
466+
- file: .toolkit-mock/0.0.7/api/v1/package-reviews.json
467467
content: |
468468
[ {
469469
"type": "drupal-module",

tests/fixtures/commands/notifications.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
- CI=false
1212
- QA_WEBSITE_URL=http://ec-behat.com
1313
resources:
14-
- file: .toolkit-mock/0.0.6/api/v1/notifications.json
14+
- file: .toolkit-mock/0.0.7/api/v1/notifications.json
1515
content: |
1616
[{
1717
"title": "Notification title 1",
@@ -44,7 +44,7 @@
4444
- CI=false
4545
- QA_WEBSITE_URL=http://ec-behat.com
4646
resources:
47-
- file: .toolkit-mock/0.0.6/api/v1/notifications.json
47+
- file: .toolkit-mock/0.0.7/api/v1/notifications.json
4848
content: |
4949
[{
5050
"title": "Notification title 1",

tests/fixtures/commands/release.yml

+3
Original file line numberDiff line numberDiff line change
@@ -132,3 +132,6 @@
132132
[Simulator] Simulating Exec('./vendor/bin/run')
133133
->arg('toolkit:generate-documentation')
134134
[Simulator] Running ./vendor/bin/run 'toolkit:generate-documentation'
135+
[Simulator] Simulating Exec('./vendor/bin/run')
136+
->arg('toolkit:update-mock-default-tag')
137+
[Simulator] Running ./vendor/bin/run 'toolkit:update-mock-default-tag'

0 commit comments

Comments
 (0)