Browse Source

Merge branch 'master' of https://bitbucket.org/ikflowdat/installer

Fernando Alonso 7 năm trước cách đây
mục cha
commit
d2a9c914c3
2 tập tin đã thay đổi với 67 bổ sung28 xóa
  1. 28 8
      tools/src/Command/TagModulesCommand.php
  2. 39 20
      tools/src/ComposerRequireCommand.php

+ 28 - 8
tools/src/Command/TagModulesCommand.php

@@ -60,35 +60,50 @@ class TagModulesCommand extends Command
                     $git->config->add('user.name', 'drone', ["global" => true]);
                     // agrego el path del repositorio
 		    $git->setRepository($git_path);
-		    // guardo cualquier cambio realizado.
-		    //$git->stash();
                     // necesito traer todos los branch's para ver si ya existe
                     $branchs = $git->branch(['all' => true]);
                     $findBranch = false;
                     $branchRemote = null;
+                    $branchOrigen = null;
                     // verifico si el branch a crear ya existe
 		    foreach ($branchs as $branch) {
+                        if ($branch['current']) {
+                            $branchOrigen = $branch['name'];
+                        }
                         if ($branch['name'] == $version) {
                             $findBranch = true;
                             $branchRemote = $branch['name'];
-                            break;
                         }
                     }
                     if (!$findBranch) {
                         // si no existe el branch y estoy creando un branch nuevo
+                        $output->writeln('Creando la rama ' . $version);
                         $git->branch->create($version);
                     }
-		    // cambio a la rama de la version y agrego los archivos modificados
-                    $git->checkout($version);
                     $git->add('composer.json');
                     $git->add('composer.lock');
 
-                    shell_exec($cd_path . "; git commit -am 'Composer para la version " . $version . " y el tag " . $tag . "'");
-                    shell_exec($cd_path . "; git push " . $optionRemoteGit . " " . $version );
+		    $output->writeln('Commit de los composer');
+                    $command = $cd_path . "; git commit -am 'Composer para la version " . $version . " y el tag " . $tag . "'";
+                    $output->writeln('\t' . $command);
+                    shell_exec($command);
+		    
+		    // cambio a la rama de la version y agrego los archivos modificados
+                    $output->writeln('Checkout de la rama ' . $version);
+                    $git->checkout($version);
+
+                    $output->writeln('Merge entre la rama ' . $version . ' y ' . $branchOrigen);
+                    $git->merge($branchOrigen, 'Merge entre la rama ' . $version . ' y ' . $branchOrigen, ['strategy' => 'ours']);
+		    
+                    $output->writeln('Push de la rama ' . $version);
+		    $command = $cd_path . "; git push " . $optionRemoteGit . " " . $version;
+		    $output->writeln('\t' . $command);
+                    shell_exec($command);
                     // estoy creando un tag
                     $tags = $git->tag();
                     if (!in_array($tag, $tags)) {
                         // el tag no existe
+                        $output->writeln('Creo el tag: ' . $tag);
                         if ($branchRemote == null) {
                             // el branch remote no existe
                             $git->tag->create($tag, $version);
@@ -98,9 +113,14 @@ class TagModulesCommand extends Command
                         }
                     }
                     // ejecuto el comando git
-                    shell_exec($cd_path . "; git push " . $optionRemoteGit . " --tags ");
+                    $output->writeln('Push de la rama.');
+		    $command = $cd_path . "; git push " . $optionRemoteGit . " --tags ";
+                    $output->writeln('\t' . $command);
+		    // tengo que hacer el  --tags para que pase todos los tags
+                    shell_exec($command);
                 } catch (GitException $e) {
                     $output->writeln("SE PRODUJO UN ERROR EN " . $sec);
+                    shell_exec($cd_path . "; git reset ");
                     $output->writeln($e->getTraceAsString());
                     $output->writeln($sec . ": " . $e->getMessage());
                     return $e->getCode();

+ 39 - 20
tools/src/ComposerRequireCommand.php

@@ -40,34 +40,53 @@ class ComposerRequireCommand extends Command
         foreach ($content as $sec => $conf) {
             $composer_file = $sec . "/composer.json";
             if (file_exists($composer_file)) {
+                $output->writeln("----------------------------------------------------------------------");
                 $output->writeln($sec);
                 $composer_data = json_decode(file_get_contents($composer_file), true);
-                foreach (array("require", "require-dev") as $k) {
-		    if (strlen($pull) > 0) {
-                        shell_exec('cd ' . $sec . '; git checkout master; git pull origin ' . $pull);
-                    }
-                    foreach ($composer_data[$k] as $package => $version) {
-                        if (strpos($packages, "*") !== false) {
-                            $preg = "|^" . str_replace("*", "[^\b]*", $packages) . "$|";
-                            if (preg_match($preg, $package)) {
-                                $composer_data[$k][$package] = (string)$new_version;
-                                $output->writeln("\t" . $package . " = " . $new_version);
-                            }
-                        } else {
-                            if (strcmp($packages, $package) === 0) {
-                                $composer_data[$k][$package] = (string)$new_version;
-                                $output->writeln("\t" . $package . " = " . $new_version);
+		try {
+                    foreach (array("require", "require-dev") as $k) {
+		        $output->writeln('Ejecutando:');
+		        $command = 'cd ' . $sec . '; git stash; git fetch; git checkout master; git pull origin master';
+		        $output->writeln("\t" . $command);
+                        shell_exec($command);
+                        if (strlen($pull) > 0) {
+		            $command = 'cd ' . $sec . '; git pull origin ' . $pull;
+		            $output->writeln("\t" . $command);
+                            shell_exec($command);
+                        }
+		        $output->writeln("\t" . 'Reemplazo composer.json');
+                        foreach ($composer_data[$k] as $package => $version) {
+                            if (strpos($packages, "*") !== false) {
+                                $preg = "|^" . str_replace("*", "[^\b]*", $packages) . "$|";
+                                if (preg_match($preg, $package)) {
+                                    $composer_data[$k][$package] = (string)$new_version;
+                                    $output->writeln("\t\t" . $package . " = " . $new_version);
+                                }
+			    } else {
+                                if (strcmp($packages, $package) === 0) {
+                                    $composer_data[$k][$package] = (string)$new_version;
+				    $output->writeln("\t\t" . $package . " = " . $new_version);
+                                }
                             }
                         }
                     }
-                }
-                file_put_contents($composer_file, json_encode($composer_data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
-		if ($dockerCompose) {
-                    shell_exec('docker-compose exec ' . $sec . ' bin/composer-update.sh');
-                }
+                    file_put_contents($composer_file, json_encode($composer_data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
+		    if ($dockerCompose) {
+		        $output->writeln('Composer update');
+		        $command = 'docker-compose exec ' . $sec . ' bin/composer-update.sh';
+		        $output->writeln("\t" . $command);
+                        shell_exec($command);
+                    }
+		} catch (Throwable $t) {
+		    $output->writeln('Se produjo un error. Reestableciendo datos.');
+		    $command = 'cd ' . $sec . '; git reset';
+		    $output->writeln("\t" . $command);
+                    $shell_exec($command);
+		}
             } else {
                 $output->writeln($sec . " no composer.json found");
             }
         }
     }
 }
+