Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default branch to main instead of master #172

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 27 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ executed before or after the release of a new version.
Installation
------------
### Option 1: As a development dependency of your project
In order to use RMT in your project you should use [Composer](http://getcomposer.org/) to install it
To use RMT in your project you should use [Composer](http://getcomposer.org/) to install it
as a dev-dependency. Just go to your project's root directory and execute:

composer require --dev liip/rmt
Expand All @@ -31,7 +31,7 @@ root folder. You can now start using RMT by executing:
Once there, your best option is to pick one of the [configuration examples](#configuration-examples) below
and adapt it to your needs.

If you are using a versioning tool, we recommend to add both Composer files (`composer.json`
If you are using a versioning tool, we recommend adding both Composer files (`composer.json`
and `composer.lock`), the RMT configuration file(`.rmt.yml`) and the `RMT` executable script
to it. The `vendor` directory should be ignored as it is populated when running
`composer install`.
Expand Down Expand Up @@ -62,9 +62,9 @@ directly `./rmt.phar` or run it by invoking it through PHP via `php rmt.phar`.
For the usage substitute RMT with whatever variant you have decided to use.

### Option 4: As Drifter role
If your are using https://github.com/liip/drifter for your project, you just need three step
If you are using https://github.com/liip/drifter for your project, you just need three step
* Activate the `rmt` role
* Re-run the provisionning `vagrant provision`
* Re-run the provisioning `vagrant provision`
* Init RMT for your project `php /home/vagrant/.config/composer/vendor/liip/rmt/RMT`

Usage
Expand Down Expand Up @@ -122,13 +122,13 @@ RMT also support JSON configs, but we recommend using YAML.

### Branch specific config

Sometimes you want to use a different release strategy according to the VCS branch, e.g. you want to add CHANGELOG entries only in the `master` branch. To do so, you have to place your default config into a root element named `_default`, then you can override parts of this default config for the
branch `master`. Example:
Sometimes you want to use a different release strategy according to the VCS branch, e.g. you want to add CHANGELOG entries only in the `main` branch. To do so, you have to place your default config into a root element named `_default`, then you can override parts of this default config for the
branch `main`. Example:

_default:
version-generator: "simple"
version-persister: "vcs-tag"
master:
main:
pre-release-actions: [changelog-update]

You can use the command `RMT config` to see the merge result between _default and your current branch.
Expand All @@ -138,7 +138,7 @@ You can use the command `RMT config` to see the merge result between _default an
Build-in version number generation strategies.

* simple: This generator is doing a simple increment (1,2,3...)
* semantic: A generator which implements [Semantic versioning](http://semver.org)
* semantic: A generator, which implements [Semantic versioning](http://semver.org)
* Option `allow-label` (boolean): To allow adding a label on a version (such as -beta, -rcXX) (default: *false*)
* Option `type`: to force the version type
* Option `label`: to force the label
Expand All @@ -151,8 +151,8 @@ Build-in version number generation strategies.
Class in charge of saving/retrieving the version number.

* vcs-tag: Save the version as a VCS tag
* Option `tag-pattern`: Allow to provide a regex that all tag must match. This allow for example to release a version 1.X.X in a specific branch and to release a 2.X.X in a separate branch
* Option `tag-prefix`: Allow to prefix all VCS tag with a string. You can have a numeric versionning but generation tags such as `v_2.3.4`. As a bonus you can use a specific placeholder: `{branch-name}` that will automatically inject the current branch name in the tag. So use, simple generation and `tag-prefix: "{branch-name}_"` and it will generate tag like `featureXY_1`, `featureXY_2`, etc...
* Option `tag-pattern`: Allow to provide a regex that all tag must match. This allows for example to release a version 1.X.X in a specific branch and to release a 2.X.X in a separate branch
* Option `tag-prefix`: Allow to prefix all VCS tag with a string. You can have a numeric versioning but generation tags such as `v_2.3.4`. As a bonus you can use a specific placeholder: `{branch-name}` that will automatically inject the current branch name in the tag. So use, simple generation and `tag-prefix: "{branch-name}_"` and it will generate tag like `featureXY_1`, `featureXY_2`, etc...

* changelog: Save the version in the changelog file
* Option `location`: Changelog file name an location (default: *CHANGELOG*)
Expand All @@ -166,9 +166,9 @@ Prerequisite actions are executed before the interactive part.
* `display-last-changes`: display your last changes
* `tests-check`: run the project test suite
* Option `command`: command to run (default: *phpunit*)
* Option `timeout`: the number of seconds after which the command times out (default: *60.0*)
* Option `timeout`: the amount of seconds after which the command times out (default: *60.0*)
* Option `expected_exit_code`: expected return code (default: *0*)
* `composer-json-check`: run a validate on the composer.json
* `composer-json-check`: run a validated on the composer.json
* Option `composer`: how to run composer (default: *php composer.phar*)
* `composer-stability-check`: will check if the composer.json is set to the right minimum-stability
* Option `stability`: the stability that should be set in the minimum-stability field (default: *stable*)
Expand All @@ -192,21 +192,21 @@ Actions can be used for pre or post release parts.
* Option `file`: path from .rmt.yml to changelog file (default: *CHANGELOG*)
* Option `dump-commits`: write all commit messages since the last release into the
changelog file (default: *false*)
* Option `insert-at`: only for addTop formatter: Number of lines to skip from the
* Option `insert-at`: only for addTop formatter: Amount lines to skip from the
top of the changelog file before adding the release number (default: *0*)
* Option `exclude-merge-commits`: Exclude merge commits from the changelog (default: *false*)
* `vcs-commit`: commit all files of the working copy (only use it with the
`working-copy-check` prerequisite)
* Option `commit-message`: specify a custom commit message. %version% will be replaced by the current / next version strings.
* `vcs-tag`: Tag the last commit
* `vcs-publish`: Publish the changes (commits and tags)
* `composer-update`: Update the version number in a composer file (note that when using packagist.org, it is recommended to not have a tag in composer.json as the version is handle by version control tags)
* `composer-update`: Update the version number in a composer file (note that when using packagist.org, it is recommended to not have a tag in composer.json as the version is handled by version control tags)
* `files-update`: Update the version in one or multiple files. For each file to update, please provide an array with
* Option `file`: path to the file to update
* Option `pattern`: optional, use to specify the string replacement pattern in your file. For example:
`const VERSION = '%version%';`
* `build-phar-package`: Builds a Phar package of the current project whose filename depends on the 'package-name' option and the deployed version: [package-name]-[version].phar
* Option `package-name`: the name of the generate package
* Option `package-name`: the name of the generated package
* Option `destination`: the destination directory to build the package into. If prefixed with a slash, is considered absolute, otherwise relative to the project root.
* Option `excluded-paths`: a regex of excluded paths, directly passed to the [Phar::buildFromDirectory](http://php.net/manual/en/phar.buildfromdirectory.php) method. Ex: `/^(?!.*cookbooks|.*\.vagrant|.*\.idea).*$/im`
* Option `metadata`: an array of metadata describing the package. Ex author, project. Note: the release version is added by default but can be overridden here.
Expand All @@ -228,7 +228,7 @@ Actions can be used for pre or post release parts.
Extend it
---------

RMT is providing some existing actions, generators, and persisters. If needed you can add your own by creating a PHP script in your project, and referencing it in the configuration via it's relative path:
RMT is providing some existing actions, generators and persisters. If needed you can add your own by creating a PHP script in your project, and referencing it in the configuration via it's relative path:

version-generator: "bin/myOwnGenerator.php"

Expand Down Expand Up @@ -284,7 +284,7 @@ Most of the time, it will be easier for you to pick up an example below and adap
prerequisites: [working-copy-check, display-last-changes]


### Using Git tags with prefix, semantic versioning, updating two files and pushing automatically
### Using Git tags with a prefix, semantic versioning, updating two files and pushing automatically

vcs: git
version-generator: semantic
Expand All @@ -297,7 +297,7 @@ Most of the time, it will be easier for you to pick up an example below and adap
- [app.ini, 'dynamic-version: %version%']
post-release-actions: [vcs-publish]

### Using semantic versioning on master and simple versioning on topic branches, markdown formatting for changelog
### Using semantic versioning on main and simple versioning on topic branches, markdown formatting for changelog

_default:
vcs: git
Expand All @@ -308,8 +308,8 @@ Most of the time, it will be easier for you to pick up an example below and adap
tag-prefix: "{branch-name}_"
post-release-actions: [vcs-publish]

# This entry allow to override some parameters for the master branch
master:
# This entry allow to override some parameters for the main branch
main:
prerequisites: [working-copy-check, display-last-changes]
pre-release-actions:
changelog-update:
Expand All @@ -323,9 +323,15 @@ Most of the time, it will be easier for you to pick up an example below and adap
version-generator: semantic
version-persister: vcs-tag

### Changing the default-branch:
_default:
vcs:
name: git
default-branch: my-default-branch

Contributing
------------
If you would like to help, by submitting one of your action scripts, generators, or persisters. Or just by reporting a
If you would like to help, by submitting one of your action scripts, generators or persisters. Or just by reporting a
bug just go to the project page [https://github.com/liip/RMT](https://github.com/liip/RMT).

If you provide a PR, try to associate it some unit or functional tests. See next section
Expand Down
2 changes: 1 addition & 1 deletion autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,5 @@
));
$loader->register();
} else {
throw new \Exception("Unable to find the an autoloader");
throw new \Exception("Unable to find an autoloader");
}
2 changes: 1 addition & 1 deletion src/Liip/RMT/Command/BaseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function loadContext(): void
try {
$branch = $vcs->getCurrentBranch();
} catch (\Exception $e) {
echo "\033[31mImpossible to read the branch name\033[37m";
echo "\033[31mUnable to read the branch name\033[37m";
}
if (isset($branch)) {
$config = $configHandler->getConfigForBranch($branch);
Expand Down
14 changes: 11 additions & 3 deletions src/Liip/RMT/Command/InitCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@ protected function configure(): void
'choices_shortcuts' => array('g' => 'git', 'h' => 'hg', 'n' => 'none'),
'default' => 'none',
)),
new InformationRequest('main-branch', array(
'description' => 'The default branch you want to use (select none if you are not using a VCS system)',
'type' => 'choice',
'choices' => array('main', 'master', 'none'),
'choices_shortcuts' => array('m' => 'main', 'mst' => 'master', 'n' => 'none'),
'default' => 'main',
)),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like so much this question. If the user is saying none at the previous question, then it makes no sense to ask him a branch name.
But I have to admit that in most case users will use Git. Maybe allow also a choice n=>none. And adjust a bit the question:

The default branch you want to use (select none if you are not using a VCS system)

new InformationRequest('generator', array(
'description' => 'The generator to use for version incrementing',
'type' => 'choice',
Expand Down Expand Up @@ -153,18 +160,19 @@ protected function execute(InputInterface $input, OutputInterface $output): int

// Create the config file from a template
$this->getOutput()->writeln("Creation of the config file <info>{$this->configPath}</info>");
$template = $this->informationCollector->getValueFor('vcs') == 'none' ?
$template = $this->informationCollector->getValueFor('vcs') === 'none' ?
__DIR__.'/../Config/templates/no-vcs-config.yml.tmpl' :
__DIR__.'/../Config/templates/default-vcs-config.yml.tmpl'
;
$config = file_get_contents($template);
$generator = $this->informationCollector->getValueFor('generator');
foreach (array(
'generator' => $generator == 'semantic-versioning' ?
'generator' => $generator === 'semantic-versioning' ?
'semantic # More complex versionning (semantic)' : 'simple # Same simple versionning',
'vcs' => $this->informationCollector->getValueFor('vcs'),
'main-branch' => $this->informationCollector->getValueFor('main-branch'),
'persister' => $this->informationCollector->getValueFor('persister'),
'changelog-format' => $generator == 'semantic-versioning' ? 'semantic' : 'simple',
'changelog-format' => $generator === 'semantic-versioning' ? 'semantic' : 'simple',
) as $key => $value) {
$config = str_replace("%%$key%%", $value, $config);
}
Expand Down
11 changes: 5 additions & 6 deletions src/Liip/RMT/Config/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function __construct($rawConfig = null, $projectRoot = null)
public function getDefaultConfig()
{
return array(
'vcs' => null,
'vcs' => array(),
'prerequisites' => array(),
'pre-release-actions' => array(),
'version-generator' => null,
Expand Down Expand Up @@ -73,7 +73,7 @@ protected function mergeConfig($branchName = null)
}

// Return custom branch config
if (isset($branchName) && isset($branchesConfig[$branchName])) {
if (isset($branchName, $branchesConfig[$branchName])) {
return array_replace_recursive($baseConfig, $branchesConfig[$branchName]);
}

Expand Down Expand Up @@ -101,7 +101,6 @@ protected function normalize($config)
// Same process but for list value elements
foreach (array('prerequisites', 'pre-release-actions', 'post-release-actions') as $configKey) {
foreach ($config[$configKey] as $key => $item) {

// Accept the element to be define by key or by value
if (!is_numeric($key)) {
if ($item == null) {
Expand Down Expand Up @@ -146,7 +145,7 @@ protected function getClassAndOptions($rawConfig, $sectionName)
} elseif (is_array($rawConfig)) {

// Handling Yml corner case (see https://github.com/liip/RMT/issues/54)
if (count($rawConfig) == 1 && key($rawConfig) !== 'name') {
if (count($rawConfig) === 1 && key($rawConfig) !== 'name') {
$name = key($rawConfig);
$rawConfig = is_array(reset($rawConfig)) ? reset($rawConfig) : array();
$rawConfig['name'] = $name;
Expand All @@ -161,7 +160,7 @@ protected function getClassAndOptions($rawConfig, $sectionName)

$options = $rawConfig;
} else {
throw new Exception("Invalid configuration for [$sectionName] should be a object name or an array with name and options");
throw new Exception("Invalid configuration for [$sectionName] should be an object name or an array with name and options");
}

return array('class' => $class, 'options' => $options);
Expand All @@ -181,7 +180,7 @@ protected function findClass($name, $sectionName)

return str_replace('.php', '', $lastPart);
} else {
throw new \Liip\RMT\Exception("Impossible to open [$file] please review your config");
throw new \Liip\RMT\Exception("Unable to open [$file] please review your config");
}
}

Expand Down
8 changes: 5 additions & 3 deletions src/Liip/RMT/Config/templates/default-vcs-config.yml.tmpl
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
_default:

# VCS CONFIG
vcs: %%vcs%%
vcs:
name: %%vcs%%
main-branch: %%main-branch%%

# PREREQUISITES
# Actions executed before any questions get asked to the user.
Expand All @@ -24,8 +26,8 @@ _default:
ask-confirmation: true

# BRANCH SPECIFIC CONFIG
# On master, we override the general config
master:
# On %%main-branch%%, we override the general config
%%main-branch%%:
version-generator: %%generator%%
version-persister:
vcs-tag:
Expand Down
4 changes: 2 additions & 2 deletions src/Liip/RMT/Information/InformationCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function registerRequests($list)

public function registerStandardRequest($name)
{
if (!in_array($name, array_keys(static::$standardRequests))) {
if (!array_key_exists($name, static::$standardRequests)) {
throw new \Exception("There is no standard request named [$name]");
}
if (!isset($this->requests[$name])) {
Expand Down Expand Up @@ -162,7 +162,7 @@ public function getValueFor($requestName, $default = null)
if ($this->hasRequest($requestName)) {
return $this->getRequest($requestName)->getValue();
} else {
if (func_num_args() == 2) {
if (func_num_args() === 2) {
return $default;
}
throw new \Exception("No request named $requestName");
Expand Down
2 changes: 1 addition & 1 deletion test/Liip/RMT/Tests/Functional/ExternalTasksTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function testInvalidScript(): void
exec('./RMT release -n', $output);
$output = implode("\n", $output);
// $this->manualDebug();
self::assertStringContainsString('Impossible to open', $output);
self::assertStringContainsString('Unable to open', $output);
self::assertStringContainsString($scriptName, $output);
}

Expand Down
4 changes: 2 additions & 2 deletions test/Liip/RMT/Tests/Functional/GitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function testInitialVersion(): void
$this->createConfig('simple', 'vcs-tag', array('vcs' => 'git'));
exec('./RMT release -n --confirm-first');
exec('git tag', $tags);
// $this->manualDebug();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please keep all this $this->manualDebug();, they are very usefully to debug

// $this->manualDebug();
self::assertEquals(array('1'), $tags);
}

Expand Down Expand Up @@ -76,6 +76,6 @@ public function testTagPrefixWithBranchNamePlaceHolder(): void
exec('./RMT release -n --confirm-first');
exec('git tag', $tags);
// $this->manualDebug();
self::assertEquals(array('_main_1'), $tags);
self::assertEquals(sprintf('_%s_1', self::DEFAULT_FUNCTIONAL_BRANCH), $tags[0]);
}
}
13 changes: 6 additions & 7 deletions test/Liip/RMT/Tests/Functional/InitCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,21 @@ public function testInitConfig(): void
$configFile = '.rmt.yml';
unlink($configFile);
self::assertFileDoesNotExist($configFile);
exec('./RMT init --configonly=n --vcs=git --generator=semantic-versioning --persister=vcs-tag -n');

// $this->manualDebug();
exec(sprintf('./RMT init --configonly=n --vcs=git --main-branch=%s --generator=semantic-versioning --persister=vcs-tag -n', self::DEFAULT_FUNCTIONAL_BRANCH));

self::assertFileExists($configFile);
$config = Yaml::parse(file_get_contents($configFile), true);

$defaultConfig = $config['_default'];
$masterConfig = $config['master'];
$mainConfig = $config[self::DEFAULT_FUNCTIONAL_BRANCH];

self::assertEquals('git', $defaultConfig['vcs']);
self::assertEquals('git', $defaultConfig['vcs']['name']);
self::assertEquals(self::DEFAULT_FUNCTIONAL_BRANCH, $defaultConfig['vcs']['main-branch']);

self::assertEquals('simple', $defaultConfig['version-generator']);
self::assertEquals('semantic', $masterConfig['version-generator']);
self::assertEquals('semantic', $mainConfig['version-generator']);

self::assertEquals(array('vcs-tag' => array('tag-prefix' => '{branch-name}_')), $defaultConfig['version-persister']);
self::assertEquals(array('vcs-tag' => array('tag-prefix' => '')), $masterConfig['version-persister']);
self::assertEquals(array('vcs-tag' => array('tag-prefix' => '')), $mainConfig['version-persister']);
}
}
Loading