Merge remote-tracking branch 'origin/beta'
This commit is contained in:
commit
152bf452e1
@ -1,4 +1,3 @@
|
|||||||
node_js:
|
node_js:
|
||||||
- 12
|
- 12
|
||||||
- 10
|
- 10.13
|
||||||
- 8.16
|
|
||||||
|
29
README.md
29
README.md
@ -24,6 +24,9 @@
|
|||||||
<a href="https://www.npmjs.com/package/semantic-release">
|
<a href="https://www.npmjs.com/package/semantic-release">
|
||||||
<img alt="npm next version" src="https://img.shields.io/npm/v/semantic-release/next.svg">
|
<img alt="npm next version" src="https://img.shields.io/npm/v/semantic-release/next.svg">
|
||||||
</a>
|
</a>
|
||||||
|
<a href="https://www.npmjs.com/package/semantic-release">
|
||||||
|
<img alt="npm beta version" src="https://img.shields.io/npm/v/semantic-release/beta.svg">
|
||||||
|
</a>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
**semantic-release** automates the whole package release workflow including: determining the next version number, generating the release notes and publishing the package.
|
**semantic-release** automates the whole package release workflow including: determining the next version number, generating the release notes and publishing the package.
|
||||||
@ -39,6 +42,7 @@ This removes the immediate connection between human emotions and version numbers
|
|||||||
- New features and fixes are immediately available to users
|
- New features and fixes are immediately available to users
|
||||||
- Notify maintainers and users of new releases
|
- Notify maintainers and users of new releases
|
||||||
- Use formalized commit message convention to document changes in the codebase
|
- Use formalized commit message convention to document changes in the codebase
|
||||||
|
- Publish on different distribution channels (such as [npm dist-tags](https://docs.npmjs.com/cli/dist-tag)) based on git merges
|
||||||
- Integrate with your [continuous integration workflow](docs/recipes/README.md#ci-configurations)
|
- Integrate with your [continuous integration workflow](docs/recipes/README.md#ci-configurations)
|
||||||
- Avoid potential errors associated with manual releases
|
- Avoid potential errors associated with manual releases
|
||||||
- Support any [package managers and languages](docs/recipes/README.md#package-managers-and-languages) via [plugins](docs/usage/plugins.md)
|
- Support any [package managers and languages](docs/recipes/README.md#package-managers-and-languages) via [plugins](docs/usage/plugins.md)
|
||||||
@ -68,11 +72,12 @@ Here is an example of the release type that will be done based on a commit messa
|
|||||||
|
|
||||||
### Triggering a release
|
### Triggering a release
|
||||||
|
|
||||||
For each new commits added to the release branch (i.e. `master`) with `git push` or by merging a pull request or merging from another branch, a CI build is triggered and runs the `semantic-release` command to make a release if there are codebase changes since the last release that affect the package functionalities.
|
For each new commits added to one of the release branches (for example `master`, `next`, `beta`), with `git push` or by merging a pull request or merging from another branch, a CI build is triggered and runs the `semantic-release` command to make a release if there are codebase changes since the last release that affect the package functionalities.
|
||||||
|
|
||||||
If you need more control over the timing of releases you have a couple of options:
|
**semantic-release** offers various ways to control the timing, the content and the audience of published releases. See example workflows in the following recipes:
|
||||||
- Publish releases on a distribution channel (for example npm’s [dist-tags](https://docs.npmjs.com/cli/dist-tag)). This way you can keep control over what your users end up using by default, and you can decide when to make an automatically released version available to the stable channel, and promote it.
|
- [Using distribution channels](docs/recipes/distribution-channels.md#publishing-on-distribution-channels)
|
||||||
- Develop on a `dev` branch and merge it to the release branch (i.e. `master`) once you are ready to publish. **semantic-release** will run only on pushes to the release branch.
|
- [Maintenance releases](docs/recipes/maintenance-releases.md#publishing-maintenance-releases)
|
||||||
|
- [Pre-releases](docs/recipes/pre-releases.md#publishing-pre-releases)
|
||||||
|
|
||||||
### Release steps
|
### Release steps
|
||||||
|
|
||||||
@ -90,6 +95,14 @@ After running the tests, the command `semantic-release` will execute the followi
|
|||||||
| Publish | Publish the release. |
|
| Publish | Publish the release. |
|
||||||
| Notify | Notify of new releases or errors. |
|
| Notify | Notify of new releases or errors. |
|
||||||
|
|
||||||
|
## Requirements
|
||||||
|
|
||||||
|
In order to use **semantic-release** you need:
|
||||||
|
- To host your code in a [Git repository](https://git-scm.com)
|
||||||
|
- Use a Continuous Integration service that allows you to [securely set up credentials](docs/usage/ci-configuration.md#authentication)
|
||||||
|
- Git CLI version [2.7.1 or higher](docs/support/FAQ.md#why-does-semantic-release-require-git-version--271) installed in your Continuous Integration environment
|
||||||
|
- [Node.js](https://nodejs.org) version [8.16.0 or higher](docs/support/FAQ.md#why-does-semantic-release-require-node-version--816) installed in your Continuous Integration environment
|
||||||
|
|
||||||
## Documentation
|
## Documentation
|
||||||
|
|
||||||
- Usage
|
- Usage
|
||||||
@ -98,14 +111,16 @@ After running the tests, the command `semantic-release` will execute the followi
|
|||||||
- [CI Configuration](docs/usage/ci-configuration.md#ci-configuration)
|
- [CI Configuration](docs/usage/ci-configuration.md#ci-configuration)
|
||||||
- [Configuration](docs/usage/configuration.md#configuration)
|
- [Configuration](docs/usage/configuration.md#configuration)
|
||||||
- [Plugins](docs/usage/plugins.md)
|
- [Plugins](docs/usage/plugins.md)
|
||||||
|
- [Workflow configuration](docs/usage/workflow-configuration.md)
|
||||||
- [Shareable configurations](docs/usage/shareable-configurations.md)
|
- [Shareable configurations](docs/usage/shareable-configurations.md)
|
||||||
- Extending
|
- Extending
|
||||||
- [Plugins](docs/extending/plugins-list.md)
|
- [Plugins](docs/extending/plugins-list.md)
|
||||||
- [Shareable configuration](docs/extending/shareable-configurations-list.md)
|
- [Shareable configuration](docs/extending/shareable-configurations-list.md)
|
||||||
- Recipes
|
- Recipes
|
||||||
- [CI configurations](docs/recipes/README.md#ci-configurations)
|
- [CI configurations](docs/recipes/README.md)
|
||||||
- [Git hosted services](docs/recipes/README.md#git-hosted-services)
|
- [Git hosted services](docs/recipes/README.md)
|
||||||
- [Package managers and languages](docs/recipes/README.md#package-managers-and-languages)
|
- [Release workflow](docs/recipes/README.md)
|
||||||
|
- [Package managers and languages](docs/recipes/README.md)
|
||||||
- Developer guide
|
- Developer guide
|
||||||
- [JavaScript API](docs/developer-guide/js-api.md)
|
- [JavaScript API](docs/developer-guide/js-api.md)
|
||||||
- [Plugins development](docs/developer-guide/plugin.md)
|
- [Plugins development](docs/developer-guide/plugin.md)
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
- [CI Configuration](docs/usage/ci-configuration.md#ci-configuration)
|
- [CI Configuration](docs/usage/ci-configuration.md#ci-configuration)
|
||||||
- [Configuration](docs/usage/configuration.md#configuration)
|
- [Configuration](docs/usage/configuration.md#configuration)
|
||||||
- [Plugins](docs/usage/plugins.md)
|
- [Plugins](docs/usage/plugins.md)
|
||||||
|
- [Workflow configuration](docs/usage/workflow-configuration.md)
|
||||||
- [Shareable configurations](docs/usage/shareable-configurations.md)
|
- [Shareable configurations](docs/usage/shareable-configurations.md)
|
||||||
|
|
||||||
## Extending
|
## Extending
|
||||||
|
@ -10,7 +10,7 @@ var execa = require('execa');
|
|||||||
var findVersions = require('find-versions');
|
var findVersions = require('find-versions');
|
||||||
var pkg = require('../package.json');
|
var pkg = require('../package.json');
|
||||||
|
|
||||||
var MIN_GIT_VERSION = '2.0.0';
|
var MIN_GIT_VERSION = '2.7.1';
|
||||||
|
|
||||||
if (!semver.satisfies(process.version, pkg.engines.node)) {
|
if (!semver.satisfies(process.version, pkg.engines.node)) {
|
||||||
console.error(
|
console.error(
|
||||||
@ -35,7 +35,7 @@ execa('git', ['--version'])
|
|||||||
process.exit(1);
|
process.exit(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Node 8+ from this point on
|
// Node 10+ from this point on
|
||||||
require('../cli')()
|
require('../cli')()
|
||||||
.then(exitCode => {
|
.then(exitCode => {
|
||||||
process.exitCode = exitCode;
|
process.exitCode = exitCode;
|
||||||
|
2
cli.js
2
cli.js
@ -19,7 +19,7 @@ module.exports = async () => {
|
|||||||
Usage:
|
Usage:
|
||||||
semantic-release [options] [plugins]`);
|
semantic-release [options] [plugins]`);
|
||||||
})
|
})
|
||||||
.option('b', {alias: 'branch', describe: 'Git branch to release from', type: 'string', group: 'Options'})
|
.option('b', {alias: 'branches', describe: 'Git branches to release from', ...stringList, group: 'Options'})
|
||||||
.option('r', {alias: 'repository-url', describe: 'Git repository URL', type: 'string', group: 'Options'})
|
.option('r', {alias: 'repository-url', describe: 'Git repository URL', type: 'string', group: 'Options'})
|
||||||
.option('t', {alias: 'tag-format', describe: 'Git tag format', type: 'string', group: 'Options'})
|
.option('t', {alias: 'tag-format', describe: 'Git tag format', type: 'string', group: 'Options'})
|
||||||
.option('p', {alias: 'plugins', describe: 'Plugins', ...stringList, group: 'Options'})
|
.option('p', {alias: 'plugins', describe: 'Plugins', ...stringList, group: 'Options'})
|
||||||
|
@ -12,7 +12,14 @@ const stderrBuffer = WritableStreamBuffer();
|
|||||||
try {
|
try {
|
||||||
const result = await semanticRelease({
|
const result = await semanticRelease({
|
||||||
// Core options
|
// Core options
|
||||||
branch: 'master',
|
branches: [
|
||||||
|
'+([0-9])?(.{+([0-9]),x}).x',
|
||||||
|
'master',
|
||||||
|
'next',
|
||||||
|
'next-major',
|
||||||
|
{name: 'beta', prerelease: true},
|
||||||
|
{name: 'alpha', prerelease: true}
|
||||||
|
],
|
||||||
repositoryUrl: 'https://github.com/me/my-package.git',
|
repositoryUrl: 'https://github.com/me/my-package.git',
|
||||||
// Shareable config
|
// Shareable config
|
||||||
extends: 'my-shareable-config',
|
extends: 'my-shareable-config',
|
||||||
@ -124,10 +131,11 @@ Type: `Object`
|
|||||||
Information related to the last release found:
|
Information related to the last release found:
|
||||||
|
|
||||||
| Name | Type | Description |
|
| Name | Type | Description |
|
||||||
|---------|----------|----------------------------------------------------------------------------------------------------|
|
|---------|----------|-------------------------------------------------------------------------------------------------------------------------------------|
|
||||||
| version | `String` | The version of the last release. |
|
| version | `String` | The version of the last release. |
|
||||||
| gitHead | `String` | The sha of the last commit being part of the last release. |
|
| gitHead | `String` | The sha of the last commit being part of the last release. |
|
||||||
| gitTag | `String` | The [Git tag](https://git-scm.com/book/en/v2/Git-Basics-Tagging) associated with the last release. |
|
| gitTag | `String` | The [Git tag](https://git-scm.com/book/en/v2/Git-Basics-Tagging) associated with the last release. |
|
||||||
|
| channel | `String` | The distribution channel on which the last release was initially made available (`undefined` for the default distribution channel). |
|
||||||
|
|
||||||
**Notes**: If no previous release is found, `lastRelease` will be an empty `Object`.
|
**Notes**: If no previous release is found, `lastRelease` will be an empty `Object`.
|
||||||
|
|
||||||
@ -137,6 +145,7 @@ Example:
|
|||||||
gitHead: 'da39a3ee5e6b4b0d3255bfef95601890afd80709',
|
gitHead: 'da39a3ee5e6b4b0d3255bfef95601890afd80709',
|
||||||
version: '1.0.0',
|
version: '1.0.0',
|
||||||
gitTag: 'v1.0.0',
|
gitTag: 'v1.0.0',
|
||||||
|
channel: 'next'
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -207,12 +216,13 @@ Type: `Object`
|
|||||||
Information related to the newly published release:
|
Information related to the newly published release:
|
||||||
|
|
||||||
| Name | Type | Description |
|
| Name | Type | Description |
|
||||||
|---------|----------|---------------------------------------------------------------------------------------------------|
|
|---------|----------|-------------------------------------------------------------------------------------------------------------------------------|
|
||||||
| type | `String` | The [semver](https://semver.org) type of the release (`patch`, `minor` or `major`). |
|
| type | `String` | The [semver](https://semver.org) type of the release (`patch`, `minor` or `major`). |
|
||||||
| version | `String` | The version of the new release. |
|
| version | `String` | The version of the new release. |
|
||||||
| gitHead | `String` | The sha of the last commit being part of the new release. |
|
| gitHead | `String` | The sha of the last commit being part of the new release. |
|
||||||
| gitTag | `String` | The [Git tag](https://git-scm.com/book/en/v2/Git-Basics-Tagging) associated with the new release. |
|
| gitTag | `String` | The [Git tag](https://git-scm.com/book/en/v2/Git-Basics-Tagging) associated with the new release. |
|
||||||
| notes | `String` | The release notes for the new release. |
|
| notes | `String` | The release notes for the new release. |
|
||||||
|
| channel | `String` | The distribution channel on which the next release will be made available (`undefined` for the default distribution channel). |
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
```js
|
```js
|
||||||
@ -222,6 +232,7 @@ Example:
|
|||||||
version: '1.1.0',
|
version: '1.1.0',
|
||||||
gitTag: 'v1.1.0',
|
gitTag: 'v1.1.0',
|
||||||
notes: 'Release notes for version 1.1.0...',
|
notes: 'Release notes for version 1.1.0...',
|
||||||
|
channel : 'next'
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -229,11 +240,11 @@ Example:
|
|||||||
|
|
||||||
Type: `Array<Object>`
|
Type: `Array<Object>`
|
||||||
|
|
||||||
The list of releases published, one release per [publish plugin](../usage/plugins.md#publish-plugin).<br>
|
The list of releases published or made available to a distribution channel.<br>
|
||||||
Each release object has the following properties:
|
Each release object has the following properties:
|
||||||
|
|
||||||
| Name | Type | Description |
|
| Name | Type | Description |
|
||||||
|------------|----------|-----------------------------------------------------------------------------------------------|
|
|------------|----------|----------------------------------------------------------------------------------------------------------------|
|
||||||
| name | `String` | **Optional.** The release name, only if set by the corresponding `publish` plugin. |
|
| name | `String` | **Optional.** The release name, only if set by the corresponding `publish` plugin. |
|
||||||
| url | `String` | **Optional.** The release URL, only if set by the corresponding `publish` plugin. |
|
| url | `String` | **Optional.** The release URL, only if set by the corresponding `publish` plugin. |
|
||||||
| type | `String` | The [semver](https://semver.org) type of the release (`patch`, `minor` or `major`). |
|
| type | `String` | The [semver](https://semver.org) type of the release (`patch`, `minor` or `major`). |
|
||||||
@ -242,6 +253,7 @@ Each release object has the following properties:
|
|||||||
| gitTag | `String` | The [Git tag](https://git-scm.com/book/en/v2/Git-Basics-Tagging) associated with the release. |
|
| gitTag | `String` | The [Git tag](https://git-scm.com/book/en/v2/Git-Basics-Tagging) associated with the release. |
|
||||||
| notes | `String` | The release notes for the release. |
|
| notes | `String` | The release notes for the release. |
|
||||||
| pluginName | `String` | The name of the plugin that published the release. |
|
| pluginName | `String` | The name of the plugin that published the release. |
|
||||||
|
| channel | `String` | The distribution channel on which the release is available (`undefined` for the default distribution channel). |
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
```js
|
```js
|
||||||
@ -255,6 +267,7 @@ Example:
|
|||||||
gitTag: 'v1.1.0',
|
gitTag: 'v1.1.0',
|
||||||
notes: 'Release notes for version 1.1.0...',
|
notes: 'Release notes for version 1.1.0...',
|
||||||
pluginName: '@semantic-release/github'
|
pluginName: '@semantic-release/github'
|
||||||
|
channel: 'next'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'npm package (@latest dist-tag)',
|
name: 'npm package (@latest dist-tag)',
|
||||||
@ -265,6 +278,7 @@ Example:
|
|||||||
gitTag: 'v1.1.0',
|
gitTag: 'v1.1.0',
|
||||||
notes: 'Release notes for version 1.1.0...',
|
notes: 'Release notes for version 1.1.0...',
|
||||||
pluginName: '@semantic-release/npm'
|
pluginName: '@semantic-release/npm'
|
||||||
|
channel: 'next'
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
```
|
```
|
||||||
|
@ -9,4 +9,9 @@
|
|||||||
## Git hosted services
|
## Git hosted services
|
||||||
- [Git authentication with SSH keys](git-auth-ssh-keys.md)
|
- [Git authentication with SSH keys](git-auth-ssh-keys.md)
|
||||||
|
|
||||||
|
## Release workflow
|
||||||
|
- [Publishing on distribution channels](distribution-channels.md)
|
||||||
|
- [Publishing maintenance releases](maintenance-releases.md)
|
||||||
|
- [Publishing pre-releases](pre-releases.md)
|
||||||
|
|
||||||
## Package managers and languages
|
## Package managers and languages
|
||||||
|
116
docs/recipes/distribution-channels.md
Normal file
116
docs/recipes/distribution-channels.md
Normal file
@ -0,0 +1,116 @@
|
|||||||
|
# Publishing on distribution channels
|
||||||
|
|
||||||
|
This recipe will walk you through a simple example that uses distribution channels to make releases available only to a subset of users, in order to collect feedbacks before distributing the release to all users.
|
||||||
|
|
||||||
|
This example uses the **semantic-release** default configuration:
|
||||||
|
- [branches](../usage/configuration.md#branches): `['+([0-9])?(.{+([0-9]),x}).x', 'master', 'next', 'next-major', {name: 'beta', prerelease: true}, {name: 'alpha', prerelease: true}]`
|
||||||
|
- [plugins](../usage/configuration.md#plugins): `['@semantic-release/commit-analyzer', '@semantic-release/release-notes-generator', '@semantic-release/npm', '@semantic-release/github']`
|
||||||
|
|
||||||
|
## Initial release
|
||||||
|
|
||||||
|
We'll start by making the first commit of the project, with the code for the initial release and the message `feat: initial commit` to `master`. When pushing that commit, **semantic-release** will release the version `1.0.0` and make it available on the default distribution channel which is the dist-tag `@latest` for npm.
|
||||||
|
|
||||||
|
The Git history of the repository is:
|
||||||
|
|
||||||
|
```
|
||||||
|
* feat: initial commit # => v1.0.0 on @latest
|
||||||
|
```
|
||||||
|
|
||||||
|
## Releasing a bug fix
|
||||||
|
|
||||||
|
We can now continue to commit changes and release updates to our users. For example we can commit a bug fix with the message `fix: a fix` to `master`. When pushing that commit, **semantic-release** will release the version `1.0.1` on the dist-tag `@latest`.
|
||||||
|
|
||||||
|
The Git history of the repository is now:
|
||||||
|
|
||||||
|
```
|
||||||
|
* feat: initial commit # => v1.0.0 on @latest
|
||||||
|
* fix: a fix # => v1.0.1 on @latest
|
||||||
|
```
|
||||||
|
|
||||||
|
## Releasing a feature on next
|
||||||
|
|
||||||
|
We now want to develop an important feature, which is a breaking change. Considering the scope of this feature we want to make it available, at first, only to our most dedicated users in order to get feedback. Once we get that feedback we can make improvements and ultimately make the new feature available to all users.
|
||||||
|
|
||||||
|
To implement that workflow we can create the branch `next` and commit our feature to this branch. When pushing that commit, **semantic-release** will release the version `2.0.0` on the dist-tag `@next`. That means only the users installing our module with `npm install example-module@next` will receive the version `2.0.0`. Other users installing with `npm install example-module` will still receive the version `1.0.1`.
|
||||||
|
|
||||||
|
The Git history of the repository is now:
|
||||||
|
|
||||||
|
```
|
||||||
|
* feat: initial commit # => v1.0.0 on @latest
|
||||||
|
* fix: a fix # => v1.0.1 on @latest
|
||||||
|
| \
|
||||||
|
| * feat: a big feature \n\n BREAKING CHANGE: it breaks something # => v2.0.0 on @next
|
||||||
|
```
|
||||||
|
|
||||||
|
## Releasing a bug fix on next
|
||||||
|
|
||||||
|
One of our users starts to use the new `2.0.0` release and reports a bug. We develop a bug fix and commit it to the `next` branch with the message `fix: fix something on the big feature`. When pushing that commit, **semantic-release** will release the version `2.0.1` on the dist-tag `@next`.
|
||||||
|
|
||||||
|
The Git history of the repository is now:
|
||||||
|
|
||||||
|
```
|
||||||
|
* feat: initial commit # => v1.0.0 on @latest
|
||||||
|
* fix: a fix # => v1.0.1 on @latest
|
||||||
|
| \
|
||||||
|
| * feat: a big feature \n\n BREAKING CHANGE: it breaks something # => v2.0.0 on @next
|
||||||
|
| * fix: fix something on the big feature # => v2.0.1 on @next
|
||||||
|
```
|
||||||
|
|
||||||
|
## Releasing a feature on latest
|
||||||
|
|
||||||
|
We now want to develop a smaller, non-breaking feature. Its scope is small enough that we don't need to have a phase of feedback and we can release it to all users right away.
|
||||||
|
|
||||||
|
If we were to commit that feature on `next` only a subset of users would get it, and we would need to wait for the end of our feedback period in order to make both the big and the small feature available to all users.
|
||||||
|
|
||||||
|
Instead, we develop that small feature commit it to `master` with the message `feat: a small feature`. When pushing that commit, **semantic-release** will release the version `1.1.0` on the dist-tag `@latest` so all users can benefit from it right away.
|
||||||
|
|
||||||
|
The Git history of the repository is now:
|
||||||
|
|
||||||
|
```
|
||||||
|
* feat: initial commit # => v1.0.0 on @latest
|
||||||
|
* fix: a fix # => v1.0.1 on @latest
|
||||||
|
| \
|
||||||
|
| * feat: a big feature \n\n BREAKING CHANGE: it breaks something # => v2.0.0 on @next
|
||||||
|
| * fix: fix something on the big feature # => v2.0.1 on @next
|
||||||
|
* | feat: a small feature # => v1.1.0 on @latest
|
||||||
|
```
|
||||||
|
|
||||||
|
## Porting a feature to next
|
||||||
|
|
||||||
|
Most of our users now have access to the small feature, but we still need to make it available to our users using the `@next` dist-tag. To do so we need to merge our changes made on `master` (the commit `feat: a small feature`) into `next`. As `master` and `next` branches have diverged, this merge might require to resolve conflicts.
|
||||||
|
|
||||||
|
Once the conflicts are resolved and the merge commit is pushed to `next`, **semantic-release** will release the version `2.1.0` on the dist-tag `@next` which contains both our small and big feature.
|
||||||
|
|
||||||
|
The Git history of the repository is now:
|
||||||
|
|
||||||
|
```
|
||||||
|
* feat: initial commit # => v1.0.0 on @latest
|
||||||
|
* fix: a fix # => v1.0.1 on @latest
|
||||||
|
| \
|
||||||
|
| * feat: a big feature \n\n BREAKING CHANGE: it breaks something # => v2.0.0 on @next
|
||||||
|
| * fix: fix something on the big feature # => v2.0.1 on @next
|
||||||
|
* | feat: a small feature # => v1.1.0 on @latest
|
||||||
|
| * Merge branch master into next # => v2.1.0 on @next
|
||||||
|
```
|
||||||
|
|
||||||
|
## Adding a version to latest
|
||||||
|
|
||||||
|
After a period of feedback from our users using the `@next` dist-tag we feel confident to make our big feature available to all users. To do so we merge the `next` branch into `master`. There should be no conflict as `next` is strictly ahead of `master`.
|
||||||
|
|
||||||
|
Once the merge commit is pushed to `next`, **semantic-release** will add the version `2.1.0` to the dist-tag `@latest` so all users will receive it when installing out module with `npm install example-module`.
|
||||||
|
|
||||||
|
The Git history of the repository is now:
|
||||||
|
|
||||||
|
```
|
||||||
|
* feat: initial commit # => v1.0.0 on @latest
|
||||||
|
* fix: a fix # => v1.0.1 on @latest
|
||||||
|
| \
|
||||||
|
| * feat: a big feature \n\n BREAKING CHANGE: it breaks something # => v2.0.0 on @next
|
||||||
|
| * fix: fix something on the big feature # => v2.0.1 on @next
|
||||||
|
* | feat: a small feature # => v1.1.0 on @latest
|
||||||
|
| * Merge branch master into next # => v2.1.0 on @next
|
||||||
|
| /|
|
||||||
|
* | Merge branch next into master # => v2.1.0 on @latest
|
||||||
|
```
|
||||||
|
|
||||||
|
We can now continue to push new fixes and features on `master`, or a new breaking change on `next` as we did before.
|
@ -10,7 +10,7 @@ In this example an [`NPM_TOKEN`](https://docs.npmjs.com/creating-and-viewing-aut
|
|||||||
|
|
||||||
[GitHub Actions](https://github.com/features/actions) support [Workflows](https://help.github.com/en/articles/configuring-workflows), allowing to run tests on multiple Node versions and publish a release only when all test pass.
|
[GitHub Actions](https://github.com/features/actions) support [Workflows](https://help.github.com/en/articles/configuring-workflows), allowing to run tests on multiple Node versions and publish a release only when all test pass.
|
||||||
|
|
||||||
**Note**: The publish pipeline must run on [Node version >= 8.16](../support/FAQ.md#why-does-semantic-release-require-node-version--816).
|
**Note**: The publish pipeline must run on [Node version >= 10.13](../support/FAQ.md#why-does-semantic-release-require-node-version--1013).
|
||||||
|
|
||||||
### `.github/workflows/release.yml` configuration for Node projects
|
### `.github/workflows/release.yml` configuration for Node projects
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@ The [Authentication](../usage/ci-configuration.md#authentication) environment va
|
|||||||
|
|
||||||
GitLab CI supports [Pipelines](https://docs.gitlab.com/ee/ci/pipelines.html) allowing to test on multiple Node versions and publishing a release only when all test pass.
|
GitLab CI supports [Pipelines](https://docs.gitlab.com/ee/ci/pipelines.html) allowing to test on multiple Node versions and publishing a release only when all test pass.
|
||||||
|
|
||||||
**Note**: The publish pipeline must run a [Node >= 8.16 version](../support/FAQ.md#why-does-semantic-release-require-node-version--816).
|
**Note**: The publish pipeline must run a [Node >= 10.13 version](../support/FAQ.md#why-does-semantic-release-require-node-version--1013).
|
||||||
|
|
||||||
### `.gitlab-ci.yml` configuration for Node projects
|
### `.gitlab-ci.yml` configuration for Node projects
|
||||||
|
|
||||||
|
156
docs/recipes/maintenance-releases.md
Normal file
156
docs/recipes/maintenance-releases.md
Normal file
@ -0,0 +1,156 @@
|
|||||||
|
# Publishing maintenance releases
|
||||||
|
|
||||||
|
This recipe will walk you through a simple example that uses Git branches and distribution channels to publish fixes and features for old versions of a package.
|
||||||
|
|
||||||
|
This example uses the **semantic-release** default configuration:
|
||||||
|
- [branches](../usage/configuration.md#branches): `['+([0-9])?(.{+([0-9]),x}).x', 'master', 'next', 'next-major', {name: 'beta', prerelease: true}, {name: 'alpha', prerelease: true}]`
|
||||||
|
- [plugins](../usage/configuration.md#plugins): `['@semantic-release/commit-analyzer', '@semantic-release/release-notes-generator', '@semantic-release/npm', '@semantic-release/github']`
|
||||||
|
|
||||||
|
## Initial release
|
||||||
|
|
||||||
|
We'll start by making the first commit of the project, with the code for the initial release and the message `feat: initial commit`. When pushing that commit, on `master` **semantic-release** will release the version `1.0.0` and make it available on the default distribution channel which is the dist-tag `@latest` for npm.
|
||||||
|
|
||||||
|
The Git history of the repository is:
|
||||||
|
|
||||||
|
```
|
||||||
|
* feat: initial commit # => v1.0.0 on @latest
|
||||||
|
```
|
||||||
|
|
||||||
|
## Releasing a breaking change
|
||||||
|
|
||||||
|
We now decide to drop Node.js 6 support for our package, and require Node.js 8 or higher, which is a breaking change.
|
||||||
|
|
||||||
|
We commit that change with the message `feat: drop Node.js 6 support \n\n BREAKING CHANGE: Node.js >= 8 required` to `master`. When pushing that commit, **semantic-release** will release the version `2.0.0` on the dist-tag `@latest`.
|
||||||
|
|
||||||
|
The Git history of the repository is now:
|
||||||
|
|
||||||
|
```
|
||||||
|
* feat: initial commit # => v1.0.0 on @latest
|
||||||
|
* feat: drop Node.js 6 support \n\n BREAKING CHANGE: Node.js >= 8 required # => v2.0.0 on @latest
|
||||||
|
```
|
||||||
|
|
||||||
|
## Releasing a feature for version 1.x users
|
||||||
|
|
||||||
|
One of our users request a new feature, however they cannot migrate to Node.js 8 or higher due to corporate policies.
|
||||||
|
|
||||||
|
If we were to push that feature on `master` and release it, the new version would require Node.js 8 or higher as the release would also contains the commit `feat: drop Node.js 6 support \n\n BREAKING CHANGE: Node.js >= 8 required`.
|
||||||
|
|
||||||
|
Instead, we create the branch `1.x` from the tag `v1.0.0` with the command `git checkout -b 1.x v1.0.0` and we commit that feature with the message `feat: a feature` to the branch `1.x`. When pushing that commit, **semantic-release** will release the version `1.1.0` on the dist-tag `@release-1.x` so users who can't migrate to Node.js 8 or higher can benefit from it.
|
||||||
|
|
||||||
|
The Git history of the repository is now:
|
||||||
|
|
||||||
|
```
|
||||||
|
* feat: initial commit # => v1.0.0 on @latest
|
||||||
|
| \
|
||||||
|
* | feat: drop Node.js 6 support \n\n BREAKING CHANGE: Node.js >= 8 required # => v2.0.0 on @latest
|
||||||
|
| * feat: a feature # => v1.1.0 on @1.x
|
||||||
|
```
|
||||||
|
|
||||||
|
## Releasing a bug fix for version 1.0.x users
|
||||||
|
|
||||||
|
Another user currently using version `1.0.0` reports a bug. They cannot migrate to Node.js 8 or higher and they also cannot migrate to `1.1.0` as they do not use the feature developed in `feat: a feature` and their corporate policies require to go through a costly quality insurance process for each `minor` upgrades.
|
||||||
|
|
||||||
|
In order to deliver the bug fix in a `patch` release, we create the branch `1.0.x` from the tag `v1.0.0` with the command `git checkout -b 1.0.x v1.0.0` and we commit that fix with the message `fix: a fix` to the branch `1.0.x`. When pushing that commit, **semantic-release** will release the version `1.0.1` on the dist-tag `@release-1.0.x` so users who can't migrate to `1.1.x` or `2.x` can benefit from it.
|
||||||
|
|
||||||
|
The Git history of the repository is now:
|
||||||
|
|
||||||
|
```
|
||||||
|
* feat: initial commit # => v1.0.0 on @latest
|
||||||
|
| \
|
||||||
|
* | feat: drop Node.js 6 support \n\n BREAKING CHANGE: Node.js >= 8 required # => v2.0.0 on @latest
|
||||||
|
| | \
|
||||||
|
| * | feat: a feature # => v1.1.0 on @1.x
|
||||||
|
| | * fix: a fix # => v1.0.1 on @1.0.x
|
||||||
|
```
|
||||||
|
|
||||||
|
## Porting a bug fix from 1.0.x to 1.x
|
||||||
|
|
||||||
|
Now that we have released a fix in version `1.0.1` we want to make it available to `1.1.x` users as well.
|
||||||
|
|
||||||
|
To do so we need to merge the changes made on `1.0.x` (the commit `fix: a fix`) into the `1.x` branch. As `1.0.x` and `1.x` branches have diverged, this merge might require to resolve conflicts.
|
||||||
|
|
||||||
|
Once the conflicts are resolved and the merge commit is pushed to the branch `1.x`, **semantic-release** will release the version `1.1.1` on the dist-tag `@release-1.x` which contains both our feature and bug fix.
|
||||||
|
|
||||||
|
The Git history of the repository is now:
|
||||||
|
|
||||||
|
```
|
||||||
|
* feat: initial commit # => v1.0.0 on @latest
|
||||||
|
| \
|
||||||
|
* | feat: drop Node.js 6 support \n\n BREAKING CHANGE: Node.js >= 8 required # => v2.0.0 on @latest
|
||||||
|
| | \
|
||||||
|
| * | feat: a feature # => v1.1.0 on @1.x
|
||||||
|
| | * fix: a fix # => v1.0.1 on @1.0.x
|
||||||
|
| | /|
|
||||||
|
| * | Merge branch 1.0.x into 1.x # => v1.1.1 on @1.x
|
||||||
|
```
|
||||||
|
|
||||||
|
## Porting bug fixes and features to master
|
||||||
|
|
||||||
|
Finally we want to make both our feature and bug fix available to users using the `@latest` dist-tag.
|
||||||
|
|
||||||
|
To do so we need to merge the changes made on `1.x` (the commits `feat: a feature` and `fix: a fix`) into `master`. As `1.x` and `master` branches have diverged, this merge might require to resolve conflicts.
|
||||||
|
|
||||||
|
Once the conflicts are resolved and the merge commit is pushed to `master`, **semantic-release** will release the version `2.1.0` on the dist-tag `@latest` which now contains the breaking change feature, the feature and the bug fix.
|
||||||
|
|
||||||
|
The Git history of the repository is now:
|
||||||
|
|
||||||
|
```
|
||||||
|
* feat: initial commit # => v1.0.0 on @latest
|
||||||
|
| \
|
||||||
|
* | feat: drop Node.js 6 support \n\n BREAKING CHANGE: Node.js >= 8 required # => v2.0.0 on @latest
|
||||||
|
| | \
|
||||||
|
| * | feat: a feature # => v1.1.0 on @1.x
|
||||||
|
| | * fix: a fix # => v1.0.1 on @1.0.x
|
||||||
|
| | /|
|
||||||
|
| * | Merge branch 1.0.x into 1.x # => v1.1.1 on @1.x
|
||||||
|
| /| |
|
||||||
|
* | | Merge branch 1.x into master # => v2.1.0 on @latest
|
||||||
|
```
|
||||||
|
|
||||||
|
## Releasing a bug fix for version 2.1.0 users
|
||||||
|
|
||||||
|
One of our users using the version `2.1.0` version reports a bug.
|
||||||
|
|
||||||
|
We can simply commit the bug fix with the message `fix: another fix` to `master`. When pushing that commit, **semantic-release** will release the version `2.1.1` on the dist-tag `@latest`.
|
||||||
|
|
||||||
|
The Git history of the repository is now:
|
||||||
|
|
||||||
|
```
|
||||||
|
* feat: initial commit # => v1.0.0 on @latest
|
||||||
|
| \
|
||||||
|
* | feat: drop Node.js 6 support \n\n BREAKING CHANGE: Node.js >= 8 required # => v2.0.0 on @latest
|
||||||
|
| | \
|
||||||
|
| * | feat: a feature # => v1.1.0 on @1.x
|
||||||
|
| | * fix: a fix # => v1.0.1 on @1.0.x
|
||||||
|
| | /|
|
||||||
|
| * | Merge branch 1.0.x into 1.x # => v1.1.1 on @1.x
|
||||||
|
| /| |
|
||||||
|
* | | Merge branch 1.x into master # => v2.1.0 on @latest
|
||||||
|
* | | fix: another fix # => v2.1.1 on @latest
|
||||||
|
```
|
||||||
|
|
||||||
|
## Porting a bug fix from master to 1.x
|
||||||
|
|
||||||
|
The bug fix `fix: another fix` also affects version `1.1.1` users, so we want to port it to the `1.x` branch.
|
||||||
|
|
||||||
|
To do so we need to cherry pick our fix commit made on `master` (`fix: another fix`) into `1.x` with `git checkout 1.x && git cherry-pick <sha of fix: another fix>`. As `master` and `1.x` branches have diverged, the cherry picking might require to resolve conflicts.
|
||||||
|
|
||||||
|
Once the conflicts are resolved and the commit is pushed to `1.x`, **semantic-release** will release the version `1.1.2` on the dist-tag `@release-1.x` which contains `feat: a feature`, `fix: a fix` and `fix: another fix` but not `feat: drop Node.js 6 support \n\n BREAKING CHANGE: Node.js >= 8 required`.
|
||||||
|
|
||||||
|
The Git history of the repository is now:
|
||||||
|
|
||||||
|
```
|
||||||
|
* feat: initial commit # => v1.0.0 on @latest
|
||||||
|
| \
|
||||||
|
* | feat: drop Node.js 6 support \n\n BREAKING CHANGE: Node.js >= 8 required # => v2.0.0 on @latest
|
||||||
|
| | \
|
||||||
|
| * | feat: a feature # => v1.1.0 on @1.x
|
||||||
|
| | * fix: a fix # => v1.0.1 on @1.0.x
|
||||||
|
| | /|
|
||||||
|
| * | Merge branch 1.0.x into 1.x # => v1.1.1 on @1.x
|
||||||
|
| /| |
|
||||||
|
* | | Merge branch 1.x into master # => v2.1.0 on @latest
|
||||||
|
* | | fix: another fix # => v2.1.1 on @latest
|
||||||
|
| | |
|
||||||
|
| * | fix: another fix # => v1.1.2 on @1.x
|
||||||
|
```
|
196
docs/recipes/pre-releases.md
Normal file
196
docs/recipes/pre-releases.md
Normal file
@ -0,0 +1,196 @@
|
|||||||
|
# Publishing pre-releases
|
||||||
|
|
||||||
|
This recipe will walk you through a simple example that uses pre-releases to publish beta versions while working on a future major release and then make only one release on the default distribution.
|
||||||
|
|
||||||
|
This example uses the **semantic-release** default configuration:
|
||||||
|
- [branches](../usage/configuration.md#branches): `['+([0-9])?(.{+([0-9]),x}).x', 'master', 'next', 'next-major', {name: 'beta', prerelease: true}, {name: 'alpha', prerelease: true}]`
|
||||||
|
- [plugins](../usage/configuration.md#plugins): `['@semantic-release/commit-analyzer', '@semantic-release/release-notes-generator', '@semantic-release/npm', '@semantic-release/github']`
|
||||||
|
|
||||||
|
## Initial release
|
||||||
|
|
||||||
|
We'll start by making the first commit of the project, with the code for the initial release and the message `feat: initial commit`. When pushing that commit, on `master` **semantic-release** will release the version `1.0.0` and make it available on the default distribution channel which is the dist-tag `@latest` for npm.
|
||||||
|
|
||||||
|
The Git history of the repository is:
|
||||||
|
|
||||||
|
```
|
||||||
|
* feat: initial commit # => v1.0.0 on @latest
|
||||||
|
```
|
||||||
|
|
||||||
|
## Working on a future release
|
||||||
|
|
||||||
|
We now decide to work on a future major release, which will be composed of multiple features, some of them being breaking changes. We want to publish our package for each new feature developed for test purpose, however we do not want to increment our package version or make it available to our users until all the features are developed and tested.
|
||||||
|
|
||||||
|
To implement that workflow we can create the branch `beta` and commit our first feature there. When pushing that commit, **semantic-release** will publish the pre-release version `2.0.0-beta.1` on the dist-tag `@beta`. That allow us to run integration tests by installing our module with `npm install example-module@beta`. Other users installing with `npm install example-module` will still receive the version `1.0.0`.
|
||||||
|
|
||||||
|
The Git history of the repository is now:
|
||||||
|
|
||||||
|
```
|
||||||
|
* feat: initial commit # => v1.0.0 on @latest
|
||||||
|
| \
|
||||||
|
| * feat: first feature \n\n BREAKING CHANGE: it breaks something # => v2.0.0-beta.1 on @beta
|
||||||
|
```
|
||||||
|
|
||||||
|
We can continue to work on our future release by committing and pushing other features or bug fixes on the `beta` branch. With each push, **semantic-release** will publish a new pre-release on the dist-tag `@beta`, which allow us to run our integration tests.
|
||||||
|
|
||||||
|
With another feature, the Git history of the repository is now:
|
||||||
|
|
||||||
|
```
|
||||||
|
* feat: initial commit # => v1.0.0 on @latest
|
||||||
|
| \
|
||||||
|
| * feat: first feature \n\n BREAKING CHANGE: it breaks something # => v2.0.0-beta.1 on @beta
|
||||||
|
| * feat: second feature # => v2.0.0-beta.2 on @beta
|
||||||
|
```
|
||||||
|
|
||||||
|
## Releasing a bug fix on the default distribution channel
|
||||||
|
|
||||||
|
In the meantime we can also continue to commit changes and release updates to our users.
|
||||||
|
|
||||||
|
For example, we can commit a bug fix with the message `fix: a fix` to `master`. When pushing that commit, **semantic-release** will release the version `1.0.1` on the dist-tag `@latest`.
|
||||||
|
|
||||||
|
The Git history of the repository is now:
|
||||||
|
|
||||||
|
```
|
||||||
|
* feat: initial commit # => v1.0.0 on @latest
|
||||||
|
| \
|
||||||
|
| * feat: first feature \n\n BREAKING CHANGE: it breaks something # => v2.0.0-beta.1 on @beta
|
||||||
|
| * feat: second feature # => v2.0.0-beta.2 on @beta
|
||||||
|
* | fix: a fix # => v1.0.1 on @latest
|
||||||
|
```
|
||||||
|
|
||||||
|
## Working on another future release
|
||||||
|
|
||||||
|
We now decide to work on another future major release, in parallel of the beta one, which will also be composed of multiple features, some of them being breaking changes.
|
||||||
|
|
||||||
|
To implement that workflow we can create the branch `alpha` from the branch `beta` and commit our first feature there. When pushing that commit, **semantic-release** will publish the pre-release version `3.0.0-alpha.1` on the dist-tag `@alpha`. That allow us to run integration tests by installing our module with `npm install example-module@alpha`. Other users installing with `npm install example-module` will still receive the version `1.0.0`.
|
||||||
|
|
||||||
|
The Git history of the repository is now:
|
||||||
|
|
||||||
|
```
|
||||||
|
* feat: initial commit # => v1.0.0 on @latest
|
||||||
|
| \
|
||||||
|
| * feat: first feature \n\n BREAKING CHANGE: it breaks something # => v2.0.0-beta.1 on @beta
|
||||||
|
| * feat: second feature # => v2.0.0-beta.2 on @beta
|
||||||
|
* | fix: a fix # => v1.0.1 on @latest
|
||||||
|
| | \
|
||||||
|
| | * feat: first feature of other release \n\n BREAKING CHANGE: it breaks something # => v3.0.0-alpha.1 on @alpha
|
||||||
|
```
|
||||||
|
|
||||||
|
We can continue to work on our future release by committing and pushing other features or bug fixes on the `alpha` branch. With each push, **semantic-release** will publish a new pre-release on the dist-tag `@alpha`, which allow us to run our integration tests.
|
||||||
|
|
||||||
|
With another feature, the Git history of the repository is now:
|
||||||
|
|
||||||
|
```
|
||||||
|
* feat: initial commit # => v1.0.0 on @latest
|
||||||
|
| \
|
||||||
|
| * feat: first feature \n\n BREAKING CHANGE: it breaks something # => v2.0.0-beta.1 on @beta
|
||||||
|
| * feat: second feature # => v2.0.0-beta.2 on @beta
|
||||||
|
* | fix: a fix # => v1.0.1 on @latest
|
||||||
|
| | \
|
||||||
|
| | * feat: first feature of other release \n\n BREAKING CHANGE: it breaks something # => v3.0.0-alpha.1 on @alpha
|
||||||
|
| | * feat: second feature of other release # => v3.0.0-alpha.2 on @alpha
|
||||||
|
```
|
||||||
|
|
||||||
|
## Publishing the 2.0.0 beta release to the default distribution channel
|
||||||
|
|
||||||
|
Once we've developed and pushed all the feature we want to include in the future version `2.0.0` in the `beta` branch and all our tests are successful we can release it to our users.
|
||||||
|
|
||||||
|
To do so we need to merge our changes made on `beta` into `master`. As `beta` and `master` branches have diverged, this merge might require to resolve conflicts.
|
||||||
|
|
||||||
|
Once the conflicts are resolved and the merge commit is pushed to `master`, **semantic-release** will release the version `2.0.0` on the dist-tag `@latest`.
|
||||||
|
|
||||||
|
The Git history of the repository is now:
|
||||||
|
|
||||||
|
```
|
||||||
|
* feat: initial commit # => v1.0.0 on @latest
|
||||||
|
| \
|
||||||
|
| * feat: first feature \n\n BREAKING CHANGE: it breaks something # => v2.0.0-beta.1 on @beta
|
||||||
|
| * feat: second feature # => v2.0.0-beta.2 on @beta
|
||||||
|
* | fix: a fix # => v1.0.1 on @latest
|
||||||
|
| | \
|
||||||
|
| | * feat: first feature of other release \n\n BREAKING CHANGE: it breaks something # => v3.0.0-alpha.1 on @alpha
|
||||||
|
| | * feat: second feature of other release # => v3.0.0-alpha.2 on @alpha
|
||||||
|
| /| |
|
||||||
|
* | | Merge branch beta into master # => v2.0.0 on @latest
|
||||||
|
```
|
||||||
|
|
||||||
|
## Publishing the 3.0.0 alpha release to the beta distribution channel
|
||||||
|
|
||||||
|
Now that we published our the version `2.0.0` that was previously in beta, we decide to promote the version `3.0.0` in alpha to beta.
|
||||||
|
|
||||||
|
To do so we need to merge our changes made on `alpha` into `beta`. There should be no conflict as `alpha` is strictly ahead of `master`.
|
||||||
|
|
||||||
|
Once the merge commit is pushed to `beta`, **semantic-release** will publish the pre-release version `3.0.0-beta.1` on the dist-tag `@beta`, which allow us to run our integration tests.
|
||||||
|
|
||||||
|
The Git history of the repository is now:
|
||||||
|
|
||||||
|
```
|
||||||
|
* feat: initial commit # => v1.0.0 on @latest
|
||||||
|
| \
|
||||||
|
| * feat: first feature \n\n BREAKING CHANGE: it breaks something # => v2.0.0-beta.1 on @beta
|
||||||
|
| * feat: second feature # => v2.0.0-beta.2 on @beta
|
||||||
|
* | fix: a fix # => v1.0.1 on @latest
|
||||||
|
| | \
|
||||||
|
| | * feat: first feature of other release \n\n BREAKING CHANGE: it breaks something # => v3.0.0-alpha.1 on @alpha
|
||||||
|
| | * feat: second feature of other release # => v3.0.0-alpha.2 on @alpha
|
||||||
|
| /| |
|
||||||
|
* | | Merge branch beta into master # => v2.0.0 on @latest
|
||||||
|
| | /|
|
||||||
|
| * | Merge branch alpha into beta # => v3.0.0-beta.1 on @beta
|
||||||
|
```
|
||||||
|
|
||||||
|
## Publishing the 3.0.0 beta release to the default distribution channel
|
||||||
|
|
||||||
|
Once we've developed and pushed all the feature we want to include in the future version `3.0.0` in the `beta` branch and all our tests are successful we can release it to our users.
|
||||||
|
|
||||||
|
To do so we need to merge our changes made on `beta` into `master`. As `beta` and `master` branches have diverged, this merge might require to resolve conflicts.
|
||||||
|
|
||||||
|
Once the conflicts are resolved and the merge commit is pushed to `master`, **semantic-release** will release the version `3.0.0` on the dist-tag `@latest`.
|
||||||
|
|
||||||
|
The Git history of the repository is now:
|
||||||
|
|
||||||
|
```
|
||||||
|
* feat: initial commit # => v1.0.0 on @latest
|
||||||
|
| \
|
||||||
|
| * feat: first feature \n\n BREAKING CHANGE: it breaks something # => v2.0.0-beta.1 on @beta
|
||||||
|
| * feat: second feature # => v2.0.0-beta.2 on @beta
|
||||||
|
* | fix: a fix # => v1.0.1 on @latest
|
||||||
|
| | \
|
||||||
|
| | * feat: first feature of other release \n\n BREAKING CHANGE: it breaks something # => v3.0.0-alpha.1 on @alpha
|
||||||
|
| | * feat: second feature of other release # => v3.0.0-alpha.2 on @alpha
|
||||||
|
| /| |
|
||||||
|
* | | Merge branch beta into master # => v2.0.0 on @latest
|
||||||
|
| | /|
|
||||||
|
| * | Merge branch alpha into beta # => v3.0.0-beta.1 on @beta
|
||||||
|
| /| |
|
||||||
|
* | | Merge branch beta into master # => v3.0.0 on @latest
|
||||||
|
```
|
||||||
|
|
||||||
|
## Working on a third future release
|
||||||
|
|
||||||
|
We can now start to work on a new future major release, version `4.0.0`, on the `@beta` distribution channel.
|
||||||
|
|
||||||
|
To do so we fist need to update the `beta` branch with all the changes from `master` (the commits `fix: a fix`). As `beta` and `master` branches have diverged, this merge might require to resolve conflicts.
|
||||||
|
|
||||||
|
We can now commit our new feature on `beta`. When pushing that commit, **semantic-release** will publish the pre-release version `3.1.0-beta.1` on the dist-tag `@beta`. That allow us to run integration tests by installing our module with `npm install example-module@beta`. Other users installing with `npm install example-module` will still receive the version `3.0.0`.
|
||||||
|
|
||||||
|
The Git history of the repository is now:
|
||||||
|
|
||||||
|
```
|
||||||
|
* feat: initial commit # => v1.0.0 on @latest
|
||||||
|
| \
|
||||||
|
| * feat: first feature \n\n BREAKING CHANGE: it breaks something # => v2.0.0-beta.1 on @beta
|
||||||
|
| * feat: second feature # => v2.0.0-beta.2 on @beta
|
||||||
|
* | fix: a fix # => v1.0.1 on @latest
|
||||||
|
| | \
|
||||||
|
| | * feat: first feature of other release \n\n BREAKING CHANGE: it breaks something # => v3.0.0-alpha.1 on @alpha
|
||||||
|
| | * feat: second feature of other release # => v3.0.0-alpha.2 on @alpha
|
||||||
|
| /| |
|
||||||
|
* | | Merge branch beta into master # => v2.0.0 on @latest
|
||||||
|
| | /|
|
||||||
|
| * | Merge branch alpha into beta # => v3.0.0-beta.1 on @beta
|
||||||
|
| /| |
|
||||||
|
* | | Merge branch beta into master # => v3.0.0 on @latest
|
||||||
|
| \| |
|
||||||
|
| * | Merge branch master into beta
|
||||||
|
| * | feat: new feature # => v3.1.0-beta.1 on @beta
|
||||||
|
```
|
@ -38,7 +38,7 @@ Yes with the [dry-run options](../usage/configuration.md#dryrun) which prints to
|
|||||||
|
|
||||||
## Can I use semantic-release with Yarn?
|
## Can I use semantic-release with Yarn?
|
||||||
|
|
||||||
If you are using a [local](../usage/installation.md#local-installation) **semantic-release** installation and run multiple CI jobs with different versions, the `yarn install` command will fail on jobs running with Node < 8 as **semantic-release** requires [Node >= 8.16](#why-does-semantic-release-require-node-version--816) and specifies it in its `package.json`s [`engines`](https://docs.npmjs.com/files/package.json#engines) key.
|
If you are using a [local](../usage/installation.md#local-installation) **semantic-release** installation and run multiple CI jobs with different versions, the `yarn install` command will fail on jobs running with Node < 8 as **semantic-release** requires [Node >= 10.13](#why-does-semantic-release-require-node-version--1013) and specifies it in its `package.json`s [`engines`](https://docs.npmjs.com/files/package.json#engines) key.
|
||||||
|
|
||||||
The recommended solution is to use the [Yarn](https://yarnpkg.com) [--ignore-engines](https://yarnpkg.com/en/docs/cli/install#toc-yarn-install-ignore-engines) option to install the project dependencies on the CI environment, so Yarn will ignore the **semantic-release**'s `engines` key:
|
The recommended solution is to use the [Yarn](https://yarnpkg.com) [--ignore-engines](https://yarnpkg.com/en/docs/cli/install#toc-yarn-install-ignore-engines) option to install the project dependencies on the CI environment, so Yarn will ignore the **semantic-release**'s `engines` key:
|
||||||
|
|
||||||
@ -48,7 +48,7 @@ $ yarn install --ignore-engines
|
|||||||
|
|
||||||
**Note**: Several CI services use Yarn by default if your repository contains a `yarn.lock` file. So you should override the install step to specify `yarn install --ignore-engines`.
|
**Note**: Several CI services use Yarn by default if your repository contains a `yarn.lock` file. So you should override the install step to specify `yarn install --ignore-engines`.
|
||||||
|
|
||||||
Alternatively you can use a [global](../usage/installation.md#global-installation) **semantic-release** installation and make sure to install and run the `semantic-release` command only in a CI jobs running with Node >= 8.16.
|
Alternatively you can use a [global](../usage/installation.md#global-installation) **semantic-release** installation and make sure to install and run the `semantic-release` command only in a CI jobs running with Node >= 10.13.
|
||||||
|
|
||||||
If your CI environment provides [nvm](https://github.com/creationix/nvm) you can switch to Node 8 before installing and running the `semantic-release` command:
|
If your CI environment provides [nvm](https://github.com/creationix/nvm) you can switch to Node 8 before installing and running the `semantic-release` command:
|
||||||
|
|
||||||
@ -73,7 +73,7 @@ Yes, **semantic-release** is a Node CLI application but it can be used to publis
|
|||||||
To publish a non-Node package (without a `package.json`) you would need to:
|
To publish a non-Node package (without a `package.json`) you would need to:
|
||||||
- Use a [global](../usage/installation.md#global-installation) **semantic-release** installation
|
- Use a [global](../usage/installation.md#global-installation) **semantic-release** installation
|
||||||
- Set **semantic-release** [options](../usage/configuration.md#options) via [CLI arguments or rc file](../usage/configuration.md#configuration)
|
- Set **semantic-release** [options](../usage/configuration.md#options) via [CLI arguments or rc file](../usage/configuration.md#configuration)
|
||||||
- Make sure your CI job executing the `semantic-release` command has access to [Node >= 8.16](#why-does-semantic-release-require-node-version--816) to execute the `semantic-release` command
|
- Make sure your CI job executing the `semantic-release` command has access to [Node >= 10.13](#why-does-semantic-release-require-node-version--1013) to execute the `semantic-release` command
|
||||||
|
|
||||||
See the [CI configuration recipes](../recipes/README.md#ci-configurations) for more details on specific CI environments.
|
See the [CI configuration recipes](../recipes/README.md#ci-configurations) for more details on specific CI environments.
|
||||||
|
|
||||||
@ -222,7 +222,7 @@ If you need more control over the timing of releases, see [Triggering a release]
|
|||||||
|
|
||||||
This is not supported by **semantic-release** as it's not considered a good practice, mostly because [Semantic Versioning](https://semver.org) rules applies differently to major version zero.
|
This is not supported by **semantic-release** as it's not considered a good practice, mostly because [Semantic Versioning](https://semver.org) rules applies differently to major version zero.
|
||||||
|
|
||||||
In early development phase when your package is not ready for production yet we recommend to publish releases on a distribution channel (for example npm’s [dist-tags](https://docs.npmjs.com/cli/dist-tag)) or to develop on a `dev` branch and merge it to `master` periodically. See [Triggering a release](../../README.md#triggering-a-release) for more details on those solutions.
|
If your project is under heavy development, with frequent breaking changes, and is not production ready yet we recommend [publishing pre-releases](../recipes/pre-releases.md#publishing-pre-releases).
|
||||||
|
|
||||||
See [“Introduction to SemVer” - Irina Gebauer](https://blog.greenkeeper.io/introduction-to-semver-d272990c44f2) for more details on [Semantic Versioning](https://semver.org) and the recommendation to start at version `1.0.0`.
|
See [“Introduction to SemVer” - Irina Gebauer](https://blog.greenkeeper.io/introduction-to-semver-d272990c44f2) for more details on [Semantic Versioning](https://semver.org) and the recommendation to start at version `1.0.0`.
|
||||||
|
|
||||||
@ -232,12 +232,16 @@ See [“Introduction to SemVer” - Irina Gebauer](https://blog.greenkeeper.io/i
|
|||||||
|
|
||||||
In addition the [verify conditions step](../../README.md#release-steps) verifies that all necessary conditions for proceeding with a release are met, and a new release will be performed [only if all your tests pass](../usage/ci-configuration.md#run-semantic-release-only-after-all-tests-succeeded).
|
In addition the [verify conditions step](../../README.md#release-steps) verifies that all necessary conditions for proceeding with a release are met, and a new release will be performed [only if all your tests pass](../usage/ci-configuration.md#run-semantic-release-only-after-all-tests-succeeded).
|
||||||
|
|
||||||
## Why does semantic-release require Node version >= 8.16?
|
## Why does semantic-release require Node version >= 10.13?
|
||||||
|
|
||||||
**semantic-release** is written using the latest [ECMAScript 2017](https://www.ecma-international.org/publications/standards/Ecma-262.htm) features, without transpilation which **requires Node version 8.16 or higher**.
|
**semantic-release** is written using the latest [ECMAScript 2017](https://www.ecma-international.org/publications/standards/Ecma-262.htm) features, without transpilation which **requires Node version 10.13 or higher**.
|
||||||
|
|
||||||
See [Node version requirement](./node-version.md#node-version-requirement) for more details and solutions.
|
See [Node version requirement](./node-version.md#node-version-requirement) for more details and solutions.
|
||||||
|
|
||||||
|
## Why does semantic-release require Git version >= 2.7.1?
|
||||||
|
|
||||||
|
**semantic-release** uses Git CLI commands to read information about the repository such as branches, commit history and tags. Certain commands and options (such as [the `--merged` option of the `git tag` command](https://git-scm.com/docs/git-tag/2.7.0#git-tag---no-mergedltcommitgt) or bug fixes related to `git ls-files`) used by **semantic-release** are only available in Git version 2.7.1 and higher.
|
||||||
|
|
||||||
## What is npx?
|
## What is npx?
|
||||||
|
|
||||||
[`npx`](https://www.npmjs.com/package/npx) – short for "npm exec" – is a CLI to find and execute npm binaries within the local `node_modules` folder or in the $PATH. If a binary can't be located npx will download the required package and execute it from its cache location.
|
[`npx`](https://www.npmjs.com/package/npx) – short for "npm exec" – is a CLI to find and execute npm binaries within the local `node_modules` folder or in the $PATH. If a binary can't be located npx will download the required package and execute it from its cache location.
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
# Node version requirement
|
# Node version requirement
|
||||||
|
|
||||||
**semantic-release** is written using the latest [ECMAScript 2017](https://www.ecma-international.org/publications/standards/Ecma-262.htm) features, without transpilation which requires **requires Node version 8.16 or higher**.
|
**semantic-release** is written using the latest [ECMAScript 2017](https://www.ecma-international.org/publications/standards/Ecma-262.htm) features, without transpilation which requires **requires Node version 10 or higher**.
|
||||||
|
|
||||||
**semantic-release** is meant to be used in a CI environment as a development support tool, not as a production dependency. Therefore the only constraint is to run the `semantic-release` in a CI environment providing Node 8 or higher.
|
**semantic-release** is meant to be used in a CI environment as a development support tool, not as a production dependency. Therefore the only constraint is to run the `semantic-release` in a CI environment providing Node 8 or higher.
|
||||||
|
|
||||||
@ -8,9 +8,9 @@ See our [Node Support Policy](node-support-policy.md) for our long-term promise
|
|||||||
|
|
||||||
## Recommended solution
|
## Recommended solution
|
||||||
|
|
||||||
### Run at least one CI job with Node >= 8.16
|
### Run at least one CI job with Node >= 10.13
|
||||||
|
|
||||||
The recommended approach is to run the `semantic-release` command from a CI job running on Node 8.16 or higher. This can either be a job used by your project to test on Node >= 8.16 or a dedicated job for the release steps.
|
The recommended approach is to run the `semantic-release` command from a CI job running on Node 10.13 or higher. This can either be a job used by your project to test on Node >= 10.13 or a dedicated job for the release steps.
|
||||||
|
|
||||||
See [CI configuration](../usage/ci-configuration.md) and [CI configuration recipes](../recipes/README.md#ci-configurations) for more details.
|
See [CI configuration](../usage/ci-configuration.md) and [CI configuration recipes](../recipes/README.md#ci-configurations) for more details.
|
||||||
|
|
||||||
|
@ -5,4 +5,5 @@
|
|||||||
- [CI Configuration](ci-configuration.md#ci-configuration)
|
- [CI Configuration](ci-configuration.md#ci-configuration)
|
||||||
- [Configuration](configuration.md#configuration)
|
- [Configuration](configuration.md#configuration)
|
||||||
- [Plugins](plugins.md)
|
- [Plugins](plugins.md)
|
||||||
|
- [Workflow configuration](workflow-configuration.md)
|
||||||
- [Shareable configurations](shareable-configurations.md)
|
- [Shareable configurations](shareable-configurations.md)
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
# Configuration
|
# Configuration
|
||||||
|
|
||||||
**semantic-release** configuration consists of:
|
**semantic-release** configuration consists of:
|
||||||
- Git repository ([URL](#repositoryurl) and options [release branch](#branch) and [tag format](#tagformat))
|
- Git repository ([URL](#repositoryurl) and options [release branches](#branches) and [tag format](#tagformat))
|
||||||
- Plugins [declaration](#plugins) and options
|
- Plugins [declaration](#plugins) and options
|
||||||
- Run mode ([debug](#debug), [dry run](#dryrun) and [local (no CI)](#ci))
|
- Run mode ([debug](#debug), [dry run](#dryrun) and [local (no CI)](#ci))
|
||||||
|
|
||||||
@ -24,7 +24,7 @@ The following three examples are the same.
|
|||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"release": {
|
"release": {
|
||||||
"branch": "next"
|
"branches": ["master", "next"]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@ -32,7 +32,7 @@ The following three examples are the same.
|
|||||||
- Via `.releaserc` file:
|
- Via `.releaserc` file:
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"branch": "next"
|
"branches": ["master", "next"]
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -58,13 +58,25 @@ List of modules or file paths containing a [shareable configuration](shareable-c
|
|||||||
|
|
||||||
**Note**: Options defined via CLI arguments or in the configuration file will take precedence over the ones defined in any shareable configuration.
|
**Note**: Options defined via CLI arguments or in the configuration file will take precedence over the ones defined in any shareable configuration.
|
||||||
|
|
||||||
### branch
|
### branches
|
||||||
|
|
||||||
Type: `String`<br>
|
Type: `Array`, `String`, `Object`<br>
|
||||||
Default: `master`<br>
|
Default: `['+([0-9])?(.{+([0-9]),x}).x', 'master', 'next', 'next-major', {name: 'beta', prerelease: true}, {name: 'alpha', prerelease: true}]`<br>
|
||||||
CLI arguments: `-b`, `--branch`
|
CLI arguments: `--branches`
|
||||||
|
|
||||||
The branch on which releases should happen.
|
The branches on which releases should happen. By default **semantic-release** will release:
|
||||||
|
- regular releases to the default distribution channel from the branch `master`
|
||||||
|
- regular releases to a distribution channel matching the branch name from any existing branch with a name matching a maintenance release range (`N.N.x` or `N.x.x` or `N.x` with `N` being a number)
|
||||||
|
- regular releases to the `next` distribution channel from the branch `next` if it exists
|
||||||
|
- regular releases to the `next-major` distribution channel from the branch `next-major` if it exists
|
||||||
|
- prereleases to the `beta` distribution channel from the branch `beta` if it exists
|
||||||
|
- prereleases to the `alpha` distribution channel from the branch `alpha` if it exists
|
||||||
|
|
||||||
|
**Note**: If your repository does not have a release branch, then **semantic-release** will fail with an `ERELEASEBRANCHES` error message. If you are using the default configuration, you can fix this error by pushing a `master` branch.
|
||||||
|
|
||||||
|
**Note**: Once **semantic-release** is configured, any user with the permission to push commits on one of those branches will be able to publish a release. It is recommended to protect those branches, for example with [GitHub protected branches](https://help.github.com/articles/about-protected-branches).
|
||||||
|
|
||||||
|
See [Workflow configuration](workflow-configuration.md#workflow-configuration) for more details.
|
||||||
|
|
||||||
### repositoryUrl
|
### repositoryUrl
|
||||||
|
|
||||||
@ -138,7 +150,7 @@ Output debugging information. This can also be enabled by setting the `DEBUG` en
|
|||||||
## Existing version tags
|
## Existing version tags
|
||||||
|
|
||||||
**semantic-release** uses [Git tags](https://git-scm.com/book/en/v2/Git-Basics-Tagging) to determine the commits added since the last release.
|
**semantic-release** uses [Git tags](https://git-scm.com/book/en/v2/Git-Basics-Tagging) to determine the commits added since the last release.
|
||||||
If a release has been published before setting up **semantic-release** you must make sure the most recent commit included in the last published release is in the [release branch](#branch) history and is tagged with the version released, formatted according to the [tag format](#tagformat) configured (defaults to `vx.y.z`).
|
If a release has been published before setting up **semantic-release** you must make sure the most recent commit included in the last published release is in the [release branches](#branches) history and is tagged with the version released, formatted according to the [tag format](#tagformat) configured (defaults to `vx.y.z`).
|
||||||
|
|
||||||
If the previous releases were published with [`npm publish`](https://docs.npmjs.com/cli/publish) this should already be the case.
|
If the previous releases were published with [`npm publish`](https://docs.npmjs.com/cli/publish) this should already be the case.
|
||||||
|
|
||||||
|
186
docs/usage/workflow-configuration.md
Normal file
186
docs/usage/workflow-configuration.md
Normal file
@ -0,0 +1,186 @@
|
|||||||
|
# Workflow configuration
|
||||||
|
|
||||||
|
**semantic-release** allow to manage and automate complex release workflow, based on multiple Git branches and distribution channels. This allow to:
|
||||||
|
- Distributes certain releases to a particular group of users via distribution channels
|
||||||
|
- Manage the availability of releases on distribution channels via branches merge
|
||||||
|
- Maintain multiple lines of releases in parallel
|
||||||
|
- Work on large future releases outside the normal flow of one version increment per Git push
|
||||||
|
|
||||||
|
See [Release workflow recipes](../recipes/README.md#release-workflow) for detailed examples.
|
||||||
|
|
||||||
|
The release workflow is configured via the [branches option](./configuration.md#branches) which accepts a single or an array of branch definitions.
|
||||||
|
Each branch can be defined either as a string, a [glob](https://github.com/micromatch/micromatch#matching-features) or an object. For string and glob definitions each [property](#branches-properties) will be defaulted.
|
||||||
|
|
||||||
|
A branch can defined as one of three types:
|
||||||
|
- [release](#release-branches): to make releases on top of the last version released
|
||||||
|
- [maintenance](#maintenance-branches): to make release on top of an old release
|
||||||
|
- [pre-release](#pre-release-branches): to make pre-releases
|
||||||
|
|
||||||
|
The type of the branch is automatically determined based on naming convention and/or [properties](#branches-properties).
|
||||||
|
|
||||||
|
## Branches properties
|
||||||
|
|
||||||
|
| Property | Branch type | Description | Default |
|
||||||
|
|--------------|-------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------|
|
||||||
|
| `name` | All | **Required.** The Git branch holding the commits to analyze and the code to release. See [name](#name). | - The value itself if defined as a `String` or the matching branches name if defined as a glob. |
|
||||||
|
| `channel` | All | The distribution channel on which to publish releases from this branch. Set to `false` to force the default distribution channel instead of using the default. See [channel](#channel). | `undefined` for the first release branch, the value of `name` for subsequent ones. |
|
||||||
|
| `range` | [maintenance](#maintenance-branches) only | **Required unless `name` is formatted like `N.N.x` or `N.x` (`N` is a number).** The range of [semantic versions](https://semver.org) to support on this branch. See [range](#range). | The value of `name`. |
|
||||||
|
| `prerelease` | [pre-release](#pre-release-branches) only | **Required.** The pre-release detonation to append to [semantic versions](https://semver.org) released from this branch. See [prerelease](#prerelease). | - |
|
||||||
|
|
||||||
|
### name
|
||||||
|
|
||||||
|
A `name` is required for any type of branch.
|
||||||
|
It can be defined as a [glob](https://github.com/micromatch/micromatch#matching-features) in which case the definition will be expanded to one per matching branch existing in the repository.
|
||||||
|
|
||||||
|
If `name` doesn't match to any branch existing in the repository, the definition will be ignored. For example the default configuration includes the definition `next` and `next-major` which will become active only when the branches `next` and/or `next-major` are created in the repository. This allow to define your workflow once with all potential branches you might use and have the effective configuration evolving as you create new branches.
|
||||||
|
|
||||||
|
For example the configuration `['+([0-9])?(.{+([0-9]),x}).x', 'master', 'next']` will be expanded as:
|
||||||
|
```js
|
||||||
|
{
|
||||||
|
branches: [
|
||||||
|
{name: '1.x', range: '1.x', channel: '1.x'}, // Only after the `1.x` is created in the repo
|
||||||
|
{name: '2.x', range: '2.x', channel: '2.x'}, // Only after the `2.x` is created in the repo
|
||||||
|
{name: 'master'},
|
||||||
|
{name: 'next', channel: 'next'}, // Only after the `next` is created in the repo
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### channel
|
||||||
|
|
||||||
|
The `channel` can be defined for any branch type. By default releases will be done on the default distribution channel (for example the `@latest` [dist-tag](https://docs.npmjs.com/cli/dist-tag) for npm) for the first [release branch](#release-branches) and on a distribution channel named based on the branch `name` for any other branch.
|
||||||
|
If the `channel` property is set to `false` the default channel will be used.
|
||||||
|
|
||||||
|
The value of `channel`, if defined as a string, is generated with [Lodash template](https://lodash.com/docs#template) with the variable `name` available.
|
||||||
|
|
||||||
|
For example the configuration `['master', {name: 'next', channel: 'channel-${name}'}]` will be expanded as:
|
||||||
|
```js
|
||||||
|
{
|
||||||
|
branches: [
|
||||||
|
{name: 'master'}, // `channel` is undefined so the default distribution channel will be used
|
||||||
|
{name: 'next', channel: 'channel-next'}, // `channel` is built with the template `channel-${name}`
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### range
|
||||||
|
|
||||||
|
A `range` only applies to maintenance branches, is required and must be formatted like `N.N.x` or `N.x` (`N` is a number). In case the `name` is formatted as a range (for example `1.x` or `1.5.x`) the branch will be considered a maintenance branch and the `name` value will be used for the `range`.
|
||||||
|
|
||||||
|
For example the configuration `['1.1.x', '1.2.x', 'master']` will be expanded as:
|
||||||
|
```js
|
||||||
|
{
|
||||||
|
branches: [
|
||||||
|
{name: '1.1.x', range: '1.1.x', channel: '1.1.x'},
|
||||||
|
{name: '1.2.x', range: '1.2.x', channel: '1.2.x'},
|
||||||
|
{name: 'master'},
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### prerelease
|
||||||
|
|
||||||
|
A `prerelease` property applies only to pre-release branches and the `prerelease` value must be valid per the [Semantic Versioning Specification](https://semver.org/#spec-item-9). It will determine the name of versions (for example if `prerelease` is set to `beta` the version be formatted like `2.0.0-beta.1`, `2.0.0-beta.2` etc...).
|
||||||
|
If the `prerelease` property is set to `true` the `name` value will be used.
|
||||||
|
|
||||||
|
The value of `prerelease`, if defined as a string, is generated with [Lodash template](https://lodash.com/docs#template) with the variable `name` available.
|
||||||
|
|
||||||
|
For example the configuration `['master', {name: 'pre/rc', prerelease: '${name.replace(/^pre\\//g, "")}'}, {name: 'beta', prerelease: true}]` will be expanded as:
|
||||||
|
```js
|
||||||
|
{
|
||||||
|
branches: [
|
||||||
|
{name: 'master'},
|
||||||
|
{name: 'pre/rc', channel: 'pre/rc', prerelease: 'rc'}, // `prerelease` is built with the template `${name.replace(/^pre\\//g, "")}`
|
||||||
|
{name: 'beta', channel: 'beta', prerelease: 'beta'}, // `prerelease` is set to `beta` as it is the value of `name`
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Branch types
|
||||||
|
|
||||||
|
### Release branches
|
||||||
|
|
||||||
|
A release branch is the base type of branch used by **semantic-release** that allows to publish releases with a [semantic version](https://semver.org), optionally on a specific distribution channel. Distribution channels (for example [npm dist-tags](https://docs.npmjs.com/cli/dist-tag) or [Chrome release channels](https://www.chromium.org/getting-involved/dev-channel)) are a way to distribute new releases only to a subset of users in order to get early feedback. Later on, those releases can be added to the general distribution channel to be made available to all users.
|
||||||
|
|
||||||
|
**semantic-release** will automatically add releases to the corresponding distribution channel when code is [merged from a release branch to another](#merging-into-a-release-branch).
|
||||||
|
|
||||||
|
A project must define a minimum of 1 release branch and can have a maximum of 3. The order of the release branch definitions is significant, as versions released on a given branch must always be higher than the last release made on the previous branch. This allow to avoid situation that would lead to an attempt to publish releases with the same version number but different codebase. When multiple release branches are configured and a commit that would create a version conflict is pushed, **semantic-release** will not perform the release and will throw an `EINVALIDNEXTVERSION` error, listing the problematic commits and the valid branches on which to move them.
|
||||||
|
|
||||||
|
**Note:** With **semantic-release** as with most package managers, a release version must be unique, independently of the distribution channel on which it is available.
|
||||||
|
|
||||||
|
See [publishing on distribution channels recipe](../recipes/distribution-channels.md) for a detailed example.
|
||||||
|
|
||||||
|
#### Pushing to a release branch
|
||||||
|
|
||||||
|
With the configuration `"branches": ["master", "next"]`, if the last release published from `master` is `1.0.0` and the last one from `next` is `2.0.0` then:
|
||||||
|
- Only versions in range `1.x.x` can be published from `master`, so only `fix` and `feat` commits can be pushed to `master`
|
||||||
|
- Once `next` get merged into `master` the release `2.0.0` will be made available on the channel associated with `master` and both `master` and `next` will accept any commit type
|
||||||
|
|
||||||
|
This verification prevent scenario such as:
|
||||||
|
1. Create a `feat` commit on `next` which triggers the release of version `1.0.0` on the `next` channel
|
||||||
|
2. Merge `next` into `master` which adds `1.0.0` on the default channel
|
||||||
|
3. Create a `feat` commit on `next` which triggers the release of version `1.1.0` on the `next` channel
|
||||||
|
4. Create a `feat` commit on `master` which would attempt to release the version `1.1.0` on the default channel
|
||||||
|
|
||||||
|
In step 4 **semantic-release** will throw an `EINVALIDNEXTVERSION` error to prevent the attempt at releasing version `1.1.0` which was already released on step 3 with a different codebase. The error will indicate that the commit should be created on `next` instead. Alternatively if the `next` branch is merged into `master`, the version `1.1.0` will be made available on the default channel and the `feat` commit would be allowed on `master` to release `1.2.0`.
|
||||||
|
|
||||||
|
#### Merging into a release branch
|
||||||
|
|
||||||
|
When merging commits associated with a release from one release branch to another, **semantic-release** will make the corresponding version available on the channel associated with the target branch.
|
||||||
|
|
||||||
|
When merging commits not associated with a release, commits from a [maintenance branch](#maintenance-branches) or commits from a [pre-release branch](#pre-release-branches) **semantic-release** will treat them as [pushed commits](#pushing-to-a-release-branch) and publish a new release if necessary.
|
||||||
|
|
||||||
|
### Maintenance branches
|
||||||
|
|
||||||
|
A maintenance branch is a type of branch used by **semantic-release** that allows to publish releases with a [semantic version](https://semver.org) on top of the codebase of an old release. This is useful when you need to provide fixes or features to users who cannot upgrade to the last version of your package.
|
||||||
|
|
||||||
|
A maintenance branch is characterized by a range which defines the versions that can be published from it. The [`range`](#range) value of each maintenance branch must be unique across the project.
|
||||||
|
|
||||||
|
**semantic-release** will always publish releases to a distribution channel specific to the range, so only the users who choose to use that particular line of versions will receive new releases.
|
||||||
|
|
||||||
|
Maintenance branches are always considered lower than [release branches](#release-branches) and similarly to them, when a commit that would create a version conflict is pushed, **semantic-release** will not perform the release and will throw an `EINVALIDNEXTVERSION` error, listing the problematic commits and the valid branches on which to move them.
|
||||||
|
|
||||||
|
**semantic-release** will automatically add releases to the corresponding distribution channel when code is [merged from a release or maintenance branch to another maintenance branch](#merging-into-a-maintenance-branch), however only version version within the branch `range` can be merged. Ia merged version is outside the maintenance branch `range` **semantic-release** will not add to the corresponding channel and will throw an `EINVALIDMAINTENANCEMERGE` error.
|
||||||
|
|
||||||
|
See [publishing maintenance releases recipe](../recipes/maintenance-releases.md) for a detailed example.
|
||||||
|
|
||||||
|
#### Pushing to a maintenance branch
|
||||||
|
|
||||||
|
With the configuration `"branches": ["1.0.x", "1.x", "master"]`, if the last release published from `master` is `1.5.0` then:
|
||||||
|
- Only versions in range `>=1.0.0 <1.1.0` can be published from `1.0.x`, so only `fix` commits can be pushed to `1.0.x`
|
||||||
|
- Only versions in range `>=1.1.0 <1.5.0` can be published from `1.x`, so only `fix` and `feat` commits can be pushed to `1.x` as long the resulting release is lower than `1.5.0`
|
||||||
|
- Once `2.0.0` is released from `master`, versions in range `>=1.1.0 <2.0.0` can be published from `1.x`, so any number of `fix` and `feat` commits can be pushed to `1.x`
|
||||||
|
|
||||||
|
#### Merging into a maintenance branch
|
||||||
|
|
||||||
|
With the configuration `"branches": ["1.0.x", "1.x", "master"]`, if the last release published from `master` is `1.0.0` then:
|
||||||
|
- Creating the branch `1.0.x` from `master` will make the `1.0.0` release available on the `1.0.x` distribution channel
|
||||||
|
- Pushing a `fix` commit on the `1.0.x` branch will release the version `1.0.1` on the `1.0.x` distribution channel
|
||||||
|
- Creating the branch `1.x` from `master` will make the `1.0.0` release available on the `1.x` distribution channel
|
||||||
|
- Merging the branch `1.0.x` into `1.x` will make the version `1.0.1` available on the `1.x` distribution channel
|
||||||
|
|
||||||
|
### Pre-release branches
|
||||||
|
|
||||||
|
A pre-release branch is a type of branch used by **semantic-release** that allows to publish releases with a [pre-release version](https://semver.org/#spec-item-9).
|
||||||
|
Using a pre-release version allow to publish multiple releases with the same version. Those release will be differentiated via there identifiers (in `1.0.0-alpha.1` the identifier is `alpha.1`).
|
||||||
|
This is useful when you need to work on a future major release that will include many breaking changes but you do not want to increment the version number for each breaking change commit.
|
||||||
|
|
||||||
|
A pre-release branch is characterized by the `prerelease` property that defines the static part of the version released (in `1.0.0-alpha.1` the static part fo the identifier is `alpha`). The [`prerelease`](#prerelease) value of each pre-release branch must be unique across the project.
|
||||||
|
|
||||||
|
**semantic-release** will always publish pre-releases to a specific distribution channel, so only the users who choose to use that particular line of versions will receive new releases.
|
||||||
|
|
||||||
|
When merging commits associated with an existing release, **semantic-release** will treat them as [pushed commits](#pushing-to-a-pre-release-branch) and publish a new release if necessary, but it will never add those releases to the distribution channel corresponding to the pre-release branch.
|
||||||
|
|
||||||
|
See [publishing pre-releases recipe](../recipes/pre-releases.md) for a detailed example.
|
||||||
|
|
||||||
|
#### Pushing to a pre-release branch
|
||||||
|
|
||||||
|
With the configuration `"branches": ["master", {"name": "beta", "prerelease": true}]`, if the last release published from `master` is `1.0.0` then:
|
||||||
|
- Pushing a `BREAKING CHANGE` commit on the `beta` branch will release the version `2.0.0-beta.1` on the `beta` distribution channel
|
||||||
|
- Pushing either a `fix`, `feat` or a `BREAKING CHANGE` commit on the `beta` branch will release the version `2.0.0-beta.2` (then `2.0.0-beta.3`, `2.0.0-beta.4`, etc...) on the `beta` distribution channel
|
||||||
|
|
||||||
|
#### Merging into a pre-release branch
|
||||||
|
|
||||||
|
With the configuration `"branches": ["master", {"name": "beta", "prerelease": true}]`, if the last release published from `master` is `1.0.0` and the last one published from `beta` is `2.0.0-beta.1` then:
|
||||||
|
- Pushing a `fix` commit on the `master` branch will release the version `1.0.1` on the default distribution channel
|
||||||
|
- Merging the branch `master` into `beta` will release the version `2.0.0-beta.2` on the `beta` distribution channel
|
131
index.js
131
index.js
@ -1,10 +1,10 @@
|
|||||||
/* eslint require-atomic-updates: off */
|
const {pick} = require('lodash');
|
||||||
|
|
||||||
const {template, pick} = require('lodash');
|
|
||||||
const marked = require('marked');
|
const marked = require('marked');
|
||||||
const TerminalRenderer = require('marked-terminal');
|
const TerminalRenderer = require('marked-terminal');
|
||||||
const envCi = require('env-ci');
|
const envCi = require('env-ci');
|
||||||
const hookStd = require('hook-std');
|
const hookStd = require('hook-std');
|
||||||
|
const semver = require('semver');
|
||||||
|
const AggregateError = require('aggregate-error');
|
||||||
const pkg = require('./package.json');
|
const pkg = require('./package.json');
|
||||||
const hideSensitive = require('./lib/hide-sensitive');
|
const hideSensitive = require('./lib/hide-sensitive');
|
||||||
const getConfig = require('./lib/get-config');
|
const getConfig = require('./lib/get-config');
|
||||||
@ -12,15 +12,18 @@ const verify = require('./lib/verify');
|
|||||||
const getNextVersion = require('./lib/get-next-version');
|
const getNextVersion = require('./lib/get-next-version');
|
||||||
const getCommits = require('./lib/get-commits');
|
const getCommits = require('./lib/get-commits');
|
||||||
const getLastRelease = require('./lib/get-last-release');
|
const getLastRelease = require('./lib/get-last-release');
|
||||||
const {extractErrors} = require('./lib/utils');
|
const getReleaseToAdd = require('./lib/get-release-to-add');
|
||||||
|
const {extractErrors, makeTag} = require('./lib/utils');
|
||||||
const getGitAuthUrl = require('./lib/get-git-auth-url');
|
const getGitAuthUrl = require('./lib/get-git-auth-url');
|
||||||
|
const getBranches = require('./lib/branches');
|
||||||
const getLogger = require('./lib/get-logger');
|
const getLogger = require('./lib/get-logger');
|
||||||
const {fetch, verifyAuth, isBranchUpToDate, getGitHead, tag, push} = require('./lib/git');
|
const {verifyAuth, isBranchUpToDate, getGitHead, tag, push, pushNotes, getTagHead, addNote} = require('./lib/git');
|
||||||
const getError = require('./lib/get-error');
|
const getError = require('./lib/get-error');
|
||||||
const {COMMIT_NAME, COMMIT_EMAIL} = require('./lib/definitions/constants');
|
const {COMMIT_NAME, COMMIT_EMAIL} = require('./lib/definitions/constants');
|
||||||
|
|
||||||
marked.setOptions({renderer: new TerminalRenderer()});
|
marked.setOptions({renderer: new TerminalRenderer()});
|
||||||
|
|
||||||
|
/* eslint complexity: off */
|
||||||
async function run(context, plugins) {
|
async function run(context, plugins) {
|
||||||
const {cwd, env, options, logger} = context;
|
const {cwd, env, options, logger} = context;
|
||||||
const {isCi, branch: ciBranch, isPr} = context.envCi;
|
const {isCi, branch: ciBranch, isPr} = context.envCi;
|
||||||
@ -46,9 +49,18 @@ async function run(context, plugins) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ciBranch !== options.branch) {
|
// Verify config
|
||||||
|
await verify(context);
|
||||||
|
|
||||||
|
options.repositoryUrl = await getGitAuthUrl(context);
|
||||||
|
context.branches = await getBranches(options.repositoryUrl, ciBranch, context);
|
||||||
|
context.branch = context.branches.find(({name}) => name === ciBranch);
|
||||||
|
|
||||||
|
if (!context.branch) {
|
||||||
logger.log(
|
logger.log(
|
||||||
`This test run was triggered on the branch ${ciBranch}, while semantic-release is configured to only publish from ${options.branch}, therefore a new version won’t be published.`
|
`This test run was triggered on the branch ${ciBranch}, while semantic-release is configured to only publish from ${context.branches
|
||||||
|
.map(({name}) => name)
|
||||||
|
.join(', ')}, therefore a new version won’t be published.`
|
||||||
);
|
);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -57,17 +69,13 @@ async function run(context, plugins) {
|
|||||||
`Run automated release from branch ${ciBranch}${options.dryRun ? ' in dry-run mode' : ''}`
|
`Run automated release from branch ${ciBranch}${options.dryRun ? ' in dry-run mode' : ''}`
|
||||||
);
|
);
|
||||||
|
|
||||||
await verify(context);
|
|
||||||
|
|
||||||
options.repositoryUrl = await getGitAuthUrl(context);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
try {
|
try {
|
||||||
await verifyAuth(options.repositoryUrl, options.branch, {cwd, env});
|
await verifyAuth(options.repositoryUrl, context.branch.name, {cwd, env});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (!(await isBranchUpToDate(options.repositoryUrl, options.branch, {cwd, env}))) {
|
if (!(await isBranchUpToDate(options.repositoryUrl, context.branch.name, {cwd, env}))) {
|
||||||
logger.log(
|
logger.log(
|
||||||
`The local branch ${options.branch} is behind the remote one, therefore a new version won't be published.`
|
`The local branch ${context.branch.name} is behind the remote one, therefore a new version won't be published.`
|
||||||
);
|
);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -76,28 +84,96 @@ async function run(context, plugins) {
|
|||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(`The command "${error.command}" failed with the error message ${error.stderr}.`);
|
logger.error(`The command "${error.command}" failed with the error message ${error.stderr}.`);
|
||||||
throw getError('EGITNOPERMISSION', {options});
|
throw getError('EGITNOPERMISSION', context);
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.success(`Allowed to push to the Git repository`);
|
logger.success(`Allowed to push to the Git repository`);
|
||||||
|
|
||||||
await plugins.verifyConditions(context);
|
await plugins.verifyConditions(context);
|
||||||
|
|
||||||
await fetch(options.repositoryUrl, {cwd, env});
|
const errors = [];
|
||||||
|
context.releases = [];
|
||||||
|
const releaseToAdd = getReleaseToAdd(context);
|
||||||
|
|
||||||
|
if (releaseToAdd) {
|
||||||
|
const {lastRelease, currentRelease, nextRelease} = releaseToAdd;
|
||||||
|
|
||||||
|
nextRelease.gitHead = await getTagHead(nextRelease.gitHead, {cwd, env});
|
||||||
|
currentRelease.gitHead = await getTagHead(currentRelease.gitHead, {cwd, env});
|
||||||
|
if (context.branch.mergeRange && !semver.satisfies(nextRelease.version, context.branch.mergeRange)) {
|
||||||
|
errors.push(getError('EINVALIDMAINTENANCEMERGE', {...context, nextRelease}));
|
||||||
|
} else {
|
||||||
|
const commits = await getCommits({...context, lastRelease, nextRelease});
|
||||||
|
nextRelease.notes = await plugins.generateNotes({...context, commits, lastRelease, nextRelease});
|
||||||
|
|
||||||
|
if (options.dryRun) {
|
||||||
|
logger.warn(`Skip ${nextRelease.gitTag} tag creation in dry-run mode`);
|
||||||
|
} else {
|
||||||
|
await addNote({channels: [...currentRelease.channels, nextRelease.channel]}, nextRelease.gitHead, {cwd, env});
|
||||||
|
await push(options.repositoryUrl, {cwd, env});
|
||||||
|
await pushNotes(options.repositoryUrl, {cwd, env});
|
||||||
|
logger.success(
|
||||||
|
`Add ${nextRelease.channel ? `channel ${nextRelease.channel}` : 'default channel'} to tag ${
|
||||||
|
nextRelease.gitTag
|
||||||
|
}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
context.branch.tags.push({
|
||||||
|
version: nextRelease.version,
|
||||||
|
channel: nextRelease.channel,
|
||||||
|
gitTag: nextRelease.gitTag,
|
||||||
|
gitHead: nextRelease.gitHead,
|
||||||
|
});
|
||||||
|
|
||||||
|
const releases = await plugins.addChannel({...context, commits, lastRelease, currentRelease, nextRelease});
|
||||||
|
context.releases.push(...releases);
|
||||||
|
await plugins.success({...context, lastRelease, commits, nextRelease, releases});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (errors.length > 0) {
|
||||||
|
throw new AggregateError(errors);
|
||||||
|
}
|
||||||
|
|
||||||
|
context.lastRelease = getLastRelease(context);
|
||||||
|
if (context.lastRelease.gitHead) {
|
||||||
|
context.lastRelease.gitHead = await getTagHead(context.lastRelease.gitHead, {cwd, env});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (context.lastRelease.gitTag) {
|
||||||
|
logger.log(
|
||||||
|
`Found git tag ${context.lastRelease.gitTag} associated with version ${context.lastRelease.version} on branch ${context.branch.name}`
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
logger.log(`No git tag version found on branch ${context.branch.name}`);
|
||||||
|
}
|
||||||
|
|
||||||
context.lastRelease = await getLastRelease(context);
|
|
||||||
context.commits = await getCommits(context);
|
context.commits = await getCommits(context);
|
||||||
|
|
||||||
const nextRelease = {type: await plugins.analyzeCommits(context), gitHead: await getGitHead({cwd, env})};
|
const nextRelease = {
|
||||||
|
type: await plugins.analyzeCommits(context),
|
||||||
|
channel: context.branch.channel || null,
|
||||||
|
gitHead: await getGitHead({cwd, env}),
|
||||||
|
};
|
||||||
if (!nextRelease.type) {
|
if (!nextRelease.type) {
|
||||||
logger.log('There are no relevant changes, so no new version is released.');
|
logger.log('There are no relevant changes, so no new version is released.');
|
||||||
return false;
|
return context.releases.length > 0 ? {releases: context.releases} : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
context.nextRelease = nextRelease;
|
context.nextRelease = nextRelease;
|
||||||
nextRelease.version = getNextVersion(context);
|
nextRelease.version = getNextVersion(context);
|
||||||
nextRelease.gitTag = template(options.tagFormat)({version: nextRelease.version});
|
nextRelease.gitTag = makeTag(options.tagFormat, nextRelease.version);
|
||||||
|
nextRelease.name = nextRelease.gitTag;
|
||||||
|
|
||||||
|
if (context.branch.type !== 'prerelease' && !semver.satisfies(nextRelease.version, context.branch.range)) {
|
||||||
|
throw getError('EINVALIDNEXTVERSION', {
|
||||||
|
...context,
|
||||||
|
validBranches: context.branches.filter(
|
||||||
|
({type, accept}) => type !== 'prerelease' && accept.includes(nextRelease.type)
|
||||||
|
),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
await plugins.verifyRelease(context);
|
await plugins.verifyRelease(context);
|
||||||
|
|
||||||
@ -109,16 +185,21 @@ async function run(context, plugins) {
|
|||||||
logger.warn(`Skip ${nextRelease.gitTag} tag creation in dry-run mode`);
|
logger.warn(`Skip ${nextRelease.gitTag} tag creation in dry-run mode`);
|
||||||
} else {
|
} else {
|
||||||
// Create the tag before calling the publish plugins as some require the tag to exists
|
// Create the tag before calling the publish plugins as some require the tag to exists
|
||||||
await tag(nextRelease.gitTag, {cwd, env});
|
await tag(nextRelease.gitTag, nextRelease.gitHead, {cwd, env});
|
||||||
|
await addNote({channels: [nextRelease.channel]}, nextRelease.gitHead, {cwd, env});
|
||||||
await push(options.repositoryUrl, {cwd, env});
|
await push(options.repositoryUrl, {cwd, env});
|
||||||
|
await pushNotes(options.repositoryUrl, {cwd, env});
|
||||||
logger.success(`Created tag ${nextRelease.gitTag}`);
|
logger.success(`Created tag ${nextRelease.gitTag}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
context.releases = await plugins.publish(context);
|
const releases = await plugins.publish(context);
|
||||||
|
context.releases.push(...releases);
|
||||||
|
|
||||||
await plugins.success(context);
|
await plugins.success({...context, releases});
|
||||||
|
|
||||||
logger.success(`Published release ${nextRelease.version}`);
|
logger.success(
|
||||||
|
`Published release ${nextRelease.version} on ${nextRelease.channel ? nextRelease.channel : 'default'} channel`
|
||||||
|
);
|
||||||
|
|
||||||
if (options.dryRun) {
|
if (options.dryRun) {
|
||||||
logger.log(`Release note for version ${nextRelease.version}:`);
|
logger.log(`Release note for version ${nextRelease.version}:`);
|
||||||
|
18
lib/branches/expand.js
Normal file
18
lib/branches/expand.js
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
const {isString, remove, omit, mapValues, template} = require('lodash');
|
||||||
|
const micromatch = require('micromatch');
|
||||||
|
const {getBranches} = require('../git');
|
||||||
|
|
||||||
|
module.exports = async (repositoryUrl, {cwd}, branches) => {
|
||||||
|
const gitBranches = await getBranches(repositoryUrl, {cwd});
|
||||||
|
|
||||||
|
return branches.reduce(
|
||||||
|
(branches, branch) => [
|
||||||
|
...branches,
|
||||||
|
...remove(gitBranches, name => micromatch(gitBranches, branch.name).includes(name)).map(name => ({
|
||||||
|
name,
|
||||||
|
...mapValues(omit(branch, 'name'), value => (isString(value) ? template(value)({name}) : value)),
|
||||||
|
})),
|
||||||
|
],
|
||||||
|
[]
|
||||||
|
);
|
||||||
|
};
|
33
lib/branches/get-tags.js
Normal file
33
lib/branches/get-tags.js
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
const {template, escapeRegExp} = require('lodash');
|
||||||
|
const semver = require('semver');
|
||||||
|
const pReduce = require('p-reduce');
|
||||||
|
const debug = require('debug')('semantic-release:get-tags');
|
||||||
|
const {getTags, getNote} = require('../../lib/git');
|
||||||
|
|
||||||
|
module.exports = async ({cwd, env, options: {tagFormat}}, branches) => {
|
||||||
|
// Generate a regex to parse tags formatted with `tagFormat`
|
||||||
|
// by replacing the `version` variable in the template by `(.+)`.
|
||||||
|
// The `tagFormat` is compiled with space as the `version` as it's an invalid tag character,
|
||||||
|
// so it's guaranteed to no be present in the `tagFormat`.
|
||||||
|
const tagRegexp = `^${escapeRegExp(template(tagFormat)({version: ' '})).replace(' ', '(.+)')}`;
|
||||||
|
|
||||||
|
return pReduce(
|
||||||
|
branches,
|
||||||
|
async (branches, branch) => {
|
||||||
|
const branchTags = await pReduce(
|
||||||
|
await getTags(branch.name, {cwd, env}),
|
||||||
|
async (branchTags, tag) => {
|
||||||
|
const [, version] = tag.match(tagRegexp) || [];
|
||||||
|
return version && semver.valid(semver.clean(version))
|
||||||
|
? [...branchTags, {gitTag: tag, version, channels: (await getNote(tag, {cwd, env})).channels || [null]}]
|
||||||
|
: branchTags;
|
||||||
|
},
|
||||||
|
[]
|
||||||
|
);
|
||||||
|
|
||||||
|
debug('found tags for branch %s: %o', branch.name, branchTags);
|
||||||
|
return [...branches, {...branch, tags: branchTags}];
|
||||||
|
},
|
||||||
|
[]
|
||||||
|
);
|
||||||
|
};
|
70
lib/branches/index.js
Normal file
70
lib/branches/index.js
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
const {isString, isRegExp} = require('lodash');
|
||||||
|
const AggregateError = require('aggregate-error');
|
||||||
|
const pEachSeries = require('p-each-series');
|
||||||
|
const DEFINITIONS = require('../definitions/branches');
|
||||||
|
const getError = require('../get-error');
|
||||||
|
const {fetch, fetchNotes, verifyBranchName} = require('../git');
|
||||||
|
const expand = require('./expand');
|
||||||
|
const getTags = require('./get-tags');
|
||||||
|
const normalize = require('./normalize');
|
||||||
|
|
||||||
|
module.exports = async (repositoryUrl, ciBranch, context) => {
|
||||||
|
const {cwd, env} = context;
|
||||||
|
|
||||||
|
const remoteBranches = await expand(
|
||||||
|
repositoryUrl,
|
||||||
|
context,
|
||||||
|
context.options.branches.map(branch => (isString(branch) || isRegExp(branch) ? {name: branch} : branch))
|
||||||
|
);
|
||||||
|
|
||||||
|
await pEachSeries(remoteBranches, async ({name}) => {
|
||||||
|
await fetch(repositoryUrl, name, ciBranch, {cwd, env});
|
||||||
|
});
|
||||||
|
|
||||||
|
await fetchNotes(repositoryUrl, {cwd, env});
|
||||||
|
|
||||||
|
const branches = await getTags(context, remoteBranches);
|
||||||
|
|
||||||
|
const errors = [];
|
||||||
|
const branchesByType = Object.entries(DEFINITIONS).reduce(
|
||||||
|
(branchesByType, [type, {filter}]) => ({[type]: branches.filter(filter), ...branchesByType}),
|
||||||
|
{}
|
||||||
|
);
|
||||||
|
|
||||||
|
const result = Object.entries(DEFINITIONS).reduce((result, [type, {branchesValidator, branchValidator}]) => {
|
||||||
|
branchesByType[type].forEach(branch => {
|
||||||
|
if (branchValidator && !branchValidator(branch)) {
|
||||||
|
errors.push(getError(`E${type.toUpperCase()}BRANCH`, {branch}));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const branchesOfType = normalize[type](branchesByType);
|
||||||
|
|
||||||
|
if (!branchesValidator(branchesOfType)) {
|
||||||
|
errors.push(getError(`E${type.toUpperCase()}BRANCHES`, {branches: branchesOfType}));
|
||||||
|
}
|
||||||
|
|
||||||
|
return {...result, [type]: branchesOfType};
|
||||||
|
}, {});
|
||||||
|
|
||||||
|
const duplicates = [...branches]
|
||||||
|
.map(branch => branch.name)
|
||||||
|
.sort()
|
||||||
|
.filter((_, idx, arr) => arr[idx] === arr[idx + 1] && arr[idx] !== arr[idx - 1]);
|
||||||
|
|
||||||
|
if (duplicates.length > 0) {
|
||||||
|
errors.push(getError('EDUPLICATEBRANCHES', {duplicates}));
|
||||||
|
}
|
||||||
|
|
||||||
|
await pEachSeries(branches, async branch => {
|
||||||
|
if (!(await verifyBranchName(branch.name))) {
|
||||||
|
errors.push(getError('EINVALIDBRANCHNAME', branch));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (errors.length > 0) {
|
||||||
|
throw new AggregateError(errors);
|
||||||
|
}
|
||||||
|
|
||||||
|
return [...result.maintenance, ...result.release, ...result.prerelease];
|
||||||
|
};
|
106
lib/branches/normalize.js
Normal file
106
lib/branches/normalize.js
Normal file
@ -0,0 +1,106 @@
|
|||||||
|
const {sortBy, isNil} = require('lodash');
|
||||||
|
const semverDiff = require('semver-diff');
|
||||||
|
const {FIRST_RELEASE, RELEASE_TYPE} = require('../definitions/constants');
|
||||||
|
const {
|
||||||
|
tagsToVersions,
|
||||||
|
isMajorRange,
|
||||||
|
getUpperBound,
|
||||||
|
getLowerBound,
|
||||||
|
highest,
|
||||||
|
lowest,
|
||||||
|
getLatestVersion,
|
||||||
|
getFirstVersion,
|
||||||
|
getRange,
|
||||||
|
} = require('../utils');
|
||||||
|
|
||||||
|
function maintenance({maintenance, release}) {
|
||||||
|
return sortBy(
|
||||||
|
maintenance.map(({name, range, channel, ...rest}) => ({
|
||||||
|
...rest,
|
||||||
|
name,
|
||||||
|
range: range || name,
|
||||||
|
channel: isNil(channel) ? name : channel,
|
||||||
|
})),
|
||||||
|
'range'
|
||||||
|
).map(({name, range, tags, ...rest}, idx, branches) => {
|
||||||
|
const versions = tagsToVersions(tags);
|
||||||
|
// Find the lower bound based on Maintenance branches
|
||||||
|
const maintenanceMin =
|
||||||
|
// If the current branch has a major range (1.x or 1.x.x) and the previous doesn't
|
||||||
|
isMajorRange(range) && branches[idx - 1] && !isMajorRange(branches[idx - 1].range)
|
||||||
|
? // Then the lowest bound is the upper bound of the previous branch range
|
||||||
|
getUpperBound(branches[idx - 1].range)
|
||||||
|
: // Otherwise the lowest bound is the lowest bound of the current branch range
|
||||||
|
getLowerBound(range);
|
||||||
|
// The actual lower bound is the highest version between the current branch last release and `maintenanceMin`
|
||||||
|
const min = highest(getLatestVersion(versions) || FIRST_RELEASE, maintenanceMin);
|
||||||
|
// Determine the first release of the default branch not present in any maintenance branch
|
||||||
|
const base =
|
||||||
|
(release[0] &&
|
||||||
|
(getFirstVersion(tagsToVersions(release[0].tags), branches) ||
|
||||||
|
getLatestVersion(tagsToVersions(release[0].tags)))) ||
|
||||||
|
FIRST_RELEASE;
|
||||||
|
// The upper bound is the lowest version between the `base` version and the upper bound of the current branch range
|
||||||
|
const max = lowest(base, getUpperBound(range));
|
||||||
|
const diff = semverDiff(min, max);
|
||||||
|
return {
|
||||||
|
...rest,
|
||||||
|
type: 'maintenance',
|
||||||
|
name,
|
||||||
|
tags,
|
||||||
|
range: getRange(min, max),
|
||||||
|
accept: diff ? RELEASE_TYPE.slice(0, RELEASE_TYPE.indexOf(diff)) : [],
|
||||||
|
mergeRange: getRange(maintenanceMin, getUpperBound(range)),
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function release({release}) {
|
||||||
|
if (release.length === 0) {
|
||||||
|
return release;
|
||||||
|
}
|
||||||
|
|
||||||
|
// The intial lastVersion is the last release from the base branch of `FIRST_RELEASE` (1.0.0)
|
||||||
|
let lastVersion = getLatestVersion(tagsToVersions(release[0].tags)) || FIRST_RELEASE;
|
||||||
|
|
||||||
|
return release.map(({name, tags, channel, ...rest}, idx) => {
|
||||||
|
const versions = tagsToVersions(tags);
|
||||||
|
// The new lastVersion is the highest version between the current branch last release and the previous branch lastVersion
|
||||||
|
lastVersion = highest(getLatestVersion(versions), lastVersion);
|
||||||
|
// The upper bound is:
|
||||||
|
// - None if the current branch is the last one of the release branches
|
||||||
|
// - Otherwise, The upper bound is the lowest version that is present on the current branch but none of the previous ones
|
||||||
|
const bound =
|
||||||
|
release.length - 1 === idx
|
||||||
|
? undefined
|
||||||
|
: getFirstVersion(tagsToVersions(release[idx + 1].tags), release.slice(0, idx + 1));
|
||||||
|
|
||||||
|
const diff = bound ? semverDiff(lastVersion, bound) : null;
|
||||||
|
return {
|
||||||
|
...rest,
|
||||||
|
channel: idx === 0 ? channel : isNil(channel) ? name : channel,
|
||||||
|
tags,
|
||||||
|
type: 'release',
|
||||||
|
name,
|
||||||
|
range: getRange(lastVersion, bound),
|
||||||
|
accept: bound ? RELEASE_TYPE.slice(0, RELEASE_TYPE.indexOf(diff)) : RELEASE_TYPE,
|
||||||
|
main: idx === 0,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function prerelease({prerelease}) {
|
||||||
|
return prerelease.map(({name, prerelease, channel, tags, ...rest}) => {
|
||||||
|
const preid = prerelease === true ? name : prerelease;
|
||||||
|
return {
|
||||||
|
...rest,
|
||||||
|
channel: isNil(channel) ? name : channel,
|
||||||
|
type: 'prerelease',
|
||||||
|
name,
|
||||||
|
prerelease: preid,
|
||||||
|
tags,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {maintenance, release, prerelease};
|
23
lib/definitions/branches.js
Normal file
23
lib/definitions/branches.js
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
const {isNil, uniqBy} = require('lodash');
|
||||||
|
const semver = require('semver');
|
||||||
|
const {isMaintenanceRange} = require('../utils');
|
||||||
|
|
||||||
|
const maintenance = {
|
||||||
|
filter: ({name, range}) => (!isNil(range) && range !== false) || isMaintenanceRange(name),
|
||||||
|
branchValidator: ({range}) => (isNil(range) ? true : isMaintenanceRange(range)),
|
||||||
|
branchesValidator: branches => uniqBy(branches, ({range}) => semver.validRange(range)).length === branches.length,
|
||||||
|
};
|
||||||
|
|
||||||
|
const prerelease = {
|
||||||
|
filter: ({prerelease}) => !isNil(prerelease) && prerelease !== false,
|
||||||
|
branchValidator: ({name, prerelease}) =>
|
||||||
|
Boolean(prerelease) && Boolean(semver.valid(`1.0.0-${prerelease === true ? name : prerelease}.1`)),
|
||||||
|
branchesValidator: branches => uniqBy(branches, 'prerelease').length === branches.length,
|
||||||
|
};
|
||||||
|
|
||||||
|
const release = {
|
||||||
|
filter: branch => !maintenance.filter(branch) && !prerelease.filter(branch),
|
||||||
|
branchesValidator: branches => branches.length <= 3 && branches.length > 0,
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = {maintenance, prerelease, release};
|
@ -1,7 +1,9 @@
|
|||||||
const RELEASE_TYPE = ['prerelease', 'prepatch', 'patch', 'preminor', 'minor', 'premajor', 'major'];
|
const RELEASE_TYPE = ['patch', 'minor', 'major'];
|
||||||
|
|
||||||
const FIRST_RELEASE = '1.0.0';
|
const FIRST_RELEASE = '1.0.0';
|
||||||
|
|
||||||
|
const FIRSTPRERELEASE = '1';
|
||||||
|
|
||||||
const COMMIT_NAME = 'semantic-release-bot';
|
const COMMIT_NAME = 'semantic-release-bot';
|
||||||
|
|
||||||
const COMMIT_EMAIL = 'semantic-release-bot@martynus.net';
|
const COMMIT_EMAIL = 'semantic-release-bot@martynus.net';
|
||||||
@ -12,12 +14,16 @@ const SECRET_REPLACEMENT = '[secure]';
|
|||||||
|
|
||||||
const SECRET_MIN_SIZE = 5;
|
const SECRET_MIN_SIZE = 5;
|
||||||
|
|
||||||
|
const GIT_NOTE_REF = 'semantic-release';
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
RELEASE_TYPE,
|
RELEASE_TYPE,
|
||||||
FIRST_RELEASE,
|
FIRST_RELEASE,
|
||||||
|
FIRSTPRERELEASE,
|
||||||
COMMIT_NAME,
|
COMMIT_NAME,
|
||||||
COMMIT_EMAIL,
|
COMMIT_EMAIL,
|
||||||
RELEASE_NOTES_SEPARATOR,
|
RELEASE_NOTES_SEPARATOR,
|
||||||
SECRET_REPLACEMENT,
|
SECRET_REPLACEMENT,
|
||||||
SECRET_MIN_SIZE,
|
SECRET_MIN_SIZE,
|
||||||
|
GIT_NOTE_REF,
|
||||||
};
|
};
|
||||||
|
@ -1,11 +1,13 @@
|
|||||||
const {inspect} = require('util');
|
const {inspect} = require('util');
|
||||||
const {toLower, isString} = require('lodash');
|
const {toLower, isString, trim} = require('lodash');
|
||||||
const pkg = require('../../package.json');
|
const pkg = require('../../package.json');
|
||||||
const {RELEASE_TYPE} = require('./constants');
|
const {RELEASE_TYPE} = require('./constants');
|
||||||
|
|
||||||
const [homepage] = pkg.homepage.split('#');
|
const [homepage] = pkg.homepage.split('#');
|
||||||
const stringify = obj => (isString(obj) ? obj : inspect(obj, {breakLength: Infinity, depth: 2, maxArrayLength: 5}));
|
const stringify = obj => (isString(obj) ? obj : inspect(obj, {breakLength: Infinity, depth: 2, maxArrayLength: 5}));
|
||||||
const linkify = file => `${homepage}/blob/master/${file}`;
|
const linkify = file => `${homepage}/blob/master/${file}`;
|
||||||
|
const wordsList = words =>
|
||||||
|
`${words.slice(0, -1).join(', ')}${words.length > 1 ? ` or ${words[words.length - 1]}` : trim(words[0])}`;
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
ENOGITREPO: ({cwd}) => ({
|
ENOGITREPO: ({cwd}) => ({
|
||||||
@ -26,11 +28,9 @@ Please make sure to add the \`repositoryUrl\` to the [semantic-release configura
|
|||||||
'docs/usage/configuration.md'
|
'docs/usage/configuration.md'
|
||||||
)}).`,
|
)}).`,
|
||||||
}),
|
}),
|
||||||
EGITNOPERMISSION: ({options}) => ({
|
EGITNOPERMISSION: ({options: {repositoryUrl}, branch: {name}}) => ({
|
||||||
message: 'Cannot push to the Git repository.',
|
message: 'Cannot push to the Git repository.',
|
||||||
details: `**semantic-release** cannot push the version tag to the branch \`${
|
details: `**semantic-release** cannot push the version tag to the branch \`${name}\` on the remote Git repository with URL \`${repositoryUrl}\`.
|
||||||
options.branch
|
|
||||||
}\` on the remote Git repository with URL \`${options.repositoryUrl}\`.
|
|
||||||
|
|
||||||
This can be caused by:
|
This can be caused by:
|
||||||
- a misconfiguration of the [repositoryUrl](${linkify('docs/usage/configuration.md#repositoryurl')}) option
|
- a misconfiguration of the [repositoryUrl](${linkify('docs/usage/configuration.md#repositoryurl')}) option
|
||||||
@ -39,7 +39,7 @@ This can be caused by:
|
|||||||
'docs/usage/ci-configuration.md#authentication'
|
'docs/usage/ci-configuration.md#authentication'
|
||||||
)})`,
|
)})`,
|
||||||
}),
|
}),
|
||||||
EINVALIDTAGFORMAT: ({tagFormat}) => ({
|
EINVALIDTAGFORMAT: ({options: {tagFormat}}) => ({
|
||||||
message: 'Invalid `tagFormat` option.',
|
message: 'Invalid `tagFormat` option.',
|
||||||
details: `The [tagFormat](${linkify(
|
details: `The [tagFormat](${linkify(
|
||||||
'docs/usage/configuration.md#tagformat'
|
'docs/usage/configuration.md#tagformat'
|
||||||
@ -47,7 +47,7 @@ This can be caused by:
|
|||||||
|
|
||||||
Your configuration for the \`tagFormat\` option is \`${stringify(tagFormat)}\`.`,
|
Your configuration for the \`tagFormat\` option is \`${stringify(tagFormat)}\`.`,
|
||||||
}),
|
}),
|
||||||
ETAGNOVERSION: ({tagFormat}) => ({
|
ETAGNOVERSION: ({options: {tagFormat}}) => ({
|
||||||
message: 'Invalid `tagFormat` option.',
|
message: 'Invalid `tagFormat` option.',
|
||||||
details: `The [tagFormat](${linkify(
|
details: `The [tagFormat](${linkify(
|
||||||
'docs/usage/configuration.md#tagformat'
|
'docs/usage/configuration.md#tagformat'
|
||||||
@ -125,4 +125,107 @@ We recommend to report the issue to the \`${pluginName}\` authors, providing the
|
|||||||
'docs/developer-guide/plugin.md'
|
'docs/developer-guide/plugin.md'
|
||||||
)})`,
|
)})`,
|
||||||
}),
|
}),
|
||||||
|
EADDCHANNELOUTPUT: ({result, pluginName}) => ({
|
||||||
|
message: 'A `addChannel` plugin returned an invalid value. It must return an `Object`.',
|
||||||
|
details: `The \`addChannel\` plugins must return an \`Object\`.
|
||||||
|
|
||||||
|
The \`addChannel\` function of the \`${pluginName}\` returned \`${stringify(result)}\` instead.
|
||||||
|
|
||||||
|
We recommend to report the issue to the \`${pluginName}\` authors, providing the following informations:
|
||||||
|
- The **semantic-release** version: \`${pkg.version}\`
|
||||||
|
- The **semantic-release** logs from your CI job
|
||||||
|
- The value returned by the plugin: \`${stringify(result)}\`
|
||||||
|
- A link to the **semantic-release** plugin developer guide: [${linkify('docs/developer-guide/plugin.md')}](${linkify(
|
||||||
|
'docs/developer-guide/plugin.md'
|
||||||
|
)})`,
|
||||||
|
}),
|
||||||
|
EINVALIDBRANCH: ({branch}) => ({
|
||||||
|
message: 'A branch is invalid in the `branches` configuration.',
|
||||||
|
details: `Each branch in the [branches configuration](${linkify(
|
||||||
|
'docs/usage/configuration.md#branches'
|
||||||
|
)}) must be either a string, a regexp or an object with a \`name\` property.
|
||||||
|
|
||||||
|
Your configuration for the problematic branch is \`${stringify(branch)}\`.`,
|
||||||
|
}),
|
||||||
|
EINVALIDBRANCHNAME: ({branch}) => ({
|
||||||
|
message: 'A branch name is invalid in the `branches` configuration.',
|
||||||
|
details: `Each branch in the [branches configuration](${linkify(
|
||||||
|
'docs/usage/configuration.md#branches'
|
||||||
|
)}) must be a [valid Git reference](https://git-scm.com/docs/git-check-ref-format#_description).
|
||||||
|
|
||||||
|
Your configuration for the problematic branch is \`${stringify(branch)}\`.`,
|
||||||
|
}),
|
||||||
|
EDUPLICATEBRANCHES: ({duplicates}) => ({
|
||||||
|
message: 'The `branches` configuration has duplicate branches.',
|
||||||
|
details: `Each branch in the [branches configuration](${linkify(
|
||||||
|
'docs/usage/configuration.md#branches'
|
||||||
|
)}) must havea unique name.
|
||||||
|
|
||||||
|
Your configuration contains duplicates for the following branch names: \`${stringify(duplicates)}\`.`,
|
||||||
|
}),
|
||||||
|
EMAINTENANCEBRANCH: ({branch}) => ({
|
||||||
|
message: 'A maintenance branch is invalid in the `branches` configuration.',
|
||||||
|
details: `Each maintenance branch in the [branches configuration](${linkify(
|
||||||
|
'docs/usage/configuration.md#branches'
|
||||||
|
)}) must have a \`range\` property formatted like \`N.x\`, \`N.x.x\` or \`N.N.x\` (\`N\` is a number).
|
||||||
|
|
||||||
|
Your configuration for the problematic branch is \`${stringify(branch)}\`.`,
|
||||||
|
}),
|
||||||
|
EMAINTENANCEBRANCHES: ({branches}) => ({
|
||||||
|
message: 'The maintenance branches are invalid in the `branches` configuration.',
|
||||||
|
details: `Each maintenance branch in the [branches configuration](${linkify(
|
||||||
|
'docs/usage/configuration.md#branches'
|
||||||
|
)}) must have a unique \`range\` property.
|
||||||
|
|
||||||
|
Your configuration for the problematic branches is \`${stringify(branches)}\`.`,
|
||||||
|
}),
|
||||||
|
ERELEASEBRANCHES: ({branches}) => ({
|
||||||
|
message: 'The release branches are invalid in the `branches` configuration.',
|
||||||
|
details: `A minimum of 1 and a maximum of 3 release branches are required in the [branches configuration](${linkify(
|
||||||
|
'docs/usage/configuration.md#branches'
|
||||||
|
)}).
|
||||||
|
|
||||||
|
This may occur if your repository does not have a release branch, such as \`master\`.
|
||||||
|
|
||||||
|
Your configuration for the problematic branches is \`${stringify(branches)}\`.`,
|
||||||
|
}),
|
||||||
|
EPRERELEASEBRANCH: ({branch}) => ({
|
||||||
|
message: 'A pre-release branch configuration is invalid in the `branches` configuration.',
|
||||||
|
details: `Each pre-release branch in the [branches configuration](${linkify(
|
||||||
|
'docs/usage/configuration.md#branches'
|
||||||
|
)}) must have a \`prerelease\` property valid per the [Semantic Versioning Specification](https://semver.org/#spec-item-9). If the \`prerelease\` property is set to \`true\`, then the \`name\` property is used instead.
|
||||||
|
|
||||||
|
Your configuration for the problematic branch is \`${stringify(branch)}\`.`,
|
||||||
|
}),
|
||||||
|
EPRERELEASEBRANCHES: ({branches}) => ({
|
||||||
|
message: 'The pre-release branches are invalid in the `branches` configuration.',
|
||||||
|
details: `Each pre-release branch in the [branches configuration](${linkify(
|
||||||
|
'docs/usage/configuration.md#branches'
|
||||||
|
)}) must have a unique \`prerelease\` property. If the \`prerelease\` property is set to \`true\`, then the \`name\` property is used instead.
|
||||||
|
|
||||||
|
Your configuration for the problematic branches is \`${stringify(branches)}\`.`,
|
||||||
|
}),
|
||||||
|
EINVALIDNEXTVERSION: ({nextRelease: {version}, branch: {name, range}, commits, validBranches}) => ({
|
||||||
|
message: `The release \`${version}\` on branch \`${name}\` cannot be published as it is out of range.`,
|
||||||
|
details: `Based on the releases published on other branches, only versions within the range \`${range}\` can be published from branch \`${name}\`.
|
||||||
|
|
||||||
|
The following commit${commits.length > 1 ? 's are' : ' is'} responsible for the invalid release:
|
||||||
|
${commits.map(({commit: {short}, subject}) => `- ${subject} (${short})`).join('\n')}
|
||||||
|
|
||||||
|
${
|
||||||
|
commits.length > 1 ? 'Those commits' : 'This commit'
|
||||||
|
} should be moved to a valid branch with [git merge](https://git-scm.com/docs/git-merge) or [git cherry-pick](https://git-scm.com/docs/git-cherry-pick) and removed from branch \`${name}\` with [git revert](https://git-scm.com/docs/git-revert) or [git reset](https://git-scm.com/docs/git-reset).
|
||||||
|
|
||||||
|
A valid branch could be ${wordsList(validBranches.map(({name}) => `\`${name}\``))}.
|
||||||
|
|
||||||
|
See the [workflow configuration documentation](${linkify('docs/usage/workflow-configuration.md')}) for more details.`,
|
||||||
|
}),
|
||||||
|
EINVALIDMAINTENANCEMERGE: ({nextRelease: {channel, gitTag, version}, branch: {mergeRange, name}}) => ({
|
||||||
|
message: `The release \`${version}\` on branch \`${name}\` cannot be published as it is out of range.`,
|
||||||
|
details: `Only releases within the range \`${mergeRange}\` can be merged into the maintenance branch \`${name}\` and published to the \`${channel}\` distribution channel.
|
||||||
|
|
||||||
|
The branch \`${name}\` head should be [reset](https://git-scm.com/docs/git-reset) to a previous commit so the commit with tag \`${gitTag}\` is removed from the branch history.
|
||||||
|
|
||||||
|
See the [workflow configuration documentation](${linkify('docs/usage/workflow-configuration.md')}) for more details.`,
|
||||||
|
}),
|
||||||
};
|
};
|
||||||
|
@ -80,6 +80,19 @@ module.exports = {
|
|||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
|
addChannel: {
|
||||||
|
required: false,
|
||||||
|
dryRun: false,
|
||||||
|
outputValidator: output => !output || isPlainObject(output),
|
||||||
|
pipelineConfig: () => ({
|
||||||
|
// Add `nextRelease` and plugin properties to published release
|
||||||
|
transform: (release, step, {nextRelease}) => ({
|
||||||
|
...(release === false ? {} : nextRelease),
|
||||||
|
...release,
|
||||||
|
...step,
|
||||||
|
}),
|
||||||
|
}),
|
||||||
|
},
|
||||||
success: {
|
success: {
|
||||||
required: false,
|
required: false,
|
||||||
dryRun: false,
|
dryRun: false,
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
const gitLogParser = require('git-log-parser');
|
|
||||||
const getStream = require('get-stream');
|
|
||||||
const debug = require('debug')('semantic-release:get-commits');
|
const debug = require('debug')('semantic-release:get-commits');
|
||||||
|
const {getCommits} = require('./git');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the list of commits on the current branch since the commit sha associated with the last release, or all the commits of the current branch if there is no last released version.
|
* Retrieve the list of commits on the current branch since the commit sha associated with the last release, or all the commits of the current branch if there is no last released version.
|
||||||
@ -9,23 +8,15 @@ const debug = require('debug')('semantic-release:get-commits');
|
|||||||
*
|
*
|
||||||
* @return {Promise<Array<Object>>} The list of commits on the branch `branch` since the last release.
|
* @return {Promise<Array<Object>>} The list of commits on the branch `branch` since the last release.
|
||||||
*/
|
*/
|
||||||
module.exports = async ({cwd, env, lastRelease: {gitHead}, logger}) => {
|
module.exports = async ({cwd, env, lastRelease: {gitHead: from}, nextRelease: {gitHead: to = 'HEAD'} = {}, logger}) => {
|
||||||
if (gitHead) {
|
if (from) {
|
||||||
debug('Use gitHead: %s', gitHead);
|
debug('Use from: %s', from);
|
||||||
} else {
|
} else {
|
||||||
logger.log('No previous release found, retrieving all commits');
|
logger.log('No previous release found, retrieving all commits');
|
||||||
}
|
}
|
||||||
|
|
||||||
Object.assign(gitLogParser.fields, {hash: 'H', message: 'B', gitTags: 'd', committerDate: {key: 'ci', type: Date}});
|
const commits = await getCommits(from, to, {cwd, env});
|
||||||
const commits = (
|
|
||||||
await getStream.array(
|
|
||||||
gitLogParser.parse({_: `${gitHead ? gitHead + '..' : ''}HEAD`}, {cwd, env: {...process.env, ...env}})
|
|
||||||
)
|
|
||||||
).map(commit => {
|
|
||||||
commit.message = commit.message.trim();
|
|
||||||
commit.gitTags = commit.gitTags.trim();
|
|
||||||
return commit;
|
|
||||||
});
|
|
||||||
logger.log(`Found ${commits.length} commits since last release`);
|
logger.log(`Found ${commits.length} commits since last release`);
|
||||||
debug('Parsed commits: %o', commits);
|
debug('Parsed commits: %o', commits);
|
||||||
return commits;
|
return commits;
|
||||||
|
@ -66,7 +66,14 @@ module.exports = async (context, opts) => {
|
|||||||
|
|
||||||
// Set default options values if not defined yet
|
// Set default options values if not defined yet
|
||||||
options = {
|
options = {
|
||||||
branch: 'master',
|
branches: [
|
||||||
|
'+([0-9])?(.{+([0-9]),x}).x',
|
||||||
|
'master',
|
||||||
|
'next',
|
||||||
|
'next-major',
|
||||||
|
{name: 'beta', prerelease: true},
|
||||||
|
{name: 'alpha', prerelease: true},
|
||||||
|
],
|
||||||
repositoryUrl: (await pkgRepoUrl({normalize: false, cwd})) || (await repoUrl({cwd, env})),
|
repositoryUrl: (await pkgRepoUrl({normalize: false, cwd})) || (await repoUrl({cwd, env})),
|
||||||
tagFormat: `v\${version}`,
|
tagFormat: `v\${version}`,
|
||||||
plugins: [
|
plugins: [
|
||||||
@ -77,6 +84,7 @@ module.exports = async (context, opts) => {
|
|||||||
],
|
],
|
||||||
// Remove `null` and `undefined` options so they can be replaced with default ones
|
// Remove `null` and `undefined` options so they can be replaced with default ones
|
||||||
...pickBy(options, option => !isNil(option)),
|
...pickBy(options, option => !isNil(option)),
|
||||||
|
...(options.branches ? {branches: castArray(options.branches)} : {}),
|
||||||
};
|
};
|
||||||
|
|
||||||
debug('options values: %O', options);
|
debug('options values: %O', options);
|
||||||
|
@ -14,7 +14,7 @@ const {verifyAuth} = require('./git');
|
|||||||
*
|
*
|
||||||
* @return {String} The formatted Git repository URL.
|
* @return {String} The formatted Git repository URL.
|
||||||
*/
|
*/
|
||||||
module.exports = async ({cwd, env, options: {repositoryUrl, branch}}) => {
|
module.exports = async ({cwd, env, branch, options: {repositoryUrl}}) => {
|
||||||
const GIT_TOKENS = {
|
const GIT_TOKENS = {
|
||||||
GIT_CREDENTIALS: undefined,
|
GIT_CREDENTIALS: undefined,
|
||||||
GH_TOKEN: undefined,
|
GH_TOKEN: undefined,
|
||||||
@ -40,14 +40,15 @@ module.exports = async ({cwd, env, options: {repositoryUrl, branch}}) => {
|
|||||||
|
|
||||||
// Test if push is allowed without transforming the URL (e.g. is ssh keys are set up)
|
// Test if push is allowed without transforming the URL (e.g. is ssh keys are set up)
|
||||||
try {
|
try {
|
||||||
await verifyAuth(repositoryUrl, branch, {cwd, env});
|
await verifyAuth(repositoryUrl, branch.name, {cwd, env});
|
||||||
} catch (_) {
|
} catch (_) {
|
||||||
const envVar = Object.keys(GIT_TOKENS).find(envVar => !isNil(env[envVar]));
|
const envVar = Object.keys(GIT_TOKENS).find(envVar => !isNil(env[envVar]));
|
||||||
const gitCredentials = `${GIT_TOKENS[envVar] || ''}${env[envVar] || ''}`;
|
const gitCredentials = `${GIT_TOKENS[envVar] || ''}${env[envVar] || ''}`;
|
||||||
|
|
||||||
if (gitCredentials) {
|
if (gitCredentials) {
|
||||||
// If credentials are set via environment variables, convert the URL to http/https and add basic auth, otherwise return `repositoryUrl` as is
|
// If credentials are set via environment variables, convert the URL to http/https and add basic auth, otherwise return `repositoryUrl` as is
|
||||||
const [match, auth, host, path] = /^(?!.+:\/\/)(?:(.*)@)?(.*?):(.*)$/.exec(repositoryUrl) || [];
|
const [match, auth, host, path] =
|
||||||
|
/^(?!.+:\/\/)(?:(?<auth>.*)@)?(?<host>.*?):(?<path>.*)$/.exec(repositoryUrl) || [];
|
||||||
const {port, hostname, ...parsed} = parse(
|
const {port, hostname, ...parsed} = parse(
|
||||||
match ? `ssh://${auth ? `${auth}@` : ''}${host}/${path}` : repositoryUrl
|
match ? `ssh://${auth ? `${auth}@` : ''}${host}/${path}` : repositoryUrl
|
||||||
);
|
);
|
||||||
|
@ -1,51 +1,44 @@
|
|||||||
const {escapeRegExp, template} = require('lodash');
|
const {isUndefined} = require('lodash');
|
||||||
const semver = require('semver');
|
const semver = require('semver');
|
||||||
const pLocate = require('p-locate');
|
const {makeTag, isSameChannel} = require('./utils');
|
||||||
const debug = require('debug')('semantic-release:get-last-release');
|
|
||||||
const {getTags, isRefInHistory, getTagHead} = require('./git');
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Last release.
|
* Last release.
|
||||||
*
|
*
|
||||||
* @typedef {Object} LastRelease
|
* @typedef {Object} LastRelease
|
||||||
* @property {string} version The version number of the last release.
|
* @property {string} version The version number of the last release.
|
||||||
* @property {string} [gitHead] The Git reference used to make the last release.
|
* @property {string} gitHead The Git reference used to make the last release.
|
||||||
|
* @property {string} gitTag The git tag associated with the last release.
|
||||||
|
* @property {string} channel The channel on which of the last release was published.
|
||||||
|
* @property {string} name The name of the last release.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine the Git tag and version of the last tagged release.
|
* Determine the Git tag and version of the last tagged release.
|
||||||
*
|
*
|
||||||
* - Obtain all the tags referencing commits in the current branch history
|
* - Filter out the branch tags that are not valid semantic version
|
||||||
* - Filter out the ones that are not valid semantic version or doesn't match the `tagFormat`
|
|
||||||
* - Sort the versions
|
* - Sort the versions
|
||||||
* - Retrive the highest version
|
* - Retrive the highest version
|
||||||
*
|
*
|
||||||
* @param {Object} context semantic-release context.
|
* @param {Object} context semantic-release context.
|
||||||
|
* @param {Object} params Function parameters.
|
||||||
|
* @param {Object} params.before Find only releases with version number lower than this version.
|
||||||
*
|
*
|
||||||
* @return {Promise<LastRelease>} The last tagged release or `undefined` if none is found.
|
* @return {LastRelease} The last tagged release or empty object if none is found.
|
||||||
*/
|
*/
|
||||||
module.exports = async ({cwd, env, options: {tagFormat}, logger}) => {
|
module.exports = ({branch, options: {tagFormat}}, {before} = {}) => {
|
||||||
// Generate a regex to parse tags formatted with `tagFormat`
|
const [{version, gitTag, channels} = {}] = branch.tags
|
||||||
// by replacing the `version` variable in the template by `(.+)`.
|
|
||||||
// The `tagFormat` is compiled with space as the `version` as it's an invalid tag character,
|
|
||||||
// so it's guaranteed to not be present in the `tagFormat`.
|
|
||||||
const tagRegexp = `^${escapeRegExp(template(tagFormat)({version: ' '})).replace(' ', '(.+)')}`;
|
|
||||||
const tags = (await getTags({cwd, env}))
|
|
||||||
.map(tag => ({gitTag: tag, version: (tag.match(tagRegexp) || new Array(2))[1]}))
|
|
||||||
.filter(
|
.filter(
|
||||||
tag => tag.version && semver.valid(semver.clean(tag.version)) && !semver.prerelease(semver.clean(tag.version))
|
tag =>
|
||||||
|
((branch.type === 'prerelease' && tag.channels.some(channel => isSameChannel(branch.channel, channel))) ||
|
||||||
|
!semver.prerelease(tag.version)) &&
|
||||||
|
(isUndefined(before) || semver.lt(tag.version, before))
|
||||||
)
|
)
|
||||||
.sort((a, b) => semver.rcompare(a.version, b.version));
|
.sort((a, b) => semver.rcompare(a.version, b.version));
|
||||||
|
|
||||||
debug('found tags: %o', tags);
|
if (gitTag) {
|
||||||
|
return {version, gitTag, channels, gitHead: gitTag, name: makeTag(tagFormat, version)};
|
||||||
const tag = await pLocate(tags, tag => isRefInHistory(tag.gitTag, {cwd, env}), {preserveOrder: true});
|
|
||||||
|
|
||||||
if (tag) {
|
|
||||||
logger.log(`Found git tag ${tag.gitTag} associated with version ${tag.version}`);
|
|
||||||
return {gitHead: await getTagHead(tag.gitTag, {cwd, env}), ...tag};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.log('No git tag version found');
|
|
||||||
return {};
|
return {};
|
||||||
};
|
};
|
||||||
|
@ -1,13 +1,33 @@
|
|||||||
const semver = require('semver');
|
const semver = require('semver');
|
||||||
const {FIRST_RELEASE} = require('./definitions/constants');
|
const {FIRST_RELEASE, FIRSTPRERELEASE} = require('./definitions/constants');
|
||||||
|
const {isSameChannel, getLatestVersion, tagsToVersions, highest} = require('./utils');
|
||||||
|
|
||||||
module.exports = ({nextRelease: {type}, lastRelease, logger}) => {
|
module.exports = ({branch, nextRelease: {type, channel}, lastRelease, logger}) => {
|
||||||
let version;
|
let version;
|
||||||
if (lastRelease.version) {
|
if (lastRelease.version) {
|
||||||
version = semver.inc(lastRelease.version, type);
|
const {major, minor, patch} = semver.parse(lastRelease.version);
|
||||||
logger.log(`The next release version is ${version}`);
|
|
||||||
|
if (branch.type === 'prerelease') {
|
||||||
|
if (
|
||||||
|
semver.prerelease(lastRelease.version) &&
|
||||||
|
lastRelease.channels.some(lastReleaseChannel => isSameChannel(lastReleaseChannel, channel))
|
||||||
|
) {
|
||||||
|
version = highest(
|
||||||
|
semver.inc(lastRelease.version, 'prerelease'),
|
||||||
|
`${semver.inc(getLatestVersion(tagsToVersions(branch.tags), {withPrerelease: true}), type)}-${
|
||||||
|
branch.prerelease
|
||||||
|
}.${FIRSTPRERELEASE}`
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
version = FIRST_RELEASE;
|
version = `${semver.inc(`${major}.${minor}.${patch}`, type)}-${branch.prerelease}.${FIRSTPRERELEASE}`;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
version = semver.inc(lastRelease.version, type);
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.log('The next release version is %s', version);
|
||||||
|
} else {
|
||||||
|
version = branch.type === 'prerelease' ? `${FIRST_RELEASE}-${branch.prerelease}.${FIRSTPRERELEASE}` : FIRST_RELEASE;
|
||||||
logger.log(`There is no previous release, the next release version is ${version}`);
|
logger.log(`There is no previous release, the next release version is ${version}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
60
lib/get-release-to-add.js
Normal file
60
lib/get-release-to-add.js
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
const {uniqBy, intersection} = require('lodash');
|
||||||
|
const semver = require('semver');
|
||||||
|
const semverDiff = require('semver-diff');
|
||||||
|
const getLastRelease = require('./get-last-release');
|
||||||
|
const {makeTag, getLowerBound} = require('./utils');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find releases that have been merged from from a higher branch but not added on the channel of the current branch.
|
||||||
|
*
|
||||||
|
* @param {Object} context semantic-release context.
|
||||||
|
*
|
||||||
|
* @return {Array<Object>} Last release and next release to be added on the channel of the current branch.
|
||||||
|
*/
|
||||||
|
module.exports = context => {
|
||||||
|
const {
|
||||||
|
branch,
|
||||||
|
branches,
|
||||||
|
options: {tagFormat},
|
||||||
|
} = context;
|
||||||
|
|
||||||
|
const higherChannels = branches
|
||||||
|
// Consider only releases of higher branches
|
||||||
|
.slice(branches.findIndex(({name}) => name === branch.name) + 1)
|
||||||
|
// Exclude prerelease branches
|
||||||
|
.filter(({type}) => type !== 'prerelease')
|
||||||
|
.map(({channel}) => channel || null);
|
||||||
|
|
||||||
|
const versiontoAdd = uniqBy(
|
||||||
|
branch.tags.filter(
|
||||||
|
({channels, version}) =>
|
||||||
|
!channels.includes(branch.channel || null) &&
|
||||||
|
intersection(channels, higherChannels).length > 0 &&
|
||||||
|
(branch.type !== 'maintenance' || semver.gte(version, getLowerBound(branch.mergeRange)))
|
||||||
|
),
|
||||||
|
'version'
|
||||||
|
).sort((a, b) => semver.compare(b.version, a.version))[0];
|
||||||
|
|
||||||
|
if (versiontoAdd) {
|
||||||
|
const {version, gitTag, channels} = versiontoAdd;
|
||||||
|
const lastRelease = getLastRelease(context, {before: version});
|
||||||
|
if (semver.gt(getLastRelease(context).version, version)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const type = lastRelease.version ? semverDiff(lastRelease.version, version) : 'major';
|
||||||
|
const name = makeTag(tagFormat, version);
|
||||||
|
return {
|
||||||
|
lastRelease,
|
||||||
|
currentRelease: {type, version, channels, gitTag, name, gitHead: gitTag},
|
||||||
|
nextRelease: {
|
||||||
|
type,
|
||||||
|
version,
|
||||||
|
channel: branch.channel || null,
|
||||||
|
gitTag: makeTag(tagFormat, version),
|
||||||
|
name,
|
||||||
|
gitHead: gitTag,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
207
lib/git.js
207
lib/git.js
@ -1,5 +1,10 @@
|
|||||||
|
const gitLogParser = require('git-log-parser');
|
||||||
|
const getStream = require('get-stream');
|
||||||
const execa = require('execa');
|
const execa = require('execa');
|
||||||
const debug = require('debug')('semantic-release:git');
|
const debug = require('debug')('semantic-release:git');
|
||||||
|
const {GIT_NOTE_REF} = require('./definitions/constants');
|
||||||
|
|
||||||
|
Object.assign(gitLogParser.fields, {hash: 'H', message: 'B', gitTags: 'd', committerDate: {key: 'ci', type: Date}});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the commit sha for a given tag.
|
* Get the commit sha for a given tag.
|
||||||
@ -7,50 +12,76 @@ const debug = require('debug')('semantic-release:git');
|
|||||||
* @param {String} tagName Tag name for which to retrieve the commit sha.
|
* @param {String} tagName Tag name for which to retrieve the commit sha.
|
||||||
* @param {Object} [execaOpts] Options to pass to `execa`.
|
* @param {Object} [execaOpts] Options to pass to `execa`.
|
||||||
*
|
*
|
||||||
* @return {string} The commit sha of the tag in parameter or `null`.
|
* @return {String} The commit sha of the tag in parameter or `null`.
|
||||||
*/
|
*/
|
||||||
async function getTagHead(tagName, execaOpts) {
|
async function getTagHead(tagName, execaOpts) {
|
||||||
try {
|
|
||||||
return (await execa('git', ['rev-list', '-1', tagName], execaOpts)).stdout;
|
return (await execa('git', ['rev-list', '-1', tagName], execaOpts)).stdout;
|
||||||
} catch (error) {
|
|
||||||
debug(error);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all the repository tags.
|
* Get all the tags for a given branch.
|
||||||
*
|
*
|
||||||
|
* @param {String} branch The branch for which to retrieve the tags.
|
||||||
* @param {Object} [execaOpts] Options to pass to `execa`.
|
* @param {Object} [execaOpts] Options to pass to `execa`.
|
||||||
*
|
*
|
||||||
* @return {Array<String>} List of git tags.
|
* @return {Array<String>} List of git tags.
|
||||||
* @throws {Error} If the `git` command fails.
|
* @throws {Error} If the `git` command fails.
|
||||||
*/
|
*/
|
||||||
async function getTags(execaOpts) {
|
async function getTags(branch, execaOpts) {
|
||||||
return (await execa('git', ['tag'], execaOpts)).stdout
|
return (await execa('git', ['tag', '--merged', branch], execaOpts)).stdout
|
||||||
.split('\n')
|
.split('\n')
|
||||||
.map(tag => tag.trim())
|
.map(tag => tag.trim())
|
||||||
.filter(Boolean);
|
.filter(Boolean);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Verify if the `ref` is in the direct history of the current branch.
|
* Retrieve a range of commits.
|
||||||
*
|
*
|
||||||
* @param {String} ref The reference to look for.
|
* @param {String} from to includes all commits made after this sha (does not include this sha).
|
||||||
|
* @param {String} to to includes all commits made before this sha (also include this sha).
|
||||||
* @param {Object} [execaOpts] Options to pass to `execa`.
|
* @param {Object} [execaOpts] Options to pass to `execa`.
|
||||||
*
|
* @return {Promise<Array<Object>>} The list of commits between `from` and `to`.
|
||||||
* @return {Boolean} `true` if the reference is in the history of the current branch, falsy otherwise.
|
|
||||||
*/
|
*/
|
||||||
async function isRefInHistory(ref, execaOpts) {
|
async function getCommits(from, to, execaOpts) {
|
||||||
try {
|
return (
|
||||||
await execa('git', ['merge-base', '--is-ancestor', ref, 'HEAD'], execaOpts);
|
await getStream.array(
|
||||||
return true;
|
gitLogParser.parse(
|
||||||
} catch (error) {
|
{_: `${from ? from + '..' : ''}${to}`},
|
||||||
if (error.exitCode === 1) {
|
{cwd: execaOpts.cwd, env: {...process.env, ...execaOpts.env}}
|
||||||
return false;
|
)
|
||||||
|
)
|
||||||
|
).map(({message, gitTags, ...commit}) => ({...commit, message: message.trim(), gitTags: gitTags.trim()}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all the repository branches.
|
||||||
|
*
|
||||||
|
* @param {String} repositoryUrl The remote repository URL.
|
||||||
|
* @param {Object} [execaOpts] Options to pass to `execa`.
|
||||||
|
*
|
||||||
|
* @return {Array<String>} List of git branches.
|
||||||
|
* @throws {Error} If the `git` command fails.
|
||||||
|
*/
|
||||||
|
async function getBranches(repositoryUrl, execaOpts) {
|
||||||
|
return (await execa('git', ['ls-remote', '--heads', repositoryUrl], execaOpts)).stdout
|
||||||
|
.split('\n')
|
||||||
|
.map(branch => branch.match(/^.+refs\/heads\/(?<branch>.+)$/)[1])
|
||||||
|
.filter(Boolean);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Verify if the `ref` exits
|
||||||
|
*
|
||||||
|
* @param {String} ref The reference to verify.
|
||||||
|
* @param {Object} [execaOpts] Options to pass to `execa`.
|
||||||
|
*
|
||||||
|
* @return {Boolean} `true` if the reference exists, falsy otherwise.
|
||||||
|
*/
|
||||||
|
async function isRefExists(ref, execaOpts) {
|
||||||
|
try {
|
||||||
|
return (await execa('git', ['rev-parse', '--verify', ref], execaOpts)).exitCode === 0;
|
||||||
|
} catch (error) {
|
||||||
debug(error);
|
debug(error);
|
||||||
throw error;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,13 +89,59 @@ async function isRefInHistory(ref, execaOpts) {
|
|||||||
* Unshallow the git repository if necessary and fetch all the tags.
|
* Unshallow the git repository if necessary and fetch all the tags.
|
||||||
*
|
*
|
||||||
* @param {String} repositoryUrl The remote repository URL.
|
* @param {String} repositoryUrl The remote repository URL.
|
||||||
|
* @param {String} branch The repository branch to fetch.
|
||||||
* @param {Object} [execaOpts] Options to pass to `execa`.
|
* @param {Object} [execaOpts] Options to pass to `execa`.
|
||||||
*/
|
*/
|
||||||
async function fetch(repositoryUrl, execaOpts) {
|
async function fetch(repositoryUrl, branch, ciBranch, execaOpts) {
|
||||||
|
const isLocalExists =
|
||||||
|
(await execa('git', ['rev-parse', '--verify', branch], {...execaOpts, reject: false})).exitCode === 0;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await execa('git', ['fetch', '--unshallow', '--tags', repositoryUrl], execaOpts);
|
await execa(
|
||||||
|
'git',
|
||||||
|
[
|
||||||
|
'fetch',
|
||||||
|
'--unshallow',
|
||||||
|
'--tags',
|
||||||
|
...(branch === ciBranch && isLocalExists
|
||||||
|
? [repositoryUrl]
|
||||||
|
: ['--update-head-ok', repositoryUrl, `+refs/heads/${branch}:refs/heads/${branch}`]),
|
||||||
|
],
|
||||||
|
execaOpts
|
||||||
|
);
|
||||||
} catch (_) {
|
} catch (_) {
|
||||||
await execa('git', ['fetch', '--tags', repositoryUrl], execaOpts);
|
await execa(
|
||||||
|
'git',
|
||||||
|
[
|
||||||
|
'fetch',
|
||||||
|
'--tags',
|
||||||
|
...(branch === ciBranch && isLocalExists
|
||||||
|
? [repositoryUrl]
|
||||||
|
: ['--update-head-ok', repositoryUrl, `+refs/heads/${branch}:refs/heads/${branch}`]),
|
||||||
|
],
|
||||||
|
execaOpts
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unshallow the git repository if necessary and fetch all the notes.
|
||||||
|
*
|
||||||
|
* @param {String} repositoryUrl The remote repository URL.
|
||||||
|
* @param {Object} [execaOpts] Options to pass to `execa`.
|
||||||
|
*/
|
||||||
|
async function fetchNotes(repositoryUrl, execaOpts) {
|
||||||
|
try {
|
||||||
|
await execa(
|
||||||
|
'git',
|
||||||
|
['fetch', '--unshallow', repositoryUrl, `+refs/notes/${GIT_NOTE_REF}:refs/notes/${GIT_NOTE_REF}`],
|
||||||
|
execaOpts
|
||||||
|
);
|
||||||
|
} catch (_) {
|
||||||
|
await execa('git', ['fetch', repositoryUrl, `+refs/notes/${GIT_NOTE_REF}:refs/notes/${GIT_NOTE_REF}`], {
|
||||||
|
...execaOpts,
|
||||||
|
reject: false,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -113,7 +190,7 @@ async function isGitRepo(execaOpts) {
|
|||||||
* Verify the write access authorization to remote repository with push dry-run.
|
* Verify the write access authorization to remote repository with push dry-run.
|
||||||
*
|
*
|
||||||
* @param {String} repositoryUrl The remote repository URL.
|
* @param {String} repositoryUrl The remote repository URL.
|
||||||
* @param {String} branch The repositoru branch for which to verify write access.
|
* @param {String} branch The repository branch for which to verify write access.
|
||||||
* @param {Object} [execaOpts] Options to pass to `execa`.
|
* @param {Object} [execaOpts] Options to pass to `execa`.
|
||||||
*
|
*
|
||||||
* @throws {Error} if not authorized to push.
|
* @throws {Error} if not authorized to push.
|
||||||
@ -131,12 +208,13 @@ async function verifyAuth(repositoryUrl, branch, execaOpts) {
|
|||||||
* Tag the commit head on the local repository.
|
* Tag the commit head on the local repository.
|
||||||
*
|
*
|
||||||
* @param {String} tagName The name of the tag.
|
* @param {String} tagName The name of the tag.
|
||||||
|
* @param {String} ref The Git reference to tag.
|
||||||
* @param {Object} [execaOpts] Options to pass to `execa`.
|
* @param {Object} [execaOpts] Options to pass to `execa`.
|
||||||
*
|
*
|
||||||
* @throws {Error} if the tag creation failed.
|
* @throws {Error} if the tag creation failed.
|
||||||
*/
|
*/
|
||||||
async function tag(tagName, execaOpts) {
|
async function tag(tagName, ref, execaOpts) {
|
||||||
await execa('git', ['tag', tagName], execaOpts);
|
await execa('git', ['tag', tagName, ref], execaOpts);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -151,6 +229,18 @@ async function push(repositoryUrl, execaOpts) {
|
|||||||
await execa('git', ['push', '--tags', repositoryUrl], execaOpts);
|
await execa('git', ['push', '--tags', repositoryUrl], execaOpts);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Push notes to the remote repository.
|
||||||
|
*
|
||||||
|
* @param {String} repositoryUrl The remote repository URL.
|
||||||
|
* @param {Object} [execaOpts] Options to pass to `execa`.
|
||||||
|
*
|
||||||
|
* @throws {Error} if the push failed.
|
||||||
|
*/
|
||||||
|
async function pushNotes(repositoryUrl, execaOpts) {
|
||||||
|
await execa('git', ['push', repositoryUrl, `refs/notes/${GIT_NOTE_REF}`], execaOpts);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Verify a tag name is a valid Git reference.
|
* Verify a tag name is a valid Git reference.
|
||||||
*
|
*
|
||||||
@ -167,6 +257,22 @@ async function verifyTagName(tagName, execaOpts) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Verify a branch name is a valid Git reference.
|
||||||
|
*
|
||||||
|
* @param {String} branch the branch name to verify.
|
||||||
|
* @param {Object} [execaOpts] Options to pass to `execa`.
|
||||||
|
*
|
||||||
|
* @return {Boolean} `true` if valid, falsy otherwise.
|
||||||
|
*/
|
||||||
|
async function verifyBranchName(branch, execaOpts) {
|
||||||
|
try {
|
||||||
|
return (await execa('git', ['check-ref-format', `refs/heads/${branch}`], execaOpts)).exitCode === 0;
|
||||||
|
} catch (error) {
|
||||||
|
debug(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Verify the local branch is up to date with the remote one.
|
* Verify the local branch is up to date with the remote one.
|
||||||
*
|
*
|
||||||
@ -177,25 +283,62 @@ async function verifyTagName(tagName, execaOpts) {
|
|||||||
* @return {Boolean} `true` is the HEAD of the current local branch is the same as the HEAD of the remote branch, falsy otherwise.
|
* @return {Boolean} `true` is the HEAD of the current local branch is the same as the HEAD of the remote branch, falsy otherwise.
|
||||||
*/
|
*/
|
||||||
async function isBranchUpToDate(repositoryUrl, branch, execaOpts) {
|
async function isBranchUpToDate(repositoryUrl, branch, execaOpts) {
|
||||||
const {stdout: remoteHead} = await execa('git', ['ls-remote', '--heads', repositoryUrl, branch], execaOpts);
|
return (
|
||||||
try {
|
(await getGitHead(execaOpts)) ===
|
||||||
return await isRefInHistory(remoteHead.match(/^(\w+)?/)[1], execaOpts);
|
(await execa('git', ['ls-remote', '--heads', repositoryUrl, branch], execaOpts)).stdout.match(/^(?<ref>\w+)?/)[1]
|
||||||
} catch (error) {
|
);
|
||||||
debug(error);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get and parse the JSON note of a given reference.
|
||||||
|
*
|
||||||
|
* @param {String} ref The Git reference for which to retrieve the note.
|
||||||
|
* @param {Object} [execaOpts] Options to pass to `execa`.
|
||||||
|
*
|
||||||
|
* @return {Object} the parsed JSON note if there is one, an empty object otherwise.
|
||||||
|
*/
|
||||||
|
async function getNote(ref, execaOpts) {
|
||||||
|
try {
|
||||||
|
return JSON.parse((await execa('git', ['notes', '--ref', GIT_NOTE_REF, 'show', ref], execaOpts)).stdout);
|
||||||
|
} catch (error) {
|
||||||
|
if (error.exitCode === 1) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
debug(error);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get and parse the JSON note of a given reference.
|
||||||
|
*
|
||||||
|
* @param {Object} note The object to save in the reference note.
|
||||||
|
* @param {String} ref The Git reference to add the note to.
|
||||||
|
* @param {Object} [execaOpts] Options to pass to `execa`.
|
||||||
|
*/
|
||||||
|
async function addNote(note, ref, execaOpts) {
|
||||||
|
await execa('git', ['notes', '--ref', GIT_NOTE_REF, 'add', '-f', '-m', JSON.stringify(note), ref], execaOpts);
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
getTagHead,
|
getTagHead,
|
||||||
getTags,
|
getTags,
|
||||||
isRefInHistory,
|
getCommits,
|
||||||
|
getBranches,
|
||||||
|
isRefExists,
|
||||||
fetch,
|
fetch,
|
||||||
|
fetchNotes,
|
||||||
getGitHead,
|
getGitHead,
|
||||||
repoUrl,
|
repoUrl,
|
||||||
isGitRepo,
|
isGitRepo,
|
||||||
verifyAuth,
|
verifyAuth,
|
||||||
tag,
|
tag,
|
||||||
push,
|
push,
|
||||||
|
pushNotes,
|
||||||
verifyTagName,
|
verifyTagName,
|
||||||
isBranchUpToDate,
|
isBranchUpToDate,
|
||||||
|
verifyBranchName,
|
||||||
|
getNote,
|
||||||
|
addNote,
|
||||||
};
|
};
|
||||||
|
80
lib/utils.js
80
lib/utils.js
@ -1,4 +1,5 @@
|
|||||||
const {isFunction} = require('lodash');
|
const {isFunction, union, template} = require('lodash');
|
||||||
|
const semver = require('semver');
|
||||||
const hideSensitive = require('./hide-sensitive');
|
const hideSensitive = require('./hide-sensitive');
|
||||||
|
|
||||||
function extractErrors(err) {
|
function extractErrors(err) {
|
||||||
@ -17,4 +18,79 @@ function hideSensitiveValues(env, objs) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {extractErrors, hideSensitiveValues};
|
function tagsToVersions(tags) {
|
||||||
|
return tags.map(({version}) => version);
|
||||||
|
}
|
||||||
|
|
||||||
|
function isMajorRange(range) {
|
||||||
|
return /^\d+\.x(?:\.x)?$/i.test(range);
|
||||||
|
}
|
||||||
|
|
||||||
|
function isMaintenanceRange(range) {
|
||||||
|
return /^\d+\.(?:\d+|x)(?:\.x)?$/i.test(range);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getUpperBound(range) {
|
||||||
|
return semver.valid(range)
|
||||||
|
? range
|
||||||
|
: ((semver.validRange(range) || '').match(/<(?<upperBound>\d+\.\d+\.\d+)$/) || [])[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
function getLowerBound(range) {
|
||||||
|
return ((semver.validRange(range) || '').match(/(?<lowerBound>\d+\.\d+\.\d+)/) || [])[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
function highest(version1, version2) {
|
||||||
|
return version1 && version2 ? (semver.gt(version1, version2) ? version1 : version2) : version1 || version2;
|
||||||
|
}
|
||||||
|
|
||||||
|
function lowest(version1, version2) {
|
||||||
|
return version1 && version2 ? (semver.lt(version1, version2) ? version1 : version2) : version1 || version2;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getLatestVersion(versions, {withPrerelease} = {}) {
|
||||||
|
return versions.filter(version => withPrerelease || !semver.prerelease(version)).sort(semver.rcompare)[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
function getEarliestVersion(versions, {withPrerelease} = {}) {
|
||||||
|
return versions.filter(version => withPrerelease || !semver.prerelease(version)).sort(semver.compare)[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
function getFirstVersion(versions, lowerBranches) {
|
||||||
|
const lowerVersion = union(...lowerBranches.map(({tags}) => tagsToVersions(tags))).sort(semver.rcompare);
|
||||||
|
if (lowerVersion[0]) {
|
||||||
|
return versions.sort(semver.compare).find(version => semver.gt(version, lowerVersion[0]));
|
||||||
|
}
|
||||||
|
|
||||||
|
return getEarliestVersion(versions);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getRange(min, max) {
|
||||||
|
return `>=${min}${max ? ` <${max}` : ''}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function makeTag(tagFormat, version) {
|
||||||
|
return template(tagFormat)({version});
|
||||||
|
}
|
||||||
|
|
||||||
|
function isSameChannel(channel, otherChannel) {
|
||||||
|
return channel === otherChannel || (!channel && !otherChannel);
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
extractErrors,
|
||||||
|
hideSensitiveValues,
|
||||||
|
tagsToVersions,
|
||||||
|
isMajorRange,
|
||||||
|
isMaintenanceRange,
|
||||||
|
getUpperBound,
|
||||||
|
getLowerBound,
|
||||||
|
highest,
|
||||||
|
lowest,
|
||||||
|
getLatestVersion,
|
||||||
|
getEarliestVersion,
|
||||||
|
getFirstVersion,
|
||||||
|
getRange,
|
||||||
|
makeTag,
|
||||||
|
isSameChannel,
|
||||||
|
};
|
||||||
|
@ -1,9 +1,14 @@
|
|||||||
const {template} = require('lodash');
|
const {template, isString, isPlainObject} = require('lodash');
|
||||||
const AggregateError = require('aggregate-error');
|
const AggregateError = require('aggregate-error');
|
||||||
const {isGitRepo, verifyTagName} = require('./git');
|
const {isGitRepo, verifyTagName} = require('./git');
|
||||||
const getError = require('./get-error');
|
const getError = require('./get-error');
|
||||||
|
|
||||||
module.exports = async ({cwd, env, options: {repositoryUrl, tagFormat}}) => {
|
module.exports = async context => {
|
||||||
|
const {
|
||||||
|
cwd,
|
||||||
|
env,
|
||||||
|
options: {repositoryUrl, tagFormat, branches},
|
||||||
|
} = context;
|
||||||
const errors = [];
|
const errors = [];
|
||||||
|
|
||||||
if (!(await isGitRepo({cwd, env}))) {
|
if (!(await isGitRepo({cwd, env}))) {
|
||||||
@ -14,16 +19,24 @@ module.exports = async ({cwd, env, options: {repositoryUrl, tagFormat}}) => {
|
|||||||
|
|
||||||
// Verify that compiling the `tagFormat` produce a valid Git tag
|
// Verify that compiling the `tagFormat` produce a valid Git tag
|
||||||
if (!(await verifyTagName(template(tagFormat)({version: '0.0.0'})))) {
|
if (!(await verifyTagName(template(tagFormat)({version: '0.0.0'})))) {
|
||||||
errors.push(getError('EINVALIDTAGFORMAT', {tagFormat}));
|
errors.push(getError('EINVALIDTAGFORMAT', context));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verify the `tagFormat` contains the variable `version` by compiling the `tagFormat` template
|
// Verify the `tagFormat` contains the variable `version` by compiling the `tagFormat` template
|
||||||
// with a space as the `version` value and verify the result contains the space.
|
// with a space as the `version` value and verify the result contains the space.
|
||||||
// The space is used as it's an invalid tag character, so it's guaranteed to no be present in the `tagFormat`.
|
// The space is used as it's an invalid tag character, so it's guaranteed to no be present in the `tagFormat`.
|
||||||
if ((template(tagFormat)({version: ' '}).match(/ /g) || []).length !== 1) {
|
if ((template(tagFormat)({version: ' '}).match(/ /g) || []).length !== 1) {
|
||||||
errors.push(getError('ETAGNOVERSION', {tagFormat}));
|
errors.push(getError('ETAGNOVERSION', context));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
branches.forEach(branch => {
|
||||||
|
if (
|
||||||
|
!((isString(branch) && branch.trim()) || (isPlainObject(branch) && isString(branch.name) && branch.name.trim()))
|
||||||
|
) {
|
||||||
|
errors.push(getError('EINVALIDBRANCH', {branch}));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
if (errors.length > 0) {
|
if (errors.length > 0) {
|
||||||
throw new AggregateError(errors);
|
throw new AggregateError(errors);
|
||||||
}
|
}
|
||||||
|
14
package.json
14
package.json
@ -22,10 +22,10 @@
|
|||||||
"Pierre Vanduynslager (https://twitter.com/@pvdlg_)"
|
"Pierre Vanduynslager (https://twitter.com/@pvdlg_)"
|
||||||
],
|
],
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@semantic-release/commit-analyzer": "^6.1.0",
|
"@semantic-release/commit-analyzer": "^7.0.0-beta",
|
||||||
"@semantic-release/error": "^2.2.0",
|
"@semantic-release/error": "^2.2.0",
|
||||||
"@semantic-release/github": "^5.1.0",
|
"@semantic-release/github": "^5.6.0-beta",
|
||||||
"@semantic-release/npm": "^5.0.5",
|
"@semantic-release/npm": "^6.0.0-beta",
|
||||||
"@semantic-release/release-notes-generator": "^7.1.2",
|
"@semantic-release/release-notes-generator": "^7.1.2",
|
||||||
"aggregate-error": "^3.0.0",
|
"aggregate-error": "^3.0.0",
|
||||||
"cosmiconfig": "^6.0.0",
|
"cosmiconfig": "^6.0.0",
|
||||||
@ -41,11 +41,13 @@
|
|||||||
"lodash": "^4.17.15",
|
"lodash": "^4.17.15",
|
||||||
"marked": "^0.7.0",
|
"marked": "^0.7.0",
|
||||||
"marked-terminal": "^3.2.0",
|
"marked-terminal": "^3.2.0",
|
||||||
"p-locate": "^4.0.0",
|
"micromatch": "^4.0.2",
|
||||||
|
"p-each-series": "^2.1.0",
|
||||||
"p-reduce": "^2.0.0",
|
"p-reduce": "^2.0.0",
|
||||||
"read-pkg-up": "^7.0.0",
|
"read-pkg-up": "^7.0.0",
|
||||||
"resolve-from": "^5.0.0",
|
"resolve-from": "^5.0.0",
|
||||||
"semver": "^6.0.0",
|
"semver": "^6.0.0",
|
||||||
|
"semver-diff": "^3.1.1",
|
||||||
"signale": "^1.2.1",
|
"signale": "^1.2.1",
|
||||||
"yargs": "^15.0.1"
|
"yargs": "^15.0.1"
|
||||||
},
|
},
|
||||||
@ -70,7 +72,7 @@
|
|||||||
"xo": "^0.25.0"
|
"xo": "^0.25.0"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=8.16"
|
"node": ">=10.13"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"bin",
|
"bin",
|
||||||
@ -111,7 +113,7 @@
|
|||||||
"trailingComma": "es5"
|
"trailingComma": "es5"
|
||||||
},
|
},
|
||||||
"publishConfig": {
|
"publishConfig": {
|
||||||
"tag": "next"
|
"access": "public"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
259
test/branches/branches.test.js
Normal file
259
test/branches/branches.test.js
Normal file
@ -0,0 +1,259 @@
|
|||||||
|
import test from 'ava';
|
||||||
|
import {union} from 'lodash';
|
||||||
|
import semver from 'semver';
|
||||||
|
import proxyquire from 'proxyquire';
|
||||||
|
|
||||||
|
const getBranch = (branches, branch) => branches.find(({name}) => name === branch);
|
||||||
|
const release = (branches, name, version) => getBranch(branches, name).tags.push({version});
|
||||||
|
const merge = (branches, source, target, tag) => {
|
||||||
|
getBranch(branches, target).tags = union(
|
||||||
|
getBranch(branches, source).tags.filter(({version}) => !tag || semver.cmp(version, '<=', tag)),
|
||||||
|
getBranch(branches, target).tags
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
test('Enforce ranges with branching release workflow', async t => {
|
||||||
|
const branches = [
|
||||||
|
{name: '1.x', tags: []},
|
||||||
|
{name: '1.0.x', tags: []},
|
||||||
|
{name: 'master', tags: []},
|
||||||
|
{name: 'next', tags: []},
|
||||||
|
{name: 'next-major', tags: []},
|
||||||
|
{name: 'beta', prerelease: true, tags: []},
|
||||||
|
{name: 'alpha', prerelease: true, tags: []},
|
||||||
|
];
|
||||||
|
const getBranches = proxyquire('../../lib/branches', {'./get-tags': () => branches, './expand': () => []});
|
||||||
|
|
||||||
|
let result = (await getBranches('repositoryUrl', 'master', {options: {branches}})).map(({name, range}) => ({
|
||||||
|
name,
|
||||||
|
range,
|
||||||
|
}));
|
||||||
|
t.is(getBranch(result, '1.0.x').range, '>=1.0.0 <1.0.0', 'Cannot release on 1.0.x before a releasing on master');
|
||||||
|
t.is(getBranch(result, '1.x').range, '>=1.1.0 <1.0.0', 'Cannot release on 1.x before a releasing on master');
|
||||||
|
t.is(getBranch(result, 'master').range, '>=1.0.0');
|
||||||
|
t.is(getBranch(result, 'next').range, '>=1.0.0');
|
||||||
|
t.is(getBranch(result, 'next-major').range, '>=1.0.0');
|
||||||
|
|
||||||
|
release(branches, 'master', '1.0.0');
|
||||||
|
result = (await getBranches('repositoryUrl', 'master', {options: {branches}})).map(({name, range}) => ({
|
||||||
|
name,
|
||||||
|
range,
|
||||||
|
}));
|
||||||
|
t.is(getBranch(result, '1.0.x').range, '>=1.0.0 <1.0.0', 'Cannot release on 1.0.x before a releasing on master');
|
||||||
|
t.is(getBranch(result, '1.x').range, '>=1.1.0 <1.0.0', 'Cannot release on 1.x before a releasing on master');
|
||||||
|
t.is(getBranch(result, 'master').range, '>=1.0.0');
|
||||||
|
t.is(getBranch(result, 'next').range, '>=1.0.0');
|
||||||
|
t.is(getBranch(result, 'next-major').range, '>=1.0.0');
|
||||||
|
|
||||||
|
release(branches, 'master', '1.0.1');
|
||||||
|
result = (await getBranches('repositoryUrl', 'master', {options: {branches}})).map(({name, range}) => ({
|
||||||
|
name,
|
||||||
|
range,
|
||||||
|
}));
|
||||||
|
t.is(getBranch(result, 'master').range, '>=1.0.1', 'Can release only > than 1.0.1 on master');
|
||||||
|
t.is(getBranch(result, 'next').range, '>=1.0.1', 'Can release only > than 1.0.1 on next');
|
||||||
|
t.is(getBranch(result, 'next-major').range, '>=1.0.1', 'Can release only > than 1.0.1 on next-major');
|
||||||
|
|
||||||
|
merge(branches, 'master', 'next');
|
||||||
|
merge(branches, 'master', 'next-major');
|
||||||
|
result = (await getBranches('repositoryUrl', 'master', {options: {branches}})).map(({name, range}) => ({
|
||||||
|
name,
|
||||||
|
range,
|
||||||
|
}));
|
||||||
|
t.is(getBranch(result, 'master').range, '>=1.0.1', 'Can release only > than 1.0.1 on master');
|
||||||
|
t.is(getBranch(result, 'next').range, '>=1.0.1', 'Can release only > than 1.0.1 on next');
|
||||||
|
t.is(getBranch(result, 'next-major').range, '>=1.0.1', 'Can release only > than 1.0.1 on next-major');
|
||||||
|
|
||||||
|
release(branches, 'next', '1.1.0');
|
||||||
|
release(branches, 'next', '1.1.1');
|
||||||
|
result = (await getBranches('repositoryUrl', 'master', {options: {branches}})).map(({name, range}) => ({
|
||||||
|
name,
|
||||||
|
range,
|
||||||
|
}));
|
||||||
|
t.is(getBranch(result, 'master').range, '>=1.0.1 <1.1.0', 'Can release only patch, > than 1.0.1 on master');
|
||||||
|
t.is(getBranch(result, 'next').range, '>=1.1.1', 'Can release only > than 1.1.1 on next');
|
||||||
|
t.is(getBranch(result, 'next-major').range, '>=1.1.1', 'Can release > than 1.1.1 on next-major');
|
||||||
|
|
||||||
|
release(branches, 'next-major', '2.0.0');
|
||||||
|
release(branches, 'next-major', '2.0.1');
|
||||||
|
result = (await getBranches('repositoryUrl', 'master', {options: {branches}})).map(({name, range}) => ({
|
||||||
|
name,
|
||||||
|
range,
|
||||||
|
}));
|
||||||
|
t.is(getBranch(result, 'master').range, '>=1.0.1 <1.1.0', 'Can release only patch, > than 1.0.1 on master');
|
||||||
|
t.is(getBranch(result, 'next').range, '>=1.1.1 <2.0.0', 'Can release only patch or minor, > than 1.1.0 on next');
|
||||||
|
t.is(getBranch(result, 'next-major').range, '>=2.0.1', 'Can release any version, > than 2.0.1 on next-major');
|
||||||
|
|
||||||
|
merge(branches, 'next-major', 'beta');
|
||||||
|
release(branches, 'beta', '3.0.0-beta.1');
|
||||||
|
merge(branches, 'beta', 'alpha');
|
||||||
|
release(branches, 'alpha', '4.0.0-alpha.1');
|
||||||
|
result = (await getBranches('repositoryUrl', 'master', {options: {branches}})).map(({name, range}) => ({
|
||||||
|
name,
|
||||||
|
range,
|
||||||
|
}));
|
||||||
|
t.is(getBranch(result, 'next-major').range, '>=2.0.1', 'Can release any version, > than 2.0.1 on next-major');
|
||||||
|
|
||||||
|
merge(branches, 'master', '1.0.x');
|
||||||
|
merge(branches, 'master', '1.x');
|
||||||
|
result = (await getBranches('repositoryUrl', 'master', {options: {branches}})).map(({name, range}) => ({
|
||||||
|
name,
|
||||||
|
range,
|
||||||
|
}));
|
||||||
|
t.is(getBranch(result, 'master').range, '>=1.0.1 <1.1.0', 'Can release only patch, > than 1.0.1 on master');
|
||||||
|
t.is(
|
||||||
|
getBranch(result, '1.0.x').range,
|
||||||
|
'>=1.0.1 <1.0.1',
|
||||||
|
'Cannot release on 1.0.x before >= 1.1.0 is released on master'
|
||||||
|
);
|
||||||
|
t.is(getBranch(result, '1.x').range, '>=1.1.0 <1.0.1', 'Cannot release on 1.x before >= 1.2.0 is released on master');
|
||||||
|
|
||||||
|
release(branches, 'master', '1.0.2');
|
||||||
|
release(branches, 'master', '1.0.3');
|
||||||
|
release(branches, 'master', '1.0.4');
|
||||||
|
result = (await getBranches('repositoryUrl', 'master', {options: {branches}})).map(({name, range}) => ({
|
||||||
|
name,
|
||||||
|
range,
|
||||||
|
}));
|
||||||
|
t.is(getBranch(result, 'master').range, '>=1.0.4 <1.1.0', 'Can release only patch, > than 1.0.4 on master');
|
||||||
|
t.is(
|
||||||
|
getBranch(result, '1.0.x').range,
|
||||||
|
'>=1.0.1 <1.0.2',
|
||||||
|
'Cannot release on 1.0.x before >= 1.1.0 is released on master'
|
||||||
|
);
|
||||||
|
t.is(getBranch(result, '1.x').range, '>=1.1.0 <1.0.2', 'Cannot release on 1.x before >= 1.2.0 is released on master');
|
||||||
|
|
||||||
|
merge(branches, 'next', 'master');
|
||||||
|
result = (await getBranches('repositoryUrl', 'master', {options: {branches}})).map(({name, range}) => ({
|
||||||
|
name,
|
||||||
|
range,
|
||||||
|
}));
|
||||||
|
|
||||||
|
t.is(getBranch(result, 'master').range, '>=1.1.1', 'Can release only > than 1.1.1 on master');
|
||||||
|
t.is(getBranch(result, 'next').range, '>=1.1.1 <2.0.0', 'Can release only patch or minor, > than 1.1.1 on next');
|
||||||
|
t.is(getBranch(result, 'next-major').range, '>=2.0.1', 'Can release any version, > than 2.0.1 on next-major');
|
||||||
|
t.is(
|
||||||
|
getBranch(result, '1.0.x').range,
|
||||||
|
'>=1.0.1 <1.0.2',
|
||||||
|
'Cannot release on 1.0.x before 1.0.x version from master are merged'
|
||||||
|
);
|
||||||
|
t.is(getBranch(result, '1.x').range, '>=1.1.0 <1.0.2', 'Cannot release on 1.x before >= 2.0.0 is released on master');
|
||||||
|
|
||||||
|
merge(branches, 'master', '1.0.x', '1.0.4');
|
||||||
|
result = (await getBranches('repositoryUrl', 'master', {options: {branches}})).map(({name, range}) => ({
|
||||||
|
name,
|
||||||
|
range,
|
||||||
|
}));
|
||||||
|
t.is(getBranch(result, 'master').range, '>=1.1.1', 'Can release only > than 1.1.1 on master');
|
||||||
|
t.is(getBranch(result, '1.0.x').range, '>=1.0.4 <1.1.0', 'Can release on 1.0.x only within range');
|
||||||
|
t.is(getBranch(result, '1.x').range, '>=1.1.0 <1.1.0', 'Cannot release on 1.x before >= 2.0.0 is released on master');
|
||||||
|
|
||||||
|
merge(branches, 'master', '1.x');
|
||||||
|
result = (await getBranches('repositoryUrl', 'master', {options: {branches}})).map(({name, range}) => ({
|
||||||
|
name,
|
||||||
|
range,
|
||||||
|
}));
|
||||||
|
t.is(getBranch(result, 'master').range, '>=1.1.1', 'Can release only > than 1.1.1 on master');
|
||||||
|
t.is(getBranch(result, '1.0.x').range, '>=1.0.4 <1.1.0', 'Can release on 1.0.x only within range');
|
||||||
|
t.is(getBranch(result, '1.x').range, '>=1.1.1 <1.1.1', 'Cannot release on 1.x before >= 2.0.0 is released on master');
|
||||||
|
|
||||||
|
merge(branches, 'next-major', 'next');
|
||||||
|
merge(branches, 'next', 'master');
|
||||||
|
result = (await getBranches('repositoryUrl', 'master', {options: {branches}})).map(({name, range}) => ({
|
||||||
|
name,
|
||||||
|
range,
|
||||||
|
}));
|
||||||
|
t.is(getBranch(result, 'master').range, '>=2.0.1', 'Can release only > than 2.0.1 on master');
|
||||||
|
t.is(getBranch(result, 'next').range, '>=2.0.1', 'Can release only > than 2.0.1 on next');
|
||||||
|
t.is(getBranch(result, 'next-major').range, '>=2.0.1', 'Can release only > than 2.0.1 on next-major');
|
||||||
|
t.is(getBranch(result, '1.x').range, '>=1.1.1 <2.0.0', 'Can release on 1.x only within range');
|
||||||
|
|
||||||
|
merge(branches, 'beta', 'master');
|
||||||
|
release(branches, 'master', '3.0.0');
|
||||||
|
result = (await getBranches('repositoryUrl', 'master', {options: {branches}})).map(({name, range}) => ({
|
||||||
|
name,
|
||||||
|
range,
|
||||||
|
}));
|
||||||
|
t.is(getBranch(result, 'master').range, '>=3.0.0', 'Can release only > than 3.0.0 on master');
|
||||||
|
t.is(getBranch(result, 'next').range, '>=3.0.0', 'Can release only > than 3.0.0 on next');
|
||||||
|
t.is(getBranch(result, 'next-major').range, '>=3.0.0', 'Can release only > than 3.0.0 on next-major');
|
||||||
|
|
||||||
|
branches.push({name: '1.1.x', tags: []});
|
||||||
|
merge(branches, '1.x', '1.1.x');
|
||||||
|
result = (await getBranches('repositoryUrl', 'master', {options: {branches}})).map(({name, range}) => ({
|
||||||
|
name,
|
||||||
|
range,
|
||||||
|
}));
|
||||||
|
t.is(getBranch(result, '1.0.x').range, '>=1.0.4 <1.1.0', 'Can release on 1.0.x only within range');
|
||||||
|
t.is(getBranch(result, '1.1.x').range, '>=1.1.1 <1.2.0', 'Can release on 1.1.x only within range');
|
||||||
|
t.is(getBranch(result, '1.x').range, '>=1.2.0 <2.0.0', 'Can release on 1.x only within range');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Throw SemanticReleaseError for invalid configurations', async t => {
|
||||||
|
const branches = [
|
||||||
|
{name: '123', range: '123', tags: []},
|
||||||
|
{name: '1.x', tags: []},
|
||||||
|
{name: 'maintenance-1', range: '1.x', tags: []},
|
||||||
|
{name: '1.x.x', tags: []},
|
||||||
|
{name: 'beta', prerelease: '', tags: []},
|
||||||
|
{name: 'alpha', prerelease: 'alpha', tags: []},
|
||||||
|
{name: 'preview', prerelease: 'alpha', tags: []},
|
||||||
|
];
|
||||||
|
const getBranches = proxyquire('../../lib/branches', {'./get-tags': () => branches, './expand': () => []});
|
||||||
|
const errors = [...(await t.throwsAsync(getBranches('repositoryUrl', 'master', {options: {branches}})))];
|
||||||
|
|
||||||
|
t.is(errors[0].name, 'SemanticReleaseError');
|
||||||
|
t.is(errors[0].code, 'EMAINTENANCEBRANCH');
|
||||||
|
t.truthy(errors[0].message);
|
||||||
|
t.truthy(errors[0].details);
|
||||||
|
t.is(errors[1].name, 'SemanticReleaseError');
|
||||||
|
t.is(errors[1].code, 'EMAINTENANCEBRANCHES');
|
||||||
|
t.truthy(errors[1].message);
|
||||||
|
t.truthy(errors[1].details);
|
||||||
|
t.is(errors[2].name, 'SemanticReleaseError');
|
||||||
|
t.is(errors[2].code, 'EPRERELEASEBRANCH');
|
||||||
|
t.truthy(errors[2].message);
|
||||||
|
t.truthy(errors[2].details);
|
||||||
|
t.is(errors[3].name, 'SemanticReleaseError');
|
||||||
|
t.is(errors[3].code, 'EPRERELEASEBRANCHES');
|
||||||
|
t.truthy(errors[3].message);
|
||||||
|
t.truthy(errors[3].details);
|
||||||
|
t.is(errors[4].name, 'SemanticReleaseError');
|
||||||
|
t.is(errors[4].code, 'ERELEASEBRANCHES');
|
||||||
|
t.truthy(errors[4].message);
|
||||||
|
t.truthy(errors[4].details);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Throw a SemanticReleaseError if there is duplicate branches', async t => {
|
||||||
|
const branches = [
|
||||||
|
{name: 'master', tags: []},
|
||||||
|
{name: 'master', tags: []},
|
||||||
|
];
|
||||||
|
const getBranches = proxyquire('../../lib/branches', {'./get-tags': () => branches, './expand': () => []});
|
||||||
|
|
||||||
|
const errors = [...(await t.throwsAsync(getBranches('repositoryUrl', 'master', {options: {branches}})))];
|
||||||
|
|
||||||
|
t.is(errors[0].name, 'SemanticReleaseError');
|
||||||
|
t.is(errors[0].code, 'EDUPLICATEBRANCHES');
|
||||||
|
t.truthy(errors[0].message);
|
||||||
|
t.truthy(errors[0].details);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Throw a SemanticReleaseError for each invalid branch name', async t => {
|
||||||
|
const branches = [
|
||||||
|
{name: '~master', tags: []},
|
||||||
|
{name: '^master', tags: []},
|
||||||
|
];
|
||||||
|
const getBranches = proxyquire('../../lib/branches', {'./get-tags': () => branches, './expand': () => []});
|
||||||
|
|
||||||
|
const errors = [...(await t.throwsAsync(getBranches('repositoryUrl', 'master', {options: {branches}})))];
|
||||||
|
|
||||||
|
t.is(errors[0].name, 'SemanticReleaseError');
|
||||||
|
t.is(errors[0].code, 'EINVALIDBRANCHNAME');
|
||||||
|
t.truthy(errors[0].message);
|
||||||
|
t.truthy(errors[0].details);
|
||||||
|
t.is(errors[1].name, 'SemanticReleaseError');
|
||||||
|
t.is(errors[1].code, 'EINVALIDBRANCHNAME');
|
||||||
|
t.truthy(errors[1].message);
|
||||||
|
t.truthy(errors[1].details);
|
||||||
|
});
|
54
test/branches/expand.test.js
Normal file
54
test/branches/expand.test.js
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
import test from 'ava';
|
||||||
|
import expand from '../../lib/branches/expand';
|
||||||
|
import {gitRepo, gitCommits, gitCheckout, gitPush} from '../helpers/git-utils';
|
||||||
|
|
||||||
|
test('Expand branches defined with globs', async t => {
|
||||||
|
const {cwd, repositoryUrl} = await gitRepo(true);
|
||||||
|
await gitCommits(['First'], {cwd});
|
||||||
|
await gitPush(repositoryUrl, 'master', {cwd});
|
||||||
|
await gitCheckout('1.0.x', true, {cwd});
|
||||||
|
await gitCommits(['Second'], {cwd});
|
||||||
|
await gitPush(repositoryUrl, '1.0.x', {cwd});
|
||||||
|
await gitCheckout('1.x.x', true, {cwd});
|
||||||
|
await gitCommits(['Third'], {cwd});
|
||||||
|
await gitPush(repositoryUrl, '1.x.x', {cwd});
|
||||||
|
await gitCheckout('2.x', true, {cwd});
|
||||||
|
await gitCommits(['Fourth'], {cwd});
|
||||||
|
await gitPush(repositoryUrl, '2.x', {cwd});
|
||||||
|
await gitCheckout('next', true, {cwd});
|
||||||
|
await gitCommits(['Fifth'], {cwd});
|
||||||
|
await gitPush(repositoryUrl, 'next', {cwd});
|
||||||
|
await gitCheckout('pre/foo', true, {cwd});
|
||||||
|
await gitCommits(['Sixth'], {cwd});
|
||||||
|
await gitPush(repositoryUrl, 'pre/foo', {cwd});
|
||||||
|
await gitCheckout('pre/bar', true, {cwd});
|
||||||
|
await gitCommits(['Seventh'], {cwd});
|
||||||
|
await gitPush(repositoryUrl, 'pre/bar', {cwd});
|
||||||
|
await gitCheckout('beta', true, {cwd});
|
||||||
|
await gitCommits(['Eighth'], {cwd});
|
||||||
|
await gitPush(repositoryUrl, 'beta', {cwd});
|
||||||
|
|
||||||
|
const branches = [
|
||||||
|
// Should match all maintenance type branches
|
||||||
|
{name: '+([0-9])?(.{+([0-9]),x}).x'},
|
||||||
|
{name: 'master', channel: 'latest'},
|
||||||
|
{name: 'next'},
|
||||||
|
{name: 'pre/{foo,bar}', channel: `\${name.replace(/^pre\\//g, '')}`, prerelease: true},
|
||||||
|
// Should be ignored as there is no matching branches in the repo
|
||||||
|
{name: 'missing'},
|
||||||
|
// Should be ignored as the matching branch in the repo is already matched by `/^pre\\/(\\w+)$/gi`
|
||||||
|
{name: '*/foo', channel: 'foo', prerelease: 'foo'},
|
||||||
|
{name: 'beta', channel: `channel-\${name}`, prerelease: true},
|
||||||
|
];
|
||||||
|
|
||||||
|
t.deepEqual(await expand(repositoryUrl, {cwd}, branches), [
|
||||||
|
{name: '1.0.x'},
|
||||||
|
{name: '1.x.x'},
|
||||||
|
{name: '2.x'},
|
||||||
|
{name: 'master', channel: 'latest'},
|
||||||
|
{name: 'next'},
|
||||||
|
{name: 'pre/bar', channel: 'bar', prerelease: true},
|
||||||
|
{name: 'pre/foo', channel: 'foo', prerelease: true},
|
||||||
|
{name: 'beta', channel: 'channel-beta', prerelease: true},
|
||||||
|
]);
|
||||||
|
});
|
153
test/branches/get-tags.test.js
Normal file
153
test/branches/get-tags.test.js
Normal file
@ -0,0 +1,153 @@
|
|||||||
|
import test from 'ava';
|
||||||
|
import getTags from '../../lib/branches/get-tags';
|
||||||
|
import {gitRepo, gitCommits, gitTagVersion, gitCheckout, gitAddNote} from '../helpers/git-utils';
|
||||||
|
|
||||||
|
test('Get the valid tags', async t => {
|
||||||
|
const {cwd} = await gitRepo();
|
||||||
|
const commits = await gitCommits(['First'], {cwd});
|
||||||
|
await gitTagVersion('foo', undefined, {cwd});
|
||||||
|
await gitTagVersion('v2.0.0', undefined, {cwd});
|
||||||
|
commits.push(...(await gitCommits(['Second'], {cwd})));
|
||||||
|
await gitTagVersion('v1.0.0', undefined, {cwd});
|
||||||
|
commits.push(...(await gitCommits(['Third'], {cwd})));
|
||||||
|
await gitTagVersion('v3.0', undefined, {cwd});
|
||||||
|
commits.push(...(await gitCommits(['Fourth'], {cwd})));
|
||||||
|
await gitTagVersion('v3.0.0-beta.1', undefined, {cwd});
|
||||||
|
|
||||||
|
const result = await getTags({cwd, options: {tagFormat: `v\${version}`}}, [{name: 'master'}]);
|
||||||
|
|
||||||
|
t.deepEqual(result, [
|
||||||
|
{
|
||||||
|
name: 'master',
|
||||||
|
tags: [
|
||||||
|
{gitTag: 'v1.0.0', version: '1.0.0', channels: [null]},
|
||||||
|
{gitTag: 'v2.0.0', version: '2.0.0', channels: [null]},
|
||||||
|
{gitTag: 'v3.0.0-beta.1', version: '3.0.0-beta.1', channels: [null]},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Get the valid tags from multiple branches', async t => {
|
||||||
|
const {cwd} = await gitRepo();
|
||||||
|
await gitCommits(['First'], {cwd});
|
||||||
|
await gitTagVersion('v1.0.0', undefined, {cwd});
|
||||||
|
await gitAddNote(JSON.stringify({channels: [null, '1.x']}), 'v1.0.0', {cwd});
|
||||||
|
await gitCommits(['Second'], {cwd});
|
||||||
|
await gitTagVersion('v1.1.0', undefined, {cwd});
|
||||||
|
await gitAddNote(JSON.stringify({channels: [null, '1.x']}), 'v1.1.0', {cwd});
|
||||||
|
await gitCheckout('1.x', true, {cwd});
|
||||||
|
await gitCheckout('master', false, {cwd});
|
||||||
|
await gitCommits(['Third'], {cwd});
|
||||||
|
await gitTagVersion('v2.0.0', undefined, {cwd});
|
||||||
|
await gitAddNote(JSON.stringify({channels: [null, 'next']}), 'v2.0.0', {cwd});
|
||||||
|
await gitCheckout('next', true, {cwd});
|
||||||
|
await gitCommits(['Fourth'], {cwd});
|
||||||
|
await gitTagVersion('v3.0.0', undefined, {cwd});
|
||||||
|
await gitAddNote(JSON.stringify({channels: ['next']}), 'v3.0.0', {cwd});
|
||||||
|
|
||||||
|
const result = await getTags({cwd, options: {tagFormat: `v\${version}`}}, [
|
||||||
|
{name: '1.x'},
|
||||||
|
{name: 'master'},
|
||||||
|
{name: 'next'},
|
||||||
|
]);
|
||||||
|
|
||||||
|
t.deepEqual(result, [
|
||||||
|
{
|
||||||
|
name: '1.x',
|
||||||
|
tags: [
|
||||||
|
{gitTag: 'v1.0.0', version: '1.0.0', channels: [null, '1.x']},
|
||||||
|
{gitTag: 'v1.1.0', version: '1.1.0', channels: [null, '1.x']},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'master',
|
||||||
|
tags: [...result[0].tags, {gitTag: 'v2.0.0', version: '2.0.0', channels: [null, 'next']}],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'next',
|
||||||
|
tags: [...result[1].tags, {gitTag: 'v3.0.0', version: '3.0.0', channels: ['next']}],
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Return branches with and empty tags array if no valid tag is found', async t => {
|
||||||
|
const {cwd} = await gitRepo();
|
||||||
|
await gitCommits(['First'], {cwd});
|
||||||
|
await gitTagVersion('foo', undefined, {cwd});
|
||||||
|
await gitCommits(['Second'], {cwd});
|
||||||
|
await gitTagVersion('v2.0.x', undefined, {cwd});
|
||||||
|
await gitCommits(['Third'], {cwd});
|
||||||
|
await gitTagVersion('v3.0', undefined, {cwd});
|
||||||
|
|
||||||
|
const result = await getTags({cwd, options: {tagFormat: `prefix@v\${version}`}}, [{name: 'master'}]);
|
||||||
|
|
||||||
|
t.deepEqual(result, [{name: 'master', tags: []}]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Return branches with and empty tags array if no valid tag is found in history of configured branches', async t => {
|
||||||
|
const {cwd} = await gitRepo();
|
||||||
|
await gitCommits(['First'], {cwd});
|
||||||
|
await gitCheckout('next', true, {cwd});
|
||||||
|
await gitCommits(['Second'], {cwd});
|
||||||
|
await gitTagVersion('v1.0.0', undefined, {cwd});
|
||||||
|
await gitAddNote(JSON.stringify({channels: [null, 'next']}), 'v1.0.0', {cwd});
|
||||||
|
await gitCommits(['Third'], {cwd});
|
||||||
|
await gitTagVersion('v2.0.0', undefined, {cwd});
|
||||||
|
await gitAddNote(JSON.stringify({channels: [null, 'next']}), 'v2.0.0', {cwd});
|
||||||
|
await gitCommits(['Fourth'], {cwd});
|
||||||
|
await gitTagVersion('v3.0.0', undefined, {cwd});
|
||||||
|
await gitAddNote(JSON.stringify({channels: [null, 'next']}), 'v3.0.0', {cwd});
|
||||||
|
await gitCheckout('master', false, {cwd});
|
||||||
|
|
||||||
|
const result = await getTags({cwd, options: {tagFormat: `prefix@v\${version}`}}, [{name: 'master'}, {name: 'next'}]);
|
||||||
|
|
||||||
|
t.deepEqual(result, [
|
||||||
|
{name: 'master', tags: []},
|
||||||
|
{name: 'next', tags: []},
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Get the highest valid tag corresponding to the "tagFormat"', async t => {
|
||||||
|
const {cwd} = await gitRepo();
|
||||||
|
await gitCommits(['First'], {cwd});
|
||||||
|
|
||||||
|
await gitTagVersion('1.0.0', undefined, {cwd});
|
||||||
|
t.deepEqual(await getTags({cwd, options: {tagFormat: `\${version}`}}, [{name: 'master'}]), [
|
||||||
|
{name: 'master', tags: [{gitTag: '1.0.0', version: '1.0.0', channels: [null]}]},
|
||||||
|
]);
|
||||||
|
|
||||||
|
await gitTagVersion('foo-1.0.0-bar', undefined, {cwd});
|
||||||
|
t.deepEqual(await getTags({cwd, options: {tagFormat: `foo-\${version}-bar`}}, [{name: 'master'}]), [
|
||||||
|
{name: 'master', tags: [{gitTag: 'foo-1.0.0-bar', version: '1.0.0', channels: [null]}]},
|
||||||
|
]);
|
||||||
|
|
||||||
|
await gitTagVersion('foo-v1.0.0-bar', undefined, {cwd});
|
||||||
|
t.deepEqual(await getTags({cwd, options: {tagFormat: `foo-v\${version}-bar`}}, [{name: 'master'}]), [
|
||||||
|
{
|
||||||
|
name: 'master',
|
||||||
|
tags: [{gitTag: 'foo-v1.0.0-bar', version: '1.0.0', channels: [null]}],
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
|
||||||
|
await gitTagVersion('(.+)/1.0.0/(a-z)', undefined, {cwd});
|
||||||
|
t.deepEqual(await getTags({cwd, options: {tagFormat: `(.+)/\${version}/(a-z)`}}, [{name: 'master'}]), [
|
||||||
|
{
|
||||||
|
name: 'master',
|
||||||
|
tags: [{gitTag: '(.+)/1.0.0/(a-z)', version: '1.0.0', channels: [null]}],
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
|
||||||
|
await gitTagVersion('2.0.0-1.0.0-bar.1', undefined, {cwd});
|
||||||
|
t.deepEqual(await getTags({cwd, options: {tagFormat: `2.0.0-\${version}-bar.1`}}, [{name: 'master'}]), [
|
||||||
|
{
|
||||||
|
name: 'master',
|
||||||
|
tags: [{gitTag: '2.0.0-1.0.0-bar.1', version: '1.0.0', channels: [null]}],
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
|
||||||
|
await gitTagVersion('3.0.0-bar.2', undefined, {cwd});
|
||||||
|
t.deepEqual(await getTags({cwd, options: {tagFormat: `\${version}-bar.2`}}, [{name: 'master'}]), [
|
||||||
|
{name: 'master', tags: [{gitTag: '3.0.0-bar.2', version: '3.0.0', channels: [null]}]},
|
||||||
|
]);
|
||||||
|
});
|
397
test/branches/normalize.test.js
Normal file
397
test/branches/normalize.test.js
Normal file
@ -0,0 +1,397 @@
|
|||||||
|
import test from 'ava';
|
||||||
|
import normalize from '../../lib/branches/normalize';
|
||||||
|
|
||||||
|
const toTags = versions => versions.map(version => ({version}));
|
||||||
|
|
||||||
|
test('Maintenance branches - initial state', t => {
|
||||||
|
const maintenance = [
|
||||||
|
{name: '1.x', channel: '1.x', tags: []},
|
||||||
|
{name: '1.1.x', tags: []},
|
||||||
|
{name: '1.2.x', tags: []},
|
||||||
|
];
|
||||||
|
const release = [{name: 'master', tags: []}];
|
||||||
|
t.deepEqual(
|
||||||
|
normalize.maintenance({maintenance, release}).map(({type, name, range, accept, channel, mergeRange}) => ({
|
||||||
|
type,
|
||||||
|
name,
|
||||||
|
range,
|
||||||
|
accept,
|
||||||
|
channel,
|
||||||
|
mergeRange,
|
||||||
|
})),
|
||||||
|
[
|
||||||
|
{
|
||||||
|
type: 'maintenance',
|
||||||
|
name: '1.1.x',
|
||||||
|
range: '>=1.1.0 <1.0.0',
|
||||||
|
accept: [],
|
||||||
|
channel: '1.1.x',
|
||||||
|
mergeRange: '>=1.1.0 <1.2.0',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'maintenance',
|
||||||
|
name: '1.2.x',
|
||||||
|
range: '>=1.2.0 <1.0.0',
|
||||||
|
accept: [],
|
||||||
|
channel: '1.2.x',
|
||||||
|
mergeRange: '>=1.2.0 <1.3.0',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'maintenance',
|
||||||
|
name: '1.x',
|
||||||
|
range: '>=1.3.0 <1.0.0',
|
||||||
|
accept: [],
|
||||||
|
channel: '1.x',
|
||||||
|
mergeRange: '>=1.3.0 <2.0.0',
|
||||||
|
},
|
||||||
|
]
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Maintenance branches - cap range to first release present on default branch and not in any Maintenance one', t => {
|
||||||
|
const maintenance = [
|
||||||
|
{name: '1.x', tags: toTags(['1.0.0', '1.1.0', '1.1.1', '1.2.0', '1.2.1', '1.3.0', '1.4.0', '1.5.0'])},
|
||||||
|
{name: 'name', range: '1.1.x', tags: toTags(['1.0.0', '1.0.1', '1.1.0', '1.1.1'])},
|
||||||
|
{name: '1.2.x', tags: toTags(['1.0.0', '1.1.0', '1.1.1', '1.2.0', '1.2.1'])},
|
||||||
|
{name: '2.x.x', tags: toTags(['1.0.0', '1.1.0', '1.1.1', '1.2.0', '1.2.1', '1.5.0'])},
|
||||||
|
];
|
||||||
|
const release = [
|
||||||
|
{
|
||||||
|
name: 'master',
|
||||||
|
tags: toTags(['1.0.0', '1.1.0', '1.1.1', '1.2.0', '1.2.1', '1.3.0', '1.4.0', '1.5.0', '1.6.0', '2.0.0']),
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
t.deepEqual(
|
||||||
|
normalize
|
||||||
|
.maintenance({maintenance, release})
|
||||||
|
.map(({type, name, range, accept, channel, mergeRange: maintenanceRange}) => ({
|
||||||
|
type,
|
||||||
|
name,
|
||||||
|
range,
|
||||||
|
accept,
|
||||||
|
channel,
|
||||||
|
mergeRange: maintenanceRange,
|
||||||
|
})),
|
||||||
|
[
|
||||||
|
{
|
||||||
|
type: 'maintenance',
|
||||||
|
name: 'name',
|
||||||
|
range: '>=1.1.1 <1.2.0',
|
||||||
|
accept: ['patch'],
|
||||||
|
channel: 'name',
|
||||||
|
mergeRange: '>=1.1.0 <1.2.0',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'maintenance',
|
||||||
|
name: '1.2.x',
|
||||||
|
range: '>=1.2.1 <1.3.0',
|
||||||
|
accept: ['patch'],
|
||||||
|
channel: '1.2.x',
|
||||||
|
mergeRange: '>=1.2.0 <1.3.0',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'maintenance',
|
||||||
|
name: '1.x',
|
||||||
|
range: '>=1.5.0 <1.6.0',
|
||||||
|
accept: ['patch'],
|
||||||
|
channel: '1.x',
|
||||||
|
mergeRange: '>=1.3.0 <2.0.0',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'maintenance',
|
||||||
|
name: '2.x.x',
|
||||||
|
range: '>=2.0.0 <1.6.0',
|
||||||
|
accept: [],
|
||||||
|
channel: '2.x.x',
|
||||||
|
mergeRange: '>=2.0.0 <3.0.0',
|
||||||
|
},
|
||||||
|
]
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Maintenance branches - cap range to default branch last release if all release are also present on maintenance branch', t => {
|
||||||
|
const maintenance = [
|
||||||
|
{name: '1.x', tags: toTags(['1.0.0', '1.2.0', '1.3.0'])},
|
||||||
|
{name: '2.x.x', tags: toTags(['1.0.0', '1.2.0', '1.3.0', '2.0.0'])},
|
||||||
|
];
|
||||||
|
const release = [{name: 'master', tags: toTags(['1.0.0', '1.2.0', '1.3.0', '2.0.0'])}];
|
||||||
|
|
||||||
|
t.deepEqual(
|
||||||
|
normalize.maintenance({maintenance, release}).map(({type, name, range, accept, channel, mergeRange}) => ({
|
||||||
|
type,
|
||||||
|
name,
|
||||||
|
range,
|
||||||
|
accept,
|
||||||
|
channel,
|
||||||
|
mergeRange,
|
||||||
|
})),
|
||||||
|
[
|
||||||
|
{
|
||||||
|
type: 'maintenance',
|
||||||
|
name: '1.x',
|
||||||
|
range: '>=1.3.0 <2.0.0',
|
||||||
|
accept: ['patch', 'minor'],
|
||||||
|
channel: '1.x',
|
||||||
|
mergeRange: '>=1.0.0 <2.0.0',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'maintenance',
|
||||||
|
name: '2.x.x',
|
||||||
|
range: '>=2.0.0 <2.0.0',
|
||||||
|
accept: [],
|
||||||
|
channel: '2.x.x',
|
||||||
|
mergeRange: '>=2.0.0 <3.0.0',
|
||||||
|
},
|
||||||
|
]
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Release branches - initial state', t => {
|
||||||
|
const release = [
|
||||||
|
{name: 'master', tags: []},
|
||||||
|
{name: 'next', channel: 'next', tags: []},
|
||||||
|
{name: 'next-major', tags: []},
|
||||||
|
];
|
||||||
|
|
||||||
|
t.deepEqual(
|
||||||
|
normalize
|
||||||
|
.release({release})
|
||||||
|
.map(({type, name, range, accept, channel, main}) => ({type, name, range, accept, channel, main})),
|
||||||
|
[
|
||||||
|
{
|
||||||
|
type: 'release',
|
||||||
|
name: 'master',
|
||||||
|
range: '>=1.0.0',
|
||||||
|
accept: ['patch', 'minor', 'major'],
|
||||||
|
channel: undefined,
|
||||||
|
main: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'release',
|
||||||
|
name: 'next',
|
||||||
|
range: '>=1.0.0',
|
||||||
|
accept: ['patch', 'minor', 'major'],
|
||||||
|
channel: 'next',
|
||||||
|
main: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'release',
|
||||||
|
name: 'next-major',
|
||||||
|
range: '>=1.0.0',
|
||||||
|
accept: ['patch', 'minor', 'major'],
|
||||||
|
channel: 'next-major',
|
||||||
|
main: false,
|
||||||
|
},
|
||||||
|
]
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Release branches - 3 release branches', t => {
|
||||||
|
const release = [
|
||||||
|
{name: 'master', tags: toTags(['1.0.0', '1.0.1', '1.0.2'])},
|
||||||
|
{name: 'next', tags: toTags(['1.0.0', '1.0.1', '1.0.2', '1.1.0', '1.2.0'])},
|
||||||
|
{name: 'next-major', tags: toTags(['1.0.0', '1.0.1', '1.0.2', '1.1.0', '1.2.0', '2.0.0', '2.0.1', '2.1.0'])},
|
||||||
|
];
|
||||||
|
|
||||||
|
t.deepEqual(
|
||||||
|
normalize
|
||||||
|
.release({release})
|
||||||
|
.map(({type, name, range, accept, channel, main}) => ({type, name, range, accept, channel, main})),
|
||||||
|
[
|
||||||
|
{type: 'release', name: 'master', range: '>=1.0.2 <1.1.0', accept: ['patch'], channel: undefined, main: true},
|
||||||
|
{
|
||||||
|
type: 'release',
|
||||||
|
name: 'next',
|
||||||
|
range: '>=1.2.0 <2.0.0',
|
||||||
|
accept: ['patch', 'minor'],
|
||||||
|
channel: 'next',
|
||||||
|
main: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'release',
|
||||||
|
name: 'next-major',
|
||||||
|
range: '>=2.1.0',
|
||||||
|
accept: ['patch', 'minor', 'major'],
|
||||||
|
channel: 'next-major',
|
||||||
|
main: false,
|
||||||
|
},
|
||||||
|
]
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Release branches - 2 release branches', t => {
|
||||||
|
const release = [
|
||||||
|
{name: 'master', tags: toTags(['1.0.0', '1.0.1', '1.1.0', '1.1.1', '1.2.0'])},
|
||||||
|
{name: 'next', tags: toTags(['1.0.0', '1.0.1', '1.1.0', '1.1.1', '1.2.0', '2.0.0', '2.0.1', '2.1.0'])},
|
||||||
|
];
|
||||||
|
|
||||||
|
t.deepEqual(
|
||||||
|
normalize
|
||||||
|
.release({release})
|
||||||
|
.map(({type, name, range, accept, channel, main}) => ({type, name, range, accept, channel, main})),
|
||||||
|
[
|
||||||
|
{
|
||||||
|
type: 'release',
|
||||||
|
name: 'master',
|
||||||
|
range: '>=1.2.0 <2.0.0',
|
||||||
|
accept: ['patch', 'minor'],
|
||||||
|
channel: undefined,
|
||||||
|
main: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'release',
|
||||||
|
name: 'next',
|
||||||
|
range: '>=2.1.0',
|
||||||
|
accept: ['patch', 'minor', 'major'],
|
||||||
|
channel: 'next',
|
||||||
|
main: false,
|
||||||
|
},
|
||||||
|
]
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Release branches - 1 release branches', t => {
|
||||||
|
const release = [{name: 'master', tags: toTags(['1.0.0', '1.1.0', '1.1.1', '1.2.0'])}];
|
||||||
|
|
||||||
|
t.deepEqual(
|
||||||
|
normalize.release({release}).map(({type, name, range, accept, channel}) => ({type, name, range, accept, channel})),
|
||||||
|
[{type: 'release', name: 'master', range: '>=1.2.0', accept: ['patch', 'minor', 'major'], channel: undefined}]
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Release branches - cap ranges to first release only present on following branch', t => {
|
||||||
|
const release = [
|
||||||
|
{name: 'master', tags: toTags(['1.0.0', '1.1.0', '1.2.0', '2.0.0'])},
|
||||||
|
{name: 'next', tags: toTags(['1.0.0', '1.1.0', '1.2.0', '2.0.0', '2.1.0'])},
|
||||||
|
{name: 'next-major', tags: toTags(['1.0.0', '1.1.0', '1.2.0', '2.0.0', '2.1.0', '2.2.0'])},
|
||||||
|
];
|
||||||
|
|
||||||
|
t.deepEqual(
|
||||||
|
normalize
|
||||||
|
.release({release})
|
||||||
|
.map(({type, name, range, accept, channel, main}) => ({type, name, range, accept, channel, main})),
|
||||||
|
[
|
||||||
|
{type: 'release', name: 'master', range: '>=2.0.0 <2.1.0', accept: ['patch'], channel: undefined, main: true},
|
||||||
|
{type: 'release', name: 'next', range: '>=2.1.0 <2.2.0', accept: ['patch'], channel: 'next', main: false},
|
||||||
|
{
|
||||||
|
type: 'release',
|
||||||
|
name: 'next-major',
|
||||||
|
range: '>=2.2.0',
|
||||||
|
accept: ['patch', 'minor', 'major'],
|
||||||
|
channel: 'next-major',
|
||||||
|
main: false,
|
||||||
|
},
|
||||||
|
]
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Release branches - Handle missing previous tags in branch history', t => {
|
||||||
|
const release = [
|
||||||
|
{name: 'master', tags: toTags(['1.0.0', '2.0.0'])},
|
||||||
|
{name: 'next', tags: toTags(['1.0.0', '1.1.0', '1.1.1', '1.2.0', '2.0.0'])},
|
||||||
|
];
|
||||||
|
|
||||||
|
t.deepEqual(
|
||||||
|
normalize
|
||||||
|
.release({release})
|
||||||
|
.map(({type, name, range, accept, channel, main}) => ({type, name, range, accept, channel, main})),
|
||||||
|
[
|
||||||
|
{
|
||||||
|
type: 'release',
|
||||||
|
name: 'master',
|
||||||
|
range: '>=2.0.0',
|
||||||
|
accept: ['patch', 'minor', 'major'],
|
||||||
|
channel: undefined,
|
||||||
|
main: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'release',
|
||||||
|
name: 'next',
|
||||||
|
range: '>=2.0.0',
|
||||||
|
accept: ['patch', 'minor', 'major'],
|
||||||
|
channel: 'next',
|
||||||
|
main: false,
|
||||||
|
},
|
||||||
|
]
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Release branches - limit releases on 2nd and 3rd branch based on 1st branch last release', t => {
|
||||||
|
const release = [
|
||||||
|
{name: 'master', tags: toTags(['1.0.0', '1.1.0', '2.0.0', '3.0.0'])},
|
||||||
|
{name: 'next', tags: toTags(['1.0.0', '1.1.0'])},
|
||||||
|
{name: 'next-major', tags: toTags(['1.0.0', '1.1.0', '2.0.0'])},
|
||||||
|
];
|
||||||
|
|
||||||
|
t.deepEqual(
|
||||||
|
normalize
|
||||||
|
.release({release})
|
||||||
|
.map(({type, name, range, accept, channel, main}) => ({type, name, range, accept, channel, main})),
|
||||||
|
[
|
||||||
|
{
|
||||||
|
type: 'release',
|
||||||
|
name: 'master',
|
||||||
|
range: '>=3.0.0',
|
||||||
|
accept: ['patch', 'minor', 'major'],
|
||||||
|
channel: undefined,
|
||||||
|
main: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'release',
|
||||||
|
name: 'next',
|
||||||
|
range: '>=3.0.0',
|
||||||
|
accept: ['patch', 'minor', 'major'],
|
||||||
|
channel: 'next',
|
||||||
|
main: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'release',
|
||||||
|
name: 'next-major',
|
||||||
|
range: '>=3.0.0',
|
||||||
|
accept: ['patch', 'minor', 'major'],
|
||||||
|
channel: 'next-major',
|
||||||
|
main: false,
|
||||||
|
},
|
||||||
|
]
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Prerelease branches', t => {
|
||||||
|
const prerelease = [
|
||||||
|
{name: 'beta', channel: 'beta', prerelease: true, tags: []},
|
||||||
|
{name: 'alpha', prerelease: 'preview', tags: []},
|
||||||
|
];
|
||||||
|
|
||||||
|
t.deepEqual(
|
||||||
|
normalize.prerelease({prerelease}).map(({type, name, channel}) => ({type, name, channel})),
|
||||||
|
[
|
||||||
|
{type: 'prerelease', name: 'beta', channel: 'beta'},
|
||||||
|
{type: 'prerelease', name: 'alpha', channel: 'alpha'},
|
||||||
|
]
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Allow to set channel to "false" to prevent default', t => {
|
||||||
|
const maintenance = [{name: '1.x', channel: false, tags: []}];
|
||||||
|
const release = [
|
||||||
|
{name: 'master', channel: false, tags: []},
|
||||||
|
{name: 'next', channel: false, tags: []},
|
||||||
|
];
|
||||||
|
const prerelease = [{name: 'beta', channel: false, prerelease: true, tags: []}];
|
||||||
|
t.deepEqual(
|
||||||
|
normalize.maintenance({maintenance, release}).map(({name, channel}) => ({name, channel})),
|
||||||
|
[{name: '1.x', channel: false}]
|
||||||
|
);
|
||||||
|
t.deepEqual(
|
||||||
|
normalize.release({release}).map(({name, channel}) => ({name, channel})),
|
||||||
|
[
|
||||||
|
{name: 'master', channel: false},
|
||||||
|
{name: 'next', channel: false},
|
||||||
|
]
|
||||||
|
);
|
||||||
|
t.deepEqual(
|
||||||
|
normalize.prerelease({prerelease}).map(({name, channel}) => ({name, channel})),
|
||||||
|
[{name: 'beta', channel: false}]
|
||||||
|
);
|
||||||
|
});
|
@ -29,6 +29,7 @@ test.serial('Pass options to semantic-release API', async t => {
|
|||||||
'',
|
'',
|
||||||
'-b',
|
'-b',
|
||||||
'master',
|
'master',
|
||||||
|
'next',
|
||||||
'-r',
|
'-r',
|
||||||
'https://github/com/owner/repo.git',
|
'https://github/com/owner/repo.git',
|
||||||
'-t',
|
'-t',
|
||||||
@ -68,7 +69,7 @@ test.serial('Pass options to semantic-release API', async t => {
|
|||||||
|
|
||||||
const exitCode = await cli();
|
const exitCode = await cli();
|
||||||
|
|
||||||
t.is(run.args[0][0].branch, 'master');
|
t.deepEqual(run.args[0][0].branches, ['master', 'next']);
|
||||||
t.is(run.args[0][0].repositoryUrl, 'https://github/com/owner/repo.git');
|
t.is(run.args[0][0].repositoryUrl, 'https://github/com/owner/repo.git');
|
||||||
t.is(run.args[0][0].tagFormat, `v\${version}`);
|
t.is(run.args[0][0].tagFormat, `v\${version}`);
|
||||||
t.deepEqual(run.args[0][0].plugins, ['plugin1', 'plugin2']);
|
t.deepEqual(run.args[0][0].plugins, ['plugin1', 'plugin2']);
|
||||||
@ -92,7 +93,7 @@ test.serial('Pass options to semantic-release API with alias arguments', async t
|
|||||||
const argv = [
|
const argv = [
|
||||||
'',
|
'',
|
||||||
'',
|
'',
|
||||||
'--branch',
|
'--branches',
|
||||||
'master',
|
'master',
|
||||||
'--repository-url',
|
'--repository-url',
|
||||||
'https://github/com/owner/repo.git',
|
'https://github/com/owner/repo.git',
|
||||||
@ -110,7 +111,7 @@ test.serial('Pass options to semantic-release API with alias arguments', async t
|
|||||||
|
|
||||||
const exitCode = await cli();
|
const exitCode = await cli();
|
||||||
|
|
||||||
t.is(run.args[0][0].branch, 'master');
|
t.deepEqual(run.args[0][0].branches, ['master']);
|
||||||
t.is(run.args[0][0].repositoryUrl, 'https://github/com/owner/repo.git');
|
t.is(run.args[0][0].repositoryUrl, 'https://github/com/owner/repo.git');
|
||||||
t.is(run.args[0][0].tagFormat, `v\${version}`);
|
t.is(run.args[0][0].tagFormat, `v\${version}`);
|
||||||
t.deepEqual(run.args[0][0].plugins, ['plugin1', 'plugin2']);
|
t.deepEqual(run.args[0][0].plugins, ['plugin1', 'plugin2']);
|
||||||
|
86
test/definitions/branches.test.js
Normal file
86
test/definitions/branches.test.js
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
import test from 'ava';
|
||||||
|
import {maintenance, prerelease, release} from '../../lib/definitions/branches';
|
||||||
|
|
||||||
|
test('A "maintenance" branch is identified by having a "range" property or a "name" formatted like "N.x", "N.x.x" or "N.N.x"', t => {
|
||||||
|
t.true(maintenance.filter({name: '1.x.x'}));
|
||||||
|
t.true(maintenance.filter({name: '1.0.x'}));
|
||||||
|
t.true(maintenance.filter({name: '1.x'}));
|
||||||
|
t.true(maintenance.filter({name: 'some-name', range: '1.x.x'}));
|
||||||
|
t.true(maintenance.filter({name: 'some-name', range: '1.1.x'}));
|
||||||
|
t.true(maintenance.filter({name: 'some-name', range: ''}));
|
||||||
|
t.true(maintenance.filter({name: 'some-name', range: true}));
|
||||||
|
|
||||||
|
t.false(maintenance.filter({name: 'some-name', range: null}));
|
||||||
|
t.false(maintenance.filter({name: 'some-name', range: false}));
|
||||||
|
t.false(maintenance.filter({name: 'some-name'}));
|
||||||
|
t.false(maintenance.filter({name: '1.0.0'}));
|
||||||
|
t.false(maintenance.filter({name: 'x.x.x'}));
|
||||||
|
});
|
||||||
|
|
||||||
|
test('A "maintenance" branches must have a "range" property formatted like "N.x", "N.x.x" or "N.N.x"', t => {
|
||||||
|
t.true(maintenance.branchValidator({name: 'some-name', range: '1.x.x'}));
|
||||||
|
t.true(maintenance.branchValidator({name: 'some-name', range: '1.1.x'}));
|
||||||
|
|
||||||
|
t.false(maintenance.branchValidator({name: 'some-name', range: '^1.0.0'}));
|
||||||
|
t.false(maintenance.branchValidator({name: 'some-name', range: '>=1.0.0 <2.0.0'}));
|
||||||
|
t.false(maintenance.branchValidator({name: 'some-name', range: '1.0.0'}));
|
||||||
|
t.false(maintenance.branchValidator({name: 'some-name', range: 'wrong-range'}));
|
||||||
|
t.false(maintenance.branchValidator({name: 'some-name', range: true}));
|
||||||
|
t.false(maintenance.branchValidator({name: 'some-name', range: ''}));
|
||||||
|
});
|
||||||
|
|
||||||
|
test('The "maintenance" branches must have unique ranges', t => {
|
||||||
|
t.true(maintenance.branchesValidator([{range: '1.x.x'}, {range: '1.0.x'}]));
|
||||||
|
|
||||||
|
t.false(maintenance.branchesValidator([{range: '1.x.x'}, {range: '1.x.x'}]));
|
||||||
|
t.false(maintenance.branchesValidator([{range: '1.x.x'}, {range: '1.x'}]));
|
||||||
|
});
|
||||||
|
|
||||||
|
test('A "prerelease" branch is identified by having a thruthy "prerelease" property', t => {
|
||||||
|
t.true(prerelease.filter({name: 'some-name', prerelease: true}));
|
||||||
|
t.true(prerelease.filter({name: 'some-name', prerelease: 'beta'}));
|
||||||
|
t.true(prerelease.filter({name: 'some-name', prerelease: ''}));
|
||||||
|
|
||||||
|
t.false(prerelease.filter({name: 'some-name', prerelease: null}));
|
||||||
|
t.false(prerelease.filter({name: 'some-name', prerelease: false}));
|
||||||
|
t.false(prerelease.filter({name: 'some-name'}));
|
||||||
|
});
|
||||||
|
|
||||||
|
test('A "prerelease" branch must have a valid prerelease detonation in "prerelease" property or in "name" if "prerelease" is "true"', t => {
|
||||||
|
t.true(prerelease.branchValidator({name: 'beta', prerelease: true}));
|
||||||
|
t.true(prerelease.branchValidator({name: 'some-name', prerelease: 'beta'}));
|
||||||
|
|
||||||
|
t.false(prerelease.branchValidator({name: 'some-name', prerelease: ''}));
|
||||||
|
t.false(prerelease.branchValidator({name: 'some-name', prerelease: null}));
|
||||||
|
t.false(prerelease.branchValidator({name: 'some-name', prerelease: false}));
|
||||||
|
t.false(prerelease.branchValidator({name: 'some-name', prerelease: '000'}));
|
||||||
|
t.false(prerelease.branchValidator({name: 'some-name', prerelease: '#beta'}));
|
||||||
|
t.false(prerelease.branchValidator({name: '000', prerelease: true}));
|
||||||
|
t.false(prerelease.branchValidator({name: '#beta', prerelease: true}));
|
||||||
|
});
|
||||||
|
|
||||||
|
test('The "prerelease" branches must have unique "prerelease" property', t => {
|
||||||
|
t.true(prerelease.branchesValidator([{prerelease: 'beta'}, {prerelease: 'alpha'}]));
|
||||||
|
|
||||||
|
t.false(prerelease.branchesValidator([{range: 'beta'}, {range: 'beta'}, {range: 'alpha'}]));
|
||||||
|
});
|
||||||
|
|
||||||
|
test('A "release" branch is identified by not havin a "range" or "prerelease" property or a "name" formatted like "N.x", "N.x.x" or "N.N.x"', t => {
|
||||||
|
t.true(release.filter({name: 'some-name'}));
|
||||||
|
|
||||||
|
t.false(release.filter({name: '1.x.x'}));
|
||||||
|
t.false(release.filter({name: '1.0.x'}));
|
||||||
|
t.false(release.filter({name: 'some-name', range: '1.x.x'}));
|
||||||
|
t.false(release.filter({name: 'some-name', range: '1.1.x'}));
|
||||||
|
t.false(release.filter({name: 'some-name', prerelease: true}));
|
||||||
|
t.false(release.filter({name: 'some-name', prerelease: 'beta'}));
|
||||||
|
});
|
||||||
|
|
||||||
|
test('There must be between 1 and 3 release branches', t => {
|
||||||
|
t.true(release.branchesValidator([{name: 'branch1'}]));
|
||||||
|
t.true(release.branchesValidator([{name: 'branch1'}, {name: 'branch2'}]));
|
||||||
|
t.true(release.branchesValidator([{name: 'branch1'}, {name: 'branch2'}, {name: 'branch3'}]));
|
||||||
|
|
||||||
|
t.false(release.branchesValidator([]));
|
||||||
|
t.false(release.branchesValidator([{name: 'branch1'}, {name: 'branch2'}, {name: 'branch3'}, {name: 'branch4'}]));
|
||||||
|
});
|
@ -33,6 +33,16 @@ test('The "publish" plugin output, if defined, must be an object or "false"', t
|
|||||||
t.true(plugins.publish.outputValidator(false));
|
t.true(plugins.publish.outputValidator(false));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('The "addChannel" plugin output, if defined, must be an object', t => {
|
||||||
|
t.false(plugins.addChannel.outputValidator(1));
|
||||||
|
t.false(plugins.addChannel.outputValidator('string'));
|
||||||
|
|
||||||
|
t.true(plugins.addChannel.outputValidator({}));
|
||||||
|
t.true(plugins.addChannel.outputValidator());
|
||||||
|
t.true(plugins.addChannel.outputValidator(null));
|
||||||
|
t.true(plugins.addChannel.outputValidator(''));
|
||||||
|
});
|
||||||
|
|
||||||
test('The "generateNotes" plugins output are concatenated with separator and sensitive data is hidden', t => {
|
test('The "generateNotes" plugins output are concatenated with separator and sensitive data is hidden', t => {
|
||||||
const env = {MY_TOKEN: 'secret token'};
|
const env = {MY_TOKEN: 'secret token'};
|
||||||
t.is(plugins.generateNotes.postprocess(['note 1', 'note 2'], {env}), `note 1${RELEASE_NOTES_SEPARATOR}note 2`);
|
t.is(plugins.generateNotes.postprocess(['note 1', 'note 2'], {env}), `note 1${RELEASE_NOTES_SEPARATOR}note 2`);
|
||||||
|
@ -66,6 +66,25 @@ test('Get all commits since gitHead (from lastRelease) on a detached head repo',
|
|||||||
t.truthy(result[0].committer.name);
|
t.truthy(result[0].committer.name);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('Get all commits between lastRelease.gitHead and a shas', async t => {
|
||||||
|
// Create a git repository, set the current working directory at the root of the repo
|
||||||
|
const {cwd} = await gitRepo();
|
||||||
|
// Add commits to the master branch
|
||||||
|
const commits = await gitCommits(['First', 'Second', 'Third'], {cwd});
|
||||||
|
|
||||||
|
// Retrieve the commits with the commits module, between commit 'First' and 'Third'
|
||||||
|
const result = await getCommits({
|
||||||
|
cwd,
|
||||||
|
lastRelease: {gitHead: commits[commits.length - 1].hash},
|
||||||
|
nextRelease: {gitHead: commits[1].hash},
|
||||||
|
logger: t.context.logger,
|
||||||
|
});
|
||||||
|
|
||||||
|
// Verify the commits created and retrieved by the module are identical
|
||||||
|
t.is(result.length, 1);
|
||||||
|
t.deepEqual(result, commits.slice(1, commits.length - 1));
|
||||||
|
});
|
||||||
|
|
||||||
test('Return empty array if lastRelease.gitHead is the last commit', async t => {
|
test('Return empty array if lastRelease.gitHead is the last commit', async t => {
|
||||||
// Create a git repository, set the current working directory at the root of the repo
|
// Create a git repository, set the current working directory at the root of the repo
|
||||||
const {cwd} = await gitRepo();
|
const {cwd} = await gitRepo();
|
||||||
|
@ -6,7 +6,7 @@ import {omit} from 'lodash';
|
|||||||
import proxyquire from 'proxyquire';
|
import proxyquire from 'proxyquire';
|
||||||
import {stub} from 'sinon';
|
import {stub} from 'sinon';
|
||||||
import yaml from 'js-yaml';
|
import yaml from 'js-yaml';
|
||||||
import {gitRepo, gitCommits, gitShallowClone, gitAddConfig} from './helpers/git-utils';
|
import {gitRepo, gitTagVersion, gitCommits, gitShallowClone, gitAddConfig} from './helpers/git-utils';
|
||||||
|
|
||||||
const DEFAULT_PLUGINS = [
|
const DEFAULT_PLUGINS = [
|
||||||
'@semantic-release/commit-analyzer',
|
'@semantic-release/commit-analyzer',
|
||||||
@ -23,8 +23,10 @@ test.beforeEach(t => {
|
|||||||
test('Default values, reading repositoryUrl from package.json', async t => {
|
test('Default values, reading repositoryUrl from package.json', async t => {
|
||||||
const pkg = {repository: 'https://host.null/owner/package.git'};
|
const pkg = {repository: 'https://host.null/owner/package.git'};
|
||||||
// Create a git repository, set the current working directory at the root of the repo
|
// Create a git repository, set the current working directory at the root of the repo
|
||||||
const {cwd} = await gitRepo();
|
const {cwd} = await gitRepo(true);
|
||||||
await gitCommits(['First'], {cwd});
|
await gitCommits(['First'], {cwd});
|
||||||
|
await gitTagVersion('v1.0.0', undefined, {cwd});
|
||||||
|
await gitTagVersion('v1.1.0', undefined, {cwd});
|
||||||
// Add remote.origin.url config
|
// Add remote.origin.url config
|
||||||
await gitAddConfig('remote.origin.url', 'git@host.null:owner/repo.git', {cwd});
|
await gitAddConfig('remote.origin.url', 'git@host.null:owner/repo.git', {cwd});
|
||||||
// Create package.json in repository root
|
// Create package.json in repository root
|
||||||
@ -33,21 +35,35 @@ test('Default values, reading repositoryUrl from package.json', async t => {
|
|||||||
const {options: result} = await t.context.getConfig({cwd});
|
const {options: result} = await t.context.getConfig({cwd});
|
||||||
|
|
||||||
// Verify the default options are set
|
// Verify the default options are set
|
||||||
t.is(result.branch, 'master');
|
t.deepEqual(result.branches, [
|
||||||
|
'+([0-9])?(.{+([0-9]),x}).x',
|
||||||
|
'master',
|
||||||
|
'next',
|
||||||
|
'next-major',
|
||||||
|
{name: 'beta', prerelease: true},
|
||||||
|
{name: 'alpha', prerelease: true},
|
||||||
|
]);
|
||||||
t.is(result.repositoryUrl, 'https://host.null/owner/package.git');
|
t.is(result.repositoryUrl, 'https://host.null/owner/package.git');
|
||||||
t.is(result.tagFormat, `v\${version}`);
|
t.is(result.tagFormat, `v\${version}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Default values, reading repositoryUrl from repo if not set in package.json', async t => {
|
test('Default values, reading repositoryUrl from repo if not set in package.json', async t => {
|
||||||
// Create a git repository, set the current working directory at the root of the repo
|
// Create a git repository, set the current working directory at the root of the repo
|
||||||
const {cwd} = await gitRepo();
|
const {cwd} = await gitRepo(true);
|
||||||
// Add remote.origin.url config
|
// Add remote.origin.url config
|
||||||
await gitAddConfig('remote.origin.url', 'https://host.null/owner/module.git', {cwd});
|
await gitAddConfig('remote.origin.url', 'https://host.null/owner/module.git', {cwd});
|
||||||
|
|
||||||
const {options: result} = await t.context.getConfig({cwd});
|
const {options: result} = await t.context.getConfig({cwd});
|
||||||
|
|
||||||
// Verify the default options are set
|
// Verify the default options are set
|
||||||
t.is(result.branch, 'master');
|
t.deepEqual(result.branches, [
|
||||||
|
'+([0-9])?(.{+([0-9]),x}).x',
|
||||||
|
'master',
|
||||||
|
'next',
|
||||||
|
'next-major',
|
||||||
|
{name: 'beta', prerelease: true},
|
||||||
|
{name: 'alpha', prerelease: true},
|
||||||
|
]);
|
||||||
t.is(result.repositoryUrl, 'https://host.null/owner/module.git');
|
t.is(result.repositoryUrl, 'https://host.null/owner/module.git');
|
||||||
t.is(result.tagFormat, `v\${version}`);
|
t.is(result.tagFormat, `v\${version}`);
|
||||||
});
|
});
|
||||||
@ -62,7 +78,14 @@ test('Default values, reading repositoryUrl (http url) from package.json if not
|
|||||||
const {options: result} = await t.context.getConfig({cwd});
|
const {options: result} = await t.context.getConfig({cwd});
|
||||||
|
|
||||||
// Verify the default options are set
|
// Verify the default options are set
|
||||||
t.is(result.branch, 'master');
|
t.deepEqual(result.branches, [
|
||||||
|
'+([0-9])?(.{+([0-9]),x}).x',
|
||||||
|
'master',
|
||||||
|
'next',
|
||||||
|
'next-major',
|
||||||
|
{name: 'beta', prerelease: true},
|
||||||
|
{name: 'alpha', prerelease: true},
|
||||||
|
]);
|
||||||
t.is(result.repositoryUrl, 'https://host.null/owner/module.git');
|
t.is(result.repositoryUrl, 'https://host.null/owner/module.git');
|
||||||
t.is(result.tagFormat, `v\${version}`);
|
t.is(result.tagFormat, `v\${version}`);
|
||||||
});
|
});
|
||||||
@ -85,7 +108,7 @@ test('Read options from package.json', async t => {
|
|||||||
const options = {
|
const options = {
|
||||||
analyzeCommits: {path: 'analyzeCommits', param: 'analyzeCommits_param'},
|
analyzeCommits: {path: 'analyzeCommits', param: 'analyzeCommits_param'},
|
||||||
generateNotes: 'generateNotes',
|
generateNotes: 'generateNotes',
|
||||||
branch: 'test_branch',
|
branches: ['test_branch'],
|
||||||
repositoryUrl: 'https://host.null/owner/module.git',
|
repositoryUrl: 'https://host.null/owner/module.git',
|
||||||
tagFormat: `v\${version}`,
|
tagFormat: `v\${version}`,
|
||||||
plugins: false,
|
plugins: false,
|
||||||
@ -95,10 +118,11 @@ test('Read options from package.json', async t => {
|
|||||||
|
|
||||||
const {options: result} = await t.context.getConfig({cwd});
|
const {options: result} = await t.context.getConfig({cwd});
|
||||||
|
|
||||||
|
const expected = {...options, branches: ['test_branch']};
|
||||||
// Verify the options contains the plugin config from package.json
|
// Verify the options contains the plugin config from package.json
|
||||||
t.deepEqual(result, options);
|
t.deepEqual(result, expected);
|
||||||
// Verify the plugins module is called with the plugin options from package.json
|
// Verify the plugins module is called with the plugin options from package.json
|
||||||
t.deepEqual(t.context.plugins.args[0][0], {cwd, options});
|
t.deepEqual(t.context.plugins.args[0][0], {options: expected, cwd});
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Read options from .releaserc.yml', async t => {
|
test('Read options from .releaserc.yml', async t => {
|
||||||
@ -106,7 +130,7 @@ test('Read options from .releaserc.yml', async t => {
|
|||||||
const {cwd} = await gitRepo();
|
const {cwd} = await gitRepo();
|
||||||
const options = {
|
const options = {
|
||||||
analyzeCommits: {path: 'analyzeCommits', param: 'analyzeCommits_param'},
|
analyzeCommits: {path: 'analyzeCommits', param: 'analyzeCommits_param'},
|
||||||
branch: 'test_branch',
|
branches: ['test_branch'],
|
||||||
repositoryUrl: 'https://host.null/owner/module.git',
|
repositoryUrl: 'https://host.null/owner/module.git',
|
||||||
tagFormat: `v\${version}`,
|
tagFormat: `v\${version}`,
|
||||||
plugins: false,
|
plugins: false,
|
||||||
@ -116,10 +140,11 @@ test('Read options from .releaserc.yml', async t => {
|
|||||||
|
|
||||||
const {options: result} = await t.context.getConfig({cwd});
|
const {options: result} = await t.context.getConfig({cwd});
|
||||||
|
|
||||||
|
const expected = {...options, branches: ['test_branch']};
|
||||||
// Verify the options contains the plugin config from package.json
|
// Verify the options contains the plugin config from package.json
|
||||||
t.deepEqual(result, options);
|
t.deepEqual(result, expected);
|
||||||
// Verify the plugins module is called with the plugin options from package.json
|
// Verify the plugins module is called with the plugin options from package.json
|
||||||
t.deepEqual(t.context.plugins.args[0][0], {cwd, options});
|
t.deepEqual(t.context.plugins.args[0][0], {options: expected, cwd});
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Read options from .releaserc.json', async t => {
|
test('Read options from .releaserc.json', async t => {
|
||||||
@ -127,7 +152,7 @@ test('Read options from .releaserc.json', async t => {
|
|||||||
const {cwd} = await gitRepo();
|
const {cwd} = await gitRepo();
|
||||||
const options = {
|
const options = {
|
||||||
analyzeCommits: {path: 'analyzeCommits', param: 'analyzeCommits_param'},
|
analyzeCommits: {path: 'analyzeCommits', param: 'analyzeCommits_param'},
|
||||||
branch: 'test_branch',
|
branches: ['test_branch'],
|
||||||
repositoryUrl: 'https://host.null/owner/module.git',
|
repositoryUrl: 'https://host.null/owner/module.git',
|
||||||
tagFormat: `v\${version}`,
|
tagFormat: `v\${version}`,
|
||||||
plugins: false,
|
plugins: false,
|
||||||
@ -137,10 +162,11 @@ test('Read options from .releaserc.json', async t => {
|
|||||||
|
|
||||||
const {options: result} = await t.context.getConfig({cwd});
|
const {options: result} = await t.context.getConfig({cwd});
|
||||||
|
|
||||||
|
const expected = {...options, branches: ['test_branch']};
|
||||||
// Verify the options contains the plugin config from package.json
|
// Verify the options contains the plugin config from package.json
|
||||||
t.deepEqual(result, options);
|
t.deepEqual(result, expected);
|
||||||
// Verify the plugins module is called with the plugin options from package.json
|
// Verify the plugins module is called with the plugin options from package.json
|
||||||
t.deepEqual(t.context.plugins.args[0][0], {cwd, options});
|
t.deepEqual(t.context.plugins.args[0][0], {options: expected, cwd});
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Read options from .releaserc.js', async t => {
|
test('Read options from .releaserc.js', async t => {
|
||||||
@ -148,7 +174,7 @@ test('Read options from .releaserc.js', async t => {
|
|||||||
const {cwd} = await gitRepo();
|
const {cwd} = await gitRepo();
|
||||||
const options = {
|
const options = {
|
||||||
analyzeCommits: {path: 'analyzeCommits', param: 'analyzeCommits_param'},
|
analyzeCommits: {path: 'analyzeCommits', param: 'analyzeCommits_param'},
|
||||||
branch: 'test_branch',
|
branches: ['test_branch'],
|
||||||
repositoryUrl: 'https://host.null/owner/module.git',
|
repositoryUrl: 'https://host.null/owner/module.git',
|
||||||
tagFormat: `v\${version}`,
|
tagFormat: `v\${version}`,
|
||||||
plugins: false,
|
plugins: false,
|
||||||
@ -158,10 +184,11 @@ test('Read options from .releaserc.js', async t => {
|
|||||||
|
|
||||||
const {options: result} = await t.context.getConfig({cwd});
|
const {options: result} = await t.context.getConfig({cwd});
|
||||||
|
|
||||||
|
const expected = {...options, branches: ['test_branch']};
|
||||||
// Verify the options contains the plugin config from package.json
|
// Verify the options contains the plugin config from package.json
|
||||||
t.deepEqual(result, options);
|
t.deepEqual(result, expected);
|
||||||
// Verify the plugins module is called with the plugin options from package.json
|
// Verify the plugins module is called with the plugin options from package.json
|
||||||
t.deepEqual(t.context.plugins.args[0][0], {cwd, options});
|
t.deepEqual(t.context.plugins.args[0][0], {options: expected, cwd});
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Read options from release.config.js', async t => {
|
test('Read options from release.config.js', async t => {
|
||||||
@ -169,7 +196,7 @@ test('Read options from release.config.js', async t => {
|
|||||||
const {cwd} = await gitRepo();
|
const {cwd} = await gitRepo();
|
||||||
const options = {
|
const options = {
|
||||||
analyzeCommits: {path: 'analyzeCommits', param: 'analyzeCommits_param'},
|
analyzeCommits: {path: 'analyzeCommits', param: 'analyzeCommits_param'},
|
||||||
branch: 'test_branch',
|
branches: ['test_branch'],
|
||||||
repositoryUrl: 'https://host.null/owner/module.git',
|
repositoryUrl: 'https://host.null/owner/module.git',
|
||||||
tagFormat: `v\${version}`,
|
tagFormat: `v\${version}`,
|
||||||
plugins: false,
|
plugins: false,
|
||||||
@ -179,10 +206,11 @@ test('Read options from release.config.js', async t => {
|
|||||||
|
|
||||||
const {options: result} = await t.context.getConfig({cwd});
|
const {options: result} = await t.context.getConfig({cwd});
|
||||||
|
|
||||||
|
const expected = {...options, branches: ['test_branch']};
|
||||||
// Verify the options contains the plugin config from package.json
|
// Verify the options contains the plugin config from package.json
|
||||||
t.deepEqual(result, options);
|
t.deepEqual(result, expected);
|
||||||
// Verify the plugins module is called with the plugin options from package.json
|
// Verify the plugins module is called with the plugin options from package.json
|
||||||
t.deepEqual(t.context.plugins.args[0][0], {cwd, options});
|
t.deepEqual(t.context.plugins.args[0][0], {options: expected, cwd});
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Prioritise CLI/API parameters over file configuration and git repo', async t => {
|
test('Prioritise CLI/API parameters over file configuration and git repo', async t => {
|
||||||
@ -193,11 +221,11 @@ test('Prioritise CLI/API parameters over file configuration and git repo', async
|
|||||||
cwd = await gitShallowClone(repositoryUrl);
|
cwd = await gitShallowClone(repositoryUrl);
|
||||||
const pkgOptions = {
|
const pkgOptions = {
|
||||||
analyzeCommits: {path: 'analyzeCommits', param: 'analyzeCommits_pkg'},
|
analyzeCommits: {path: 'analyzeCommits', param: 'analyzeCommits_pkg'},
|
||||||
branch: 'branch_pkg',
|
branches: ['branch_pkg'],
|
||||||
};
|
};
|
||||||
const options = {
|
const options = {
|
||||||
analyzeCommits: {path: 'analyzeCommits', param: 'analyzeCommits_cli'},
|
analyzeCommits: {path: 'analyzeCommits', param: 'analyzeCommits_cli'},
|
||||||
branch: 'branch_cli',
|
branches: ['branch_cli'],
|
||||||
repositoryUrl: 'http://cli-url.com/owner/package',
|
repositoryUrl: 'http://cli-url.com/owner/package',
|
||||||
tagFormat: `cli\${version}`,
|
tagFormat: `cli\${version}`,
|
||||||
plugins: false,
|
plugins: false,
|
||||||
@ -208,10 +236,11 @@ test('Prioritise CLI/API parameters over file configuration and git repo', async
|
|||||||
|
|
||||||
const result = await t.context.getConfig({cwd}, options);
|
const result = await t.context.getConfig({cwd}, options);
|
||||||
|
|
||||||
|
const expected = {...options, branches: ['branch_cli']};
|
||||||
// Verify the options contains the plugin config from CLI/API
|
// Verify the options contains the plugin config from CLI/API
|
||||||
t.deepEqual(result.options, options);
|
t.deepEqual(result.options, expected);
|
||||||
// Verify the plugins module is called with the plugin options from CLI/API
|
// Verify the plugins module is called with the plugin options from CLI/API
|
||||||
t.deepEqual(t.context.plugins.args[0][0], {cwd, options});
|
t.deepEqual(t.context.plugins.args[0][0], {options: expected, cwd});
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Read configuration from file path in "extends"', async t => {
|
test('Read configuration from file path in "extends"', async t => {
|
||||||
@ -221,7 +250,7 @@ test('Read configuration from file path in "extends"', async t => {
|
|||||||
const options = {
|
const options = {
|
||||||
analyzeCommits: {path: 'analyzeCommits', param: 'analyzeCommits_param'},
|
analyzeCommits: {path: 'analyzeCommits', param: 'analyzeCommits_param'},
|
||||||
generateNotes: 'generateNotes',
|
generateNotes: 'generateNotes',
|
||||||
branch: 'test_branch',
|
branches: ['test_branch'],
|
||||||
repositoryUrl: 'https://host.null/owner/module.git',
|
repositoryUrl: 'https://host.null/owner/module.git',
|
||||||
tagFormat: `v\${version}`,
|
tagFormat: `v\${version}`,
|
||||||
plugins: ['plugin-1', ['plugin-2', {plugin2Opt: 'value'}]],
|
plugins: ['plugin-1', ['plugin-2', {plugin2Opt: 'value'}]],
|
||||||
@ -232,10 +261,11 @@ test('Read configuration from file path in "extends"', async t => {
|
|||||||
|
|
||||||
const {options: result} = await t.context.getConfig({cwd});
|
const {options: result} = await t.context.getConfig({cwd});
|
||||||
|
|
||||||
|
const expected = {...options, branches: ['test_branch']};
|
||||||
// Verify the options contains the plugin config from shareable.json
|
// Verify the options contains the plugin config from shareable.json
|
||||||
t.deepEqual(result, options);
|
t.deepEqual(result, expected);
|
||||||
// Verify the plugins module is called with the plugin options from shareable.json
|
// Verify the plugins module is called with the plugin options from shareable.json
|
||||||
t.deepEqual(t.context.plugins.args[0][0], {cwd, options});
|
t.deepEqual(t.context.plugins.args[0][0], {options: expected, cwd});
|
||||||
t.deepEqual(t.context.plugins.args[0][1], {
|
t.deepEqual(t.context.plugins.args[0][1], {
|
||||||
analyzeCommits: './shareable.json',
|
analyzeCommits: './shareable.json',
|
||||||
generateNotes: './shareable.json',
|
generateNotes: './shareable.json',
|
||||||
@ -251,7 +281,7 @@ test('Read configuration from module path in "extends"', async t => {
|
|||||||
const options = {
|
const options = {
|
||||||
analyzeCommits: {path: 'analyzeCommits', param: 'analyzeCommits_param'},
|
analyzeCommits: {path: 'analyzeCommits', param: 'analyzeCommits_param'},
|
||||||
generateNotes: 'generateNotes',
|
generateNotes: 'generateNotes',
|
||||||
branch: 'test_branch',
|
branches: ['test_branch'],
|
||||||
repositoryUrl: 'https://host.null/owner/module.git',
|
repositoryUrl: 'https://host.null/owner/module.git',
|
||||||
tagFormat: `v\${version}`,
|
tagFormat: `v\${version}`,
|
||||||
plugins: false,
|
plugins: false,
|
||||||
@ -260,12 +290,13 @@ test('Read configuration from module path in "extends"', async t => {
|
|||||||
await outputJson(path.resolve(cwd, 'package.json'), {release: pkgOptions});
|
await outputJson(path.resolve(cwd, 'package.json'), {release: pkgOptions});
|
||||||
await outputJson(path.resolve(cwd, 'node_modules/shareable/index.json'), options);
|
await outputJson(path.resolve(cwd, 'node_modules/shareable/index.json'), options);
|
||||||
|
|
||||||
const {options: results} = await t.context.getConfig({cwd});
|
const {options: result} = await t.context.getConfig({cwd});
|
||||||
|
|
||||||
|
const expected = {...options, branches: ['test_branch']};
|
||||||
// Verify the options contains the plugin config from shareable.json
|
// Verify the options contains the plugin config from shareable.json
|
||||||
t.deepEqual(results, options);
|
t.deepEqual(result, expected);
|
||||||
// Verify the plugins module is called with the plugin options from shareable.json
|
// Verify the plugins module is called with the plugin options from shareable.json
|
||||||
t.deepEqual(t.context.plugins.args[0][0], {cwd, options});
|
t.deepEqual(t.context.plugins.args[0][0], {options: expected, cwd});
|
||||||
t.deepEqual(t.context.plugins.args[0][1], {
|
t.deepEqual(t.context.plugins.args[0][1], {
|
||||||
analyzeCommits: 'shareable',
|
analyzeCommits: 'shareable',
|
||||||
generateNotes: 'shareable',
|
generateNotes: 'shareable',
|
||||||
@ -279,14 +310,14 @@ test('Read configuration from an array of paths in "extends"', async t => {
|
|||||||
const options1 = {
|
const options1 = {
|
||||||
verifyRelease: 'verifyRelease1',
|
verifyRelease: 'verifyRelease1',
|
||||||
analyzeCommits: {path: 'analyzeCommits1', param: 'analyzeCommits_param1'},
|
analyzeCommits: {path: 'analyzeCommits1', param: 'analyzeCommits_param1'},
|
||||||
branch: 'test_branch',
|
branches: ['test_branch'],
|
||||||
repositoryUrl: 'https://host.null/owner/module.git',
|
repositoryUrl: 'https://host.null/owner/module.git',
|
||||||
};
|
};
|
||||||
const options2 = {
|
const options2 = {
|
||||||
verifyRelease: 'verifyRelease2',
|
verifyRelease: 'verifyRelease2',
|
||||||
generateNotes: 'generateNotes2',
|
generateNotes: 'generateNotes2',
|
||||||
analyzeCommits: {path: 'analyzeCommits2', param: 'analyzeCommits_param2'},
|
analyzeCommits: {path: 'analyzeCommits2', param: 'analyzeCommits_param2'},
|
||||||
branch: 'test_branch',
|
branches: ['test_branch'],
|
||||||
tagFormat: `v\${version}`,
|
tagFormat: `v\${version}`,
|
||||||
plugins: false,
|
plugins: false,
|
||||||
};
|
};
|
||||||
@ -295,12 +326,13 @@ test('Read configuration from an array of paths in "extends"', async t => {
|
|||||||
await outputJson(path.resolve(cwd, 'shareable1.json'), options1);
|
await outputJson(path.resolve(cwd, 'shareable1.json'), options1);
|
||||||
await outputJson(path.resolve(cwd, 'shareable2.json'), options2);
|
await outputJson(path.resolve(cwd, 'shareable2.json'), options2);
|
||||||
|
|
||||||
const {options: results} = await t.context.getConfig({cwd});
|
const {options: result} = await t.context.getConfig({cwd});
|
||||||
|
|
||||||
|
const expected = {...options1, ...options2, branches: ['test_branch']};
|
||||||
// Verify the options contains the plugin config from shareable1.json and shareable2.json
|
// Verify the options contains the plugin config from shareable1.json and shareable2.json
|
||||||
t.deepEqual(results, {...options1, ...options2});
|
t.deepEqual(result, expected);
|
||||||
// Verify the plugins module is called with the plugin options from shareable1.json and shareable2.json
|
// Verify the plugins module is called with the plugin options from shareable1.json and shareable2.json
|
||||||
t.deepEqual(t.context.plugins.args[0][0], {cwd, options: {...options1, ...options2}});
|
t.deepEqual(t.context.plugins.args[0][0], {options: expected, cwd});
|
||||||
t.deepEqual(t.context.plugins.args[0][1], {
|
t.deepEqual(t.context.plugins.args[0][1], {
|
||||||
verifyRelease1: './shareable1.json',
|
verifyRelease1: './shareable1.json',
|
||||||
verifyRelease2: './shareable2.json',
|
verifyRelease2: './shareable2.json',
|
||||||
@ -315,7 +347,7 @@ test('Prioritize configuration from config file over "extends"', async t => {
|
|||||||
const {cwd} = await gitRepo();
|
const {cwd} = await gitRepo();
|
||||||
const pkgOptions = {
|
const pkgOptions = {
|
||||||
extends: './shareable.json',
|
extends: './shareable.json',
|
||||||
branch: 'test_pkg',
|
branches: ['test_pkg'],
|
||||||
generateNotes: 'generateNotes',
|
generateNotes: 'generateNotes',
|
||||||
publish: [{path: 'publishPkg', param: 'publishPkg_param'}],
|
publish: [{path: 'publishPkg', param: 'publishPkg_param'}],
|
||||||
};
|
};
|
||||||
@ -323,7 +355,7 @@ test('Prioritize configuration from config file over "extends"', async t => {
|
|||||||
analyzeCommits: 'analyzeCommits',
|
analyzeCommits: 'analyzeCommits',
|
||||||
generateNotes: 'generateNotesShareable',
|
generateNotes: 'generateNotesShareable',
|
||||||
publish: [{path: 'publishShareable', param: 'publishShareable_param'}],
|
publish: [{path: 'publishShareable', param: 'publishShareable_param'}],
|
||||||
branch: 'test_branch',
|
branches: ['test_branch'],
|
||||||
repositoryUrl: 'https://host.null/owner/module.git',
|
repositoryUrl: 'https://host.null/owner/module.git',
|
||||||
tagFormat: `v\${version}`,
|
tagFormat: `v\${version}`,
|
||||||
plugins: false,
|
plugins: false,
|
||||||
@ -332,12 +364,13 @@ test('Prioritize configuration from config file over "extends"', async t => {
|
|||||||
await outputJson(path.resolve(cwd, 'package.json'), {release: pkgOptions});
|
await outputJson(path.resolve(cwd, 'package.json'), {release: pkgOptions});
|
||||||
await outputJson(path.resolve(cwd, 'shareable.json'), options1);
|
await outputJson(path.resolve(cwd, 'shareable.json'), options1);
|
||||||
|
|
||||||
const {options} = await t.context.getConfig({cwd});
|
const {options: result} = await t.context.getConfig({cwd});
|
||||||
|
|
||||||
|
const expected = omit({...options1, ...pkgOptions, branches: ['test_pkg']}, 'extends');
|
||||||
// Verify the options contains the plugin config from package.json and shareable.json
|
// Verify the options contains the plugin config from package.json and shareable.json
|
||||||
t.deepEqual(options, omit({...options1, ...pkgOptions}, 'extends'));
|
t.deepEqual(result, expected);
|
||||||
// Verify the plugins module is called with the plugin options from package.json and shareable.json
|
// Verify the plugins module is called with the plugin options from package.json and shareable.json
|
||||||
t.deepEqual(t.context.plugins.args[0][0], {cwd, options: omit({...options, ...pkgOptions}, 'extends')});
|
t.deepEqual(t.context.plugins.args[0][0], {options: expected, cwd});
|
||||||
t.deepEqual(t.context.plugins.args[0][1], {
|
t.deepEqual(t.context.plugins.args[0][1], {
|
||||||
analyzeCommits: './shareable.json',
|
analyzeCommits: './shareable.json',
|
||||||
generateNotesShareable: './shareable.json',
|
generateNotesShareable: './shareable.json',
|
||||||
@ -350,13 +383,13 @@ test('Prioritize configuration from cli/API options over "extends"', async t =>
|
|||||||
const {cwd} = await gitRepo();
|
const {cwd} = await gitRepo();
|
||||||
const cliOptions = {
|
const cliOptions = {
|
||||||
extends: './shareable2.json',
|
extends: './shareable2.json',
|
||||||
branch: 'branch_opts',
|
branches: ['branch_opts'],
|
||||||
publish: [{path: 'publishOpts', param: 'publishOpts_param'}],
|
publish: [{path: 'publishOpts', param: 'publishOpts_param'}],
|
||||||
repositoryUrl: 'https://host.null/owner/module.git',
|
repositoryUrl: 'https://host.null/owner/module.git',
|
||||||
};
|
};
|
||||||
const pkgOptions = {
|
const pkgOptions = {
|
||||||
extends: './shareable1.json',
|
extends: './shareable1.json',
|
||||||
branch: 'branch_pkg',
|
branches: ['branch_pkg'],
|
||||||
generateNotes: 'generateNotes',
|
generateNotes: 'generateNotes',
|
||||||
publish: [{path: 'publishPkg', param: 'publishPkg_param'}],
|
publish: [{path: 'publishPkg', param: 'publishPkg_param'}],
|
||||||
};
|
};
|
||||||
@ -364,13 +397,13 @@ test('Prioritize configuration from cli/API options over "extends"', async t =>
|
|||||||
analyzeCommits: 'analyzeCommits1',
|
analyzeCommits: 'analyzeCommits1',
|
||||||
generateNotes: 'generateNotesShareable1',
|
generateNotes: 'generateNotesShareable1',
|
||||||
publish: [{path: 'publishShareable', param: 'publishShareable_param1'}],
|
publish: [{path: 'publishShareable', param: 'publishShareable_param1'}],
|
||||||
branch: 'test_branch1',
|
branches: ['test_branch1'],
|
||||||
repositoryUrl: 'https://host.null/owner/module.git',
|
repositoryUrl: 'https://host.null/owner/module.git',
|
||||||
};
|
};
|
||||||
const options2 = {
|
const options2 = {
|
||||||
analyzeCommits: 'analyzeCommits2',
|
analyzeCommits: 'analyzeCommits2',
|
||||||
publish: [{path: 'publishShareable', param: 'publishShareable_param2'}],
|
publish: [{path: 'publishShareable', param: 'publishShareable_param2'}],
|
||||||
branch: 'test_branch2',
|
branches: ['test_branch2'],
|
||||||
tagFormat: `v\${version}`,
|
tagFormat: `v\${version}`,
|
||||||
plugins: false,
|
plugins: false,
|
||||||
};
|
};
|
||||||
@ -379,15 +412,13 @@ test('Prioritize configuration from cli/API options over "extends"', async t =>
|
|||||||
await outputJson(path.resolve(cwd, 'shareable1.json'), options1);
|
await outputJson(path.resolve(cwd, 'shareable1.json'), options1);
|
||||||
await outputJson(path.resolve(cwd, 'shareable2.json'), options2);
|
await outputJson(path.resolve(cwd, 'shareable2.json'), options2);
|
||||||
|
|
||||||
const {options} = await t.context.getConfig({cwd}, cliOptions);
|
const {options: result} = await t.context.getConfig({cwd}, cliOptions);
|
||||||
|
|
||||||
|
const expected = omit({...options2, ...pkgOptions, ...cliOptions, branches: ['branch_opts']}, 'extends');
|
||||||
// Verify the options contains the plugin config from package.json and shareable2.json
|
// Verify the options contains the plugin config from package.json and shareable2.json
|
||||||
t.deepEqual(options, omit({...options2, ...pkgOptions, ...cliOptions}, 'extends'));
|
t.deepEqual(result, expected);
|
||||||
// Verify the plugins module is called with the plugin options from package.json and shareable2.json
|
// Verify the plugins module is called with the plugin options from package.json and shareable2.json
|
||||||
t.deepEqual(t.context.plugins.args[0][0], {
|
t.deepEqual(t.context.plugins.args[0][0], {options: expected, cwd});
|
||||||
cwd,
|
|
||||||
options: omit({...options2, ...pkgOptions, ...cliOptions}, 'extends'),
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Allow to unset properties defined in shareable config with "null"', async t => {
|
test('Allow to unset properties defined in shareable config with "null"', async t => {
|
||||||
@ -396,7 +427,7 @@ test('Allow to unset properties defined in shareable config with "null"', async
|
|||||||
const pkgOptions = {
|
const pkgOptions = {
|
||||||
extends: './shareable.json',
|
extends: './shareable.json',
|
||||||
analyzeCommits: null,
|
analyzeCommits: null,
|
||||||
branch: 'test_branch',
|
branches: ['test_branch'],
|
||||||
repositoryUrl: 'https://host.null/owner/module.git',
|
repositoryUrl: 'https://host.null/owner/module.git',
|
||||||
plugins: null,
|
plugins: null,
|
||||||
};
|
};
|
||||||
@ -427,6 +458,7 @@ test('Allow to unset properties defined in shareable config with "null"', async
|
|||||||
},
|
},
|
||||||
cwd,
|
cwd,
|
||||||
});
|
});
|
||||||
|
|
||||||
t.deepEqual(t.context.plugins.args[0][1], {
|
t.deepEqual(t.context.plugins.args[0][1], {
|
||||||
generateNotes: './shareable.json',
|
generateNotes: './shareable.json',
|
||||||
analyzeCommits: './shareable.json',
|
analyzeCommits: './shareable.json',
|
||||||
@ -440,7 +472,7 @@ test('Allow to unset properties defined in shareable config with "undefined"', a
|
|||||||
const pkgOptions = {
|
const pkgOptions = {
|
||||||
extends: './shareable.json',
|
extends: './shareable.json',
|
||||||
analyzeCommits: undefined,
|
analyzeCommits: undefined,
|
||||||
branch: 'test_branch',
|
branches: ['test_branch'],
|
||||||
repositoryUrl: 'https://host.null/owner/module.git',
|
repositoryUrl: 'https://host.null/owner/module.git',
|
||||||
};
|
};
|
||||||
const options1 = {
|
const options1 = {
|
||||||
@ -453,18 +485,17 @@ test('Allow to unset properties defined in shareable config with "undefined"', a
|
|||||||
await writeFile(path.resolve(cwd, 'release.config.js'), `module.exports = ${format(pkgOptions)}`);
|
await writeFile(path.resolve(cwd, 'release.config.js'), `module.exports = ${format(pkgOptions)}`);
|
||||||
await outputJson(path.resolve(cwd, 'shareable.json'), options1);
|
await outputJson(path.resolve(cwd, 'shareable.json'), options1);
|
||||||
|
|
||||||
const {options} = await t.context.getConfig({cwd});
|
const {options: result} = await t.context.getConfig({cwd});
|
||||||
|
|
||||||
// Verify the options contains the plugin config from shareable.json
|
const expected = {
|
||||||
t.deepEqual(options, {...omit(options1, 'analyzeCommits'), ...omit(pkgOptions, ['extends', 'analyzeCommits'])});
|
|
||||||
// Verify the plugins module is called with the plugin options from shareable.json
|
|
||||||
t.deepEqual(t.context.plugins.args[0][0], {
|
|
||||||
options: {
|
|
||||||
...omit(options1, 'analyzeCommits'),
|
...omit(options1, 'analyzeCommits'),
|
||||||
...omit(pkgOptions, ['extends', 'analyzeCommits']),
|
...omit(pkgOptions, ['extends', 'analyzeCommits']),
|
||||||
},
|
branches: ['test_branch'],
|
||||||
cwd,
|
};
|
||||||
});
|
// Verify the options contains the plugin config from shareable.json
|
||||||
|
t.deepEqual(result, expected);
|
||||||
|
// Verify the plugins module is called with the plugin options from shareable.json
|
||||||
|
t.deepEqual(t.context.plugins.args[0][0], {options: expected, cwd});
|
||||||
t.deepEqual(t.context.plugins.args[0][1], {
|
t.deepEqual(t.context.plugins.args[0][1], {
|
||||||
generateNotes: './shareable.json',
|
generateNotes: './shareable.json',
|
||||||
analyzeCommits: './shareable.json',
|
analyzeCommits: './shareable.json',
|
||||||
|
@ -8,7 +8,7 @@ test('Return the same "git" formatted URL if "gitCredentials" is not defined', a
|
|||||||
const {cwd} = await gitRepo();
|
const {cwd} = await gitRepo();
|
||||||
|
|
||||||
t.is(
|
t.is(
|
||||||
await getAuthUrl({cwd, env, options: {branch: 'master', repositoryUrl: 'git@host.null:owner/repo.git'}}),
|
await getAuthUrl({cwd, env, branch: {name: 'master'}, options: {repositoryUrl: 'git@host.null:owner/repo.git'}}),
|
||||||
'git@host.null:owner/repo.git'
|
'git@host.null:owner/repo.git'
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@ -17,7 +17,12 @@ test('Return the same "https" formatted URL if "gitCredentials" is not defined',
|
|||||||
const {cwd} = await gitRepo();
|
const {cwd} = await gitRepo();
|
||||||
|
|
||||||
t.is(
|
t.is(
|
||||||
await getAuthUrl({cwd, env, options: {branch: 'master', repositoryUrl: 'https://host.null/owner/repo.git'}}),
|
await getAuthUrl({
|
||||||
|
cwd,
|
||||||
|
env,
|
||||||
|
branch: {name: 'master'},
|
||||||
|
options: {repositoryUrl: 'https://host.null/owner/repo.git'},
|
||||||
|
}),
|
||||||
'https://host.null/owner/repo.git'
|
'https://host.null/owner/repo.git'
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@ -26,7 +31,12 @@ test('Return the "https" formatted URL if "gitCredentials" is not defined and re
|
|||||||
const {cwd} = await gitRepo();
|
const {cwd} = await gitRepo();
|
||||||
|
|
||||||
t.is(
|
t.is(
|
||||||
await getAuthUrl({cwd, env, options: {branch: 'master', repositoryUrl: 'git+https://host.null/owner/repo.git'}}),
|
await getAuthUrl({
|
||||||
|
cwd,
|
||||||
|
env,
|
||||||
|
branch: {name: 'master'},
|
||||||
|
options: {repositoryUrl: 'git+https://host.null/owner/repo.git'},
|
||||||
|
}),
|
||||||
'https://host.null/owner/repo.git'
|
'https://host.null/owner/repo.git'
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@ -35,7 +45,7 @@ test('Do not add trailing ".git" if not present in the origian URL', async t =>
|
|||||||
const {cwd} = await gitRepo();
|
const {cwd} = await gitRepo();
|
||||||
|
|
||||||
t.is(
|
t.is(
|
||||||
await getAuthUrl({cwd, env, options: {branch: 'master', repositoryUrl: 'git@host.null:owner/repo'}}),
|
await getAuthUrl({cwd, env, vranch: {name: 'master'}, options: {repositoryUrl: 'git@host.null:owner/repo'}}),
|
||||||
'git@host.null:owner/repo'
|
'git@host.null:owner/repo'
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@ -47,7 +57,8 @@ test('Handle "https" URL with group and subgroup', async t => {
|
|||||||
await getAuthUrl({
|
await getAuthUrl({
|
||||||
cwd,
|
cwd,
|
||||||
env,
|
env,
|
||||||
options: {branch: 'master', repositoryUrl: 'https://host.null/group/subgroup/owner/repo.git'},
|
branch: {name: 'master'},
|
||||||
|
options: {repositoryUrl: 'https://host.null/group/subgroup/owner/repo.git'},
|
||||||
}),
|
}),
|
||||||
'https://host.null/group/subgroup/owner/repo.git'
|
'https://host.null/group/subgroup/owner/repo.git'
|
||||||
);
|
);
|
||||||
@ -60,7 +71,8 @@ test('Handle "git" URL with group and subgroup', async t => {
|
|||||||
await getAuthUrl({
|
await getAuthUrl({
|
||||||
cwd,
|
cwd,
|
||||||
env,
|
env,
|
||||||
options: {branch: 'master', repositoryUrl: 'git@host.null:group/subgroup/owner/repo.git'},
|
branch: {name: 'master'},
|
||||||
|
options: {repositoryUrl: 'git@host.null:group/subgroup/owner/repo.git'},
|
||||||
}),
|
}),
|
||||||
'git@host.null:group/subgroup/owner/repo.git'
|
'git@host.null:group/subgroup/owner/repo.git'
|
||||||
);
|
);
|
||||||
@ -70,7 +82,12 @@ test('Convert shorthand URL', async t => {
|
|||||||
const {cwd} = await gitRepo();
|
const {cwd} = await gitRepo();
|
||||||
|
|
||||||
t.is(
|
t.is(
|
||||||
await getAuthUrl({cwd, env, options: {repositoryUrl: 'semantic-release/semantic-release'}}),
|
await getAuthUrl({
|
||||||
|
cwd,
|
||||||
|
env,
|
||||||
|
branch: {name: 'master'},
|
||||||
|
options: {repositoryUrl: 'semantic-release/semantic-release'},
|
||||||
|
}),
|
||||||
'https://github.com/semantic-release/semantic-release.git'
|
'https://github.com/semantic-release/semantic-release.git'
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@ -82,7 +99,8 @@ test('Convert GitLab shorthand URL', async t => {
|
|||||||
await getAuthUrl({
|
await getAuthUrl({
|
||||||
cwd,
|
cwd,
|
||||||
env,
|
env,
|
||||||
options: {branch: 'master', repositoryUrl: 'gitlab:semantic-release/semantic-release'},
|
branch: {name: 'master'},
|
||||||
|
options: {repositoryUrl: 'gitlab:semantic-release/semantic-release'},
|
||||||
}),
|
}),
|
||||||
'https://gitlab.com/semantic-release/semantic-release.git'
|
'https://gitlab.com/semantic-release/semantic-release.git'
|
||||||
);
|
);
|
||||||
@ -95,7 +113,8 @@ test('Return the "https" formatted URL if "gitCredentials" is defined and reposi
|
|||||||
await getAuthUrl({
|
await getAuthUrl({
|
||||||
cwd,
|
cwd,
|
||||||
env: {...env, GIT_CREDENTIALS: 'user:pass'},
|
env: {...env, GIT_CREDENTIALS: 'user:pass'},
|
||||||
options: {branch: 'master', repositoryUrl: 'git@host.null:owner/repo.git'},
|
branch: {name: 'master'},
|
||||||
|
options: {repositoryUrl: 'git@host.null:owner/repo.git'},
|
||||||
}),
|
}),
|
||||||
'https://user:pass@host.null/owner/repo.git'
|
'https://user:pass@host.null/owner/repo.git'
|
||||||
);
|
);
|
||||||
@ -121,7 +140,8 @@ test('Return the "https" formatted URL if "gitCredentials" is defined and reposi
|
|||||||
await getAuthUrl({
|
await getAuthUrl({
|
||||||
cwd,
|
cwd,
|
||||||
env: {...env, GIT_CREDENTIALS: 'user:pass'},
|
env: {...env, GIT_CREDENTIALS: 'user:pass'},
|
||||||
options: {branch: 'master', repositoryUrl: 'https://host.null/owner/repo.git'},
|
branch: {name: 'master'},
|
||||||
|
options: {repositoryUrl: 'https://host.null/owner/repo.git'},
|
||||||
}),
|
}),
|
||||||
'https://user:pass@host.null/owner/repo.git'
|
'https://user:pass@host.null/owner/repo.git'
|
||||||
);
|
);
|
||||||
@ -134,7 +154,8 @@ test('Return the "http" formatted URL if "gitCredentials" is defined and reposit
|
|||||||
await getAuthUrl({
|
await getAuthUrl({
|
||||||
cwd,
|
cwd,
|
||||||
env: {...env, GIT_CREDENTIALS: 'user:pass'},
|
env: {...env, GIT_CREDENTIALS: 'user:pass'},
|
||||||
options: {branch: 'master', repositoryUrl: 'http://host.null/owner/repo.git'},
|
branch: {name: 'master'},
|
||||||
|
options: {repositoryUrl: 'http://host.null/owner/repo.git'},
|
||||||
}),
|
}),
|
||||||
'http://user:pass@host.null/owner/repo.git'
|
'http://user:pass@host.null/owner/repo.git'
|
||||||
);
|
);
|
||||||
@ -160,7 +181,8 @@ test('Return the "https" formatted URL if "gitCredentials" is defined and reposi
|
|||||||
await getAuthUrl({
|
await getAuthUrl({
|
||||||
cwd,
|
cwd,
|
||||||
env: {...env, GIT_CREDENTIALS: 'user:pass'},
|
env: {...env, GIT_CREDENTIALS: 'user:pass'},
|
||||||
options: {branch: 'master', repositoryUrl: 'git+https://host.null/owner/repo.git'},
|
branch: {name: 'master'},
|
||||||
|
options: {repositoryUrl: 'git+https://host.null/owner/repo.git'},
|
||||||
}),
|
}),
|
||||||
'https://user:pass@host.null/owner/repo.git'
|
'https://user:pass@host.null/owner/repo.git'
|
||||||
);
|
);
|
||||||
@ -173,7 +195,8 @@ test('Return the "http" formatted URL if "gitCredentials" is defined and reposit
|
|||||||
await getAuthUrl({
|
await getAuthUrl({
|
||||||
cwd,
|
cwd,
|
||||||
env: {...env, GIT_CREDENTIALS: 'user:pass'},
|
env: {...env, GIT_CREDENTIALS: 'user:pass'},
|
||||||
options: {branch: 'master', repositoryUrl: 'git+http://host.null/owner/repo.git'},
|
branch: {name: 'master'},
|
||||||
|
options: {repositoryUrl: 'git+http://host.null/owner/repo.git'},
|
||||||
}),
|
}),
|
||||||
'http://user:pass@host.null/owner/repo.git'
|
'http://user:pass@host.null/owner/repo.git'
|
||||||
);
|
);
|
||||||
@ -199,7 +222,8 @@ test('Return the "https" formatted URL if "gitCredentials" is defined with "GH_T
|
|||||||
await getAuthUrl({
|
await getAuthUrl({
|
||||||
cwd,
|
cwd,
|
||||||
env: {...env, GH_TOKEN: 'token'},
|
env: {...env, GH_TOKEN: 'token'},
|
||||||
options: {branch: 'master', repositoryUrl: 'git@host.null:owner/repo.git'},
|
branch: {name: 'master'},
|
||||||
|
options: {repositoryUrl: 'git@host.null:owner/repo.git'},
|
||||||
}),
|
}),
|
||||||
'https://token@host.null/owner/repo.git'
|
'https://token@host.null/owner/repo.git'
|
||||||
);
|
);
|
||||||
@ -212,7 +236,8 @@ test('Return the "https" formatted URL if "gitCredentials" is defined with "GITH
|
|||||||
await getAuthUrl({
|
await getAuthUrl({
|
||||||
cwd,
|
cwd,
|
||||||
env: {...env, GITHUB_TOKEN: 'token'},
|
env: {...env, GITHUB_TOKEN: 'token'},
|
||||||
options: {branch: 'master', repositoryUrl: 'git@host.null:owner/repo.git'},
|
branch: {name: 'master'},
|
||||||
|
options: {repositoryUrl: 'git@host.null:owner/repo.git'},
|
||||||
}),
|
}),
|
||||||
'https://token@host.null/owner/repo.git'
|
'https://token@host.null/owner/repo.git'
|
||||||
);
|
);
|
||||||
@ -225,7 +250,8 @@ test('Return the "https" formatted URL if "gitCredentials" is defined with "GL_T
|
|||||||
await getAuthUrl({
|
await getAuthUrl({
|
||||||
cwd,
|
cwd,
|
||||||
env: {...env, GL_TOKEN: 'token'},
|
env: {...env, GL_TOKEN: 'token'},
|
||||||
options: {branch: 'master', repositoryUrl: 'git@host.null:owner/repo.git'},
|
branch: {name: 'master'},
|
||||||
|
options: {repositoryUrl: 'git@host.null:owner/repo.git'},
|
||||||
}),
|
}),
|
||||||
'https://gitlab-ci-token:token@host.null/owner/repo.git'
|
'https://gitlab-ci-token:token@host.null/owner/repo.git'
|
||||||
);
|
);
|
||||||
@ -238,7 +264,8 @@ test('Return the "https" formatted URL if "gitCredentials" is defined with "GITL
|
|||||||
await getAuthUrl({
|
await getAuthUrl({
|
||||||
cwd,
|
cwd,
|
||||||
env: {...env, GITLAB_TOKEN: 'token'},
|
env: {...env, GITLAB_TOKEN: 'token'},
|
||||||
options: {branch: 'master', repositoryUrl: 'git@host.null:owner/repo.git'},
|
branch: {name: 'master'},
|
||||||
|
options: {repositoryUrl: 'git@host.null:owner/repo.git'},
|
||||||
}),
|
}),
|
||||||
'https://gitlab-ci-token:token@host.null/owner/repo.git'
|
'https://gitlab-ci-token:token@host.null/owner/repo.git'
|
||||||
);
|
);
|
||||||
@ -251,7 +278,8 @@ test('Return the "https" formatted URL if "gitCredentials" is defined with "BB_T
|
|||||||
await getAuthUrl({
|
await getAuthUrl({
|
||||||
cwd,
|
cwd,
|
||||||
env: {...env, BB_TOKEN: 'token'},
|
env: {...env, BB_TOKEN: 'token'},
|
||||||
options: {branch: 'master', repositoryUrl: 'git@host.null:owner/repo.git'},
|
branch: {name: 'master'},
|
||||||
|
options: {repositoryUrl: 'git@host.null:owner/repo.git'},
|
||||||
}),
|
}),
|
||||||
'https://x-token-auth:token@host.null/owner/repo.git'
|
'https://x-token-auth:token@host.null/owner/repo.git'
|
||||||
);
|
);
|
||||||
@ -264,7 +292,8 @@ test('Return the "https" formatted URL if "gitCredentials" is defined with "BITB
|
|||||||
await getAuthUrl({
|
await getAuthUrl({
|
||||||
cwd,
|
cwd,
|
||||||
env: {...env, BITBUCKET_TOKEN: 'token'},
|
env: {...env, BITBUCKET_TOKEN: 'token'},
|
||||||
options: {branch: 'master', repositoryUrl: 'git@host.null:owner/repo.git'},
|
branch: {name: 'master'},
|
||||||
|
options: {repositoryUrl: 'git@host.null:owner/repo.git'},
|
||||||
}),
|
}),
|
||||||
'https://x-token-auth:token@host.null/owner/repo.git'
|
'https://x-token-auth:token@host.null/owner/repo.git'
|
||||||
);
|
);
|
||||||
@ -290,7 +319,8 @@ test('Handle "https" URL with group and subgroup, with "GIT_CREDENTIALS"', async
|
|||||||
await getAuthUrl({
|
await getAuthUrl({
|
||||||
cwd,
|
cwd,
|
||||||
env: {...env, GIT_CREDENTIALS: 'user:pass'},
|
env: {...env, GIT_CREDENTIALS: 'user:pass'},
|
||||||
options: {branch: 'master', repositoryUrl: 'https://host.null/group/subgroup/owner/repo.git'},
|
branch: {name: 'master'},
|
||||||
|
options: {repositoryUrl: 'https://host.null/group/subgroup/owner/repo.git'},
|
||||||
}),
|
}),
|
||||||
'https://user:pass@host.null/group/subgroup/owner/repo.git'
|
'https://user:pass@host.null/group/subgroup/owner/repo.git'
|
||||||
);
|
);
|
||||||
@ -303,7 +333,8 @@ test('Handle "git" URL with group and subgroup, with "GIT_CREDENTIALS', async t
|
|||||||
await getAuthUrl({
|
await getAuthUrl({
|
||||||
cwd,
|
cwd,
|
||||||
env: {...env, GIT_CREDENTIALS: 'user:pass'},
|
env: {...env, GIT_CREDENTIALS: 'user:pass'},
|
||||||
options: {branch: 'master', repositoryUrl: 'git@host.null:group/subgroup/owner/repo.git'},
|
branch: {name: 'master'},
|
||||||
|
options: {repositoryUrl: 'git@host.null:group/subgroup/owner/repo.git'},
|
||||||
}),
|
}),
|
||||||
'https://user:pass@host.null/group/subgroup/owner/repo.git'
|
'https://user:pass@host.null/group/subgroup/owner/repo.git'
|
||||||
);
|
);
|
||||||
@ -313,7 +344,12 @@ test('Do not add git credential to repositoryUrl if push is allowed', async t =>
|
|||||||
const {cwd, repositoryUrl} = await gitRepo(true);
|
const {cwd, repositoryUrl} = await gitRepo(true);
|
||||||
|
|
||||||
t.is(
|
t.is(
|
||||||
await getAuthUrl({cwd, env: {...env, GIT_CREDENTIALS: 'user:pass'}, options: {branch: 'master', repositoryUrl}}),
|
await getAuthUrl({
|
||||||
|
cwd,
|
||||||
|
env: {...env, GIT_CREDENTIALS: 'user:pass'},
|
||||||
|
branch: {name: 'master'},
|
||||||
|
options: {repositoryUrl},
|
||||||
|
}),
|
||||||
repositoryUrl
|
repositoryUrl
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
@ -1,151 +1,80 @@
|
|||||||
import test from 'ava';
|
import test from 'ava';
|
||||||
import {stub} from 'sinon';
|
|
||||||
import getLastRelease from '../lib/get-last-release';
|
import getLastRelease from '../lib/get-last-release';
|
||||||
import {gitRepo, gitCommits, gitTagVersion, gitCheckout} from './helpers/git-utils';
|
|
||||||
|
|
||||||
test.beforeEach(t => {
|
test('Get the highest non-prerelease valid tag', t => {
|
||||||
// Stub the logger functions
|
const result = getLastRelease({
|
||||||
t.context.log = stub();
|
branch: {
|
||||||
t.context.logger = {log: t.context.log};
|
name: 'master',
|
||||||
|
tags: [
|
||||||
|
{version: '2.0.0', gitTag: 'v2.0.0', gitHead: 'v2.0.0'},
|
||||||
|
{version: '1.0.0', gitTag: 'v1.0.0', gitHead: 'v1.0.0'},
|
||||||
|
{version: '3.0.0-beta.1', gitTag: 'v3.0.0-beta.1', gitHead: 'v3.0.0-beta.1'},
|
||||||
|
],
|
||||||
|
type: 'release',
|
||||||
|
},
|
||||||
|
options: {tagFormat: `v\${version}`},
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Get the highest non-prerelease valid tag', async t => {
|
t.deepEqual(result, {version: '2.0.0', gitTag: 'v2.0.0', name: 'v2.0.0', gitHead: 'v2.0.0', channels: undefined});
|
||||||
// Create a git repository, set the current working directory at the root of the repo
|
|
||||||
const {cwd} = await gitRepo();
|
|
||||||
// Create some commits and tags
|
|
||||||
await gitCommits(['First'], {cwd});
|
|
||||||
await gitTagVersion('foo', undefined, {cwd});
|
|
||||||
const commits = await gitCommits(['Second'], {cwd});
|
|
||||||
await gitTagVersion('v2.0.0', undefined, {cwd});
|
|
||||||
await gitCommits(['Third'], {cwd});
|
|
||||||
await gitTagVersion('v1.0.0', undefined, {cwd});
|
|
||||||
await gitCommits(['Fourth'], {cwd});
|
|
||||||
await gitTagVersion('v3.0', undefined, {cwd});
|
|
||||||
await gitCommits(['Fifth'], {cwd});
|
|
||||||
await gitTagVersion('v3.0.0-beta.1', undefined, {cwd});
|
|
||||||
|
|
||||||
const result = await getLastRelease({cwd, options: {tagFormat: `v\${version}`}, logger: t.context.logger});
|
|
||||||
|
|
||||||
t.deepEqual(result, {gitHead: commits[0].hash, gitTag: 'v2.0.0', version: '2.0.0'});
|
|
||||||
t.deepEqual(t.context.log.args[0], ['Found git tag v2.0.0 associated with version 2.0.0']);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Get the highest tag in the history of the current branch', async t => {
|
test('Get the highest prerelease valid tag, ignoring other tags from other prerelease channels', t => {
|
||||||
// Create a git repository, set the current working directory at the root of the repo
|
const result = getLastRelease({
|
||||||
const {cwd} = await gitRepo();
|
branch: {
|
||||||
// Add commit to the master branch
|
name: 'beta',
|
||||||
await gitCommits(['First'], {cwd});
|
prerelease: 'beta',
|
||||||
// Create the tag corresponding to version 1.0.0
|
channel: 'beta',
|
||||||
// Create the new branch 'other-branch' from master
|
tags: [
|
||||||
await gitCheckout('other-branch', true, {cwd});
|
{version: '1.0.0-beta.1', gitTag: 'v1.0.0-beta.1', gitHead: 'v1.0.0-beta.1', channels: ['beta']},
|
||||||
// Add commit to the 'other-branch' branch
|
{version: '1.0.0-beta.2', gitTag: 'v1.0.0-beta.2', gitHead: 'v1.0.0-beta.2', channels: ['beta']},
|
||||||
await gitCommits(['Second'], {cwd});
|
{version: '1.0.0-alpha.1', gitTag: 'v1.0.0-alpha.1', gitHead: 'v1.0.0-alpha.1', channels: ['alpha']},
|
||||||
// Create the tag corresponding to version 3.0.0
|
],
|
||||||
await gitTagVersion('v3.0.0', undefined, {cwd});
|
type: 'prerelease',
|
||||||
// Checkout master
|
},
|
||||||
await gitCheckout('master', false, {cwd});
|
options: {tagFormat: `v\${version}`},
|
||||||
// Add another commit to the master branch
|
|
||||||
const commits = await gitCommits(['Third'], {cwd});
|
|
||||||
// Create the tag corresponding to version 2.0.0
|
|
||||||
await gitTagVersion('v2.0.0', undefined, {cwd});
|
|
||||||
|
|
||||||
const result = await getLastRelease({cwd, options: {tagFormat: `v\${version}`}, logger: t.context.logger});
|
|
||||||
|
|
||||||
t.deepEqual(result, {gitHead: commits[0].hash, gitTag: 'v2.0.0', version: '2.0.0'});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Match the tag name from the begining of the string', async t => {
|
t.deepEqual(result, {
|
||||||
// Create a git repository, set the current working directory at the root of the repo
|
version: '1.0.0-beta.2',
|
||||||
const {cwd} = await gitRepo();
|
gitTag: 'v1.0.0-beta.2',
|
||||||
const commits = await gitCommits(['First'], {cwd});
|
name: 'v1.0.0-beta.2',
|
||||||
await gitTagVersion('prefix/v1.0.0', undefined, {cwd});
|
gitHead: 'v1.0.0-beta.2',
|
||||||
await gitTagVersion('prefix/v2.0.0', undefined, {cwd});
|
channels: ['beta'],
|
||||||
await gitTagVersion('other-prefix/v3.0.0', undefined, {cwd});
|
});
|
||||||
|
|
||||||
const result = await getLastRelease({cwd, options: {tagFormat: `prefix/v\${version}`}, logger: t.context.logger});
|
|
||||||
|
|
||||||
t.deepEqual(result, {gitHead: commits[0].hash, gitTag: 'prefix/v2.0.0', version: '2.0.0'});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Return empty object if no valid tag is found', async t => {
|
test('Return empty object if no valid tag is found', t => {
|
||||||
// Create a git repository, set the current working directory at the root of the repo
|
const result = getLastRelease({
|
||||||
const {cwd} = await gitRepo();
|
branch: {
|
||||||
// Create some commits and tags
|
name: 'master',
|
||||||
await gitCommits(['First'], {cwd});
|
tags: [{version: '3.0.0-beta.1', gitTag: 'v3.0.0-beta.1', gitHead: 'v3.0.0-beta.1'}],
|
||||||
await gitTagVersion('foo', undefined, {cwd});
|
type: 'release',
|
||||||
await gitCommits(['Second'], {cwd});
|
},
|
||||||
await gitTagVersion('v2.0.x', undefined, {cwd});
|
options: {tagFormat: `v\${version}`},
|
||||||
await gitCommits(['Third'], {cwd});
|
});
|
||||||
await gitTagVersion('v3.0', undefined, {cwd});
|
|
||||||
|
|
||||||
const result = await getLastRelease({cwd, options: {tagFormat: `v\${version}`}, logger: t.context.logger});
|
|
||||||
|
|
||||||
t.deepEqual(result, {});
|
t.deepEqual(result, {});
|
||||||
t.is(t.context.log.args[0][0], 'No git tag version found');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Return empty object if no valid tag is found in history', async t => {
|
test('Get the highest non-prerelease valid tag before a certain version', t => {
|
||||||
// Create a git repository, set the current working directory at the root of the repo
|
const result = getLastRelease(
|
||||||
const {cwd} = await gitRepo();
|
{
|
||||||
await gitCommits(['First'], {cwd});
|
branch: {
|
||||||
await gitCheckout('other-branch', true, {cwd});
|
name: 'master',
|
||||||
await gitCommits(['Second'], {cwd});
|
channel: undefined,
|
||||||
await gitTagVersion('v1.0.0', undefined, {cwd});
|
tags: [
|
||||||
await gitTagVersion('v2.0.0', undefined, {cwd});
|
{version: '2.0.0', gitTag: 'v2.0.0', gitHead: 'v2.0.0'},
|
||||||
await gitTagVersion('v3.0.0', undefined, {cwd});
|
{version: '1.0.0', gitTag: 'v1.0.0', gitHead: 'v1.0.0'},
|
||||||
await gitCheckout('master', false, {cwd});
|
{version: '2.0.0-beta.1', gitTag: 'v2.0.0-beta.1', gitHead: 'v2.0.0-beta.1'},
|
||||||
|
{version: '2.1.0', gitTag: 'v2.1.0', gitHead: 'v2.1.0'},
|
||||||
|
{version: '2.1.1', gitTag: 'v2.1.1', gitHead: 'v2.1.1'},
|
||||||
|
],
|
||||||
|
type: 'release',
|
||||||
|
},
|
||||||
|
options: {tagFormat: `v\${version}`},
|
||||||
|
},
|
||||||
|
{before: '2.1.0'}
|
||||||
|
);
|
||||||
|
|
||||||
const result = await getLastRelease({cwd, options: {tagFormat: `v\${version}`}, logger: t.context.logger});
|
t.deepEqual(result, {version: '2.0.0', gitTag: 'v2.0.0', name: 'v2.0.0', gitHead: 'v2.0.0', channels: undefined});
|
||||||
|
|
||||||
t.deepEqual(result, {});
|
|
||||||
t.is(t.context.log.args[0][0], 'No git tag version found');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Get the highest valid tag corresponding to the "tagFormat"', async t => {
|
|
||||||
// Create a git repository, set the current working directory at the root of the repo
|
|
||||||
const {cwd} = await gitRepo();
|
|
||||||
// Create some commits and tags
|
|
||||||
const [{hash: gitHead}] = await gitCommits(['First'], {cwd});
|
|
||||||
|
|
||||||
await gitTagVersion('1.0.0', undefined, {cwd});
|
|
||||||
t.deepEqual(await getLastRelease({cwd, options: {tagFormat: `\${version}`}, logger: t.context.logger}), {
|
|
||||||
gitHead,
|
|
||||||
gitTag: '1.0.0',
|
|
||||||
version: '1.0.0',
|
|
||||||
});
|
|
||||||
|
|
||||||
await gitTagVersion('foo-1.0.0-bar', undefined, {cwd});
|
|
||||||
t.deepEqual(await getLastRelease({cwd, options: {tagFormat: `foo-\${version}-bar`}, logger: t.context.logger}), {
|
|
||||||
gitHead,
|
|
||||||
gitTag: 'foo-1.0.0-bar',
|
|
||||||
version: '1.0.0',
|
|
||||||
});
|
|
||||||
|
|
||||||
await gitTagVersion('foo-v1.0.0-bar', undefined, {cwd});
|
|
||||||
t.deepEqual(await getLastRelease({cwd, options: {tagFormat: `foo-v\${version}-bar`}, logger: t.context.logger}), {
|
|
||||||
gitHead,
|
|
||||||
gitTag: 'foo-v1.0.0-bar',
|
|
||||||
version: '1.0.0',
|
|
||||||
});
|
|
||||||
|
|
||||||
await gitTagVersion('(.+)/1.0.0/(a-z)', undefined, {cwd});
|
|
||||||
t.deepEqual(await getLastRelease({cwd, options: {tagFormat: `(.+)/\${version}/(a-z)`}, logger: t.context.logger}), {
|
|
||||||
gitHead,
|
|
||||||
gitTag: '(.+)/1.0.0/(a-z)',
|
|
||||||
version: '1.0.0',
|
|
||||||
});
|
|
||||||
|
|
||||||
await gitTagVersion('2.0.0-1.0.0-bar.1', undefined, {cwd});
|
|
||||||
t.deepEqual(await getLastRelease({cwd, options: {tagFormat: `2.0.0-\${version}-bar.1`}, logger: t.context.logger}), {
|
|
||||||
gitHead,
|
|
||||||
gitTag: '2.0.0-1.0.0-bar.1',
|
|
||||||
version: '1.0.0',
|
|
||||||
});
|
|
||||||
|
|
||||||
await gitTagVersion('3.0.0-bar.1', undefined, {cwd});
|
|
||||||
t.deepEqual(await getLastRelease({cwd, options: {tagFormat: `\${version}-bar.1`}, logger: t.context.logger}), {
|
|
||||||
gitHead,
|
|
||||||
gitTag: '3.0.0-bar.1',
|
|
||||||
version: '3.0.0',
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
@ -9,33 +9,269 @@ test.beforeEach(t => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Increase version for patch release', t => {
|
test('Increase version for patch release', t => {
|
||||||
const version = getNextVersion({
|
t.is(
|
||||||
|
getNextVersion({
|
||||||
|
branch: {name: 'master', type: 'release', tags: [{gitTag: 'v1.0.0', version: '1.0.0', channels: [null]}]},
|
||||||
nextRelease: {type: 'patch'},
|
nextRelease: {type: 'patch'},
|
||||||
lastRelease: {version: '1.0.0'},
|
lastRelease: {version: '1.0.0', channels: [null]},
|
||||||
logger: t.context.logger,
|
logger: t.context.logger,
|
||||||
});
|
}),
|
||||||
t.is(version, '1.0.1');
|
'1.0.1'
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Increase version for minor release', t => {
|
test('Increase version for minor release', t => {
|
||||||
const version = getNextVersion({
|
t.is(
|
||||||
|
getNextVersion({
|
||||||
|
branch: {name: 'master', type: 'release', tags: [{gitTag: 'v1.0.0', version: '1.0.0', channels: [null]}]},
|
||||||
nextRelease: {type: 'minor'},
|
nextRelease: {type: 'minor'},
|
||||||
lastRelease: {version: '1.0.0'},
|
lastRelease: {version: '1.0.0', channels: [null]},
|
||||||
logger: t.context.logger,
|
logger: t.context.logger,
|
||||||
});
|
}),
|
||||||
t.is(version, '1.1.0');
|
'1.1.0'
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Increase version for major release', t => {
|
test('Increase version for major release', t => {
|
||||||
const version = getNextVersion({
|
t.is(
|
||||||
|
getNextVersion({
|
||||||
|
branch: {name: 'master', type: 'release', tags: [{gitTag: 'v1.0.0', version: '1.0.0', channels: [null]}]},
|
||||||
nextRelease: {type: 'major'},
|
nextRelease: {type: 'major'},
|
||||||
lastRelease: {version: '1.0.0'},
|
lastRelease: {version: '1.0.0', channels: [null]},
|
||||||
logger: t.context.logger,
|
logger: t.context.logger,
|
||||||
});
|
}),
|
||||||
t.is(version, '2.0.0');
|
'2.0.0'
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Return 1.0.0 if there is no previous release', t => {
|
test('Return 1.0.0 if there is no previous release', t => {
|
||||||
const version = getNextVersion({nextRelease: {type: 'minor'}, lastRelease: {}, logger: t.context.logger});
|
t.is(
|
||||||
t.is(version, '1.0.0');
|
getNextVersion({
|
||||||
|
branch: {name: 'master', type: 'release', tags: []},
|
||||||
|
nextRelease: {type: 'minor'},
|
||||||
|
lastRelease: {},
|
||||||
|
logger: t.context.logger,
|
||||||
|
}),
|
||||||
|
'1.0.0'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Increase version for patch release on prerelease branch', t => {
|
||||||
|
t.is(
|
||||||
|
getNextVersion({
|
||||||
|
branch: {
|
||||||
|
name: 'beta',
|
||||||
|
type: 'prerelease',
|
||||||
|
prerelease: 'beta',
|
||||||
|
tags: [{gitTag: 'v1.0.0', version: '1.0.0', channels: [null]}],
|
||||||
|
},
|
||||||
|
nextRelease: {type: 'patch', channel: 'beta'},
|
||||||
|
lastRelease: {version: '1.0.0', channels: [null]},
|
||||||
|
logger: t.context.logger,
|
||||||
|
}),
|
||||||
|
'1.0.1-beta.1'
|
||||||
|
);
|
||||||
|
|
||||||
|
t.is(
|
||||||
|
getNextVersion({
|
||||||
|
branch: {
|
||||||
|
name: 'beta',
|
||||||
|
type: 'prerelease',
|
||||||
|
prerelease: 'beta',
|
||||||
|
tags: [
|
||||||
|
{gitTag: 'v1.0.0', version: '1.0.0', channels: [null]},
|
||||||
|
{gitTag: 'v1.0.1-beta.1', version: '1.0.1-beta.1', channels: ['beta']},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
nextRelease: {type: 'patch', channel: 'beta'},
|
||||||
|
lastRelease: {version: '1.0.1-beta.1', channels: ['beta']},
|
||||||
|
logger: t.context.logger,
|
||||||
|
}),
|
||||||
|
'1.0.1-beta.2'
|
||||||
|
);
|
||||||
|
|
||||||
|
t.is(
|
||||||
|
getNextVersion({
|
||||||
|
branch: {
|
||||||
|
name: 'alpha',
|
||||||
|
type: 'prerelease',
|
||||||
|
prerelease: 'alpha',
|
||||||
|
tags: [{gitTag: 'v1.0.1-beta.1', version: '1.0.1-beta.1', channels: ['beta']}],
|
||||||
|
},
|
||||||
|
nextRelease: {type: 'patch', channel: 'alpha'},
|
||||||
|
lastRelease: {version: '1.0.1-beta.1', channels: ['beta']},
|
||||||
|
logger: t.context.logger,
|
||||||
|
}),
|
||||||
|
'1.0.2-alpha.1'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Increase version for minor release on prerelease branch', t => {
|
||||||
|
t.is(
|
||||||
|
getNextVersion({
|
||||||
|
branch: {
|
||||||
|
name: 'beta',
|
||||||
|
type: 'prerelease',
|
||||||
|
prerelease: 'beta',
|
||||||
|
tags: [{gitTag: 'v1.0.0', version: '1.0.0', channels: [null]}],
|
||||||
|
},
|
||||||
|
nextRelease: {type: 'minor', channel: 'beta'},
|
||||||
|
lastRelease: {version: '1.0.0', channels: [null]},
|
||||||
|
logger: t.context.logger,
|
||||||
|
}),
|
||||||
|
'1.1.0-beta.1'
|
||||||
|
);
|
||||||
|
|
||||||
|
t.is(
|
||||||
|
getNextVersion({
|
||||||
|
branch: {
|
||||||
|
name: 'beta',
|
||||||
|
type: 'prerelease',
|
||||||
|
prerelease: 'beta',
|
||||||
|
tags: [
|
||||||
|
{gitTag: 'v1.0.0', version: '1.0.0', channels: [null]},
|
||||||
|
{gitTag: 'v1.1.0-beta.1', version: '1.1.0-beta.1', channels: ['beta']},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
nextRelease: {type: 'minor', channel: 'beta'},
|
||||||
|
lastRelease: {version: '1.1.0-beta.1', channels: ['beta']},
|
||||||
|
logger: t.context.logger,
|
||||||
|
}),
|
||||||
|
'1.1.0-beta.2'
|
||||||
|
);
|
||||||
|
|
||||||
|
t.is(
|
||||||
|
getNextVersion({
|
||||||
|
branch: {
|
||||||
|
name: 'alpha',
|
||||||
|
type: 'prerelease',
|
||||||
|
prerelease: 'alpha',
|
||||||
|
tags: [{gitTag: 'v1.1.0-beta.1', version: '1.1.0-beta.1', channels: ['beta']}],
|
||||||
|
},
|
||||||
|
nextRelease: {type: 'minor', channel: 'alpha'},
|
||||||
|
lastRelease: {version: '1.1.0-beta.1', channels: ['beta']},
|
||||||
|
logger: t.context.logger,
|
||||||
|
}),
|
||||||
|
'1.2.0-alpha.1'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Increase version for major release on prerelease branch', t => {
|
||||||
|
t.is(
|
||||||
|
getNextVersion({
|
||||||
|
branch: {
|
||||||
|
name: 'beta',
|
||||||
|
type: 'prerelease',
|
||||||
|
prerelease: 'beta',
|
||||||
|
tags: [{gitTag: 'v1.0.0', version: '1.0.0', channels: [null]}],
|
||||||
|
},
|
||||||
|
nextRelease: {type: 'major', channel: 'beta'},
|
||||||
|
lastRelease: {version: '1.0.0', channels: [null]},
|
||||||
|
logger: t.context.logger,
|
||||||
|
}),
|
||||||
|
'2.0.0-beta.1'
|
||||||
|
);
|
||||||
|
|
||||||
|
t.is(
|
||||||
|
getNextVersion({
|
||||||
|
branch: {
|
||||||
|
name: 'beta',
|
||||||
|
type: 'prerelease',
|
||||||
|
prerelease: 'beta',
|
||||||
|
tags: [
|
||||||
|
{gitTag: 'v1.0.0', version: '1.0.0', channels: [null]},
|
||||||
|
{gitTag: 'v2.0.0-beta.1', version: '2.0.0-beta.1', channels: ['beta']},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
nextRelease: {type: 'major', channel: 'beta'},
|
||||||
|
lastRelease: {version: '2.0.0-beta.1', channels: ['beta']},
|
||||||
|
logger: t.context.logger,
|
||||||
|
}),
|
||||||
|
'2.0.0-beta.2'
|
||||||
|
);
|
||||||
|
|
||||||
|
t.is(
|
||||||
|
getNextVersion({
|
||||||
|
branch: {
|
||||||
|
name: 'alpha',
|
||||||
|
type: 'prerelease',
|
||||||
|
prerelease: 'alpha',
|
||||||
|
tags: [{gitTag: 'v2.0.0-beta.1', version: '2.0.0-beta.1', channels: ['beta']}],
|
||||||
|
},
|
||||||
|
nextRelease: {type: 'major', channel: 'alpha'},
|
||||||
|
lastRelease: {version: '2.0.0-beta.1', channels: ['beta']},
|
||||||
|
logger: t.context.logger,
|
||||||
|
}),
|
||||||
|
'3.0.0-alpha.1'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Return 1.0.0 if there is no previous release on prerelease branch', t => {
|
||||||
|
t.is(
|
||||||
|
getNextVersion({
|
||||||
|
branch: {name: 'beta', type: 'prerelease', prerelease: 'beta', tags: []},
|
||||||
|
nextRelease: {type: 'minor'},
|
||||||
|
lastRelease: {},
|
||||||
|
logger: t.context.logger,
|
||||||
|
}),
|
||||||
|
'1.0.0-beta.1'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Increase version for release on prerelease branch after previous commits were merged to release branch', t => {
|
||||||
|
t.is(
|
||||||
|
getNextVersion({
|
||||||
|
branch: {
|
||||||
|
name: 'beta',
|
||||||
|
type: 'prerelease',
|
||||||
|
prerelease: 'beta',
|
||||||
|
tags: [
|
||||||
|
{gitTag: 'v1.0.0', version: '1.0.0', channels: [null]},
|
||||||
|
{gitTag: 'v1.1.0', version: '1.1.0', channels: [null]}, // Version v1.1.0 released on default branch after beta was merged into master
|
||||||
|
{gitTag: 'v1.1.0-beta.1', version: '1.1.0-beta.1', channels: [null, 'beta']},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
nextRelease: {type: 'minor'},
|
||||||
|
lastRelease: {version: '1.1.0', channels: [null]},
|
||||||
|
logger: t.context.logger,
|
||||||
|
}),
|
||||||
|
'1.2.0-beta.1'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Increase version for release on prerelease branch based on highest commit type since last regular release', t => {
|
||||||
|
t.is(
|
||||||
|
getNextVersion({
|
||||||
|
branch: {
|
||||||
|
name: 'beta',
|
||||||
|
type: 'prerelease',
|
||||||
|
prerelease: 'beta',
|
||||||
|
tags: [
|
||||||
|
{gitTag: 'v1.0.0', version: '1.0.0', channels: [null]},
|
||||||
|
{gitTag: 'v1.1.0-beta.1', version: '1.1.0-beta.1', channels: [null, 'beta']},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
nextRelease: {type: 'major'},
|
||||||
|
lastRelease: {version: 'v1.1.0-beta.1', channels: [null]},
|
||||||
|
logger: t.context.logger,
|
||||||
|
}),
|
||||||
|
'2.0.0-beta.1'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Increase version for release on prerelease branch when there is no regular releases on other branches', t => {
|
||||||
|
t.is(
|
||||||
|
getNextVersion({
|
||||||
|
branch: {
|
||||||
|
name: 'beta',
|
||||||
|
type: 'prerelease',
|
||||||
|
prerelease: 'beta',
|
||||||
|
tags: [{gitTag: 'v1.0.0-beta.1', version: '1.0.0-beta.1', channels: ['beta']}],
|
||||||
|
},
|
||||||
|
nextRelease: {type: 'minor', channel: 'beta'},
|
||||||
|
lastRelease: {version: 'v1.0.0-beta.1', channels: ['beta']},
|
||||||
|
logger: t.context.logger,
|
||||||
|
}),
|
||||||
|
'1.0.0-beta.2'
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
282
test/get-release-to-add.test.js
Normal file
282
test/get-release-to-add.test.js
Normal file
@ -0,0 +1,282 @@
|
|||||||
|
import test from 'ava';
|
||||||
|
import getReleaseToAdd from '../lib/get-release-to-add';
|
||||||
|
|
||||||
|
test('Return versions merged from release to maintenance branch, excluding lower than branch start range', t => {
|
||||||
|
const result = getReleaseToAdd({
|
||||||
|
branch: {
|
||||||
|
name: '2.x',
|
||||||
|
channel: '2.x',
|
||||||
|
type: 'maintenance',
|
||||||
|
mergeRange: '>=2.0.0 <3.0.0',
|
||||||
|
tags: [
|
||||||
|
{gitTag: 'v2.0.0', version: '2.0.0', channels: ['2.x']},
|
||||||
|
{gitTag: 'v2.0.0', version: '2.0.0', channels: [null]},
|
||||||
|
{gitTag: 'v2.1.0', version: '2.1.0', channels: [null]},
|
||||||
|
{gitTag: 'v2.1.1', version: '2.1.1', channels: [null]},
|
||||||
|
{gitTag: 'v1.0.0', version: '1.0.0', channels: [null]},
|
||||||
|
{gitTag: 'v1.1.0', version: '1.1.0', channels: [null]},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
branches: [{name: '2.x', channel: '2.x'}, {name: 'master'}],
|
||||||
|
options: {tagFormat: `v\${version}`},
|
||||||
|
});
|
||||||
|
|
||||||
|
t.deepEqual(result, {
|
||||||
|
lastRelease: {version: '2.1.0', channels: [null], gitTag: 'v2.1.0', name: 'v2.1.0', gitHead: 'v2.1.0'},
|
||||||
|
currentRelease: {
|
||||||
|
type: 'patch',
|
||||||
|
version: '2.1.1',
|
||||||
|
channels: [null],
|
||||||
|
gitTag: 'v2.1.1',
|
||||||
|
name: 'v2.1.1',
|
||||||
|
gitHead: 'v2.1.1',
|
||||||
|
},
|
||||||
|
nextRelease: {
|
||||||
|
type: 'patch',
|
||||||
|
version: '2.1.1',
|
||||||
|
channel: '2.x',
|
||||||
|
gitTag: 'v2.1.1',
|
||||||
|
name: 'v2.1.1',
|
||||||
|
gitHead: 'v2.1.1',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Return versions merged between release branches', t => {
|
||||||
|
const result = getReleaseToAdd({
|
||||||
|
branch: {
|
||||||
|
name: 'master',
|
||||||
|
tags: [
|
||||||
|
{gitTag: 'v1.0.0', version: '1.0.0', channels: [null, 'next']},
|
||||||
|
{gitTag: 'v1.1.0', version: '1.1.0', channels: ['next']},
|
||||||
|
{gitTag: 'v2.0.0', version: '2.0.0', channels: ['next-major']},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
branches: [{name: 'master'}, {name: 'next', channel: 'next'}, {name: 'next-major', channel: 'next-major'}],
|
||||||
|
options: {tagFormat: `v\${version}`},
|
||||||
|
});
|
||||||
|
|
||||||
|
t.deepEqual(result, {
|
||||||
|
lastRelease: {
|
||||||
|
version: '1.1.0',
|
||||||
|
gitTag: 'v1.1.0',
|
||||||
|
name: 'v1.1.0',
|
||||||
|
gitHead: 'v1.1.0',
|
||||||
|
channels: ['next'],
|
||||||
|
},
|
||||||
|
currentRelease: {
|
||||||
|
type: 'major',
|
||||||
|
version: '2.0.0',
|
||||||
|
channels: ['next-major'],
|
||||||
|
gitTag: 'v2.0.0',
|
||||||
|
name: 'v2.0.0',
|
||||||
|
gitHead: 'v2.0.0',
|
||||||
|
},
|
||||||
|
nextRelease: {
|
||||||
|
type: 'major',
|
||||||
|
version: '2.0.0',
|
||||||
|
channel: null,
|
||||||
|
gitTag: 'v2.0.0',
|
||||||
|
name: 'v2.0.0',
|
||||||
|
gitHead: 'v2.0.0',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Return releases sorted by ascending order', t => {
|
||||||
|
const result = getReleaseToAdd({
|
||||||
|
branch: {
|
||||||
|
name: 'master',
|
||||||
|
tags: [
|
||||||
|
{gitTag: 'v2.0.0', version: '2.0.0', channels: ['next-major']},
|
||||||
|
{gitTag: 'v1.1.0', version: '1.1.0', channels: ['next']},
|
||||||
|
{gitTag: 'v1.0.0', version: '1.0.0', channels: [null, 'next']},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
branches: [{name: 'master'}, {name: 'next', channel: 'next'}, {name: 'next-major', channel: 'next-major'}],
|
||||||
|
options: {tagFormat: `v\${version}`},
|
||||||
|
});
|
||||||
|
|
||||||
|
t.deepEqual(result, {
|
||||||
|
lastRelease: {version: '1.1.0', gitTag: 'v1.1.0', name: 'v1.1.0', gitHead: 'v1.1.0', channels: ['next']},
|
||||||
|
currentRelease: {
|
||||||
|
type: 'major',
|
||||||
|
version: '2.0.0',
|
||||||
|
channels: ['next-major'],
|
||||||
|
gitTag: 'v2.0.0',
|
||||||
|
name: 'v2.0.0',
|
||||||
|
gitHead: 'v2.0.0',
|
||||||
|
},
|
||||||
|
nextRelease: {
|
||||||
|
type: 'major',
|
||||||
|
version: '2.0.0',
|
||||||
|
channel: null,
|
||||||
|
gitTag: 'v2.0.0',
|
||||||
|
name: 'v2.0.0',
|
||||||
|
gitHead: 'v2.0.0',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test('No lastRelease', t => {
|
||||||
|
const result = getReleaseToAdd({
|
||||||
|
branch: {
|
||||||
|
name: 'master',
|
||||||
|
tags: [{gitTag: 'v1.0.0', version: '1.0.0', channels: ['next']}],
|
||||||
|
},
|
||||||
|
branches: [{name: 'master'}, {name: 'next', channel: 'next'}],
|
||||||
|
options: {tagFormat: `v\${version}`},
|
||||||
|
});
|
||||||
|
|
||||||
|
t.deepEqual(result, {
|
||||||
|
lastRelease: {},
|
||||||
|
currentRelease: {
|
||||||
|
type: 'major',
|
||||||
|
version: '1.0.0',
|
||||||
|
channels: ['next'],
|
||||||
|
gitTag: 'v1.0.0',
|
||||||
|
name: 'v1.0.0',
|
||||||
|
gitHead: 'v1.0.0',
|
||||||
|
},
|
||||||
|
nextRelease: {
|
||||||
|
type: 'major',
|
||||||
|
version: '1.0.0',
|
||||||
|
channel: null,
|
||||||
|
gitTag: 'v1.0.0',
|
||||||
|
name: 'v1.0.0',
|
||||||
|
gitHead: 'v1.0.0',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Ignore pre-release versions', t => {
|
||||||
|
const result = getReleaseToAdd({
|
||||||
|
branch: {
|
||||||
|
name: 'master',
|
||||||
|
tags: [
|
||||||
|
{gitTag: 'v1.0.0', version: '1.0.0', channels: [null, 'next']},
|
||||||
|
{gitTag: 'v1.1.0', version: '1.1.0', channels: ['next']},
|
||||||
|
{gitTag: 'v2.0.0-alpha.1', version: '2.0.0-alpha.1', channels: ['alpha']},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
branches: [
|
||||||
|
{name: 'master'},
|
||||||
|
{name: 'next', channel: 'next'},
|
||||||
|
{name: 'alpha', type: 'prerelease', channel: 'alpha'},
|
||||||
|
],
|
||||||
|
options: {tagFormat: `v\${version}`},
|
||||||
|
});
|
||||||
|
|
||||||
|
t.deepEqual(result, {
|
||||||
|
lastRelease: {version: '1.0.0', channels: [null, 'next'], gitTag: 'v1.0.0', name: 'v1.0.0', gitHead: 'v1.0.0'},
|
||||||
|
currentRelease: {
|
||||||
|
type: 'minor',
|
||||||
|
version: '1.1.0',
|
||||||
|
channels: ['next'],
|
||||||
|
gitTag: 'v1.1.0',
|
||||||
|
name: 'v1.1.0',
|
||||||
|
gitHead: 'v1.1.0',
|
||||||
|
},
|
||||||
|
nextRelease: {
|
||||||
|
type: 'minor',
|
||||||
|
version: '1.1.0',
|
||||||
|
channel: null,
|
||||||
|
gitTag: 'v1.1.0',
|
||||||
|
name: 'v1.1.0',
|
||||||
|
gitHead: 'v1.1.0',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Exclude versions merged from release to maintenance branch if they have the same "channel"', t => {
|
||||||
|
const result = getReleaseToAdd({
|
||||||
|
branch: {
|
||||||
|
name: '2.x',
|
||||||
|
channel: 'latest',
|
||||||
|
type: 'maintenance',
|
||||||
|
mergeRange: '>=2.0.0 <3.0.0',
|
||||||
|
tags: [
|
||||||
|
{gitTag: 'v2.0.0', version: '2.0.0', channels: [null]},
|
||||||
|
{gitTag: 'v2.0.0', version: '2.0.0', channels: [null]},
|
||||||
|
{gitTag: 'v2.1.0', version: '2.1.0', channels: [null]},
|
||||||
|
{gitTag: 'v2.1.1', version: '2.1.1', channels: [null]},
|
||||||
|
{gitTag: 'v1.0.0', version: '1.0.0', channels: [null]},
|
||||||
|
{gitTag: 'v1.1.0', version: '1.1.0', channels: [null]},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
branches: [
|
||||||
|
{name: '2.x', channel: 'latest'},
|
||||||
|
{name: 'master', channel: 'latest'},
|
||||||
|
],
|
||||||
|
options: {tagFormat: `v\${version}`},
|
||||||
|
});
|
||||||
|
|
||||||
|
t.is(result, undefined);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Exclude versions merged between release branches if they have the same "channel"', t => {
|
||||||
|
const result = getReleaseToAdd({
|
||||||
|
branch: {
|
||||||
|
name: 'master',
|
||||||
|
channel: 'latest',
|
||||||
|
tags: [
|
||||||
|
{gitTag: 'v1.0.0', channels: ['latest'], version: '1.0.0'},
|
||||||
|
{gitTag: 'v1.1.0', channels: ['latest'], version: '1.1.0'},
|
||||||
|
{gitTag: 'v2.0.0', channels: ['latest'], version: '2.0.0'},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
branches: [
|
||||||
|
{name: 'master', channel: 'latest'},
|
||||||
|
{name: 'next', channel: 'latest'},
|
||||||
|
{name: 'next-major', channel: 'latest'},
|
||||||
|
],
|
||||||
|
options: {tagFormat: `v\${version}`},
|
||||||
|
});
|
||||||
|
|
||||||
|
t.is(result, undefined);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Exclude versions merged between release branches if they all have "channel" set to "false"', t => {
|
||||||
|
const result = getReleaseToAdd({
|
||||||
|
branch: {
|
||||||
|
name: 'master',
|
||||||
|
channel: false,
|
||||||
|
tags: [
|
||||||
|
{gitTag: 'v1.0.0', version: '1.0.0', channels: [null]},
|
||||||
|
{gitTag: 'v1.1.0', version: '1.1.0', channels: [null]},
|
||||||
|
{gitTag: 'v2.0.0', version: '2.0.0', channels: [null]},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
branches: [
|
||||||
|
{name: 'master', channel: false},
|
||||||
|
{name: 'next', channel: false},
|
||||||
|
{name: 'next-major', channel: false},
|
||||||
|
],
|
||||||
|
options: {tagFormat: `v\${version}`},
|
||||||
|
});
|
||||||
|
|
||||||
|
t.is(result, undefined);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Exclude versions number less than the latest version already released on that branch', t => {
|
||||||
|
const result = getReleaseToAdd({
|
||||||
|
branch: {
|
||||||
|
name: '2.x',
|
||||||
|
channel: '2.x',
|
||||||
|
type: 'maintenance',
|
||||||
|
mergeRange: '>=2.0.0 <3.0.0',
|
||||||
|
tags: [
|
||||||
|
{gitTag: 'v2.0.0', version: '2.0.0', channels: ['2.x']},
|
||||||
|
{gitTag: 'v2.0.0', version: '2.0.0', channels: [null]},
|
||||||
|
{gitTag: 'v2.1.0', version: '2.1.0', channels: [null]},
|
||||||
|
{gitTag: 'v2.1.1', version: '2.1.1', channels: [null, '2.x']},
|
||||||
|
{gitTag: 'v1.0.0', version: '1.0.0', channels: [null]},
|
||||||
|
{gitTag: 'v1.1.0', version: '1.1.0', channels: [null]},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
branches: [{name: '2.x', channel: '2.x'}, {name: 'master'}],
|
||||||
|
options: {tagFormat: `v\${version}`},
|
||||||
|
});
|
||||||
|
|
||||||
|
t.is(result, undefined);
|
||||||
|
});
|
194
test/git.test.js
194
test/git.test.js
@ -2,16 +2,20 @@ import test from 'ava';
|
|||||||
import tempy from 'tempy';
|
import tempy from 'tempy';
|
||||||
import {
|
import {
|
||||||
getTagHead,
|
getTagHead,
|
||||||
isRefInHistory,
|
isRefExists,
|
||||||
fetch,
|
fetch,
|
||||||
getGitHead,
|
getGitHead,
|
||||||
repoUrl,
|
repoUrl,
|
||||||
tag,
|
tag,
|
||||||
push,
|
push,
|
||||||
getTags,
|
getTags,
|
||||||
|
getBranches,
|
||||||
isGitRepo,
|
isGitRepo,
|
||||||
verifyTagName,
|
verifyTagName,
|
||||||
isBranchUpToDate,
|
isBranchUpToDate,
|
||||||
|
getNote,
|
||||||
|
addNote,
|
||||||
|
fetchNotes,
|
||||||
} from '../lib/git';
|
} from '../lib/git';
|
||||||
import {
|
import {
|
||||||
gitRepo,
|
gitRepo,
|
||||||
@ -25,6 +29,9 @@ import {
|
|||||||
gitRemoteTagHead,
|
gitRemoteTagHead,
|
||||||
gitPush,
|
gitPush,
|
||||||
gitDetachedHead,
|
gitDetachedHead,
|
||||||
|
gitDetachedHeadFromBranch,
|
||||||
|
gitAddNote,
|
||||||
|
gitGetNote,
|
||||||
} from './helpers/git-utils';
|
} from './helpers/git-utils';
|
||||||
|
|
||||||
test('Get the last commit sha', async t => {
|
test('Get the last commit sha', async t => {
|
||||||
@ -56,7 +63,7 @@ test('Unshallow and fetch repository', async t => {
|
|||||||
// Verify the shallow clone contains only one commit
|
// Verify the shallow clone contains only one commit
|
||||||
t.is((await gitGetCommits(undefined, {cwd})).length, 1);
|
t.is((await gitGetCommits(undefined, {cwd})).length, 1);
|
||||||
|
|
||||||
await fetch(repositoryUrl, {cwd});
|
await fetch(repositoryUrl, 'master', 'master', {cwd});
|
||||||
|
|
||||||
// Verify the shallow clone contains all the commits
|
// Verify the shallow clone contains all the commits
|
||||||
t.is((await gitGetCommits(undefined, {cwd})).length, 2);
|
t.is((await gitGetCommits(undefined, {cwd})).length, 2);
|
||||||
@ -64,10 +71,15 @@ test('Unshallow and fetch repository', async t => {
|
|||||||
|
|
||||||
test('Do not throw error when unshallow a complete repository', async t => {
|
test('Do not throw error when unshallow a complete repository', async t => {
|
||||||
// Create a git repository, set the current working directory at the root of the repo
|
// Create a git repository, set the current working directory at the root of the repo
|
||||||
const {cwd, repositoryUrl} = await gitRepo();
|
const {cwd, repositoryUrl} = await gitRepo(true);
|
||||||
// Add commits to the master branch
|
|
||||||
await gitCommits(['First'], {cwd});
|
await gitCommits(['First'], {cwd});
|
||||||
await t.notThrowsAsync(fetch(repositoryUrl, {cwd}));
|
await gitPush(repositoryUrl, 'master', {cwd});
|
||||||
|
await gitCheckout('second-branch', true, {cwd});
|
||||||
|
await gitCommits(['Second'], {cwd});
|
||||||
|
await gitPush(repositoryUrl, 'second-branch', {cwd});
|
||||||
|
|
||||||
|
await t.notThrowsAsync(fetch(repositoryUrl, 'master', 'master', {cwd}));
|
||||||
|
await t.notThrowsAsync(fetch(repositoryUrl, 'second-branch', 'master', {cwd}));
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Fetch all tags on a detached head repository', async t => {
|
test('Fetch all tags on a detached head repository', async t => {
|
||||||
@ -82,28 +94,66 @@ test('Fetch all tags on a detached head repository', async t => {
|
|||||||
await gitPush(repositoryUrl, 'master', {cwd});
|
await gitPush(repositoryUrl, 'master', {cwd});
|
||||||
cwd = await gitDetachedHead(repositoryUrl, commit.hash);
|
cwd = await gitDetachedHead(repositoryUrl, commit.hash);
|
||||||
|
|
||||||
await fetch(repositoryUrl, {cwd});
|
await fetch(repositoryUrl, 'master', 'master', {cwd});
|
||||||
|
|
||||||
t.deepEqual((await getTags({cwd})).sort(), ['v1.0.0', 'v1.0.1', 'v1.1.0'].sort());
|
t.deepEqual((await getTags('master', {cwd})).sort(), ['v1.0.0', 'v1.0.1', 'v1.1.0'].sort());
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Verify if the commit `sha` is in the direct history of the current branch', async t => {
|
test('Fetch all tags on a repository with a detached head from branch', async t => {
|
||||||
|
let {cwd, repositoryUrl} = await gitRepo();
|
||||||
|
|
||||||
|
await gitCommits(['First'], {cwd});
|
||||||
|
await gitTagVersion('v1.0.0', undefined, {cwd});
|
||||||
|
await gitCommits(['Second'], {cwd});
|
||||||
|
await gitTagVersion('v1.0.1', undefined, {cwd});
|
||||||
|
const [commit] = await gitCommits(['Third'], {cwd});
|
||||||
|
await gitTagVersion('v1.1.0', undefined, {cwd});
|
||||||
|
await gitPush(repositoryUrl, 'master', {cwd});
|
||||||
|
await gitCheckout('other-branch', true, {cwd});
|
||||||
|
await gitPush(repositoryUrl, 'other-branch', {cwd});
|
||||||
|
await gitCheckout('master', false, {cwd});
|
||||||
|
await gitCommits(['Fourth'], {cwd});
|
||||||
|
await gitTagVersion('v2.0.0', undefined, {cwd});
|
||||||
|
await gitPush(repositoryUrl, 'master', {cwd});
|
||||||
|
cwd = await gitDetachedHeadFromBranch(repositoryUrl, 'other-branch', commit.hash);
|
||||||
|
|
||||||
|
await fetch(repositoryUrl, 'master', 'other-branch', {cwd});
|
||||||
|
await fetch(repositoryUrl, 'other-branch', 'other-branch', {cwd});
|
||||||
|
|
||||||
|
t.deepEqual((await getTags('other-branch', {cwd})).sort(), ['v1.0.0', 'v1.0.1', 'v1.1.0'].sort());
|
||||||
|
t.deepEqual((await getTags('master', {cwd})).sort(), ['v1.0.0', 'v1.0.1', 'v1.1.0', 'v2.0.0'].sort());
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Verify if a branch exists', async t => {
|
||||||
// Create a git repository, set the current working directory at the root of the repo
|
// Create a git repository, set the current working directory at the root of the repo
|
||||||
const {cwd} = await gitRepo();
|
const {cwd} = await gitRepo();
|
||||||
// Add commits to the master branch
|
// Add commits to the master branch
|
||||||
const commits = await gitCommits(['First'], {cwd});
|
await gitCommits(['First'], {cwd});
|
||||||
// Create the new branch 'other-branch' from master
|
// Create the new branch 'other-branch' from master
|
||||||
await gitCheckout('other-branch', true, {cwd});
|
await gitCheckout('other-branch', true, {cwd});
|
||||||
// Add commits to the 'other-branch' branch
|
// Add commits to the 'other-branch' branch
|
||||||
const otherCommits = await gitCommits(['Second'], {cwd});
|
await gitCommits(['Second'], {cwd});
|
||||||
await gitCheckout('master', false, {cwd});
|
|
||||||
|
|
||||||
t.true(await isRefInHistory(commits[0].hash, {cwd}));
|
t.true(await isRefExists('master', {cwd}));
|
||||||
t.falsy(await isRefInHistory(otherCommits[0].hash, {cwd}));
|
t.true(await isRefExists('other-branch', {cwd}));
|
||||||
await t.throwsAsync(isRefInHistory('non-existant-sha', {cwd}));
|
t.falsy(await isRefExists('next', {cwd}));
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Get the commit sha for a given tag or falsy if the tag does not exists', async t => {
|
test('Get all branches', async t => {
|
||||||
|
const {cwd, repositoryUrl} = await gitRepo(true);
|
||||||
|
await gitCommits(['First'], {cwd});
|
||||||
|
await gitPush(repositoryUrl, 'master', {cwd});
|
||||||
|
await gitCheckout('second-branch', true, {cwd});
|
||||||
|
await gitCommits(['Second'], {cwd});
|
||||||
|
await gitPush(repositoryUrl, 'second-branch', {cwd});
|
||||||
|
await gitCheckout('third-branch', true, {cwd});
|
||||||
|
await gitCommits(['Third'], {cwd});
|
||||||
|
await gitPush(repositoryUrl, 'third-branch', {cwd});
|
||||||
|
|
||||||
|
t.deepEqual((await getBranches(repositoryUrl, {cwd})).sort(), ['master', 'second-branch', 'third-branch'].sort());
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Get the commit sha for a given tag', async t => {
|
||||||
// Create a git repository, set the current working directory at the root of the repo
|
// Create a git repository, set the current working directory at the root of the repo
|
||||||
const {cwd} = await gitRepo();
|
const {cwd} = await gitRepo();
|
||||||
// Add commits to the master branch
|
// Add commits to the master branch
|
||||||
@ -112,7 +162,6 @@ test('Get the commit sha for a given tag or falsy if the tag does not exists', a
|
|||||||
await gitTagVersion('v1.0.0', undefined, {cwd});
|
await gitTagVersion('v1.0.0', undefined, {cwd});
|
||||||
|
|
||||||
t.is(await getTagHead('v1.0.0', {cwd}), commits[0].hash);
|
t.is(await getTagHead('v1.0.0', {cwd}), commits[0].hash);
|
||||||
t.falsy(await getTagHead('missing_tag', {cwd}));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Return git remote repository url from config', async t => {
|
test('Return git remote repository url from config', async t => {
|
||||||
@ -146,7 +195,7 @@ test('Add tag on head commit', async t => {
|
|||||||
const {cwd} = await gitRepo();
|
const {cwd} = await gitRepo();
|
||||||
const commits = await gitCommits(['Test commit'], {cwd});
|
const commits = await gitCommits(['Test commit'], {cwd});
|
||||||
|
|
||||||
await tag('tag_name', {cwd});
|
await tag('tag_name', 'HEAD', {cwd});
|
||||||
|
|
||||||
await t.is(await gitCommitTag(commits[0].hash, {cwd}), 'tag_name');
|
await t.is(await gitCommitTag(commits[0].hash, {cwd}), 'tag_name');
|
||||||
});
|
});
|
||||||
@ -156,13 +205,13 @@ test('Push tag to remote repository', async t => {
|
|||||||
const {cwd, repositoryUrl} = await gitRepo(true);
|
const {cwd, repositoryUrl} = await gitRepo(true);
|
||||||
const commits = await gitCommits(['Test commit'], {cwd});
|
const commits = await gitCommits(['Test commit'], {cwd});
|
||||||
|
|
||||||
await tag('tag_name', {cwd});
|
await tag('tag_name', 'HEAD', {cwd});
|
||||||
await push(repositoryUrl, {cwd});
|
await push(repositoryUrl, {cwd});
|
||||||
|
|
||||||
t.is(await gitRemoteTagHead(repositoryUrl, 'tag_name', {cwd}), commits[0].hash);
|
t.is(await gitRemoteTagHead(repositoryUrl, 'tag_name', {cwd}), commits[0].hash);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Push tag to remote repository with remote branch ahaed', async t => {
|
test('Push tag to remote repository with remote branch ahead', async t => {
|
||||||
const {cwd, repositoryUrl} = await gitRepo(true);
|
const {cwd, repositoryUrl} = await gitRepo(true);
|
||||||
const commits = await gitCommits(['First'], {cwd});
|
const commits = await gitCommits(['First'], {cwd});
|
||||||
await gitPush(repositoryUrl, 'master', {cwd});
|
await gitPush(repositoryUrl, 'master', {cwd});
|
||||||
@ -170,7 +219,7 @@ test('Push tag to remote repository with remote branch ahaed', async t => {
|
|||||||
await gitCommits(['Second'], {cwd: tmpRepo});
|
await gitCommits(['Second'], {cwd: tmpRepo});
|
||||||
await gitPush('origin', 'master', {cwd: tmpRepo});
|
await gitPush('origin', 'master', {cwd: tmpRepo});
|
||||||
|
|
||||||
await tag('tag_name', {cwd});
|
await tag('tag_name', 'HEAD', {cwd});
|
||||||
await push(repositoryUrl, {cwd});
|
await push(repositoryUrl, {cwd});
|
||||||
|
|
||||||
t.is(await gitRemoteTagHead(repositoryUrl, 'tag_name', {cwd}), commits[0].hash);
|
t.is(await gitRemoteTagHead(repositoryUrl, 'tag_name', {cwd}), commits[0].hash);
|
||||||
@ -206,7 +255,7 @@ test('Return falsy for invalid tag names', async t => {
|
|||||||
test('Throws error if obtaining the tags fails', async t => {
|
test('Throws error if obtaining the tags fails', async t => {
|
||||||
const cwd = tempy.directory();
|
const cwd = tempy.directory();
|
||||||
|
|
||||||
await t.throwsAsync(getTags({cwd}));
|
await t.throwsAsync(getTags('master', {cwd}));
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Return "true" if repository is up to date', async t => {
|
test('Return "true" if repository is up to date', async t => {
|
||||||
@ -232,11 +281,102 @@ test('Return falsy if repository is not up to date', async t => {
|
|||||||
t.falsy(await isBranchUpToDate(repositoryUrl, 'master', {cwd}));
|
t.falsy(await isBranchUpToDate(repositoryUrl, 'master', {cwd}));
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Return "true" if local repository is ahead', async t => {
|
test('Return falsy if detached head repository is not up to date', async t => {
|
||||||
const {cwd, repositoryUrl} = await gitRepo(true);
|
let {cwd, repositoryUrl} = await gitRepo();
|
||||||
await gitCommits(['First'], {cwd});
|
|
||||||
await gitPush(repositoryUrl, 'master', {cwd});
|
|
||||||
await gitCommits(['Second'], {cwd});
|
|
||||||
|
|
||||||
t.true(await isBranchUpToDate(repositoryUrl, 'master', {cwd}));
|
const [commit] = await gitCommits(['First'], {cwd});
|
||||||
|
await gitCommits(['Second'], {cwd});
|
||||||
|
await gitPush(repositoryUrl, 'master', {cwd});
|
||||||
|
cwd = await gitDetachedHead(repositoryUrl, commit.hash);
|
||||||
|
await fetch(repositoryUrl, 'master', 'master', {cwd});
|
||||||
|
|
||||||
|
t.falsy(await isBranchUpToDate(repositoryUrl, 'master', {cwd}));
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Get a commit note', async t => {
|
||||||
|
// Create a git repository, set the current working directory at the root of the repo
|
||||||
|
const {cwd} = await gitRepo();
|
||||||
|
// Add commits to the master branch
|
||||||
|
const commits = await gitCommits(['First'], {cwd});
|
||||||
|
|
||||||
|
await gitAddNote(JSON.stringify({note: 'note'}), commits[0].hash, {cwd});
|
||||||
|
|
||||||
|
t.deepEqual(await getNote(commits[0].hash, {cwd}), {note: 'note'});
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Return empty object if there is no commit note', async t => {
|
||||||
|
// Create a git repository, set the current working directory at the root of the repo
|
||||||
|
const {cwd} = await gitRepo();
|
||||||
|
// Add commits to the master branch
|
||||||
|
const commits = await gitCommits(['First'], {cwd});
|
||||||
|
|
||||||
|
t.deepEqual(await getNote(commits[0].hash, {cwd}), {});
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Throw error if a commit note in invalid', async t => {
|
||||||
|
// Create a git repository, set the current working directory at the root of the repo
|
||||||
|
const {cwd} = await gitRepo();
|
||||||
|
// Add commits to the master branch
|
||||||
|
const commits = await gitCommits(['First'], {cwd});
|
||||||
|
|
||||||
|
await gitAddNote('non-json note', commits[0].hash, {cwd});
|
||||||
|
|
||||||
|
await t.throwsAsync(getNote(commits[0].hash, {cwd}));
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Add a commit note', async t => {
|
||||||
|
// Create a git repository, set the current working directory at the root of the repo
|
||||||
|
const {cwd} = await gitRepo();
|
||||||
|
// Add commits to the master branch
|
||||||
|
const commits = await gitCommits(['First'], {cwd});
|
||||||
|
|
||||||
|
await addNote({note: 'note'}, commits[0].hash, {cwd});
|
||||||
|
|
||||||
|
t.is(await gitGetNote(commits[0].hash, {cwd}), '{"note":"note"}');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Overwrite a commit note', async t => {
|
||||||
|
// Create a git repository, set the current working directory at the root of the repo
|
||||||
|
const {cwd} = await gitRepo();
|
||||||
|
// Add commits to the master branch
|
||||||
|
const commits = await gitCommits(['First'], {cwd});
|
||||||
|
|
||||||
|
await addNote({note: 'note'}, commits[0].hash, {cwd});
|
||||||
|
await addNote({note: 'note2'}, commits[0].hash, {cwd});
|
||||||
|
|
||||||
|
t.is(await gitGetNote(commits[0].hash, {cwd}), '{"note":"note2"}');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Unshallow and fetch repository with notes', async t => {
|
||||||
|
// Create a git repository, set the current working directory at the root of the repo
|
||||||
|
let {cwd, repositoryUrl} = await gitRepo();
|
||||||
|
// Add commits to the master branch
|
||||||
|
const commits = await gitCommits(['First', 'Second'], {cwd});
|
||||||
|
await gitAddNote(JSON.stringify({note: 'note'}), commits[0].hash, {cwd});
|
||||||
|
// Create a shallow clone with only 1 commit
|
||||||
|
cwd = await gitShallowClone(repositoryUrl);
|
||||||
|
|
||||||
|
// Verify the shallow clone doesn't contains the note
|
||||||
|
await t.throwsAsync(gitGetNote(commits[0].hash, {cwd}));
|
||||||
|
|
||||||
|
await fetch(repositoryUrl, 'master', 'master', {cwd});
|
||||||
|
await fetchNotes(repositoryUrl, {cwd});
|
||||||
|
|
||||||
|
// Verify the shallow clone contains the note
|
||||||
|
t.is(await gitGetNote(commits[0].hash, {cwd}), '{"note":"note"}');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Fetch all notes on a detached head repository', async t => {
|
||||||
|
let {cwd, repositoryUrl} = await gitRepo();
|
||||||
|
|
||||||
|
await gitCommits(['First'], {cwd});
|
||||||
|
const [commit] = await gitCommits(['Second'], {cwd});
|
||||||
|
await gitPush(repositoryUrl, 'master', {cwd});
|
||||||
|
await gitAddNote(JSON.stringify({note: 'note'}), commit.hash, {cwd});
|
||||||
|
cwd = await gitDetachedHead(repositoryUrl, commit.hash);
|
||||||
|
|
||||||
|
await fetch(repositoryUrl, 'master', 'master', {cwd});
|
||||||
|
await fetchNotes(repositoryUrl, {cwd});
|
||||||
|
|
||||||
|
t.is(await gitGetNote(commit.hash, {cwd}), '{"note":"note"}');
|
||||||
});
|
});
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
import tempy from 'tempy';
|
import tempy from 'tempy';
|
||||||
import execa from 'execa';
|
import execa from 'execa';
|
||||||
import fileUrl from 'file-url';
|
import fileUrl from 'file-url';
|
||||||
import pReduce from 'p-reduce';
|
import pEachSeries from 'p-each-series';
|
||||||
import gitLogParser from 'git-log-parser';
|
import gitLogParser from 'git-log-parser';
|
||||||
import getStream from 'get-stream';
|
import getStream from 'get-stream';
|
||||||
|
import {GIT_NOTE_REF} from '../../lib/definitions/constants';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Commit message informations.
|
* Commit message informations.
|
||||||
@ -69,10 +70,9 @@ export async function initBareRepo(repositoryUrl, branch = 'master') {
|
|||||||
* @returns {Array<Commit>} The created commits, in reverse order (to match `git log` order).
|
* @returns {Array<Commit>} The created commits, in reverse order (to match `git log` order).
|
||||||
*/
|
*/
|
||||||
export async function gitCommits(messages, execaOpts) {
|
export async function gitCommits(messages, execaOpts) {
|
||||||
await pReduce(
|
await pEachSeries(
|
||||||
messages,
|
messages,
|
||||||
async (_, message) =>
|
async message => (await execa('git', ['commit', '-m', message, '--allow-empty', '--no-gpg-sign'], execaOpts)).stdout
|
||||||
(await execa('git', ['commit', '-m', message, '--allow-empty', '--no-gpg-sign'], execaOpts)).stdout
|
|
||||||
);
|
);
|
||||||
return (await gitGetCommits(undefined, execaOpts)).slice(0, messages.length);
|
return (await gitGetCommits(undefined, execaOpts)).slice(0, messages.length);
|
||||||
}
|
}
|
||||||
@ -166,6 +166,17 @@ export async function gitDetachedHead(repositoryUrl, head) {
|
|||||||
return cwd;
|
return cwd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function gitDetachedHeadFromBranch(repositoryUrl, branch, head) {
|
||||||
|
const cwd = tempy.directory();
|
||||||
|
|
||||||
|
await execa('git', ['init'], {cwd});
|
||||||
|
await execa('git', ['remote', 'add', 'origin', repositoryUrl], {cwd});
|
||||||
|
await execa('git', ['fetch', '--force', repositoryUrl, `${branch}:remotes/origin/${branch}`], {cwd});
|
||||||
|
await execa('git', ['reset', '--hard', head], {cwd});
|
||||||
|
await execa('git', ['checkout', '-q', '-B', branch], {cwd});
|
||||||
|
return cwd;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a new Git configuration.
|
* Add a new Git configuration.
|
||||||
*
|
*
|
||||||
@ -202,7 +213,7 @@ export async function gitRemoteTagHead(repositoryUrl, tagName, execaOpts) {
|
|||||||
return (await execa('git', ['ls-remote', '--tags', repositoryUrl, tagName], execaOpts)).stdout
|
return (await execa('git', ['ls-remote', '--tags', repositoryUrl, tagName], execaOpts)).stdout
|
||||||
.split('\n')
|
.split('\n')
|
||||||
.filter(tag => Boolean(tag))
|
.filter(tag => Boolean(tag))
|
||||||
.map(tag => tag.match(/^(\S+)/)[1])[0];
|
.map(tag => tag.match(/^(?<tag>\S+)/)[1])[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -229,3 +240,54 @@ export async function gitCommitTag(gitHead, execaOpts) {
|
|||||||
export async function gitPush(repositoryUrl, branch, execaOpts) {
|
export async function gitPush(repositoryUrl, branch, execaOpts) {
|
||||||
await execa('git', ['push', '--tags', repositoryUrl, `HEAD:${branch}`], execaOpts);
|
await execa('git', ['push', '--tags', repositoryUrl, `HEAD:${branch}`], execaOpts);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Merge a branch into the current one with `git merge`.
|
||||||
|
*
|
||||||
|
* @param {String} ref The ref to merge.
|
||||||
|
* @param {Object} [execaOpts] Options to pass to `execa`.
|
||||||
|
*/
|
||||||
|
export async function merge(ref, execaOpts) {
|
||||||
|
await execa('git', ['merge', '--no-ff', ref], execaOpts);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Merge a branch into the current one with `git merge --ff`.
|
||||||
|
*
|
||||||
|
* @param {String} ref The ref to merge.
|
||||||
|
* @param {Object} [execaOpts] Options to pass to `execa`.
|
||||||
|
*/
|
||||||
|
export async function mergeFf(ref, execaOpts) {
|
||||||
|
await execa('git', ['merge', '--ff', ref], execaOpts);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Merge a branch into the current one with `git rebase`.
|
||||||
|
*
|
||||||
|
* @param {String} ref The ref to merge.
|
||||||
|
* @param {Object} [execaOpts] Options to pass to `execa`.
|
||||||
|
*/
|
||||||
|
export async function rebase(ref, execaOpts) {
|
||||||
|
await execa('git', ['rebase', ref], execaOpts);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a note to a Git reference.
|
||||||
|
*
|
||||||
|
* @param {String} note The note to add.
|
||||||
|
* @param {String} ref The ref to add the note to.
|
||||||
|
* @param {Object} [execaOpts] Options to pass to `execa`.
|
||||||
|
*/
|
||||||
|
export async function gitAddNote(note, ref, execaOpts) {
|
||||||
|
await execa('git', ['notes', '--ref', GIT_NOTE_REF, 'add', '-m', note, ref], execaOpts);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the note associated with a Git reference.
|
||||||
|
*
|
||||||
|
* @param {String} ref The ref to get the note from.
|
||||||
|
* @param {Object} [execaOpts] Options to pass to `execa`.
|
||||||
|
*/
|
||||||
|
export async function gitGetNote(ref, execaOpts) {
|
||||||
|
return (await execa('git', ['notes', '--ref', GIT_NOTE_REF, 'show', ref], execaOpts)).stdout;
|
||||||
|
}
|
||||||
|
@ -3,7 +3,7 @@ import getStream from 'get-stream';
|
|||||||
import pRetry from 'p-retry';
|
import pRetry from 'p-retry';
|
||||||
import {initBareRepo, gitShallowClone} from './git-utils';
|
import {initBareRepo, gitShallowClone} from './git-utils';
|
||||||
|
|
||||||
const IMAGE = 'pvdlg/docker-gitbox';
|
const IMAGE = 'pvdlg/docker-gitbox:latest';
|
||||||
const SERVER_PORT = 80;
|
const SERVER_PORT = 80;
|
||||||
const HOST_PORT = 2080;
|
const HOST_PORT = 2080;
|
||||||
const SERVER_HOST = 'localhost';
|
const SERVER_HOST = 'localhost';
|
||||||
|
5
test/helpers/npm-utils.js
Normal file
5
test/helpers/npm-utils.js
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
import execa from 'execa';
|
||||||
|
|
||||||
|
export async function npmView(packageName, env) {
|
||||||
|
return JSON.parse((await execa('npm', ['view', packageName, '--json'], {env})).stdout);
|
||||||
|
}
|
1006
test/index.test.js
1006
test/index.test.js
File diff suppressed because it is too large
Load Diff
@ -5,8 +5,20 @@ import {escapeRegExp} from 'lodash';
|
|||||||
import {writeJson, readJson} from 'fs-extra';
|
import {writeJson, readJson} from 'fs-extra';
|
||||||
import execa from 'execa';
|
import execa from 'execa';
|
||||||
import {WritableStreamBuffer} from 'stream-buffers';
|
import {WritableStreamBuffer} from 'stream-buffers';
|
||||||
|
import delay from 'delay';
|
||||||
import {SECRET_REPLACEMENT} from '../lib/definitions/constants';
|
import {SECRET_REPLACEMENT} from '../lib/definitions/constants';
|
||||||
import {gitHead, gitTagHead, gitRepo, gitCommits, gitRemoteTagHead, gitPush} from './helpers/git-utils';
|
import {
|
||||||
|
gitHead,
|
||||||
|
gitTagHead,
|
||||||
|
gitRepo,
|
||||||
|
gitCommits,
|
||||||
|
gitRemoteTagHead,
|
||||||
|
gitPush,
|
||||||
|
gitCheckout,
|
||||||
|
merge,
|
||||||
|
gitGetNote,
|
||||||
|
} from './helpers/git-utils';
|
||||||
|
import {npmView} from './helpers/npm-utils';
|
||||||
import gitbox from './helpers/gitbox';
|
import gitbox from './helpers/gitbox';
|
||||||
import mockServer from './helpers/mockserver';
|
import mockServer from './helpers/mockserver';
|
||||||
import npmRegistry from './helpers/npm-registry';
|
import npmRegistry from './helpers/npm-registry';
|
||||||
@ -58,7 +70,7 @@ test('Release patch, minor and major versions', async t => {
|
|||||||
version: '0.0.0-dev',
|
version: '0.0.0-dev',
|
||||||
repository: {url: repositoryUrl},
|
repository: {url: repositoryUrl},
|
||||||
publishConfig: {registry: npmRegistry.url},
|
publishConfig: {registry: npmRegistry.url},
|
||||||
release: {success: false, fail: false},
|
release: {branches: ['master', 'next'], success: false, fail: false},
|
||||||
});
|
});
|
||||||
// Create a npm-shrinkwrap.json file
|
// Create a npm-shrinkwrap.json file
|
||||||
await execa('npm', ['shrinkwrap'], {env: testEnv, cwd});
|
await execa('npm', ['shrinkwrap'], {env: testEnv, cwd});
|
||||||
@ -86,7 +98,7 @@ test('Release patch, minor and major versions', async t => {
|
|||||||
let createReleaseMock = await mockServer.mock(
|
let createReleaseMock = await mockServer.mock(
|
||||||
`/repos/${owner}/${packageName}/releases`,
|
`/repos/${owner}/${packageName}/releases`,
|
||||||
{
|
{
|
||||||
body: {tag_name: `v${version}`, target_commitish: 'master', name: `v${version}`},
|
body: {tag_name: `v${version}`, name: `v${version}`},
|
||||||
headers: [{name: 'Authorization', values: [`token ${env.GH_TOKEN}`]}],
|
headers: [{name: 'Authorization', values: [`token ${env.GH_TOKEN}`]}],
|
||||||
},
|
},
|
||||||
{body: {html_url: `release-url/${version}`}}
|
{body: {html_url: `release-url/${version}`}}
|
||||||
@ -105,15 +117,14 @@ test('Release patch, minor and major versions', async t => {
|
|||||||
t.is((await readJson(path.resolve(cwd, 'npm-shrinkwrap.json'))).version, version);
|
t.is((await readJson(path.resolve(cwd, 'npm-shrinkwrap.json'))).version, version);
|
||||||
|
|
||||||
// Retrieve the published package from the registry and check version and gitHead
|
// Retrieve the published package from the registry and check version and gitHead
|
||||||
let [, releasedVersion, releasedGitHead] = /^version = '(.+)'\s+gitHead = '(.+)'$/.exec(
|
let {
|
||||||
(await execa('npm', ['show', packageName, 'version', 'gitHead'], {env: testEnv, cwd})).stdout
|
'dist-tags': {latest: releasedVersion},
|
||||||
);
|
} = await npmView(packageName, testEnv);
|
||||||
let head = await gitHead({cwd});
|
let head = await gitHead({cwd});
|
||||||
t.is(releasedVersion, version);
|
t.is(releasedVersion, version);
|
||||||
t.is(releasedGitHead, head);
|
|
||||||
t.is(await gitTagHead(`v${version}`, {cwd}), head);
|
t.is(await gitTagHead(`v${version}`, {cwd}), head);
|
||||||
t.is(await gitRemoteTagHead(authUrl, `v${version}`, {cwd}), head);
|
t.is(await gitRemoteTagHead(authUrl, `v${version}`, {cwd}), head);
|
||||||
t.log(`+ released ${releasedVersion} with head ${releasedGitHead}`);
|
t.log(`+ released ${releasedVersion}`);
|
||||||
|
|
||||||
await mockServer.verify(verifyMock);
|
await mockServer.verify(verifyMock);
|
||||||
await mockServer.verify(createReleaseMock);
|
await mockServer.verify(createReleaseMock);
|
||||||
@ -128,7 +139,7 @@ test('Release patch, minor and major versions', async t => {
|
|||||||
createReleaseMock = await mockServer.mock(
|
createReleaseMock = await mockServer.mock(
|
||||||
`/repos/${owner}/${packageName}/releases`,
|
`/repos/${owner}/${packageName}/releases`,
|
||||||
{
|
{
|
||||||
body: {tag_name: `v${version}`, target_commitish: 'master', name: `v${version}`},
|
body: {tag_name: `v${version}`, name: `v${version}`},
|
||||||
headers: [{name: 'Authorization', values: [`token ${env.GH_TOKEN}`]}],
|
headers: [{name: 'Authorization', values: [`token ${env.GH_TOKEN}`]}],
|
||||||
},
|
},
|
||||||
{body: {html_url: `release-url/${version}`}}
|
{body: {html_url: `release-url/${version}`}}
|
||||||
@ -147,15 +158,14 @@ test('Release patch, minor and major versions', async t => {
|
|||||||
t.is((await readJson(path.resolve(cwd, 'npm-shrinkwrap.json'))).version, version);
|
t.is((await readJson(path.resolve(cwd, 'npm-shrinkwrap.json'))).version, version);
|
||||||
|
|
||||||
// Retrieve the published package from the registry and check version and gitHead
|
// Retrieve the published package from the registry and check version and gitHead
|
||||||
[, releasedVersion, releasedGitHead] = /^version = '(.+)'\s+gitHead = '(.+)'$/.exec(
|
({
|
||||||
(await execa('npm', ['show', packageName, 'version', 'gitHead'], {env: testEnv, cwd})).stdout
|
'dist-tags': {latest: releasedVersion},
|
||||||
);
|
} = await npmView(packageName, testEnv));
|
||||||
head = await gitHead({cwd});
|
head = await gitHead({cwd});
|
||||||
t.is(releasedVersion, version);
|
t.is(releasedVersion, version);
|
||||||
t.is(releasedGitHead, head);
|
|
||||||
t.is(await gitTagHead(`v${version}`, {cwd}), head);
|
t.is(await gitTagHead(`v${version}`, {cwd}), head);
|
||||||
t.is(await gitRemoteTagHead(authUrl, `v${version}`, {cwd}), head);
|
t.is(await gitRemoteTagHead(authUrl, `v${version}`, {cwd}), head);
|
||||||
t.log(`+ released ${releasedVersion} with head ${releasedGitHead}`);
|
t.log(`+ released ${releasedVersion}`);
|
||||||
|
|
||||||
await mockServer.verify(verifyMock);
|
await mockServer.verify(verifyMock);
|
||||||
await mockServer.verify(createReleaseMock);
|
await mockServer.verify(createReleaseMock);
|
||||||
@ -170,7 +180,7 @@ test('Release patch, minor and major versions', async t => {
|
|||||||
createReleaseMock = await mockServer.mock(
|
createReleaseMock = await mockServer.mock(
|
||||||
`/repos/${owner}/${packageName}/releases`,
|
`/repos/${owner}/${packageName}/releases`,
|
||||||
{
|
{
|
||||||
body: {tag_name: `v${version}`, target_commitish: 'master', name: `v${version}`},
|
body: {tag_name: `v${version}`, name: `v${version}`},
|
||||||
headers: [{name: 'Authorization', values: [`token ${env.GH_TOKEN}`]}],
|
headers: [{name: 'Authorization', values: [`token ${env.GH_TOKEN}`]}],
|
||||||
},
|
},
|
||||||
{body: {html_url: `release-url/${version}`}}
|
{body: {html_url: `release-url/${version}`}}
|
||||||
@ -189,20 +199,19 @@ test('Release patch, minor and major versions', async t => {
|
|||||||
t.is((await readJson(path.resolve(cwd, 'npm-shrinkwrap.json'))).version, version);
|
t.is((await readJson(path.resolve(cwd, 'npm-shrinkwrap.json'))).version, version);
|
||||||
|
|
||||||
// Retrieve the published package from the registry and check version and gitHead
|
// Retrieve the published package from the registry and check version and gitHead
|
||||||
[, releasedVersion, releasedGitHead] = /^version = '(.+)'\s+gitHead = '(.+)'$/.exec(
|
({
|
||||||
(await execa('npm', ['show', packageName, 'version', 'gitHead'], {env: testEnv, cwd})).stdout
|
'dist-tags': {latest: releasedVersion},
|
||||||
);
|
} = await npmView(packageName, testEnv));
|
||||||
head = await gitHead({cwd});
|
head = await gitHead({cwd});
|
||||||
t.is(releasedVersion, version);
|
t.is(releasedVersion, version);
|
||||||
t.is(releasedGitHead, head);
|
|
||||||
t.is(await gitTagHead(`v${version}`, {cwd}), head);
|
t.is(await gitTagHead(`v${version}`, {cwd}), head);
|
||||||
t.is(await gitRemoteTagHead(authUrl, `v${version}`, {cwd}), head);
|
t.is(await gitRemoteTagHead(authUrl, `v${version}`, {cwd}), head);
|
||||||
t.log(`+ released ${releasedVersion} with head ${releasedGitHead}`);
|
t.log(`+ released ${releasedVersion}`);
|
||||||
|
|
||||||
await mockServer.verify(verifyMock);
|
await mockServer.verify(verifyMock);
|
||||||
await mockServer.verify(createReleaseMock);
|
await mockServer.verify(createReleaseMock);
|
||||||
|
|
||||||
/* Major release */
|
/* Major release on next */
|
||||||
version = '2.0.0';
|
version = '2.0.0';
|
||||||
verifyMock = await mockServer.mock(
|
verifyMock = await mockServer.mock(
|
||||||
`/repos/${owner}/${packageName}`,
|
`/repos/${owner}/${packageName}`,
|
||||||
@ -212,16 +221,18 @@ test('Release patch, minor and major versions', async t => {
|
|||||||
createReleaseMock = await mockServer.mock(
|
createReleaseMock = await mockServer.mock(
|
||||||
`/repos/${owner}/${packageName}/releases`,
|
`/repos/${owner}/${packageName}/releases`,
|
||||||
{
|
{
|
||||||
body: {tag_name: `v${version}`, target_commitish: 'master', name: `v${version}`},
|
body: {tag_name: `v${version}`, name: `v${version}`},
|
||||||
headers: [{name: 'Authorization', values: [`token ${env.GH_TOKEN}`]}],
|
headers: [{name: 'Authorization', values: [`token ${env.GH_TOKEN}`]}],
|
||||||
},
|
},
|
||||||
{body: {html_url: `release-url/${version}`}}
|
{body: {html_url: `release-url/${version}`}}
|
||||||
);
|
);
|
||||||
|
|
||||||
t.log('Commit a breaking change');
|
t.log('Commit a breaking change on next');
|
||||||
|
await gitCheckout('next', true, {cwd});
|
||||||
|
await gitPush('origin', 'next', {cwd});
|
||||||
await gitCommits(['feat: foo\n\n BREAKING CHANGE: bar'], {cwd});
|
await gitCommits(['feat: foo\n\n BREAKING CHANGE: bar'], {cwd});
|
||||||
t.log('$ semantic-release');
|
t.log('$ semantic-release');
|
||||||
({stdout, exitCode} = await execa(cli, [], {env, cwd}));
|
({stdout, exitCode} = await execa(cli, [], {env: {...env, TRAVIS_BRANCH: 'next'}, cwd}));
|
||||||
t.regex(stdout, new RegExp(`Published GitHub release: release-url/${version}`));
|
t.regex(stdout, new RegExp(`Published GitHub release: release-url/${version}`));
|
||||||
t.regex(stdout, new RegExp(`Publishing version ${version} to npm registry`));
|
t.regex(stdout, new RegExp(`Publishing version ${version} to npm registry`));
|
||||||
t.is(exitCode, 0);
|
t.is(exitCode, 0);
|
||||||
@ -231,18 +242,66 @@ test('Release patch, minor and major versions', async t => {
|
|||||||
t.is((await readJson(path.resolve(cwd, 'npm-shrinkwrap.json'))).version, version);
|
t.is((await readJson(path.resolve(cwd, 'npm-shrinkwrap.json'))).version, version);
|
||||||
|
|
||||||
// Retrieve the published package from the registry and check version and gitHead
|
// Retrieve the published package from the registry and check version and gitHead
|
||||||
[, releasedVersion, releasedGitHead] = /^version = '(.+)'\s+gitHead = '(.+)'$/.exec(
|
({
|
||||||
(await execa('npm', ['show', packageName, 'version', 'gitHead'], {env: testEnv, cwd})).stdout
|
'dist-tags': {next: releasedVersion},
|
||||||
);
|
} = await npmView(packageName, testEnv));
|
||||||
head = await gitHead({cwd});
|
head = await gitHead({cwd});
|
||||||
t.is(releasedVersion, version);
|
t.is(releasedVersion, version);
|
||||||
t.is(releasedGitHead, head);
|
t.is(await gitGetNote(`v${version}`, {cwd}), '{"channels":["next"]}');
|
||||||
t.is(await gitTagHead(`v${version}`, {cwd}), head);
|
t.is(await gitTagHead(`v${version}`, {cwd}), head);
|
||||||
t.is(await gitRemoteTagHead(authUrl, `v${version}`, {cwd}), head);
|
t.is(await gitRemoteTagHead(authUrl, `v${version}`, {cwd}), head);
|
||||||
t.log(`+ released ${releasedVersion} with head ${releasedGitHead}`);
|
t.log(`+ released ${releasedVersion} on @next`);
|
||||||
|
|
||||||
await mockServer.verify(verifyMock);
|
await mockServer.verify(verifyMock);
|
||||||
await mockServer.verify(createReleaseMock);
|
await mockServer.verify(createReleaseMock);
|
||||||
|
|
||||||
|
/* Merge next into master */
|
||||||
|
version = '2.0.0';
|
||||||
|
const releaseId = 1;
|
||||||
|
verifyMock = await mockServer.mock(
|
||||||
|
`/repos/${owner}/${packageName}`,
|
||||||
|
{headers: [{name: 'Authorization', values: [`token ${env.GH_TOKEN}`]}]},
|
||||||
|
{body: {permissions: {push: true}}, method: 'GET'}
|
||||||
|
);
|
||||||
|
const getReleaseMock = await mockServer.mock(
|
||||||
|
`/repos/${owner}/${packageName}/releases/tags/v2.0.0`,
|
||||||
|
{headers: [{name: 'Authorization', values: [`token ${env.GH_TOKEN}`]}]},
|
||||||
|
{body: {id: releaseId}, method: 'GET'}
|
||||||
|
);
|
||||||
|
const updateReleaseMock = await mockServer.mock(
|
||||||
|
`/repos/${owner}/${packageName}/releases/${releaseId}`,
|
||||||
|
{
|
||||||
|
body: {name: `v${version}`, prerelease: false},
|
||||||
|
headers: [{name: 'Authorization', values: [`token ${env.GH_TOKEN}`]}],
|
||||||
|
},
|
||||||
|
{body: {html_url: `release-url/${version}`}, method: 'PATCH'}
|
||||||
|
);
|
||||||
|
|
||||||
|
t.log('Merge next into master');
|
||||||
|
await gitCheckout('master', false, {cwd});
|
||||||
|
await merge('next', {cwd});
|
||||||
|
await gitPush('origin', 'master', {cwd});
|
||||||
|
t.log('$ semantic-release');
|
||||||
|
({stdout, exitCode} = await execa(cli, [], {env, cwd}));
|
||||||
|
t.regex(stdout, new RegExp(`Updated GitHub release: release-url/${version}`));
|
||||||
|
t.regex(stdout, new RegExp(`Adding version ${version} to npm registry on dist-tag latest`));
|
||||||
|
t.is(exitCode, 0);
|
||||||
|
|
||||||
|
// Wait for 3s as the change of dist-tag takes time to be reflected in the registry
|
||||||
|
await delay(3000);
|
||||||
|
// Retrieve the published package from the registry and check version and gitHead
|
||||||
|
({
|
||||||
|
'dist-tags': {latest: releasedVersion},
|
||||||
|
} = await npmView(packageName, testEnv));
|
||||||
|
t.is(releasedVersion, version);
|
||||||
|
t.is(await gitGetNote(`v${version}`, {cwd}), '{"channels":["next",null]}');
|
||||||
|
t.is(await gitTagHead(`v${version}`, {cwd}), await gitTagHead(`v${version}`, {cwd}));
|
||||||
|
t.is(await gitRemoteTagHead(authUrl, `v${version}`, {cwd}), await gitRemoteTagHead(authUrl, `v${version}`, {cwd}));
|
||||||
|
t.log(`+ added ${releasedVersion}`);
|
||||||
|
|
||||||
|
await mockServer.verify(verifyMock);
|
||||||
|
await mockServer.verify(getReleaseMock);
|
||||||
|
await mockServer.verify(updateReleaseMock);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Exit with 1 if a plugin is not found', async t => {
|
test('Exit with 1 if a plugin is not found', async t => {
|
||||||
@ -366,7 +425,7 @@ test('Allow local releases with "noCi" option', async t => {
|
|||||||
const createReleaseMock = await mockServer.mock(
|
const createReleaseMock = await mockServer.mock(
|
||||||
`/repos/${owner}/${packageName}/releases`,
|
`/repos/${owner}/${packageName}/releases`,
|
||||||
{
|
{
|
||||||
body: {tag_name: `v${version}`, target_commitish: 'master', name: `v${version}`},
|
body: {tag_name: `v${version}`, name: `v${version}`},
|
||||||
headers: [{name: 'Authorization', values: [`token ${env.GH_TOKEN}`]}],
|
headers: [{name: 'Authorization', values: [`token ${env.GH_TOKEN}`]}],
|
||||||
},
|
},
|
||||||
{body: {html_url: `release-url/${version}`}}
|
{body: {html_url: `release-url/${version}`}}
|
||||||
@ -384,9 +443,7 @@ test('Allow local releases with "noCi" option', async t => {
|
|||||||
t.is((await readJson(path.resolve(cwd, 'package.json'))).version, version);
|
t.is((await readJson(path.resolve(cwd, 'package.json'))).version, version);
|
||||||
|
|
||||||
// Retrieve the published package from the registry and check version and gitHead
|
// Retrieve the published package from the registry and check version and gitHead
|
||||||
const [, releasedVersion, releasedGitHead] = /^version = '(.+)'\s+gitHead = '(.+)'$/.exec(
|
const {version: releasedVersion, gitHead: releasedGitHead} = await npmView(packageName, testEnv);
|
||||||
(await execa('npm', ['show', packageName, 'version', 'gitHead'], {env: testEnv, cwd})).stdout
|
|
||||||
);
|
|
||||||
|
|
||||||
const head = await gitHead({cwd});
|
const head = await gitHead({cwd});
|
||||||
t.is(releasedVersion, version);
|
t.is(releasedVersion, version);
|
||||||
@ -439,9 +496,7 @@ test('Pass options via CLI arguments', async t => {
|
|||||||
t.is((await readJson(path.resolve(cwd, 'package.json'))).version, version);
|
t.is((await readJson(path.resolve(cwd, 'package.json'))).version, version);
|
||||||
|
|
||||||
// Retrieve the published package from the registry and check version and gitHead
|
// Retrieve the published package from the registry and check version and gitHead
|
||||||
const [, releasedVersion, releasedGitHead] = /^version = '(.+)'\s+gitHead = '(.+)'$/.exec(
|
const {version: releasedVersion, gitHead: releasedGitHead} = await npmView(packageName, testEnv);
|
||||||
(await execa('npm', ['show', packageName, 'version', 'gitHead'], {env: testEnv, cwd})).stdout
|
|
||||||
);
|
|
||||||
const head = await gitHead({cwd});
|
const head = await gitHead({cwd});
|
||||||
t.is(releasedVersion, version);
|
t.is(releasedVersion, version);
|
||||||
t.is(releasedGitHead, head);
|
t.is(releasedGitHead, head);
|
||||||
@ -482,7 +537,7 @@ test('Run via JS API', async t => {
|
|||||||
const createReleaseMock = await mockServer.mock(
|
const createReleaseMock = await mockServer.mock(
|
||||||
`/repos/${owner}/${packageName}/releases`,
|
`/repos/${owner}/${packageName}/releases`,
|
||||||
{
|
{
|
||||||
body: {tag_name: `v${version}`, target_commitish: 'master', name: `v${version}`},
|
body: {tag_name: `v${version}`, name: `v${version}`},
|
||||||
headers: [{name: 'Authorization', values: [`token ${env.GH_TOKEN}`]}],
|
headers: [{name: 'Authorization', values: [`token ${env.GH_TOKEN}`]}],
|
||||||
},
|
},
|
||||||
{body: {html_url: `release-url/${version}`}}
|
{body: {html_url: `release-url/${version}`}}
|
||||||
@ -497,9 +552,7 @@ test('Run via JS API', async t => {
|
|||||||
t.is((await readJson(path.resolve(cwd, 'package.json'))).version, version);
|
t.is((await readJson(path.resolve(cwd, 'package.json'))).version, version);
|
||||||
|
|
||||||
// Retrieve the published package from the registry and check version and gitHead
|
// Retrieve the published package from the registry and check version and gitHead
|
||||||
const [, releasedVersion, releasedGitHead] = /^version = '(.+)'\s+gitHead = '(.+)'$/.exec(
|
const {version: releasedVersion, gitHead: releasedGitHead} = await npmView(packageName, testEnv);
|
||||||
(await execa('npm', ['show', packageName, 'version', 'gitHead'], {env: testEnv, cwd})).stdout
|
|
||||||
);
|
|
||||||
const head = await gitHead({cwd});
|
const head = await gitHead({cwd});
|
||||||
t.is(releasedVersion, version);
|
t.is(releasedVersion, version);
|
||||||
t.is(releasedGitHead, head);
|
t.is(releasedGitHead, head);
|
||||||
|
@ -152,6 +152,24 @@ test('Wrap "publish" plugin in a function that validate the output of the plugin
|
|||||||
t.regex(error.details, /2/);
|
t.regex(error.details, /2/);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('Wrap "addChannel" plugin in a function that validate the output of the plugin', async t => {
|
||||||
|
const addChannel = stub().resolves(2);
|
||||||
|
const plugin = normalize(
|
||||||
|
{cwd, options: {}, stderr: t.context.stderr, logger: t.context.logger},
|
||||||
|
'addChannel',
|
||||||
|
addChannel,
|
||||||
|
{}
|
||||||
|
);
|
||||||
|
|
||||||
|
const error = await t.throwsAsync(plugin({options: {}}));
|
||||||
|
|
||||||
|
t.is(error.code, 'EADDCHANNELOUTPUT');
|
||||||
|
t.is(error.name, 'SemanticReleaseError');
|
||||||
|
t.truthy(error.message);
|
||||||
|
t.truthy(error.details);
|
||||||
|
t.regex(error.details, /2/);
|
||||||
|
});
|
||||||
|
|
||||||
test('Plugin is called with "pluginConfig" (with object definition) and input', async t => {
|
test('Plugin is called with "pluginConfig" (with object definition) and input', async t => {
|
||||||
const pluginFunction = stub().resolves();
|
const pluginFunction = stub().resolves();
|
||||||
const pluginConf = {path: pluginFunction, conf: 'confValue'};
|
const pluginConf = {path: pluginFunction, conf: 'confValue'};
|
||||||
|
186
test/utils.test.js
Normal file
186
test/utils.test.js
Normal file
@ -0,0 +1,186 @@
|
|||||||
|
import test from 'ava';
|
||||||
|
import AggregateError from 'aggregate-error';
|
||||||
|
import {
|
||||||
|
extractErrors,
|
||||||
|
tagsToVersions,
|
||||||
|
isMajorRange,
|
||||||
|
isMaintenanceRange,
|
||||||
|
getUpperBound,
|
||||||
|
getLowerBound,
|
||||||
|
highest,
|
||||||
|
lowest,
|
||||||
|
getLatestVersion,
|
||||||
|
getEarliestVersion,
|
||||||
|
getFirstVersion,
|
||||||
|
getRange,
|
||||||
|
makeTag,
|
||||||
|
isSameChannel,
|
||||||
|
} from '../lib/utils';
|
||||||
|
|
||||||
|
test('extractErrors', t => {
|
||||||
|
const errors = [new Error('Error 1'), new Error('Error 2')];
|
||||||
|
|
||||||
|
t.deepEqual(extractErrors(new AggregateError(errors)), errors);
|
||||||
|
t.deepEqual(extractErrors(errors[0]), [errors[0]]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('tagsToVersions', t => {
|
||||||
|
t.deepEqual(tagsToVersions([{version: '1.0.0'}, {version: '1.1.0'}, {version: '1.2.0'}]), [
|
||||||
|
'1.0.0',
|
||||||
|
'1.1.0',
|
||||||
|
'1.2.0',
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('isMajorRange', t => {
|
||||||
|
t.false(isMajorRange('1.1.x'));
|
||||||
|
t.false(isMajorRange('1.11.x'));
|
||||||
|
t.false(isMajorRange('11.1.x'));
|
||||||
|
t.false(isMajorRange('11.11.x'));
|
||||||
|
t.false(isMajorRange('1.1.X'));
|
||||||
|
t.false(isMajorRange('1.1.0'));
|
||||||
|
|
||||||
|
t.true(isMajorRange('1.x.x'));
|
||||||
|
t.true(isMajorRange('11.x.x'));
|
||||||
|
t.true(isMajorRange('1.X.X'));
|
||||||
|
t.true(isMajorRange('1.x'));
|
||||||
|
t.true(isMajorRange('11.x'));
|
||||||
|
t.true(isMajorRange('1.X'));
|
||||||
|
});
|
||||||
|
|
||||||
|
test('isMaintenanceRange', t => {
|
||||||
|
t.true(isMaintenanceRange('1.1.x'));
|
||||||
|
t.true(isMaintenanceRange('11.1.x'));
|
||||||
|
t.true(isMaintenanceRange('11.11.x'));
|
||||||
|
t.true(isMaintenanceRange('1.11.x'));
|
||||||
|
t.true(isMaintenanceRange('1.x.x'));
|
||||||
|
t.true(isMaintenanceRange('11.x.x'));
|
||||||
|
t.true(isMaintenanceRange('1.x'));
|
||||||
|
t.true(isMaintenanceRange('11.x'));
|
||||||
|
t.true(isMaintenanceRange('1.1.X'));
|
||||||
|
t.true(isMaintenanceRange('1.X.X'));
|
||||||
|
t.true(isMaintenanceRange('1.X'));
|
||||||
|
|
||||||
|
t.false(isMaintenanceRange('1.1.0'));
|
||||||
|
t.false(isMaintenanceRange('11.1.0'));
|
||||||
|
t.false(isMaintenanceRange('1.11.0'));
|
||||||
|
t.false(isMaintenanceRange('11.11.0'));
|
||||||
|
t.false(isMaintenanceRange('~1.0.0'));
|
||||||
|
t.false(isMaintenanceRange('^1.0.0'));
|
||||||
|
});
|
||||||
|
|
||||||
|
test('getUpperBound', t => {
|
||||||
|
t.is(getUpperBound('1.x.x'), '2.0.0');
|
||||||
|
t.is(getUpperBound('1.X.X'), '2.0.0');
|
||||||
|
t.is(getUpperBound('10.x.x'), '11.0.0');
|
||||||
|
t.is(getUpperBound('1.x'), '2.0.0');
|
||||||
|
t.is(getUpperBound('10.x'), '11.0.0');
|
||||||
|
t.is(getUpperBound('1.0.x'), '1.1.0');
|
||||||
|
t.is(getUpperBound('10.0.x'), '10.1.0');
|
||||||
|
t.is(getUpperBound('10.10.x'), '10.11.0');
|
||||||
|
t.is(getUpperBound('1.0.0'), '1.0.0');
|
||||||
|
t.is(getUpperBound('10.0.0'), '10.0.0');
|
||||||
|
|
||||||
|
t.is(getUpperBound('foo'), undefined);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('getLowerBound', t => {
|
||||||
|
t.is(getLowerBound('1.x.x'), '1.0.0');
|
||||||
|
t.is(getLowerBound('1.X.X'), '1.0.0');
|
||||||
|
t.is(getLowerBound('10.x.x'), '10.0.0');
|
||||||
|
t.is(getLowerBound('1.x'), '1.0.0');
|
||||||
|
t.is(getLowerBound('10.x'), '10.0.0');
|
||||||
|
t.is(getLowerBound('1.0.x'), '1.0.0');
|
||||||
|
t.is(getLowerBound('10.0.x'), '10.0.0');
|
||||||
|
t.is(getLowerBound('1.10.x'), '1.10.0');
|
||||||
|
t.is(getLowerBound('1.0.0'), '1.0.0');
|
||||||
|
t.is(getLowerBound('10.0.0'), '10.0.0');
|
||||||
|
|
||||||
|
t.is(getLowerBound('foo'), undefined);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('highest', t => {
|
||||||
|
t.is(highest('1.0.0', '2.0.0'), '2.0.0');
|
||||||
|
t.is(highest('1.1.1', '1.1.0'), '1.1.1');
|
||||||
|
t.is(highest(null, '1.0.0'), '1.0.0');
|
||||||
|
t.is(highest('1.0.0'), '1.0.0');
|
||||||
|
t.is(highest(), undefined);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('lowest', t => {
|
||||||
|
t.is(lowest('1.0.0', '2.0.0'), '1.0.0');
|
||||||
|
t.is(lowest('1.1.1', '1.1.0'), '1.1.0');
|
||||||
|
t.is(lowest(null, '1.0.0'), '1.0.0');
|
||||||
|
t.is(lowest(), undefined);
|
||||||
|
});
|
||||||
|
|
||||||
|
test.serial('getLatestVersion', t => {
|
||||||
|
t.is(getLatestVersion(['1.2.3-alpha.3', '1.2.0', '1.0.1', '1.0.0-alpha.1']), '1.2.0');
|
||||||
|
t.is(getLatestVersion(['1.2.3-alpha.3', '1.2.3-alpha.2']), undefined);
|
||||||
|
|
||||||
|
t.is(getLatestVersion(['1.2.3-alpha.3', '1.2.0', '1.0.1', '1.0.0-alpha.1']), '1.2.0');
|
||||||
|
t.is(getLatestVersion(['1.2.3-alpha.3', '1.2.3-alpha.2']), undefined);
|
||||||
|
|
||||||
|
t.is(getLatestVersion(['1.2.3-alpha.3', '1.2.0', '1.0.1', '1.0.0-alpha.1'], {withPrerelease: true}), '1.2.3-alpha.3');
|
||||||
|
t.is(getLatestVersion(['1.2.3-alpha.3', '1.2.3-alpha.2'], {withPrerelease: true}), '1.2.3-alpha.3');
|
||||||
|
|
||||||
|
t.is(getLatestVersion([]), undefined);
|
||||||
|
});
|
||||||
|
|
||||||
|
test.serial('getEarliestVersion', t => {
|
||||||
|
t.is(getEarliestVersion(['1.2.3-alpha.3', '1.2.0', '1.0.0', '1.0.1-alpha.1']), '1.0.0');
|
||||||
|
t.is(getEarliestVersion(['1.2.3-alpha.3', '1.2.3-alpha.2']), undefined);
|
||||||
|
|
||||||
|
t.is(getEarliestVersion(['1.2.3-alpha.3', '1.2.0', '1.0.0', '1.0.1-alpha.1']), '1.0.0');
|
||||||
|
t.is(getEarliestVersion(['1.2.3-alpha.3', '1.2.3-alpha.2']), undefined);
|
||||||
|
|
||||||
|
t.is(
|
||||||
|
getEarliestVersion(['1.2.3-alpha.3', '1.2.0', '1.0.1', '1.0.0-alpha.1'], {withPrerelease: true}),
|
||||||
|
'1.0.0-alpha.1'
|
||||||
|
);
|
||||||
|
t.is(getEarliestVersion(['1.2.3-alpha.3', '1.2.3-alpha.2'], {withPrerelease: true}), '1.2.3-alpha.2');
|
||||||
|
|
||||||
|
t.is(getEarliestVersion([]), undefined);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('getFirstVersion', t => {
|
||||||
|
t.is(getFirstVersion(['1.2.0', '1.0.0', '1.3.0', '1.1.0', '1.4.0'], []), '1.0.0');
|
||||||
|
t.is(
|
||||||
|
getFirstVersion(
|
||||||
|
['1.2.0', '1.0.0', '1.3.0', '1.1.0', '1.4.0'],
|
||||||
|
[
|
||||||
|
{name: 'master', tags: [{version: '1.0.0'}, {version: '1.1.0'}]},
|
||||||
|
{name: 'next', tags: [{version: '1.0.0'}, {version: '1.1.0'}, {version: '1.2.0'}]},
|
||||||
|
]
|
||||||
|
),
|
||||||
|
'1.3.0'
|
||||||
|
);
|
||||||
|
t.is(
|
||||||
|
getFirstVersion(
|
||||||
|
['1.2.0', '1.0.0', '1.1.0'],
|
||||||
|
[
|
||||||
|
{name: 'master', tags: [{version: '1.0.0'}, {version: '1.1.0'}]},
|
||||||
|
{name: 'next', tags: [{version: '1.0.0'}, {version: '1.1.0'}, {version: '1.2.0'}]},
|
||||||
|
]
|
||||||
|
),
|
||||||
|
undefined
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('getRange', t => {
|
||||||
|
t.is(getRange('1.0.0', '1.1.0'), '>=1.0.0 <1.1.0');
|
||||||
|
t.is(getRange('1.0.0'), '>=1.0.0');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('makeTag', t => {
|
||||||
|
t.is(makeTag(`v\${version}`, '1.0.0'), 'v1.0.0');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('isSameChannel', t => {
|
||||||
|
t.true(isSameChannel('next', 'next'));
|
||||||
|
t.true(isSameChannel(null, undefined));
|
||||||
|
t.true(isSameChannel(false, undefined));
|
||||||
|
t.true(isSameChannel('', false));
|
||||||
|
|
||||||
|
t.false(isSameChannel('next', false));
|
||||||
|
});
|
@ -5,7 +5,7 @@ import {gitRepo} from './helpers/git-utils';
|
|||||||
|
|
||||||
test('Throw a AggregateError', async t => {
|
test('Throw a AggregateError', async t => {
|
||||||
const {cwd} = await gitRepo();
|
const {cwd} = await gitRepo();
|
||||||
const options = {};
|
const options = {branches: [{name: 'master'}, {name: ''}]};
|
||||||
|
|
||||||
const errors = [...(await t.throwsAsync(verify({cwd, options})))];
|
const errors = [...(await t.throwsAsync(verify({cwd, options})))];
|
||||||
|
|
||||||
@ -21,11 +21,15 @@ test('Throw a AggregateError', async t => {
|
|||||||
t.is(errors[2].code, 'ETAGNOVERSION');
|
t.is(errors[2].code, 'ETAGNOVERSION');
|
||||||
t.truthy(errors[2].message);
|
t.truthy(errors[2].message);
|
||||||
t.truthy(errors[2].details);
|
t.truthy(errors[2].details);
|
||||||
|
t.is(errors[3].name, 'SemanticReleaseError');
|
||||||
|
t.is(errors[3].code, 'EINVALIDBRANCH');
|
||||||
|
t.truthy(errors[3].message);
|
||||||
|
t.truthy(errors[3].details);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Throw a SemanticReleaseError if does not run on a git repository', async t => {
|
test('Throw a SemanticReleaseError if does not run on a git repository', async t => {
|
||||||
const cwd = tempy.directory();
|
const cwd = tempy.directory();
|
||||||
const options = {};
|
const options = {branches: []};
|
||||||
|
|
||||||
const errors = [...(await t.throwsAsync(verify({cwd, options})))];
|
const errors = [...(await t.throwsAsync(verify({cwd, options})))];
|
||||||
|
|
||||||
@ -37,7 +41,7 @@ test('Throw a SemanticReleaseError if does not run on a git repository', async t
|
|||||||
|
|
||||||
test('Throw a SemanticReleaseError if the "tagFormat" is not valid', async t => {
|
test('Throw a SemanticReleaseError if the "tagFormat" is not valid', async t => {
|
||||||
const {cwd, repositoryUrl} = await gitRepo(true);
|
const {cwd, repositoryUrl} = await gitRepo(true);
|
||||||
const options = {repositoryUrl, tagFormat: `?\${version}`};
|
const options = {repositoryUrl, tagFormat: `?\${version}`, branches: []};
|
||||||
|
|
||||||
const errors = [...(await t.throwsAsync(verify({cwd, options})))];
|
const errors = [...(await t.throwsAsync(verify({cwd, options})))];
|
||||||
|
|
||||||
@ -49,7 +53,7 @@ test('Throw a SemanticReleaseError if the "tagFormat" is not valid', async t =>
|
|||||||
|
|
||||||
test('Throw a SemanticReleaseError if the "tagFormat" does not contains the "version" variable', async t => {
|
test('Throw a SemanticReleaseError if the "tagFormat" does not contains the "version" variable', async t => {
|
||||||
const {cwd, repositoryUrl} = await gitRepo(true);
|
const {cwd, repositoryUrl} = await gitRepo(true);
|
||||||
const options = {repositoryUrl, tagFormat: 'test'};
|
const options = {repositoryUrl, tagFormat: 'test', branches: []};
|
||||||
|
|
||||||
const errors = [...(await t.throwsAsync(verify({cwd, options})))];
|
const errors = [...(await t.throwsAsync(verify({cwd, options})))];
|
||||||
|
|
||||||
@ -61,7 +65,7 @@ test('Throw a SemanticReleaseError if the "tagFormat" does not contains the "ver
|
|||||||
|
|
||||||
test('Throw a SemanticReleaseError if the "tagFormat" contains multiple "version" variables', async t => {
|
test('Throw a SemanticReleaseError if the "tagFormat" contains multiple "version" variables', async t => {
|
||||||
const {cwd, repositoryUrl} = await gitRepo(true);
|
const {cwd, repositoryUrl} = await gitRepo(true);
|
||||||
const options = {repositoryUrl, tagFormat: `\${version}v\${version}`};
|
const options = {repositoryUrl, tagFormat: `\${version}v\${version}`, branches: []};
|
||||||
|
|
||||||
const errors = [...(await t.throwsAsync(verify({cwd, options})))];
|
const errors = [...(await t.throwsAsync(verify({cwd, options})))];
|
||||||
|
|
||||||
@ -71,9 +75,43 @@ test('Throw a SemanticReleaseError if the "tagFormat" contains multiple "version
|
|||||||
t.truthy(errors[0].details);
|
t.truthy(errors[0].details);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('Throw a SemanticReleaseError for each invalid branch', async t => {
|
||||||
|
const {cwd, repositoryUrl} = await gitRepo(true);
|
||||||
|
const options = {
|
||||||
|
repositoryUrl,
|
||||||
|
tagFormat: `v\${version}`,
|
||||||
|
branches: [{name: ''}, {name: ' '}, {name: 1}, {}, {name: ''}, 1, 'master'],
|
||||||
|
};
|
||||||
|
|
||||||
|
const errors = [...(await t.throwsAsync(verify({cwd, options})))];
|
||||||
|
|
||||||
|
t.is(errors[0].name, 'SemanticReleaseError');
|
||||||
|
t.is(errors[0].code, 'EINVALIDBRANCH');
|
||||||
|
t.truthy(errors[0].message);
|
||||||
|
t.truthy(errors[0].details);
|
||||||
|
t.is(errors[1].name, 'SemanticReleaseError');
|
||||||
|
t.is(errors[1].code, 'EINVALIDBRANCH');
|
||||||
|
t.truthy(errors[1].message);
|
||||||
|
t.truthy(errors[1].details);
|
||||||
|
t.is(errors[2].name, 'SemanticReleaseError');
|
||||||
|
t.is(errors[2].code, 'EINVALIDBRANCH');
|
||||||
|
t.truthy(errors[2].message);
|
||||||
|
t.truthy(errors[2].details);
|
||||||
|
t.is(errors[3].name, 'SemanticReleaseError');
|
||||||
|
t.is(errors[3].code, 'EINVALIDBRANCH');
|
||||||
|
t.truthy(errors[3].message);
|
||||||
|
t.truthy(errors[3].details);
|
||||||
|
t.is(errors[4].code, 'EINVALIDBRANCH');
|
||||||
|
t.truthy(errors[4].message);
|
||||||
|
t.truthy(errors[4].details);
|
||||||
|
t.is(errors[5].code, 'EINVALIDBRANCH');
|
||||||
|
t.truthy(errors[5].message);
|
||||||
|
t.truthy(errors[5].details);
|
||||||
|
});
|
||||||
|
|
||||||
test('Return "true" if all verification pass', async t => {
|
test('Return "true" if all verification pass', async t => {
|
||||||
const {cwd, repositoryUrl} = await gitRepo(true);
|
const {cwd, repositoryUrl} = await gitRepo(true);
|
||||||
const options = {repositoryUrl, tagFormat: `v\${version}`};
|
const options = {repositoryUrl, tagFormat: `v\${version}`, branches: [{name: 'master'}]};
|
||||||
|
|
||||||
await t.notThrowsAsync(verify({cwd, options}));
|
await t.notThrowsAsync(verify({cwd, options}));
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user