Bläddra i källkod

test gitlab-ci.yml tag

Guillermo Espinoza 6 år sedan
förälder
incheckning
752bdb1d0e
2 ändrade filer med 39 tillägg och 21 borttagningar
  1. 1 1
      .gitlab-ci.yml
  2. 38 20
      tools/src/Command/TagModulesCommand.php

+ 1 - 1
.gitlab-ci.yml

@@ -69,7 +69,7 @@ installer_tag:
     - cd tools
     - composer install --no-interaction --no-progress
     - php cmd.php make:installImages $(pwd) --client='develop' --develop=1
-    - chmod 0600 keys/bitbucket.id_rsa ; eval $(ssh-agent); ssh-add keys/bitbucket.id_rsa ; php cmd.php make:tag:vendors repositories.ini ${CI_COMMIT_TAG}
+    - chmod 0600 keys/bitbucket.id_rsa ; eval $(ssh-agent); ssh-add keys/bitbucket.id_rsa ; php cmd.php make:tag:vendors repositories.ini ${CI_COMMIT_TAG} --branch=1
     - chmod 0600 keys/bitbucket.id_rsa ; eval $(ssh-agent); ssh-add keys/bitbucket.id_rsa ; php cmd.php get:source git.ini --timeout=120
     - chmod 0600 keys/bitbucket.id_rsa ; eval $(ssh-agent); ssh-add keys/bitbucket.id_rsa ; php cmd.php composer:require git.ini 'ik/*' ${CI_COMMIT_TAG} --composer_update=0
     - chmod 0600 keys/bitbucket.id_rsa ; eval $(ssh-agent); ssh-add keys/bitbucket.id_rsa ; php cmd.php make:tag:modules git.ini ${CI_COMMIT_TAG}

+ 38 - 20
tools/src/Command/TagModulesCommand.php

@@ -2,17 +2,14 @@
 
 namespace FD3\Command;
 
+use PHPGit\Exception\GitException;
+use PHPGit\Git;
 use Symfony\Component\Console\Command\Command;
-use Symfony\Component\Console\Input\InputInterface;
 use Symfony\Component\Console\Input\InputArgument;
+use Symfony\Component\Console\Input\InputInterface;
 use Symfony\Component\Console\Input\InputOption;
 use Symfony\Component\Console\Output\OutputInterface;
 
-use PHPGit\Git;
-use PHPGit\Exception\GitException;
-
-use WriteiniFile\WriteiniFile;
-
 class TagModulesCommand extends Command
 {
     protected function configure()
@@ -32,7 +29,7 @@ class TagModulesCommand extends Command
     {
         $file = $input->getArgument("ini_file");
         $tag = $input->getArgument("tag");
-	$optionRemoteGit = $input->getOption('remote_git');
+        $optionRemoteGit = $input->getOption('remote_git');
         if (strtolower(substr($tag, 0, 1)) == 'v') {
             $version = explode(".", $tag);
             if (count($version) == 3) {
@@ -54,19 +51,19 @@ class TagModulesCommand extends Command
                 try {
                     $git = new Git();
                     $git_path = $dirname . '/' . $sec;
-		    $cd_path = "cd " . $git_path;
+                    $cd_path = "cd " . $git_path;
                     // agrego datos del usuario
                     $git->config->add('user.email', 'drone@flowdat.com', ["global" => true]);
                     $git->config->add('user.name', 'drone', ["global" => true]);
                     // agrego el path del repositorio
-		    $git->setRepository($git_path);
+                    $git->setRepository($git_path);
                     // 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) {
+                    foreach ($branchs as $branch) {
                         if ($branch['current']) {
                             $branchOrigen = $branch['name'];
                         }
@@ -80,24 +77,43 @@ class TagModulesCommand extends Command
                         $output->writeln('Creando la rama ' . $version);
                         $git->branch->create($version);
                     }
-                    $git->add('composer.json');
-                    $git->add('composer.lock');
 
-		    $output->writeln('Commit de los composer');
+                    $flag = false;
+                    $files = [
+                        'composer.json',
+                        'composer.lock',
+                    ];
+                    $status = $git->status();
+                    if (isset($status['changes'])) {
+                        foreach ($status['changes'] as $file) {
+                            if (in_array($file['file'], $files)) {
+                                $git->add($file);
+                                $flag = true;
+                            }
+                        }
+                    }
+
+                    if ($flag == false) {
+                        $output->writeln('No hay cambios en el repositorio');
+
+                        continue;
+                    }
+
+                    $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
+
+                    // 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);
+                    $command = $cd_path . "; git push " . $optionRemoteGit . " " . $version;
+                    $output->writeln("\t" . $command);
                     shell_exec($command);
                     // estoy creando un tag
                     $tags = $git->tag();
@@ -114,19 +130,21 @@ class TagModulesCommand extends Command
                     }
                     // ejecuto el comando git
                     $output->writeln('Push de la rama.');
-		    $command = $cd_path . "; git push " . $optionRemoteGit . " --tags ";
+                    $command = $cd_path . "; git push " . $optionRemoteGit . " --tags ";
                     $output->writeln("\t" . $command);
-		    // tengo que hacer el  --tags para que pase todos los tags
+                    // 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();
                 }
             }
         }
+
         return 0;
     }
 }