/** * Executes the flo project-setup command. * @param InputInterface $input * @param OutputInterface $output * @throws \Exception * * @return null */ protected function execute(InputInterface $input, OutputInterface $output) { $this->checkGitRoot(); $fs = new Filesystem(); $helper = $this->getHelper('question'); if ($fs->exists($this::FLO_YAML_PATH)) { throw new \Exception("flo.yml already exists."); } // Questions. $org_question = new Question('Please enter the name of the GitHub organization/username: '******'NBCUOTS'); $repo_question = new Question('Please enter the name of your github repository: '); $shortname_question = new Question('Please enter project short name: '); $github_question = new Question('Please enter the GitHub git url: '); $acquia_question = new Question('Please enter the Acquia git url: '); $pull_request_question = new Question('Please enter the pull-request domain: '); $pull_request_prefix_question = new Question('Please enter the pull-request prefix (ex: p7): '); // Prompts. $organization = $helper->ask($input, $output, $org_question); $repository = $helper->ask($input, $output, $repo_question); $shortname = $helper->ask($input, $output, $shortname_question); $github_git_url = $helper->ask($input, $output, $github_question); $acquia_git_url = $helper->ask($input, $output, $acquia_question); $pull_request_domain = $helper->ask($input, $output, $pull_request_question); $pull_request_prefix = $helper->ask($input, $output, $pull_request_prefix_question); $flo_yml = array('organization' => $organization, 'repository' => $repository, 'shortname' => $shortname, 'github_git_uri' => $github_git_url, 'acquia_git_uri' => $acquia_git_url, 'pull_request' => array('domain' => $pull_request_domain, 'prefix' => $pull_request_prefix)); $fs->dumpFile($this::FLO_YAML_PATH, Yaml::dump($flo_yml, 2, 2)); if ($fs->exists($this::FLO_YAML_PATH)) { $output->writeln("<info>Flo.yml created.</info>"); } }
/** * Test a valid dump of the file. * */ public function testDumpFile() { $fs = new Filesystem(); $this->file = sys_get_temp_dir() . '/FilesystemTest-TEST'; $fs->dumpFile($this->file, "Test Invalid Dir"); $this->assertEquals("Test Invalid Dir", file_get_contents($this->file)); }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $fs = new Filesystem(); $dumper = new Dumper(); $home_directory = $this->getHome(); $flo_config_file = $home_directory . '/.config/flo'; if (!$fs->exists($flo_config_file)) { $fs->dumpFile($flo_config_file, ""); $output->writeln("<error>No flo config file exist.</error>"); } $flo_config = Yaml::parse($flo_config_file); $config_name = $input->getArgument('config-name'); $config_value = $input->getArgument('config-value'); $flo_config[$config_name] = $config_value; $updated_config = $dumper->dump($flo_config, 1); $fs->dumpFile($flo_config_file, $updated_config); $output->writeln("<info>{$config_name}: {$config_value} has been saved.</info>"); }
/** * Helper function to write configuration file. */ protected function writeConfig() { // Create a sample flo.yml file. $project_config = <<<EOT --- organization: NBCUOTS repository: Publisher7_nbcuflo shortname: Publisher7_nbcuflo github_git_uri: git@github.com:NBCUOTS/Publisher7_nbcuflo.git pull_request: domain: pr.publisher7.com prefix: flo-test scripts: pre_deploy_cmd: - scripts/pre-deploy.sh post_deploy_cmd: - scripts/post-deploy.sh EOT; $this->fs->dumpFile($this->root . "/flo.yml", $project_config); }
/** * Process the New Release command. * * {@inheritDoc} * * - Update the version.php file * - Commit the change and tag it * * This command assumes you are running it from the root of the repository. * Additionally, this command makes changes to the master branch. */ protected function execute(InputInterface $input, OutputInterface $output) { // Get the version information from the project config. $config_vars = $this->getConfigParameter('vars'); if (array_key_exists('version_file', $config_vars)) { $version_file = $config_vars['version_file']; } else { throw new \Exception("You must have a vars:version_file set up in your project-config.yml. Ex. version_file: ./version.php"); } if (array_key_exists('version_constant', $config_vars)) { $version_constant = $config_vars['version_constant']; } else { throw new \Exception("You must have a vars:version_constant set up in your project-config.yml. Ex. version_constant: MY_PROJECT_VERSION"); } // Determine the new version number. $increment = $input->getArgument('increment'); try { // This will succeed when a specific version number is provided (as // opposed to "major" or "minor" or "patch"), otherwise an exception will // be thrown and the "catch" is used. $version = new version($increment); $version_number = $version->getVersion(); } catch (\Exception $e) { // Get the current version from the version file if it exists. Otherwise // we're starting from scratch. if (file_exists($version_file)) { include $version_file; } $current_version = defined($version_constant) ? new version(constant($version_constant)) : new version('0.0.0'); $version_number = $current_version->inc($increment); } // Update version file. $fs = new Filesystem(); $fs->dumpFile($version_file, "<?php define('{$version_constant}', '{$version_number}');\n"); $output->writeln("<info>Successfully updated the {$version_file} file and set the {$version_constant} to {$version_number}</info>"); // Commit the updated version file. $process = new Process('git add ' . $version_file . ' && git commit -m "Preparing for new tag: ' . $version_number . '"'); $process->run(); if (!$process->isSuccessful()) { throw new \RuntimeException($process->getErrorOutput()); } // Tag the commit. $process = new Process('git tag ' . $version_number); $process->run(); if (!$process->isSuccessful()) { throw new \RuntimeException($process->getErrorOutput()); } }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $fs = new Filesystem(); $dumper = new Dumper(); $home_directory = $this->getHome(); $flo_config_file = $home_directory . '/.config/flo'; if (!$fs->exists($flo_config_file)) { return $output->writeln("<error>No flo config file exist.</error>"); } $flo_config = Yaml::parse($flo_config_file); $config_name = $input->getArgument('config-name'); if (isset($flo_config[$config_name])) { // If it exists remove the key and resaved the config file. unset($flo_config[$config_name]); $updated_config = $dumper->dump($flo_config, 1); $fs->dumpFile($flo_config_file, $updated_config); $output->writeln("<info>{$config_name} has been deleted.</info>"); } else { // No config exist as info since they wanted to remove it anyways. $output->writeln("<info>No config key '{$config_name}' exist.</info>"); } }
/** * Test the New Release command. * * @param string $initial_version * (optional) A semantic version number or an empty string. * @param string $increment * A semantic version number or major | minor | patch. * @param string $expected_version * A semantic version number or an empty string. * * @dataProvider newReleaseProvider */ public function testNewRelease($initial_version, $increment, $expected_version) { $fs = new Filesystem(); $version_file = $this->root . '/' . $this->versionFile; $initial_content = "<?php define('{$this->versionConstant}', '{$initial_version}');\n"; $expected_content = "<?php define('{$this->versionConstant}', '{$expected_version}');\n"; // Setup some project configs making sure that version file and version // constant are unique between tests. $project_config = "---\nvars:\n version_file: {$this->versionFile}\n version_constant: {$this->versionConstant}"; $fs->dumpFile($this->root . "/flo.yml", $project_config); if (!empty($initial_version)) { $fs->dumpFile($version_file, $initial_content); } $this->runNewRelease($increment); // Assert that the version.php file has the correct contents. $this->assertEquals($expected_content, file_get_contents($version_file), 'The version file contained the correct version information.'); // Assert that the git tag was created correctly. $process = new Process("git show-ref {$expected_version}"); $success = $process->run(); $this->assertTrue($success === 0, "The git tag ({$expected_version}) was created successfully."); // Assert that the tagged commit has the proper change to the version file. $process = new Process("git show {$expected_version}"); $process->run(); $this->assertContains('+' . $expected_content, $process->getOutput(), 'The tagged commit contains the proper change to the version file.'); }