diff --git a/docker-compose.yml b/docker-compose.yml index 7da02660c..d58eedfb6 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,4 +1,3 @@ -version: '2' services: web: image: registry.fpfis.eu/fpfis/httpd-php:8.1-ci diff --git a/src/Mock.php b/src/Mock.php index 04cb9b1f8..03bc9ee4b 100644 --- a/src/Mock.php +++ b/src/Mock.php @@ -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. diff --git a/src/TaskRunner/Commands/ReleaseCommands.php b/src/TaskRunner/Commands/ReleaseCommands.php index 8d3da7ad8..ebcde9662 100644 --- a/src/TaskRunner/Commands/ReleaseCommands.php +++ b/src/TaskRunner/Commands/ReleaseCommands.php @@ -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. * @@ -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'), ]); } diff --git a/tests/fixtures/commands/component-check.yml b/tests/fixtures/commands/component-check.yml index 03423a679..83ea57c18 100644 --- a/tests/fixtures/commands/component-check.yml +++ b/tests/fixtures/commands/component-check.yml @@ -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", @@ -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", @@ -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", diff --git a/tests/fixtures/commands/notifications.yml b/tests/fixtures/commands/notifications.yml index 39cbae4c9..fe01a59ae 100644 --- a/tests/fixtures/commands/notifications.yml +++ b/tests/fixtures/commands/notifications.yml @@ -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", @@ -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", diff --git a/tests/fixtures/commands/release.yml b/tests/fixtures/commands/release.yml index 81cbb1551..d798e1ac2 100644 --- a/tests/fixtures/commands/release.yml +++ b/tests/fixtures/commands/release.yml @@ -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'