@@ -40,6 +40,13 @@ class DeployProjectCommand extends AbstractProjectDeploymentCommand
4040 */
4141 public const NAME = 'project:deploy ' ;
4242
43+ /**
44+ * The assets directory where the asset files were copied to.
45+ *
46+ * @var string
47+ */
48+ private $ assetsDirectory ;
49+
4350 /**
4451 * The build "uploads" directory.
4552 *
@@ -50,10 +57,11 @@ class DeployProjectCommand extends AbstractProjectDeploymentCommand
5057 /**
5158 * Constructor.
5259 */
53- public function __construct (ApiClient $ apiClient , CliConfiguration $ cliConfiguration , ProjectConfiguration $ projectConfiguration , string $ uploadsDirectory , array $ deploymentSteps = [])
60+ public function __construct (ApiClient $ apiClient , string $ assetsDirectory , CliConfiguration $ cliConfiguration , ProjectConfiguration $ projectConfiguration , string $ uploadsDirectory , array $ deploymentSteps = [])
5461 {
5562 parent ::__construct ($ apiClient , $ cliConfiguration , $ projectConfiguration , $ deploymentSteps );
5663
64+ $ this ->assetsDirectory = $ assetsDirectory ;
5765 $ this ->uploadsDirectory = $ uploadsDirectory ;
5866 }
5967
@@ -86,7 +94,7 @@ protected function createDeployment(InputInterface $input, OutputInterface $outp
8694 $ this ->invoke ($ output , ImportUploadsCommand::NAME , ['path ' => $ this ->uploadsDirectory , '--environment ' => $ environment , '--force ' => null ]);
8795 }
8896
89- $ deployment = $ this ->apiClient ->createDeployment ($ projectId , $ environment , $ this ->projectConfiguration );
97+ $ deployment = $ this ->apiClient ->createDeployment ($ projectId , $ environment , $ this ->projectConfiguration , $ this -> generateDirectoryHash ( $ this -> assetsDirectory ) );
9098
9199 if (!$ deployment ->has ('id ' )) {
92100 throw new RuntimeException ('There was an error creating the deployment ' );
@@ -102,4 +110,20 @@ protected function getSuccessMessage(string $environment): string
102110 {
103111 return sprintf ('Project deployed successfully to "<comment>%s</comment>" environment ' , $ environment );
104112 }
113+
114+ /**
115+ * Generate a hash for the content of the given directory.
116+ */
117+ private function generateDirectoryHash (string $ directory ): string
118+ {
119+ $ iterator = new \RecursiveIteratorIterator (new \RecursiveDirectoryIterator ($ directory ), \RecursiveIteratorIterator::SELF_FIRST );
120+
121+ return hash ('sha256 ' , collect ($ iterator )->filter (function (\SplFileInfo $ file ) {
122+ return $ file ->isFile ();
123+ })->mapWithKeys (function (\SplFileInfo $ file ) {
124+ return [substr ($ file ->getRealPath (), (int ) strrpos ($ file ->getRealPath (), '.ymir ' )) => $ file ->getRealPath ()];
125+ })->map (function (string $ realPath , string $ relativePath ) {
126+ return sprintf ('%s|%s ' , $ relativePath , hash_file ('sha256 ' , $ realPath ));
127+ })->implode ('' ));
128+ }
105129}
0 commit comments