|
@@ -0,0 +1,112 @@
|
|
|
|
+<?php
|
|
|
|
+
|
|
|
|
+namespace FD3\Command;
|
|
|
|
+
|
|
|
|
+use Symfony\Component\Console\Command\Command;
|
|
|
|
+use Symfony\Component\Console\Input\InputInterface;
|
|
|
|
+use Symfony\Component\Console\Input\InputArgument;
|
|
|
|
+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()
|
|
|
|
+ {
|
|
|
|
+ $this
|
|
|
|
+ ->setName('make:tag:modules')
|
|
|
|
+ ->setDescription('Tags all vendor from bitbucket')
|
|
|
|
+ ->setHelp('Tag all vendors from bitbucket')
|
|
|
|
+ ->addArgument('ini_file', InputArgument::REQUIRED,
|
|
|
|
+ 'The ini file from where to get the source code config.')
|
|
|
|
+ ->addArgument('tag', InputArgument::REQUIRED, 'Create tag e.g. vX.Y.Z and branch X.Y')
|
|
|
|
+ ->addOption('remote_git', null, InputOption::VALUE_OPTIONAL,
|
|
|
|
+ 'Indicates the remote for git', 'origin');
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ protected function execute(InputInterface $input, OutputInterface $output)
|
|
|
|
+ {
|
|
|
|
+ $file = $input->getArgument("ini_file");
|
|
|
|
+ $tag = $input->getArgument("tag");
|
|
|
|
+ $optionRemoteGit = $input->getOption('remote_git');
|
|
|
|
+ if (strtolower(substr($tag, 0, 1)) == 'v') {
|
|
|
|
+ $version = explode(".", $tag);
|
|
|
|
+ if (count($version) == 3) {
|
|
|
|
+ unset($version[count($version) - 1]);
|
|
|
|
+ }
|
|
|
|
+ $version = implode(".", $version);
|
|
|
|
+
|
|
|
|
+ $realpath = realpath($file);
|
|
|
|
+ $dirname = dirname($realpath);
|
|
|
|
+ if (!chdir($dirname)) {
|
|
|
|
+ throw new \Exception("Can't change working directory to " . $dirname);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $content = parse_ini_file($realpath, true);
|
|
|
|
+ foreach ($content as $sec => $conf) {
|
|
|
|
+ $output->writeln("----------------------------------------------------------------------");
|
|
|
|
+ $output->writeln($sec);
|
|
|
|
+ $content[$sec]["branch"] = $version;
|
|
|
|
+ try {
|
|
|
|
+ $git = new Git();
|
|
|
|
+ $git_path = $dirname . '/' . $sec;
|
|
|
|
+ $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);
|
|
|
|
+ // 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;
|
|
|
|
+ // verifico si el branch a crear ya existe
|
|
|
|
+ foreach ($branchs as $branch) {
|
|
|
|
+ if ($branch['name'] == $version) {
|
|
|
|
+ $findBranch = true;
|
|
|
|
+ $branchRemote = $branch['name'];
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (!$findBranch) {
|
|
|
|
+ // si no existe el branch y estoy creando un branch nuevo
|
|
|
|
+ $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 );
|
|
|
|
+ // estoy creando un tag
|
|
|
|
+ $tags = $git->tag();
|
|
|
|
+ if (!in_array($tag, $tags)) {
|
|
|
|
+ // el tag no existe
|
|
|
|
+ if ($branchRemote == null) {
|
|
|
|
+ // el branch remote no existe
|
|
|
|
+ $git->tag->create($tag, $version);
|
|
|
|
+ } else {
|
|
|
|
+ // utilizo el branch remoto
|
|
|
|
+ $git->tag->create($tag, $branchRemote);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // ejecuto el comando git
|
|
|
|
+ shell_exec($cd_path . "; git push " . $optionRemoteGit . " --tags ");
|
|
|
|
+ } catch (GitException $e) {
|
|
|
|
+ $output->writeln("SE PRODUJO UN ERROR EN " . $sec);
|
|
|
|
+ $output->writeln($e->getTraceAsString());
|
|
|
|
+ $output->writeln($sec . ": " . $e->getMessage());
|
|
|
|
+ return $e->getCode();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return 0;
|
|
|
|
+ }
|
|
|
|
+}
|