1414 */
1515class TestInfrastructure extends BaseModule
1616{
17+ private const USE_CACHED_WORKDIR_OPTION = 'use_cached_workdir ' ;
18+
1719 /**
1820 * Creates the work directory
1921 *
@@ -69,6 +71,57 @@ public function cleanupWorkDir(): bool
6971 return $ this ->createWorkDir ();
7072 }
7173
74+ /**
75+ * @param string $version
76+ * @return bool
77+ */
78+ public function isCacheWorkDirExists (string $ version ): bool
79+ {
80+ return $ this ->_getConfig (self ::USE_CACHED_WORKDIR_OPTION ) && is_dir ($ this ->getCachedWorkDirPath ($ version ));
81+ }
82+
83+ /**
84+ * @param string $version
85+ * @return void
86+ */
87+ public function cacheWorkDir (string $ version ): void
88+ {
89+ if (!$ this ->_getConfig (self ::USE_CACHED_WORKDIR_OPTION )) {
90+ return ;
91+ }
92+
93+ $ this ->copyDir ($ this ->getWorkDirPath (), $ this ->getCachedWorkDirPath ($ version ));
94+ }
95+
96+ /**
97+ * @param string $version
98+ */
99+ public function restoreWorkDirFromCache (string $ version ): void
100+ {
101+ $ this ->copyDir ($ this ->getCachedWorkDirPath ($ version ), $ this ->getWorkDirPath ());
102+ }
103+
104+ /**
105+ * Copy directory recursively.
106+ *
107+ * @param string $source The path of source folder
108+ * @param string $destination The path of destination folder
109+ * @return void
110+ */
111+ public function copyDir ($ source , $ destination ): void
112+ {
113+ if (!is_dir (dirname ($ destination ))) {
114+ mkdir (dirname ($ destination ));
115+ }
116+
117+ $ this ->taskRsync ()
118+ ->arg ('-l ' )
119+ ->recursive ()
120+ ->fromPath ($ source . '/ ' )
121+ ->toPath ($ destination . '/ ' )
122+ ->excludeVcs ()
123+ ->run ();
124+ }
72125
73126 /**
74127 * Clones cloud template to the work directory
@@ -82,7 +135,7 @@ public function cloneTemplateToWorkDir(string $branch = 'master'): bool
82135 ->printOutput ($ this ->_getConfig ('printOutput ' ))
83136 ->interactive (false )
84137 ->stopOnFail ()
85- ->cloneRepo ($ this ->_getConfig ('template_repo ' ), '. ' , $ branch )
138+ ->cloneShallow ($ this ->_getConfig ('template_repo ' ), '. ' , $ branch )
86139 ->dir ($ this ->getWorkDirPath ())
87140 ->run ()
88141 ->wasSuccessful ();
@@ -407,9 +460,8 @@ public function runEceDockerCommand(string $command): bool
407460 */
408461 public function replaceImagesWithGenerated (): bool
409462 {
410-
411463 if (true === $ this ->_getConfig ('use_generated_images ' )) {
412- $ this ->debug ('Tests use new generatedx Docker images ' );
464+ $ this ->debug ('Tests use new generated Docker images ' );
413465 $ path = $ this ->getWorkDirPath () . DIRECTORY_SEPARATOR . 'docker-compose.yml ' ;
414466
415467 return (bool )file_put_contents (
0 commit comments