@@ -83,6 +83,47 @@ public function toolkitVersionWrite(ConsoleIO $io, string $version)
83
83
return $ this ->collectionBuilder ()->addTaskList ($ tasks );
84
84
}
85
85
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
+
86
127
/**
87
128
* Write the release changelog to the CHANGELOG.md file.
88
129
*
@@ -165,6 +206,7 @@ public function toolkitPrepareRelease(string $version)
165
206
$ this ->taskExec ($ runnerBin )->args (['toolkit:changelog-write ' , $ version ]),
166
207
$ this ->taskExec ($ runnerBin )->arg ('toolkit:generate-commands-list ' ),
167
208
$ this ->taskExec ($ runnerBin )->arg ('toolkit:generate-documentation ' ),
209
+ $ this ->taskExec ($ runnerBin )->arg ('toolkit:update-mock-default-tag ' ),
168
210
]);
169
211
}
170
212
0 commit comments