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 11 commits into
base: master
Choose a base branch
from
Open
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ jobs:
run: |
git config --global user.email "test@test.com"
git config --global user.name "John Doe"
git config --global init.defaultBranch master # TODO: use main, need to adjust tests to match
git config --global init.defaultBranch main

- name: Run tests
run: phpunit
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ cache.properties
bin
!bin/UpdateApplicationVersionCurrentVersion.php
.phpunit.result.cache
.idea/
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 this for your local git ignore

4 changes: 3 additions & 1 deletion .rmt.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
vcs: git
vcs:
name: git
main-branch: main
Copy link
Member

Choose a reason for hiding this comment

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

Let's do one thing at a time. Let's first merge this PR and then after this, I will change the main branch name of this repo. So please set master here for now


prerequisites:
- working-copy-check:
Expand Down
40 changes: 20 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ RMT - Release Management Tool
[![Total Downloads](https://poser.pugx.org/liip/RMT/d/total.png)](https://packagist.org/packages/liip/RMT)
[![License](https://poser.pugx.org/liip/rmt/license.svg)](https://packagist.org/packages/liip/rmt)

RMT is a handy tool to help releasing new versions of your software. You can define the type
RMT is a handy tool to help releasing a new versions of your software. You can define the type
Copy link
Member

Choose a reason for hiding this comment

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

new versionS. It was just before

of version generator you want to use (e.g. semantic versioning), where you want to store
the version (e.g. in a changelog file or as a VCS tag) and a list of actions that should be
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 @@ -123,12 +123,12 @@ 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
Copy link
Member

Choose a reason for hiding this comment

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

One missing master here

branch `master`. Example:
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 @@ -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 @@ -325,7 +325,7 @@ Most of the time, it will be easier for you to pick up an example below and adap

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',
'type' => 'choice',
'choices' => array('main', 'master'),
'choices_shortcuts' => array('m' => 'main', 'mst' => 'master'),
'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 @@ -25,7 +25,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 @@ -69,7 +69,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 @@ -97,7 +97,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 @@ -142,7 +141,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 @@ -157,7 +156,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 @@ -177,7 +176,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, we override the general config
Copy link
Member

Choose a reason for hiding this comment

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

Please also use the %%main-branch%% in this comment

%%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)) {
jeanmonod marked this conversation as resolved.
Show resolved Hide resolved
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
Loading