From 7b4052470b23261c9e679a17bff034da311fd894 Mon Sep 17 00:00:00 2001 From: Pierre Vanduynslager Date: Sat, 7 Jul 2018 01:30:46 -0400 Subject: [PATCH 001/107] feat: support multiple branches and distribution channels - Allow to configure multiple branches to release from - Allow to define a distribution channel associated with each branch - Manage the availability on distribution channels based on git merges - Support regular releases, maintenance releases and pre-releases - Add the `addChannel` plugin step to make an existing release available on a different distribution channel BREAKING CHANGE: the `branch` option has been removed in favor of `branches` The new `branches` option expect either an Array or a single branch definition. To migrate your configuration: - If you want to publish package from multiple branches, please the configuration documentation - If you use the default configuration and want to publish only from `master`: nothing to change - If you use the `branch` configuration and want to publish only from one branch: replace `branch` by `branches` (`"branch": "my-release-branch"` => `"branches": "my-release-branch"`) --- .travis.yml | 5 +- README.md | 4 + cli.js | 2 +- docs/developer-guide/js-api.md | 53 +- docs/recipes/README.md | 5 + docs/recipes/distribution-channels.md | 116 ++++ docs/recipes/maintenance-releases.md | 156 +++++ docs/recipes/pre-releases.md | 196 ++++++ docs/usage/configuration.md | 28 +- docs/usage/workflow-configuration.md | 187 ++++++ index.js | 97 ++- lib/branches/expand.js | 18 + lib/branches/get-tags.js | 39 ++ lib/branches/index.js | 62 ++ lib/branches/normalize.js | 110 ++++ lib/definitions/branches.js | 23 + lib/definitions/constants.js | 5 +- lib/definitions/errors.js | 119 +++- lib/definitions/plugins.js | 16 +- lib/get-commits.js | 19 +- lib/get-config.js | 10 +- lib/get-git-auth-url.js | 4 +- lib/get-last-release.js | 40 +- lib/get-next-version.js | 15 +- lib/get-releases-to-add.js | 64 ++ lib/git.js | 111 +++- lib/utils.js | 72 ++- lib/verify.js | 12 +- package.json | 10 +- test/branches/branches.test.js | 199 ++++++ test/branches/expand.test.js | 46 ++ test/branches/get-tags.test.js | 202 ++++++ test/branches/normalize.test.js | 307 ++++++++++ test/cli.test.js | 7 +- test/definitions/branches.test.js | 86 +++ test/definitions/plugins.test.js | 10 + test/get-commits.test.js | 19 + test/get-config.test.js | 157 +++-- test/get-git-auth-url.test.js | 80 ++- test/get-last-release.test.js | 183 ++---- test/get-next-version.test.js | 134 +++- test/get-releases-to-add.test.js | 258 ++++++++ test/git.test.js | 51 +- test/helpers/git-utils.js | 47 +- test/helpers/npm-utils.js | 5 + test/index.test.js | 844 +++++++++++++++++++++++--- test/integration.test.js | 137 +++-- test/plugins/normalize.test.js | 18 + test/utils.test.js | 153 +++++ test/verify.test.js | 50 +- 50 files changed, 4072 insertions(+), 519 deletions(-) create mode 100644 docs/recipes/distribution-channels.md create mode 100644 docs/recipes/maintenance-releases.md create mode 100644 docs/recipes/pre-releases.md create mode 100644 docs/usage/workflow-configuration.md create mode 100644 lib/branches/expand.js create mode 100644 lib/branches/get-tags.js create mode 100644 lib/branches/index.js create mode 100644 lib/branches/normalize.js create mode 100644 lib/definitions/branches.js create mode 100644 lib/get-releases-to-add.js create mode 100644 test/branches/branches.test.js create mode 100644 test/branches/expand.test.js create mode 100644 test/branches/get-tags.test.js create mode 100644 test/branches/normalize.test.js create mode 100644 test/definitions/branches.test.js create mode 100644 test/get-releases-to-add.test.js create mode 100644 test/helpers/npm-utils.js create mode 100644 test/utils.test.js diff --git a/.travis.yml b/.travis.yml index c3c0da4d22..3661cbb942 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,11 +7,14 @@ node_js: - 10 - 8 -# Trigger a push build on master and greenkeeper branches + PRs build on every branches +# Trigger a push build on release and greenkeeper branches + PRs build on every branches # Avoid double build on PRs (See https://github.com/travis-ci/travis-ci/issues/1147) branches: only: - master + - next + - beta + - /^\d+(.\d+)?.x$/ - /^greenkeeper.*$/ # Retry install on fail to avoid failing a build on network/disk/external errors diff --git a/README.md b/README.md index c402a4e806..4c62f904e1 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,9 @@ npm next version + + npm beta version +

**semantic-release** automates the whole package release workflow including: determining the next version number, generating the release notes and publishing the package. @@ -44,6 +47,7 @@ This removes the immediate connection between human emotions and version numbers - New features and fixes are immediately available to users - Notify maintainers and users of new releases - 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) - 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) diff --git a/cli.js b/cli.js index 1ef5f5baa7..2767c49e19 100755 --- a/cli.js +++ b/cli.js @@ -19,7 +19,7 @@ module.exports = async () => { Usage: 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('t', {alias: 'tag-format', describe: 'Git tag format', type: 'string', group: 'Options'}) .option('p', {alias: 'plugins', describe: 'Plugins', ...stringList, group: 'Options'}) diff --git a/docs/developer-guide/js-api.md b/docs/developer-guide/js-api.md index 415bf0ee66..4f6bd1ac89 100644 --- a/docs/developer-guide/js-api.md +++ b/docs/developer-guide/js-api.md @@ -123,11 +123,12 @@ Type: `Object` Information related to the last release found: -| Name | Type | Description | -|---------|----------|----------------------------------------------------------------------------------------------------| -| version | `String` | The version 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. | +| Name | Type | Description | +|---------|----------|-------------------------------------------------------------------------------------------------------------------------------------| +| version | `String` | The version 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. | +| 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`. @@ -137,6 +138,7 @@ Example: gitHead: 'da39a3ee5e6b4b0d3255bfef95601890afd80709', version: '1.0.0', gitTag: 'v1.0.0', + channel: 'next' } ``` @@ -206,13 +208,14 @@ Type: `Object` Information related to the newly published release: -| Name | Type | Description | -|---------|----------|---------------------------------------------------------------------------------------------------| -| type | `String` | The [semver](https://semver.org) type of the release (`patch`, `minor` or `major`). | -| version | `String` | The version 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. | -| notes | `String` | The release notes for the new release. | +| Name | Type | Description | +|---------|----------|-------------------------------------------------------------------------------------------------------------------------------| +| type | `String` | The [semver](https://semver.org) type of the release (`patch`, `minor` or `major`). | +| version | `String` | The version 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. | +| 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: ```js @@ -222,6 +225,7 @@ Example: version: '1.1.0', gitTag: 'v1.1.0', notes: 'Release notes for version 1.1.0...', + channel : 'next' } ``` @@ -229,19 +233,20 @@ Example: Type: `Array` -The list of releases published, one release per [publish plugin](../usage/plugins.md#publish-plugin).
+The list of releases published or made available to a distribution channel.
Each release object has the following properties: -| Name | Type | Description | -|------------|----------|-----------------------------------------------------------------------------------------------| -| 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. | -| type | `String` | The [semver](https://semver.org) type of the release (`patch`, `minor` or `major`). | -| version | `String` | The version of the release. | -| gitHead | `String` | The sha of the last commit being part of 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. | -| pluginName | `String` | The name of the plugin that published the release. | +| Name | Type | Description | +|------------|----------|----------------------------------------------------------------------------------------------------------------| +| 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. | +| type | `String` | The [semver](https://semver.org) type of the release (`patch`, `minor` or `major`). | +| version | `String` | The version of the release. | +| gitHead | `String` | The sha of the last commit being part of 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. | +| 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: ```js @@ -255,6 +260,7 @@ Example: gitTag: 'v1.1.0', notes: 'Release notes for version 1.1.0...', pluginName: '@semantic-release/github' + channel: 'next' }, { name: 'npm package (@latest dist-tag)', @@ -265,6 +271,7 @@ Example: gitTag: 'v1.1.0', notes: 'Release notes for version 1.1.0...', pluginName: '@semantic-release/npm' + channel: 'next' } ] ``` diff --git a/docs/recipes/README.md b/docs/recipes/README.md index c22cd9436b..28d381ffc3 100644 --- a/docs/recipes/README.md +++ b/docs/recipes/README.md @@ -9,4 +9,9 @@ ## Git hosted services - [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 diff --git a/docs/recipes/distribution-channels.md b/docs/recipes/distribution-channels.md new file mode 100644 index 0000000000..0d9abafa27 --- /dev/null +++ b/docs/recipes/distribution-channels.md @@ -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): `['+([1-9])?(.{+([1-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. diff --git a/docs/recipes/maintenance-releases.md b/docs/recipes/maintenance-releases.md new file mode 100644 index 0000000000..0eb93ee2d7 --- /dev/null +++ b/docs/recipes/maintenance-releases.md @@ -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): `['+([1-9])?(.{+([1-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 `. 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 +``` diff --git a/docs/recipes/pre-releases.md b/docs/recipes/pre-releases.md new file mode 100644 index 0000000000..1f7891858b --- /dev/null +++ b/docs/recipes/pre-releases.md @@ -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): `['+([1-9])?(.{+([1-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 +``` diff --git a/docs/usage/configuration.md b/docs/usage/configuration.md index 12e4d0ec7b..4004f32caa 100644 --- a/docs/usage/configuration.md +++ b/docs/usage/configuration.md @@ -1,7 +1,7 @@ # Configuration **semantic-release** configuration consists of: -- Git repository options ([URL](#repositoryurl), [release branch](#branch) and [tag format](#tagformat)) +- Git repository options ([URL](#repositoryurl), [release branches](#branches) and [tag format](#tagformat)) - [plugins](#plugins) definition - run mode ([debug](#debug), [dry run](#dryrun) and [local (no CI)](#ci)) @@ -25,7 +25,7 @@ Via `release` key in the project's `package.json` file: ```json { "release": { - "branch": "next" + "branches": ["master", "next"] } } ``` @@ -37,7 +37,7 @@ Via `.releaserc` file: ```json { - "branch": "next" + "branches": ["master", "next"] } ``` ```bash @@ -67,13 +67,23 @@ 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. -### branch +### branches -Type: `String`
-Default: `master`
-CLI arguments: `-b`, `--branch` +Type: `Array`, `String`, `Object`
+Default: `['+([1-9])?(.{+([1-9]),x}).x', 'master', 'next', 'next-major', {name: 'beta', prerelease: true}, {name: 'alpha', prerelease: true}]`
+CLI arguments: `--branches` + +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 -The branch on which releases should happen. +**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 [Plugins configuration](plugins.md#plugins) for more details. ### repositoryUrl @@ -144,7 +154,7 @@ Output debugging information. This can also be enabled by setting the `DEBUG` en ## 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. 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`). +**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 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. diff --git a/docs/usage/workflow-configuration.md b/docs/usage/workflow-configuration.md new file mode 100644 index 0000000000..022920311e --- /dev/null +++ b/docs/usage/workflow-configuration.md @@ -0,0 +1,187 @@ +# 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 parrallel +- 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. 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 `['+([1-9])?(.{+([1-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. If it's not defined, releases will be done on the default distribution channel (for example the `@latest` [dist-tag](https://docs.npmjs.com/cli/dist-tag) for npm). +The value of `channel`, if defined, 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, is required 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` then: +- Only versions in range `1.x.x` can be published from `master`, so only `fix` and `feat` commits can be pushed to `master` +- Only versions in range `>=2.0.0` release can be published from `next`, so a `BREAKING CHANGE` commit must be pushed first on `next` and can be followed by any type of commits + +With the configuration `"branches": ["master", "next", "next-major"]`, if the last release published from `master` is `1.0.0` then: +- Only versions in range `1.0.x` can be published from `master`, so only `fix` commits can be pushed to `master` +- Only versions in range `>=1.1.0` can be published from `next`, so a `feat` commit must be pushed first on `next` and can be followed by `fix` and `feat` commits +- Only versions in range `>=2.0.0` release can be published from `next`, so a `BREAKING CHANGE` commit must be pushed first on `next-major` and can be followed by any type of commits + +Those verifications prevent situations such as: +1. Create a `feat` commit on `next` which triggers the release of version `1.0.0` on channel `next` +2. Merge `next` into `master` which adds `1.0.0` on the default channel +3. Push a `fix` commit to `master` which triggers the release of version `1.0.1` on the default channel +4. Push a `fix` commit to `next` which would attempt to release the version `1.0.1` on channel `next` and fails as this version already exists + +#### 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 diff --git a/index.js b/index.js index 0bbfa08799..a9ccf47e5d 100644 --- a/index.js +++ b/index.js @@ -1,8 +1,11 @@ -const {template, pick} = require('lodash'); +const {pick} = require('lodash'); const marked = require('marked'); const TerminalRenderer = require('marked-terminal'); const envCi = require('env-ci'); const hookStd = require('hook-std'); +const pEachSeries = require('p-each-series'); +const semver = require('semver'); +const AggregateError = require('aggregate-error'); const pkg = require('./package.json'); const hideSensitive = require('./lib/hide-sensitive'); const getConfig = require('./lib/get-config'); @@ -10,8 +13,10 @@ const verify = require('./lib/verify'); const getNextVersion = require('./lib/get-next-version'); const getCommits = require('./lib/get-commits'); const getLastRelease = require('./lib/get-last-release'); -const {extractErrors} = require('./lib/utils'); +const getReleasesToAdd = require('./lib/get-releases-to-add'); +const {extractErrors, makeTag} = require('./lib/utils'); const getGitAuthUrl = require('./lib/get-git-auth-url'); +const getBranches = require('./lib/branches'); const getLogger = require('./lib/get-logger'); const {fetch, verifyAuth, isBranchUpToDate, getGitHead, tag, push} = require('./lib/git'); const getError = require('./lib/get-error'); @@ -19,6 +24,7 @@ const {COMMIT_NAME, COMMIT_EMAIL} = require('./lib/definitions/constants'); marked.setOptions({renderer: new TerminalRenderer()}); +/* eslint complexity: ["warn", 25] */ async function run(context, plugins) { const {cwd, env, options, logger} = context; const {isCi, branch: ciBranch, isPr} = envCi({env, cwd}); @@ -44,11 +50,19 @@ async function run(context, plugins) { return false; } - if (ciBranch !== options.branch) { + // Verify config + await verify(context); + + await fetch({cwd, env}); + + context.branches = await getBranches(context); + context.branch = context.branches.find(({name}) => name === ciBranch); + + if (!context.branch) { 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; } @@ -56,17 +70,17 @@ async function run(context, plugins) { `Run automated release from branch ${ciBranch}${options.dryRun ? ' in dry-run mode' : ''}` ); - await verify(context); - options.repositoryUrl = await getGitAuthUrl(context); try { try { - await verifyAuth(options.repositoryUrl, options.branch, {cwd, env}); + await verifyAuth(options.repositoryUrl, context.branch.name, {cwd, env}); } catch (error) { - if (!(await isBranchUpToDate(options.branch, {cwd, env}))) { + if (!(await isBranchUpToDate(context.branch.name, {cwd, env}))) { 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; } @@ -81,20 +95,65 @@ async function run(context, plugins) { await plugins.verifyConditions(context); - await fetch(options.repositoryUrl, {cwd, env}); + const releasesToAdd = getReleasesToAdd(context); + const errors = []; + context.releases = []; + + await pEachSeries(releasesToAdd, async ({lastRelease, currentRelease, nextRelease}) => { + if (context.branch['merge-range'] && !semver.satisfies(nextRelease.version, context.branch['merge-range'])) { + errors.push(getError('EINVALIDMAINTENANCEMERGE', {nextRelease, branch: context.branch})); + return; + } + + const commits = await getCommits({...context, lastRelease, nextRelease}); + nextRelease.notes = await plugins.generateNotes({...context, commits, lastRelease, nextRelease}); + + logger.log('Create tag %s', nextRelease.gitTag); + await tag(nextRelease.gitTag, nextRelease.gitHead, {cwd, env}); + await push(options.repositoryUrl, context.branch.name, {cwd, env}); + 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 = await getLastRelease(context); - context.commits = await getCommits(context); - const nextRelease = {type: await plugins.analyzeCommits(context), gitHead: await getGitHead({cwd, env})}; + context.commits = await getCommits(context); + const nextRelease = { + type: await plugins.analyzeCommits(context), + channel: context.branch.channel, + gitHead: await getGitHead({cwd, env}), + }; if (!nextRelease.type) { 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; nextRelease.version = getNextVersion(context); - nextRelease.gitTag = template(options.tagFormat)({version: nextRelease.version}); + nextRelease.gitTag = makeTag(options.tagFormat, nextRelease.version, nextRelease.channel); + nextRelease.name = makeTag(options.tagFormat, nextRelease.version); + + 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); @@ -106,12 +165,12 @@ async function run(context, plugins) { logger.warn(`Skip ${nextRelease.gitTag} tag creation in dry-run mode`); } else { // Create the tag before calling the publish plugins as some require the tag to exists - await tag(nextRelease.gitTag, {cwd, env}); - await push(options.repositoryUrl, options.branch, {cwd, env}); + await tag(nextRelease.gitTag, nextRelease.gitHead, {cwd, env}); + await push(options.repositoryUrl, context.branch.name, {cwd, env}); logger.success(`Created tag ${nextRelease.gitTag}`); } - context.releases = await plugins.publish(context); + context.releases.push(...(await plugins.publish(context))); await plugins.success(context); diff --git a/lib/branches/expand.js b/lib/branches/expand.js new file mode 100644 index 0000000000..c40632acb2 --- /dev/null +++ b/lib/branches/expand.js @@ -0,0 +1,18 @@ +const {isString, remove, omit, mapValues, template} = require('lodash'); +const micromatch = require('micromatch'); +const {getBranches} = require('../git'); + +module.exports = async ({cwd}, branches) => { + const gitBranches = await getBranches({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)), + })), + ], + [] + ); +}; diff --git a/lib/branches/get-tags.js b/lib/branches/get-tags.js new file mode 100644 index 0000000000..194f25de00 --- /dev/null +++ b/lib/branches/get-tags.js @@ -0,0 +1,39 @@ +const {template, escapeRegExp} = require('lodash'); +const semver = require('semver'); +const pReduce = require('p-reduce'); +const debug = require('debug')('semantic-release:get-tags'); +const {getTags, isRefInHistory, getTagHead} = 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(' ', '(.[^@]+)@?(.+)?')}`; + const tags = (await getTags({cwd, env})) + .map(tag => { + const [, version, channel] = tag.match(tagRegexp) || []; + return {gitTag: tag, version, channel}; + }) + .filter(({version}) => version && semver.valid(semver.clean(version))); + + debug('found tags: %o', tags); + + return pReduce( + branches, + async (branches, branch) => { + const branchTags = await pReduce( + tags, + async (tags, {gitTag, ...rest}) => + (await isRefInHistory(gitTag, branch.name, true, {cwd, env})) + ? [...tags, {...rest, gitTag, gitHead: await getTagHead(gitTag, {cwd, env})}] + : tags, + [] + ); + + debug('found tags for branch %s: %o', branch.name, branchTags); + return [...branches, {...branch, tags: branchTags}]; + }, + [] + ); +}; diff --git a/lib/branches/index.js b/lib/branches/index.js new file mode 100644 index 0000000000..b039a3ee80 --- /dev/null +++ b/lib/branches/index.js @@ -0,0 +1,62 @@ +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 {verifyBranchName} = require('../git'); +const expand = require('./expand'); +const getTags = require('./get-tags'); +const normalize = require('./normalize'); + +module.exports = async context => { + const branches = await getTags( + context, + await expand( + context, + context.options.branches.map(branch => (isString(branch) || isRegExp(branch) ? {name: branch} : branch)) + ) + ); + + 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((val, 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]; +}; diff --git a/lib/branches/normalize.js b/lib/branches/normalize.js new file mode 100644 index 0000000000..34e4049e0b --- /dev/null +++ b/lib/branches/normalize.js @@ -0,0 +1,110 @@ +const {sortBy} = require('lodash'); +const semver = require('semver'); +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: channel || name, + })), + '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)) : [], + 'merge-range': getRange(maintenanceMin, getUpperBound(range)), + }; + }); +} + +function release({release}) { + if (release.length === 0) { + return release; + } + const breakpoints = release.length > 2 ? ['minor', 'major'] : ['major']; + + // The intial bound is the last release from the base branch of `FIRST_RELEASE` (1.0.0) + let bound = getLatestVersion(tagsToVersions(release[0].tags)) || FIRST_RELEASE; + + return release.map(({name, tags, channel, ...rest}, idx) => { + const versions = tagsToVersions(tags); + // The lower bound is the highest version between the current branch last release and the previous branch upper bound (`bound`) + const min = highest(getLatestVersion(versions), bound); + if (release.length - 1 === idx) { + // If the current branch is the last one of the release branch, there is no upper bound + bound = undefined; + } else { + // The default upper bound is the lower bound increment with the release type of the current branch position + const upperBound = semver.inc(min, breakpoints[idx]); + // Find the lowest version that is present on the current branch but none of the previous ones + const nextFirstVersion = getFirstVersion(tagsToVersions(release[idx + 1].tags), release.slice(0, idx + 1)); + // The upper bound is the lowest version between `nextFirstVersion` and the default upper bound + bound = lowest(nextFirstVersion, upperBound); + } + const diff = bound ? semverDiff(min, bound) : null; + return { + ...rest, + channel: idx === 0 ? channel : channel || name, + tags, + type: 'release', + name, + range: getRange(min, bound), + accept: bound ? RELEASE_TYPE.slice(0, RELEASE_TYPE.indexOf(diff)) : RELEASE_TYPE, + }; + }); +} + +function prerelease({prerelease}) { + return prerelease.map(({name, prerelease, channel, tags, ...rest}) => { + const preid = prerelease === true ? name : prerelease; + return { + ...rest, + channel: channel || name, + type: 'prerelease', + name, + prerelease: preid, + tags, + }; + }); +} + +module.exports = {maintenance, release, prerelease}; diff --git a/lib/definitions/branches.js b/lib/definitions/branches.js new file mode 100644 index 0000000000..1a2ddd7ea8 --- /dev/null +++ b/lib/definitions/branches.js @@ -0,0 +1,23 @@ +const {isUndefined, uniqBy} = require('lodash'); +const semver = require('semver'); +const {isMaintenanceRange} = require('../utils'); + +const maintenance = { + filter: ({name, range}) => !isUndefined(range) || isMaintenanceRange(name), + branchValidator: ({range}) => (isUndefined(range) ? true : isMaintenanceRange(range)), + branchesValidator: branches => uniqBy(branches, ({range}) => semver.validRange(range)).length === branches.length, +}; + +const prerelease = { + filter: ({prerelease}) => !isUndefined(prerelease), + 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}; diff --git a/lib/definitions/constants.js b/lib/definitions/constants.js index 300733c828..491a1a71a3 100644 --- a/lib/definitions/constants.js +++ b/lib/definitions/constants.js @@ -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 FIRSTPRERELEASE = '1'; + const COMMIT_NAME = 'semantic-release-bot'; const COMMIT_EMAIL = 'semantic-release-bot@martynus.net'; @@ -15,6 +17,7 @@ const SECRET_MIN_SIZE = 5; module.exports = { RELEASE_TYPE, FIRST_RELEASE, + FIRSTPRERELEASE, COMMIT_NAME, COMMIT_EMAIL, RELEASE_NOTES_SEPARATOR, diff --git a/lib/definitions/errors.js b/lib/definitions/errors.js index 96945df399..9c0be3100b 100644 --- a/lib/definitions/errors.js +++ b/lib/definitions/errors.js @@ -1,12 +1,14 @@ const url = require('url'); const {inspect} = require('util'); -const {toLower, isString} = require('lodash'); +const {toLower, isString, trim} = require('lodash'); const pkg = require('../../package.json'); const {RELEASE_TYPE} = require('./constants'); const homepage = url.format({...url.parse(pkg.homepage), hash: null}); const stringify = obj => (isString(obj) ? obj : inspect(obj, {breakLength: Infinity, depth: 2, maxArrayLength: 5})); 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 = { ENOGITREPO: ({cwd}) => ({ @@ -125,4 +127,119 @@ We recommend to report the issue to the \`${pluginName}\` authors, providing the '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' + )}). + +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, branch, commits, validBranches}) => ({ + message: `The release \`${nextRelease.version}\` on branch \`${ + 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 \`${ + branch.range + }\` can be published from branch \`${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 \`${ + 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, branch}) => ({ + message: `The release \`${nextRelease.version}\` on branch \`${ + branch.name + }\` cannot be published as it is out of range.`, + details: `Only releases within the range \`${branch['merge-range']}\` can be merged into the maintenance branch \`${ + branch.name + }\` and published to the \`${nextRelease.channel}\` distribution channel. + +The branch \`${ + branch.name + }\` head should be [reset](https://git-scm.com/docs/git-reset) to a previous commit so the commit with tag \`${ + nextRelease.gitTag + }\` is removed from the branch history. + +See the [workflow configuration documentation](${linkify('docs/usage/workflow-configuration.md')}) for more details.`, + }), }; diff --git a/lib/definitions/plugins.js b/lib/definitions/plugins.js index adb07ee7f1..f3516c33e7 100644 --- a/lib/definitions/plugins.js +++ b/lib/definitions/plugins.js @@ -71,8 +71,22 @@ module.exports = { pipelineConfig: () => ({ // Add `nextRelease` and plugin properties to published release transform: (release, step, {nextRelease}) => ({ - ...(isPlainObject(release) ? release : {}), ...nextRelease, + ...(release || {}), + ...step, + }), + }), + }, + addChannel: { + default: ['@semantic-release/npm', '@semantic-release/github'], + required: false, + dryRun: false, + outputValidator: output => !output || isPlainObject(output), + pipelineConfig: () => ({ + // Add `nextRelease` and plugin properties to published release + transform: (release, step, {nextRelease}) => ({ + ...nextRelease, + ...(release || {}), ...step, }), }), diff --git a/lib/get-commits.js b/lib/get-commits.js index 69d20dfb82..2bd5ec777c 100644 --- a/lib/get-commits.js +++ b/lib/get-commits.js @@ -1,6 +1,5 @@ -const gitLogParser = require('git-log-parser'); -const getStream = require('get-stream'); 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. @@ -9,21 +8,15 @@ const debug = require('debug')('semantic-release:get-commits'); * * @return {Promise>} The list of commits on the branch `branch` since the last release. */ -module.exports = async ({cwd, env, lastRelease: {gitHead}, logger}) => { - if (gitHead) { - debug('Use gitHead: %s', gitHead); +module.exports = async ({cwd, env, lastRelease: {gitHead: from}, nextRelease: {gitHead: to = 'HEAD'} = {}, logger}) => { + if (from) { + debug('Use from: %s', from); } else { 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 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; - }); + const commits = await getCommits(from, to, {cwd, env}); + logger.log(`Found ${commits.length} commits since last release`); debug('Parsed commits: %o', commits); return commits; diff --git a/lib/get-config.js b/lib/get-config.js index aaa76b7a6f..1ee2abb688 100644 --- a/lib/get-config.js +++ b/lib/get-config.js @@ -62,7 +62,14 @@ module.exports = async (context, opts) => { // Set default options values if not defined yet options = { - branch: 'master', + branches: [ + '+([1-9])?(.{+([1-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})), tagFormat: `v\${version}`, plugins: [ @@ -73,6 +80,7 @@ module.exports = async (context, opts) => { ], // Remove `null` and `undefined` options so they can be replaced with default ones ...pickBy(options, option => !isNil(option)), + ...(options.branches ? {branches: castArray(options.branches)} : {}), }; debug('options values: %O', options); diff --git a/lib/get-git-auth-url.js b/lib/get-git-auth-url.js index eaa4243c33..421d19d1f5 100644 --- a/lib/get-git-auth-url.js +++ b/lib/get-git-auth-url.js @@ -24,7 +24,7 @@ const GIT_TOKENS = { * * @return {String} The formatted Git repository URL. */ -module.exports = async ({cwd, env, options: {repositoryUrl, branch}}) => { +module.exports = async ({cwd, env, branch, options: {repositoryUrl}}) => { const info = hostedGitInfo.fromUrl(repositoryUrl, {noGitPlus: true}); const {protocol, ...parsed} = parse(repositoryUrl); @@ -38,7 +38,7 @@ 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) try { - await verifyAuth(repositoryUrl, branch, {cwd, env}); + await verifyAuth(repositoryUrl, branch.name, {cwd, env}); } catch (error) { const envVar = Object.keys(GIT_TOKENS).find(envVar => !isNil(env[envVar])); const gitCredentials = `${GIT_TOKENS[envVar] || ''}${env[envVar] || ''}`; diff --git a/lib/get-last-release.js b/lib/get-last-release.js index 7ec1417491..1fbf4a7e04 100644 --- a/lib/get-last-release.js +++ b/lib/get-last-release.js @@ -1,8 +1,6 @@ -const {escapeRegExp, template} = require('lodash'); +const {isUndefined} = require('lodash'); const semver = require('semver'); -const pLocate = require('p-locate'); -const debug = require('debug')('semantic-release:get-last-release'); -const {getTags, isRefInHistory, getTagHead} = require('./git'); +const {makeTag} = require('./utils'); /** * Last release. @@ -15,37 +13,27 @@ const {getTags, isRefInHistory, getTagHead} = require('./git'); /** * 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 ones that are not valid semantic version or doesn't match the `tagFormat` + * - Filter out the branch tags that are not valid semantic version * - Sort the versions * - Retrive the highest version * * @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} 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}) => { - // 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(' ', '(.+)')}`; - const tags = (await getTags({cwd, env})) - .map(tag => ({gitTag: tag, version: (tag.match(tagRegexp) || new Array(2))[1]})) - .filter( - tag => tag.version && semver.valid(semver.clean(tag.version)) && !semver.prerelease(semver.clean(tag.version)) - ) +module.exports = ({branch: {name, tags, type}, options: {tagFormat}, logger}, {before} = {}) => { + const [{version, gitTag, gitHead, channel} = {}] = tags + .filter(tag => type === 'prerelease' || !semver.prerelease(tag.version)) + .filter(tag => isUndefined(before) || semver.lt(tag.version, before)) .sort((a, b) => semver.rcompare(a.version, b.version)); - debug('found tags: %o', tags); - - 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}; + if (gitTag) { + logger.log(`Found git tag ${gitTag} associated with version ${version} on branch ${name}`); + return {version, gitTag, gitHead, channel, name: makeTag(tagFormat, version)}; } - logger.log('No git tag version found'); + logger.log(`No git tag version found on branch ${name}`); return {}; }; diff --git a/lib/get-next-version.js b/lib/get-next-version.js index 10089e9faa..f4c4439e50 100644 --- a/lib/get-next-version.js +++ b/lib/get-next-version.js @@ -1,13 +1,18 @@ const semver = require('semver'); -const {FIRST_RELEASE} = require('./definitions/constants'); +const {FIRST_RELEASE, FIRSTPRERELEASE} = require('./definitions/constants'); -module.exports = ({nextRelease: {type}, lastRelease, logger}) => { +module.exports = ({branch, nextRelease: {type}, lastRelease, logger}) => { let version; if (lastRelease.version) { - version = semver.inc(lastRelease.version, type); - logger.log(`The next release version is ${version}`); + version = + branch.type === 'prerelease' + ? semver.prerelease(lastRelease.version) + ? semver.inc(lastRelease.version, 'prerelease') + : `${semver.inc(lastRelease.version, type)}-${branch.prerelease}.${FIRSTPRERELEASE}` + : semver.inc(lastRelease.version, type); + logger.log('The next release version is %s', version); } else { - version = FIRST_RELEASE; + version = branch.type === 'prerelease' ? `${FIRST_RELEASE}-${branch.prerelease}.${FIRSTPRERELEASE}` : FIRST_RELEASE; logger.log(`There is no previous release, the next release version is ${version}`); } diff --git a/lib/get-releases-to-add.js b/lib/get-releases-to-add.js new file mode 100644 index 0000000000..a800dcebd1 --- /dev/null +++ b/lib/get-releases-to-add.js @@ -0,0 +1,64 @@ +const {uniq} = require('lodash'); +const semver = require('semver'); +const semverDiff = require('semver-diff'); +const getLastRelease = require('./get-last-release'); +const {makeTag} = 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} Last release and next release to be added on the channel of the current branch. + */ +module.exports = context => { + const { + branch, + branches, + options: {tagFormat}, + } = context; + + return ( + branches + // Consider only releases of higher branches + .slice(branches.findIndex(({name}) => name === branch.name) + 1) + // Exclude prerelease branches + .filter(({type}) => type !== 'prerelease') + // Find higher branch releases merged to building branch but not released on associated channel + .reduce( + (releases, higherBranch) => [ + ...releases, + // For all unique release version of the higher branch merged on current branch + ...uniq(branch.tags.filter(({channel}) => channel === higherBranch.channel)) + // Find ones that are not released on the building branch channel + .filter(tag => + branch.tags.every( + ({version, channel}) => + version !== tag.version || channel === higherBranch.channel || channel !== branch.channel + ) + ) + // Sort in ascending order to add the most recent release last + .sort((a, b) => semver.compare(a.version, b.version)) + // Construct the last and next release to add to the building branch channel + .map(({version, gitHead, gitTag}) => { + const lastRelease = getLastRelease(context, {before: version}); + const type = lastRelease.version ? semverDiff(lastRelease.version, version) : 'major'; + const name = makeTag(tagFormat, version); + return { + lastRelease, + currentRelease: {type, version, channel: higherBranch.channel, gitTag, name, gitHead}, + nextRelease: { + type, + version, + channel: branch.channel, + gitTag: makeTag(tagFormat, version, branch.channel), + name, + gitHead, + }, + }; + }), + ], + [] + ) + ); +}; diff --git a/lib/git.js b/lib/git.js index be0cdaa1fe..62b285a5a0 100644 --- a/lib/git.js +++ b/lib/git.js @@ -1,13 +1,18 @@ +const {trimStart, matches, pick, memoize} = require('lodash'); +const gitLogParser = require('git-log-parser'); +const getStream = require('get-stream'); const execa = require('execa'); const debug = require('debug')('semantic-release:git'); +Object.assign(gitLogParser.fields, {hash: 'H', message: 'B', gitTags: 'd', committerDate: {key: 'ci', type: Date}}); + /** * Get the commit sha for a given tag. * * @param {String} tagName Tag name for which to retrieve the commit sha. * @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) { try { @@ -33,19 +38,67 @@ async function getTags(execaOpts) { } /** - * Verify if the `ref` is in the direct history of the current branch. + * Retrieve a range of commits. + * + * @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`. + * @return {Promise>} The list of commits between `from` and `to`. + */ +async function getCommits(from, to, execaOpts) { + return (await getStream.array( + gitLogParser.parse( + {_: `${from ? from + '..' : ''}${to}`}, + {cwd: execaOpts.cwd, env: {...process.env, ...execaOpts.env}} + ) + )).map(({message, gitTags, ...commit}) => ({...commit, message: message.trim(), gitTags: gitTags.trim()})); +} + +/** + * Get all the repository branches. + * + * @param {Object} [execaOpts] Options to pass to `execa`. + * + * @return {Array} List of git branches. + * @throws {Error} If the `git` command fails. + */ +async function getBranches(execaOpts) { + return (await execa.stdout('git', ['branch', '--list', '--no-color'], execaOpts)) + .split('\n') + .map(branch => trimStart(branch, '*').trim()) + .filter(Boolean); +} + +const getBranchCommits = memoize((branch, execaOpts) => + getStream.array(gitLogParser.parse({_: branch}, {cwd: execaOpts.cwd, env: {...process.env, ...execaOpts.env}})) +); + +/** + * Verify if the `ref` is in the direct history of a given branch. * * @param {String} ref The reference to look for. + * @param {String} branch The branch for which to check if the `ref` is in history. + * @param {Boolean} findRebasedTags Weither consider in history tags associated with a commit that was rebased to another branch (i.e. GitHub Rebase and Merge feature). * @param {Object} [execaOpts] Options to pass to `execa`. * * @return {Boolean} `true` if the reference is in the history of the current branch, falsy otherwise. */ -async function isRefInHistory(ref, execaOpts) { +async function isRefInHistory(ref, branch, findRebasedTags, execaOpts) { + if (!(await isRefExists(branch, execaOpts))) { + return false; + } + try { - await execa('git', ['merge-base', '--is-ancestor', ref, 'HEAD'], execaOpts); + await execa('git', ['merge-base', '--is-ancestor', ref, branch], execaOpts); return true; } catch (error) { if (error.code === 1) { + if (findRebasedTags) { + const [tagCommit] = await getStream.array( + gitLogParser.parse({_: ref, n: '1'}, {cwd: execaOpts.cwd, env: {...process.env, ...execaOpts.env}}) + ); + return (await getBranchCommits(branch, execaOpts)).some(matches(pick(tagCommit, ['message', 'author']))); + } return false; } @@ -54,17 +107,32 @@ async function isRefInHistory(ref, execaOpts) { } } +/** + * 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)).code === 0; + } catch (error) { + debug(error); + } +} + /** * Unshallow the git repository if necessary and fetch all the tags. * - * @param {String} repositoryUrl The remote repository URL. * @param {Object} [execaOpts] Options to pass to `execa`. */ -async function fetch(repositoryUrl, execaOpts) { +async function fetch(execaOpts) { try { - await execa('git', ['fetch', '--unshallow', '--tags', repositoryUrl], execaOpts); + await execa('git', ['fetch', '--unshallow', '--tags'], execaOpts); } catch (error) { - await execa('git', ['fetch', '--tags', repositoryUrl], execaOpts); + await execa('git', ['fetch', '--tags'], execaOpts); } } @@ -131,12 +199,13 @@ async function verifyAuth(repositoryUrl, branch, execaOpts) { * Tag the commit head on the local repository. * * @param {String} tagName The name of the tag. + * @param {String} ref The Git reference to tag. * @param {Object} [execaOpts] Options to pass to `execa`. * * @throws {Error} if the tag creation failed. */ -async function tag(tagName, execaOpts) { - await execa('git', ['tag', tagName], execaOpts); +async function tag(tagName, ref, execaOpts) { + await execa('git', ['tag', tagName, ref], execaOpts); } /** @@ -168,6 +237,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)).code === 0; + } catch (error) { + debug(error); + } +} + /** * Verify the local branch is up to date with the remote one. * @@ -179,7 +264,7 @@ async function verifyTagName(tagName, execaOpts) { async function isBranchUpToDate(branch, execaOpts) { const remoteHead = await execa.stdout('git', ['ls-remote', '--heads', 'origin', branch], execaOpts); try { - return await isRefInHistory(remoteHead.match(/^(\w+)?/)[1], execaOpts); + return await isRefInHistory(remoteHead.match(/^(\w+)?/)[1], branch, false, execaOpts); } catch (error) { debug(error); } @@ -188,7 +273,10 @@ async function isBranchUpToDate(branch, execaOpts) { module.exports = { getTagHead, getTags, + getCommits, + getBranches, isRefInHistory, + isRefExists, fetch, getGitHead, repoUrl, @@ -198,4 +286,5 @@ module.exports = { push, verifyTagName, isBranchUpToDate, + verifyBranchName, }; diff --git a/lib/utils.js b/lib/utils.js index b3e1a2509c..697b00a5ac 100644 --- a/lib/utils.js +++ b/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'); function extractErrors(err) { @@ -17,4 +18,71 @@ 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\.[\dx](?:\.x)?$/i.test(range); +} + +function getUpperBound(range) { + return semver.valid(range) ? range : ((semver.validRange(range) || '').match(/<(\d\.\d\.\d)$/) || [])[1]; +} + +function getLowerBound(range) { + return ((semver.validRange(range) || '').match(/(\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, channel) { + return template(tagFormat)({version: `${version}${channel ? `@${channel}` : ''}`}); +} + +module.exports = { + extractErrors, + hideSensitiveValues, + tagsToVersions, + isMajorRange, + isMaintenanceRange, + getUpperBound, + getLowerBound, + highest, + lowest, + getLatestVersion, + getEarliestVersion, + getFirstVersion, + getRange, + makeTag, +}; diff --git a/lib/verify.js b/lib/verify.js index 462d9a60da..a4eaf727d0 100644 --- a/lib/verify.js +++ b/lib/verify.js @@ -1,9 +1,9 @@ -const {template} = require('lodash'); +const {template, isString, isPlainObject} = require('lodash'); const AggregateError = require('aggregate-error'); const {isGitRepo, verifyTagName} = require('./git'); const getError = require('./get-error'); -module.exports = async ({cwd, env, options: {repositoryUrl, tagFormat}}) => { +module.exports = async ({cwd, env, options: {repositoryUrl, tagFormat, branches}}) => { const errors = []; if (!(await isGitRepo({cwd, env}))) { @@ -24,6 +24,14 @@ module.exports = async ({cwd, env, options: {repositoryUrl, tagFormat}}) => { errors.push(getError('ETAGNOVERSION', {tagFormat})); } + 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) { throw new AggregateError(errors); } diff --git a/package.json b/package.json index b7eb7bd34a..dd076f8fea 100644 --- a/package.json +++ b/package.json @@ -21,8 +21,8 @@ "dependencies": { "@semantic-release/commit-analyzer": "^6.1.0", "@semantic-release/error": "^2.2.0", - "@semantic-release/github": "^5.1.0", - "@semantic-release/npm": "^5.0.5", + "@semantic-release/github": "^5.3.0-beta.1", + "@semantic-release/npm": "^5.2.0-beta.1", "@semantic-release/release-notes-generator": "^7.1.2", "aggregate-error": "^1.0.0", "cosmiconfig": "^5.0.1", @@ -38,11 +38,13 @@ "lodash": "^4.17.4", "marked": "^0.5.0", "marked-terminal": "^3.0.0", - "p-locate": "^3.0.0", + "micromatch": "3.1.5", + "p-each-series": "^1.0.0", "p-reduce": "^1.0.0", "read-pkg-up": "^4.0.0", "resolve-from": "^4.0.0", "semver": "^5.4.1", + "semver-diff": "^2.1.0", "signale": "^1.2.1", "yargs": "^12.0.0" }, @@ -110,7 +112,7 @@ "trailingComma": "es5" }, "publishConfig": { - "tag": "next" + "access": "public" }, "repository": { "type": "git", diff --git a/test/branches/branches.test.js b/test/branches/branches.test.js new file mode 100644 index 0000000000..31c19c36b4 --- /dev/null +++ b/test/branches/branches.test.js @@ -0,0 +1,199 @@ +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}); + + let result = (await getBranches({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 <1.1.0', 'Can release only patch on master'); + t.is(getBranch(result, 'next').range, '>=1.1.0 <2.0.0', 'Can release only minor on next'); + t.is(getBranch(result, 'next-major').range, '>=2.0.0', 'Can release only major on next-major'); + + release(branches, 'master', '1.0.0'); + result = (await getBranches({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 <1.1.0', 'Can release only patch on master'); + + release(branches, 'master', '1.0.1'); + result = (await getBranches({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'); + + merge(branches, 'master', 'next'); + merge(branches, 'master', 'next-major'); + result = (await getBranches({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.0 <2.0.0', 'Can release only minor on next'); + t.is(getBranch(result, 'next-major').range, '>=2.0.0', 'Can release only major on next-major'); + + release(branches, 'next', '1.1.0'); + release(branches, 'next', '1.1.1'); + result = (await getBranches({options: {branches}})).map(({name, range}) => ({name, range})); + t.is(getBranch(result, 'next').range, '>=1.1.1 <2.0.0', 'Can release only patch or minor, > than 1.1.0 on next'); + + release(branches, 'next-major', '2.0.0'); + release(branches, 'next-major', '2.0.1'); + result = (await getBranches({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, '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({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'); + release(branches, 'master', '1.0.1'); + result = (await getBranches({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({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({options: {branches}})).map(({name, range}) => ({name, range})); + t.is(getBranch(result, 'master').range, '>=1.1.1 <1.2.0', 'Can release only patch, > than 1.1.1 on master'); + t.is(getBranch(result, 'next').range, '>=1.2.0 <2.0.0', 'Can release only patch or minor, > than 1.2.0 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({options: {branches}})).map(({name, range}) => ({name, range})); + t.is(getBranch(result, 'master').range, '>=1.1.1 <1.2.0', 'Can release only patch, > 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({options: {branches}})).map(({name, range}) => ({name, range})); + t.is(getBranch(result, 'master').range, '>=1.1.1 <1.2.0', 'Can release only patch, > 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({options: {branches}})).map(({name, range}) => ({name, range})); + t.is(getBranch(result, 'master').range, '>=2.0.1 <2.1.0', 'Can release only patch, > than 2.0.1 on master'); + t.is(getBranch(result, 'next').range, '>=2.1.0 <3.0.0', 'Can release only minor on next'); + t.is(getBranch(result, 'next-major').range, '>=3.0.0', 'Can release only major 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'); + result = (await getBranches({options: {branches}})).map(({name, range}) => ({name, range})); + t.is(getBranch(result, 'master').range, '>=2.0.1 <2.1.0', 'Can release only patch, > than 2.0.1 on master'); + t.is(getBranch(result, 'next').range, '>=2.1.0 <3.0.0', 'Can release only minor on next'); + t.is(getBranch(result, 'next-major').range, '>=3.0.0', 'Can release only major on next-major'); + + branches.push({name: '1.1.x', tags: []}); + merge(branches, '1.x', '1.1.x'); + result = (await getBranches({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}); + const errors = [...(await t.throws(getBranches({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}); + + const errors = [...(await t.throws(getBranches({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}); + + const errors = [...(await t.throws(getBranches({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); +}); diff --git a/test/branches/expand.test.js b/test/branches/expand.test.js new file mode 100644 index 0000000000..ec0f3853e2 --- /dev/null +++ b/test/branches/expand.test.js @@ -0,0 +1,46 @@ +import test from 'ava'; +import expand from '../../lib/branches/expand'; +import {gitRepo, gitCommits, gitCheckout} from '../helpers/git-utils'; + +test('Expand branches defined with globs', async t => { + const {cwd} = await gitRepo(); + await gitCommits(['First'], {cwd}); + await gitCheckout('1.1.x', true, {cwd}); + await gitCommits(['Second'], {cwd}); + await gitCheckout('1.x.x', true, {cwd}); + await gitCommits(['Third'], {cwd}); + await gitCheckout('2.x', true, {cwd}); + await gitCommits(['Fourth'], {cwd}); + await gitCheckout('next', true, {cwd}); + await gitCommits(['Fifth'], {cwd}); + await gitCheckout('pre/foo', true, {cwd}); + await gitCommits(['Sixth'], {cwd}); + await gitCheckout('pre/bar', true, {cwd}); + await gitCommits(['Seventh'], {cwd}); + await gitCheckout('beta', true, {cwd}); + await gitCommits(['Eighth'], {cwd}); + + const branches = [ + // Should match all maintenance type branches + {name: '+([1-9])?(.{+([1-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({cwd}, branches), [ + {name: '1.1.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}, + ]); +}); diff --git a/test/branches/get-tags.test.js b/test/branches/get-tags.test.js new file mode 100644 index 0000000000..0ebe140dc9 --- /dev/null +++ b/test/branches/get-tags.test.js @@ -0,0 +1,202 @@ +import test from 'ava'; +import getTags from '../../lib/branches/get-tags'; +import {gitRepo, gitCommits, gitTagVersion, gitCheckout, merge, changeAuthor} 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', channel: undefined, gitHead: commits[1].hash}, + {gitTag: 'v2.0.0', version: '2.0.0', channel: undefined, gitHead: commits[0].hash}, + {gitTag: 'v3.0.0-beta.1', version: '3.0.0-beta.1', channel: undefined, gitHead: commits[3].hash}, + ], + }, + ]); +}); + +test('Get the valid tags from multiple branches', async t => { + const {cwd} = await gitRepo(); + const commits = await gitCommits(['First'], {cwd}); + await gitTagVersion('v1.0.0', undefined, {cwd}); + await gitTagVersion('v1.0.0@1.x', undefined, {cwd}); + commits.push(...(await gitCommits(['Second'], {cwd}))); + await gitTagVersion('v1.1.0', undefined, {cwd}); + await gitTagVersion('v1.1.0@1.x', undefined, {cwd}); + await gitCheckout('1.x', true, {cwd}); + await gitCheckout('master', false, {cwd}); + commits.push(...(await gitCommits(['Third'], {cwd}))); + await gitTagVersion('v2.0.0', undefined, {cwd}); + await gitTagVersion('v2.0.0@next', undefined, {cwd}); + await gitCheckout('next', true, {cwd}); + commits.push(...(await gitCommits(['Fourth'], {cwd}))); + await gitTagVersion('v3.0.0@next', undefined, {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', channel: undefined, gitHead: commits[0].hash}, + {gitTag: 'v1.0.0@1.x', version: '1.0.0', channel: '1.x', gitHead: commits[0].hash}, + {gitTag: 'v1.1.0', version: '1.1.0', channel: undefined, gitHead: commits[1].hash}, + {gitTag: 'v1.1.0@1.x', version: '1.1.0', channel: '1.x', gitHead: commits[1].hash}, + ], + }, + { + name: 'master', + tags: [ + ...result[0].tags, + {gitTag: 'v2.0.0', version: '2.0.0', channel: undefined, gitHead: commits[2].hash}, + {gitTag: 'v2.0.0@next', version: '2.0.0', channel: 'next', gitHead: commits[2].hash}, + ], + }, + { + name: 'next', + tags: [...result[1].tags, {gitTag: 'v3.0.0@next', version: '3.0.0', channel: 'next', gitHead: commits[3].hash}], + }, + ]); +}); + +test('Match the tag name from the begining of the string and the channel from the last "@"', async t => { + const {cwd} = await gitRepo(); + const commits = await gitCommits(['First'], {cwd}); + await gitTagVersion('prefix@v1.0.0', undefined, {cwd}); + await gitTagVersion('prefix@v1.0.0@next', undefined, {cwd}); + await gitTagVersion('prefix@v2.0.0', undefined, {cwd}); + await gitTagVersion('prefix@v2.0.0@next', undefined, {cwd}); + await gitTagVersion('other-prefix@v3.0.0', undefined, {cwd}); + + const result = await getTags({cwd, options: {tagFormat: `prefix@v\${version}`}}, [{name: 'master'}]); + + t.deepEqual(result, [ + { + name: 'master', + tags: [ + {gitTag: 'prefix@v1.0.0', version: '1.0.0', channel: undefined, gitHead: commits[0].hash}, + {gitTag: 'prefix@v1.0.0@next', version: '1.0.0', channel: 'next', gitHead: commits[0].hash}, + {gitTag: 'prefix@v2.0.0', version: '2.0.0', channel: undefined, gitHead: commits[0].hash}, + {gitTag: 'prefix@v2.0.0@next', version: '2.0.0', channel: 'next', gitHead: commits[0].hash}, + ], + }, + ]); +}); + +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'}, {name: 'next'}]); + + t.deepEqual(result, [{name: 'master', tags: []}, {name: 'next', 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('other-branch', true, {cwd}); + await gitCommits(['Second'], {cwd}); + await gitTagVersion('v1.0.0', undefined, {cwd}); + await gitTagVersion('v1.0.0@next', undefined, {cwd}); + await gitTagVersion('v2.0.0', undefined, {cwd}); + await gitTagVersion('v2.0.0@next', undefined, {cwd}); + await gitTagVersion('v3.0.0', undefined, {cwd}); + await gitTagVersion('v3.0.0@next', undefined, {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(); + const commits = 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', channel: undefined, gitHead: commits[0].hash}]}, + ]); + + 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', channel: undefined, gitHead: commits[0].hash}]}, + ]); + + 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', channel: undefined, gitHead: commits[0].hash}], + }, + ]); + + 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', channel: undefined, gitHead: commits[0].hash}], + }, + ]); + + 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', channel: undefined, gitHead: commits[0].hash}], + }, + ]); + + 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', channel: undefined, gitHead: commits[0].hash}]}, + ]); +}); + +test('Get the tag on branch where commits have been rebased', async t => { + const {cwd} = await gitRepo(); + const commits = await gitCommits(['First'], {cwd}); + await gitCheckout('next', true, {cwd}); + commits.push(...(await gitCommits(['Second/n/n/commit body'], {cwd}))); + await gitTagVersion('v1.0.0@next', undefined, {cwd}); + await gitCheckout('master', false, {cwd}); + await merge('next', {cwd}); + // Simulate GitHub "Rebase and Merge" by changing the committer info, which will result in a new commit sha and losing the tag + await changeAuthor(commits[1].hash, {cwd}); + + const result = await getTags({cwd, options: {tagFormat: `v\${version}`}}, [{name: 'master'}, {name: 'next'}]); + + t.deepEqual(result, [ + { + name: 'master', + tags: [{gitTag: 'v1.0.0@next', version: '1.0.0', channel: 'next', gitHead: commits[1].hash}], + }, + { + name: 'next', + tags: [{gitTag: 'v1.0.0@next', version: '1.0.0', channel: 'next', gitHead: commits[1].hash}], + }, + ]); +}); diff --git a/test/branches/normalize.test.js b/test/branches/normalize.test.js new file mode 100644 index 0000000000..cb4a7b36b9 --- /dev/null +++ b/test/branches/normalize.test.js @@ -0,0 +1,307 @@ +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', 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, 'merge-range': maintenanceRange}) => ({ + type, + name, + range, + accept, + channel, + 'merge-range': maintenanceRange, + })), + [ + { + type: 'maintenance', + name: '1.1.x', + range: '>=1.1.0 <1.0.0', + accept: [], + channel: '1.1.x', + 'merge-range': '>=1.1.0 <1.2.0', + }, + { + type: 'maintenance', + name: '1.2.x', + range: '>=1.2.0 <1.0.0', + accept: [], + channel: '1.2.x', + 'merge-range': '>=1.2.0 <1.3.0', + }, + { + type: 'maintenance', + name: '1.x', + range: '>=1.3.0 <1.0.0', + accept: [], + channel: '1.x', + 'merge-range': '>=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, 'merge-range': maintenanceRange}) => ({ + type, + name, + range, + accept, + channel, + 'merge-range': maintenanceRange, + })), + [ + { + type: 'maintenance', + name: 'name', + range: '>=1.1.1 <1.2.0', + accept: ['patch'], + channel: 'name', + 'merge-range': '>=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', + 'merge-range': '>=1.2.0 <1.3.0', + }, + { + type: 'maintenance', + name: '1.x', + range: '>=1.5.0 <1.6.0', + accept: ['patch'], + channel: '1.x', + 'merge-range': '>=1.3.0 <2.0.0', + }, + { + type: 'maintenance', + name: '2.x.x', + range: '>=2.0.0 <1.6.0', + accept: [], + channel: '2.x.x', + 'merge-range': '>=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, 'merge-range': maintenanceRange}) => ({ + type, + name, + range, + accept, + channel, + 'merge-range': maintenanceRange, + })), + [ + { + type: 'maintenance', + name: '1.x', + range: '>=1.3.0 <2.0.0', + accept: ['patch', 'minor'], + channel: '1.x', + 'merge-range': '>=1.0.0 <2.0.0', + }, + { + type: 'maintenance', + name: '2.x.x', + range: '>=2.0.0 <2.0.0', + accept: [], + channel: '2.x.x', + 'merge-range': '>=2.0.0 <3.0.0', + }, + ] + ); +}); + +test('Release branches - initial state', t => { + const release = [{name: 'master', tags: []}, {name: 'next', tags: []}, {name: 'next-major', tags: []}]; + + t.deepEqual( + normalize.release({release}).map(({type, name, range, accept, channel}) => ({type, name, range, accept, channel})), + [ + {type: 'release', name: 'master', range: '>=1.0.0 <1.1.0', accept: ['patch'], channel: undefined}, + {type: 'release', name: 'next', range: '>=1.1.0 <2.0.0', accept: ['patch', 'minor'], channel: 'next'}, + { + type: 'release', + name: 'next-major', + range: '>=2.0.0', + accept: ['patch', 'minor', 'major'], + channel: 'next-major', + }, + ] + ); +}); + +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}) => ({type, name, range, accept, channel})), + [ + {type: 'release', name: 'master', range: '>=1.0.2 <1.1.0', accept: ['patch'], channel: undefined}, + {type: 'release', name: 'next', range: '>=1.2.0 <2.0.0', accept: ['patch', 'minor'], channel: 'next'}, + { + type: 'release', + name: 'next-major', + range: '>=2.1.0', + accept: ['patch', 'minor', 'major'], + channel: 'next-major', + }, + ] + ); +}); + +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}) => ({type, name, range, accept, channel})), + [ + {type: 'release', name: 'master', range: '>=1.2.0 <2.0.0', accept: ['patch', 'minor'], channel: undefined}, + {type: 'release', name: 'next', range: '>=2.1.0', accept: ['patch', 'minor', 'major'], channel: 'next'}, + ] + ); +}); + +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}) => ({type, name, range, accept, channel})), + [ + {type: 'release', name: 'master', range: '>=2.0.0 <2.1.0', accept: ['patch'], channel: undefined}, + {type: 'release', name: 'next', range: '>=2.1.0 <2.2.0', accept: ['patch'], channel: 'next'}, + { + type: 'release', + name: 'next-major', + range: '>=2.2.0', + accept: ['patch', 'minor', 'major'], + channel: 'next-major', + }, + ] + ); +}); + +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}) => ({type, name, range, accept, channel})), + [ + {type: 'release', name: 'master', range: '>=2.0.0 <3.0.0', accept: ['patch', 'minor'], channel: undefined}, + {type: 'release', name: 'next', range: '>=3.0.0', accept: ['patch', 'minor', 'major'], channel: 'next'}, + ] + ); +}); + +test('Release branches - enforce release gaps after downstream merge', t => { + const release = [ + {name: 'master', tags: toTags(['1.0.0', '1.1.0', '2.0.0'])}, + {name: 'next', tags: toTags(['1.0.0', '1.1.0', '2.0.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}) => ({type, name, range, accept, channel})), + [ + {type: 'release', name: 'master', range: '>=2.0.0 <2.1.0', accept: ['patch'], channel: undefined}, + {type: 'release', name: 'next', range: '>=2.1.0 <3.0.0', accept: ['patch', 'minor'], channel: 'next'}, + { + type: 'release', + name: 'next-major', + range: '>=3.0.0', + accept: ['patch', 'minor', 'major'], + channel: 'next-major', + }, + ] + ); +}); + +test('Release branches - limit releases on 2nd and 3rd branche 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}) => ({type, name, range, accept, channel})), + [ + {type: 'release', name: 'master', range: '>=3.0.0 <3.1.0', accept: ['patch'], channel: undefined}, + {type: 'release', name: 'next', range: '>=3.1.0 <4.0.0', accept: ['patch', 'minor'], channel: 'next'}, + { + type: 'release', + name: 'next-major', + range: '>=4.0.0', + accept: ['patch', 'minor', 'major'], + channel: 'next-major', + }, + ] + ); +}); + +test('Prerelease branches', t => { + const prerelease = [{name: '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'}, + ]); +}); diff --git a/test/cli.test.js b/test/cli.test.js index bad7efaffe..aca4d03ffb 100644 --- a/test/cli.test.js +++ b/test/cli.test.js @@ -29,6 +29,7 @@ test.serial('Pass options to semantic-release API', async t => { '', '-b', 'master', + 'next', '-r', 'https://github/com/owner/repo.git', '-t', @@ -68,7 +69,7 @@ test.serial('Pass options to semantic-release API', async t => { 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].tagFormat, `v\${version}`); 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 = [ '', '', - '--branch', + '--branches', 'master', '--repository-url', '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(); - 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].tagFormat, `v\${version}`); t.deepEqual(run.args[0][0].plugins, ['plugin1', 'plugin2']); diff --git a/test/definitions/branches.test.js b/test/definitions/branches.test.js new file mode 100644 index 0000000000..22d48416b1 --- /dev/null +++ b/test/definitions/branches.test.js @@ -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: null})); + t.true(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: ''})); + t.false(maintenance.branchValidator({name: 'some-name', range: null})); + t.false(maintenance.branchValidator({name: 'some-name', range: false})); +}); + +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 range "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.true(prerelease.filter({name: 'some-name', prerelease: null})); + t.true(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'}])); +}); diff --git a/test/definitions/plugins.test.js b/test/definitions/plugins.test.js index 9f869d9ad1..effca5c08c 100644 --- a/test/definitions/plugins.test.js +++ b/test/definitions/plugins.test.js @@ -32,6 +32,16 @@ test('The "publish" plugin output, if defined, must be an object', t => { t.true(plugins.publish.outputValidator('')); }); +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 => { const env = {MY_TOKEN: 'secret token'}; t.is(plugins.generateNotes.postprocess(['note 1', 'note 2'], {env}), `note 1${RELEASE_NOTES_SEPARATOR}note 2`); diff --git a/test/get-commits.test.js b/test/get-commits.test.js index 2fee322fa1..5313f917a6 100644 --- a/test/get-commits.test.js +++ b/test/get-commits.test.js @@ -66,6 +66,25 @@ test('Get all commits since gitHead (from lastRelease) on a detached head repo', 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 => { // Create a git repository, set the current working directory at the root of the repo const {cwd} = await gitRepo(); diff --git a/test/get-config.test.js b/test/get-config.test.js index 2fb13a7a57..6978723598 100644 --- a/test/get-config.test.js +++ b/test/get-config.test.js @@ -6,7 +6,7 @@ import {omit} from 'lodash'; import proxyquire from 'proxyquire'; import {stub} from 'sinon'; 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 = [ '@semantic-release/commit-analyzer', @@ -23,8 +23,10 @@ test.beforeEach(t => { test('Default values, reading repositoryUrl from package.json', async t => { const pkg = {repository: 'https://host.null/owner/package.git'}; // 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 gitTagVersion('v1.0.0', undefined, {cwd}); + await gitTagVersion('v1.1.0', undefined, {cwd}); // Add remote.origin.url config await gitAddConfig('remote.origin.url', 'git@host.null:owner/repo.git', {cwd}); // 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}); // Verify the default options are set - t.is(result.branch, 'master'); + t.deepEqual(result.branches, [ + '+([1-9])?(.{+([1-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.tagFormat, `v\${version}`); }); 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 - const {cwd} = await gitRepo(); + const {cwd} = await gitRepo(true); // Add remote.origin.url config await gitAddConfig('remote.origin.url', 'https://host.null/owner/module.git', {cwd}); const {options: result} = await t.context.getConfig({cwd}); // Verify the default options are set - t.is(result.branch, 'master'); + t.deepEqual(result.branches, [ + '+([1-9])?(.{+([1-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.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}); // Verify the default options are set - t.is(result.branch, 'master'); + t.deepEqual(result.branches, [ + '+([1-9])?(.{+([1-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.tagFormat, `v\${version}`); }); @@ -73,7 +96,7 @@ test('Read options from package.json', async t => { const options = { analyzeCommits: {path: 'analyzeCommits', param: 'analyzeCommits_param'}, generateNotes: 'generateNotes', - branch: 'test_branch', + branches: ['test_branch'], repositoryUrl: 'https://host.null/owner/module.git', tagFormat: `v\${version}`, plugins: false, @@ -83,10 +106,11 @@ test('Read options from package.json', async t => { const {options: result} = await t.context.getConfig({cwd}); + const expected = {...options, branches: ['test_branch']}; // 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 - 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 => { @@ -94,7 +118,7 @@ test('Read options from .releaserc.yml', async t => { const {cwd} = await gitRepo(); const options = { analyzeCommits: {path: 'analyzeCommits', param: 'analyzeCommits_param'}, - branch: 'test_branch', + branches: ['test_branch'], repositoryUrl: 'https://host.null/owner/module.git', tagFormat: `v\${version}`, plugins: false, @@ -104,10 +128,11 @@ test('Read options from .releaserc.yml', async t => { const {options: result} = await t.context.getConfig({cwd}); + const expected = {...options, branches: ['test_branch']}; // 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 - 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 => { @@ -115,7 +140,7 @@ test('Read options from .releaserc.json', async t => { const {cwd} = await gitRepo(); const options = { analyzeCommits: {path: 'analyzeCommits', param: 'analyzeCommits_param'}, - branch: 'test_branch', + branches: ['test_branch'], repositoryUrl: 'https://host.null/owner/module.git', tagFormat: `v\${version}`, plugins: false, @@ -125,10 +150,11 @@ test('Read options from .releaserc.json', async t => { const {options: result} = await t.context.getConfig({cwd}); + const expected = {...options, branches: ['test_branch']}; // 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 - 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 => { @@ -136,7 +162,7 @@ test('Read options from .releaserc.js', async t => { const {cwd} = await gitRepo(); const options = { analyzeCommits: {path: 'analyzeCommits', param: 'analyzeCommits_param'}, - branch: 'test_branch', + branches: ['test_branch'], repositoryUrl: 'https://host.null/owner/module.git', tagFormat: `v\${version}`, plugins: false, @@ -146,10 +172,11 @@ test('Read options from .releaserc.js', async t => { const {options: result} = await t.context.getConfig({cwd}); + const expected = {...options, branches: ['test_branch']}; // 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 - 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 => { @@ -157,7 +184,7 @@ test('Read options from release.config.js', async t => { const {cwd} = await gitRepo(); const options = { analyzeCommits: {path: 'analyzeCommits', param: 'analyzeCommits_param'}, - branch: 'test_branch', + branches: ['test_branch'], repositoryUrl: 'https://host.null/owner/module.git', tagFormat: `v\${version}`, plugins: false, @@ -167,10 +194,11 @@ test('Read options from release.config.js', async t => { const {options: result} = await t.context.getConfig({cwd}); + const expected = {...options, branches: ['test_branch']}; // 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 - 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 => { @@ -181,11 +209,11 @@ test('Prioritise CLI/API parameters over file configuration and git repo', async cwd = await gitShallowClone(repositoryUrl); const pkgOptions = { analyzeCommits: {path: 'analyzeCommits', param: 'analyzeCommits_pkg'}, - branch: 'branch_pkg', + branches: ['branch_pkg'], }; const options = { analyzeCommits: {path: 'analyzeCommits', param: 'analyzeCommits_cli'}, - branch: 'branch_cli', + branches: ['branch_cli'], repositoryUrl: 'http://cli-url.com/owner/package', tagFormat: `cli\${version}`, plugins: false, @@ -196,10 +224,11 @@ test('Prioritise CLI/API parameters over file configuration and git repo', async const result = await t.context.getConfig({cwd}, options); + const expected = {...options, branches: ['branch_cli']}; // 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 - 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 => { @@ -209,7 +238,7 @@ test('Read configuration from file path in "extends"', async t => { const options = { analyzeCommits: {path: 'analyzeCommits', param: 'analyzeCommits_param'}, generateNotes: 'generateNotes', - branch: 'test_branch', + branches: ['test_branch'], repositoryUrl: 'https://host.null/owner/module.git', tagFormat: `v\${version}`, plugins: ['plugin-1', ['plugin-2', {plugin2Opt: 'value'}]], @@ -220,10 +249,11 @@ test('Read configuration from file path in "extends"', async t => { const {options: result} = await t.context.getConfig({cwd}); + const expected = {...options, branches: ['test_branch']}; // 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 - 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], { analyzeCommits: './shareable.json', generateNotes: './shareable.json', @@ -239,7 +269,7 @@ test('Read configuration from module path in "extends"', async t => { const options = { analyzeCommits: {path: 'analyzeCommits', param: 'analyzeCommits_param'}, generateNotes: 'generateNotes', - branch: 'test_branch', + branches: ['test_branch'], repositoryUrl: 'https://host.null/owner/module.git', tagFormat: `v\${version}`, plugins: false, @@ -248,12 +278,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, '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 - t.deepEqual(results, options); + 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], {cwd, options}); + t.deepEqual(t.context.plugins.args[0][0], {options: expected, cwd}); t.deepEqual(t.context.plugins.args[0][1], { analyzeCommits: 'shareable', generateNotes: 'shareable', @@ -267,14 +298,14 @@ test('Read configuration from an array of paths in "extends"', async t => { const options1 = { verifyRelease: 'verifyRelease1', analyzeCommits: {path: 'analyzeCommits1', param: 'analyzeCommits_param1'}, - branch: 'test_branch', + branches: ['test_branch'], repositoryUrl: 'https://host.null/owner/module.git', }; const options2 = { verifyRelease: 'verifyRelease2', generateNotes: 'generateNotes2', analyzeCommits: {path: 'analyzeCommits2', param: 'analyzeCommits_param2'}, - branch: 'test_branch', + branches: ['test_branch'], tagFormat: `v\${version}`, plugins: false, }; @@ -283,12 +314,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, '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 - 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 - 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], { verifyRelease1: './shareable1.json', verifyRelease2: './shareable2.json', @@ -303,7 +335,7 @@ test('Prioritize configuration from config file over "extends"', async t => { const {cwd} = await gitRepo(); const pkgOptions = { extends: './shareable.json', - branch: 'test_pkg', + branches: ['test_pkg'], generateNotes: 'generateNotes', publish: [{path: 'publishPkg', param: 'publishPkg_param'}], }; @@ -311,7 +343,7 @@ test('Prioritize configuration from config file over "extends"', async t => { analyzeCommits: 'analyzeCommits', generateNotes: 'generateNotesShareable', publish: [{path: 'publishShareable', param: 'publishShareable_param'}], - branch: 'test_branch', + branches: ['test_branch'], repositoryUrl: 'https://host.null/owner/module.git', tagFormat: `v\${version}`, plugins: false, @@ -320,12 +352,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, '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 - 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 - 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], { analyzeCommits: './shareable.json', generateNotesShareable: './shareable.json', @@ -338,13 +371,13 @@ test('Prioritize configuration from cli/API options over "extends"', async t => const {cwd} = await gitRepo(); const cliOptions = { extends: './shareable2.json', - branch: 'branch_opts', + branches: ['branch_opts'], publish: [{path: 'publishOpts', param: 'publishOpts_param'}], repositoryUrl: 'https://host.null/owner/module.git', }; const pkgOptions = { extends: './shareable1.json', - branch: 'branch_pkg', + branches: ['branch_pkg'], generateNotes: 'generateNotes', publish: [{path: 'publishPkg', param: 'publishPkg_param'}], }; @@ -352,13 +385,13 @@ test('Prioritize configuration from cli/API options over "extends"', async t => analyzeCommits: 'analyzeCommits1', generateNotes: 'generateNotesShareable1', publish: [{path: 'publishShareable', param: 'publishShareable_param1'}], - branch: 'test_branch1', + branches: ['test_branch1'], repositoryUrl: 'https://host.null/owner/module.git', }; const options2 = { analyzeCommits: 'analyzeCommits2', publish: [{path: 'publishShareable', param: 'publishShareable_param2'}], - branch: 'test_branch2', + branches: ['test_branch2'], tagFormat: `v\${version}`, plugins: false, }; @@ -367,15 +400,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, '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 - 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 - t.deepEqual(t.context.plugins.args[0][0], { - cwd, - options: omit({...options2, ...pkgOptions, ...cliOptions}, 'extends'), - }); + t.deepEqual(t.context.plugins.args[0][0], {options: expected, cwd}); }); test('Allow to unset properties defined in shareable config with "null"', async t => { @@ -384,7 +415,7 @@ test('Allow to unset properties defined in shareable config with "null"', async const pkgOptions = { extends: './shareable.json', analyzeCommits: null, - branch: 'test_branch', + branches: ['test_branch'], repositoryUrl: 'https://host.null/owner/module.git', plugins: null, }; @@ -415,6 +446,7 @@ test('Allow to unset properties defined in shareable config with "null"', async }, cwd, }); + t.deepEqual(t.context.plugins.args[0][1], { generateNotes: './shareable.json', analyzeCommits: './shareable.json', @@ -428,7 +460,7 @@ test('Allow to unset properties defined in shareable config with "undefined"', a const pkgOptions = { extends: './shareable.json', analyzeCommits: undefined, - branch: 'test_branch', + branches: ['test_branch'], repositoryUrl: 'https://host.null/owner/module.git', }; const options1 = { @@ -441,18 +473,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 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, 'analyzeCommits'), + ...omit(pkgOptions, ['extends', 'analyzeCommits']), + branches: ['test_branch'], + }; // Verify the options contains the plugin config from shareable.json - t.deepEqual(options, {...omit(options1, 'analyzeCommits'), ...omit(pkgOptions, ['extends', 'analyzeCommits'])}); + 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: { - ...omit(options1, 'analyzeCommits'), - ...omit(pkgOptions, ['extends', 'analyzeCommits']), - }, - cwd, - }); + t.deepEqual(t.context.plugins.args[0][0], {options: expected, cwd}); t.deepEqual(t.context.plugins.args[0][1], { generateNotes: './shareable.json', analyzeCommits: './shareable.json', diff --git a/test/get-git-auth-url.test.js b/test/get-git-auth-url.test.js index 16b5815913..f4b2633624 100644 --- a/test/get-git-auth-url.test.js +++ b/test/get-git-auth-url.test.js @@ -8,7 +8,7 @@ test('Return the same "git" formatted URL if "gitCredentials" is not defined', a const {cwd} = await gitRepo(); 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' ); }); @@ -17,7 +17,12 @@ test('Return the same "https" formatted URL if "gitCredentials" is not defined', const {cwd} = await gitRepo(); 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' ); }); @@ -26,7 +31,12 @@ test('Return the "https" formatted URL if "gitCredentials" is not defined and re const {cwd} = await gitRepo(); 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' ); }); @@ -35,7 +45,7 @@ test('Do not add trailing ".git" if not present in the origian URL', async t => const {cwd} = await gitRepo(); 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' ); }); @@ -47,7 +57,8 @@ test('Handle "https" URL with group and subgroup', async t => { await getAuthUrl({ cwd, 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' ); @@ -60,7 +71,8 @@ test('Handle "git" URL with group and subgroup', async t => { await getAuthUrl({ cwd, 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' ); @@ -70,7 +82,12 @@ test('Convert shorthand URL', async t => { const {cwd} = await gitRepo(); t.is( - await getAuthUrl({cwd, env, options: {repositoryUrl: 'semanitc-release/semanitc-release'}}), + await getAuthUrl({ + cwd, + env, + branch: {name: 'master'}, + options: {repositoryUrl: 'semanitc-release/semanitc-release'}, + }), 'https://github.com/semanitc-release/semanitc-release.git' ); }); @@ -82,7 +99,8 @@ test('Convert GitLab shorthand URL', async t => { await getAuthUrl({ cwd, env, - options: {branch: 'master', repositoryUrl: 'gitlab:semanitc-release/semanitc-release'}, + branch: {name: 'master'}, + options: {repositoryUrl: 'gitlab:semanitc-release/semanitc-release'}, }), 'https://gitlab.com/semanitc-release/semanitc-release.git' ); @@ -95,7 +113,8 @@ test('Return the "https" formatted URL if "gitCredentials" is defined and reposi await getAuthUrl({ cwd, 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' ); @@ -121,7 +140,8 @@ test('Return the "https" formatted URL if "gitCredentials" is defined and reposi await getAuthUrl({ cwd, 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' ); @@ -134,7 +154,8 @@ test('Return the "http" formatted URL if "gitCredentials" is defined and reposit await getAuthUrl({ cwd, 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' ); @@ -147,7 +168,8 @@ test('Return the "https" formatted URL if "gitCredentials" is defined and reposi await getAuthUrl({ cwd, 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' ); @@ -160,7 +182,8 @@ test('Return the "http" formatted URL if "gitCredentials" is defined and reposit await getAuthUrl({ cwd, 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' ); @@ -173,7 +196,8 @@ test('Return the "https" formatted URL if "gitCredentials" is defined with "GH_T await getAuthUrl({ cwd, 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' ); @@ -186,7 +210,8 @@ test('Return the "https" formatted URL if "gitCredentials" is defined with "GITH await getAuthUrl({ cwd, 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' ); @@ -199,7 +224,8 @@ test('Return the "https" formatted URL if "gitCredentials" is defined with "GL_T await getAuthUrl({ cwd, 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' ); @@ -212,7 +238,8 @@ test('Return the "https" formatted URL if "gitCredentials" is defined with "GITL await getAuthUrl({ cwd, 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' ); @@ -225,7 +252,8 @@ test('Return the "https" formatted URL if "gitCredentials" is defined with "BB_T await getAuthUrl({ cwd, 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' ); @@ -238,7 +266,8 @@ test('Return the "https" formatted URL if "gitCredentials" is defined with "BITB await getAuthUrl({ cwd, 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' ); @@ -251,7 +280,8 @@ test('Handle "https" URL with group and subgroup, with "GIT_CREDENTIALS"', async await getAuthUrl({ cwd, 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' ); @@ -264,7 +294,8 @@ test('Handle "git" URL with group and subgroup, with "GIT_CREDENTIALS', async t await getAuthUrl({ cwd, 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' ); @@ -274,7 +305,12 @@ test('Do not add git credential to repositoryUrl if push is allowed', async t => const {cwd, repositoryUrl} = await gitRepo(true); 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 ); }); diff --git a/test/get-last-release.test.js b/test/get-last-release.test.js index bf842ccdea..f61200f297 100644 --- a/test/get-last-release.test.js +++ b/test/get-last-release.test.js @@ -1,7 +1,6 @@ import test from 'ava'; import {stub} from 'sinon'; import getLastRelease from '../lib/get-last-release'; -import {gitRepo, gitCommits, gitTagVersion, gitCheckout} from './helpers/git-utils'; test.beforeEach(t => { // Stub the logger functions @@ -9,143 +8,61 @@ test.beforeEach(t => { t.context.logger = {log: t.context.log}; }); -test('Get the highest non-prerelease valid tag', 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 - 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 => { - // Create a git repository, set the current working directory at the root of the repo - const {cwd} = await gitRepo(); - // Add commit to the master branch - await gitCommits(['First'], {cwd}); - // Create the tag corresponding to version 1.0.0 - // Create the new branch 'other-branch' from master - await gitCheckout('other-branch', true, {cwd}); - // Add commit to the 'other-branch' branch - await gitCommits(['Second'], {cwd}); - // Create the tag corresponding to version 3.0.0 - await gitTagVersion('v3.0.0', undefined, {cwd}); - // Checkout master - await gitCheckout('master', false, {cwd}); - // 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 => { - // Create a git repository, set the current working directory at the root of the repo - const {cwd} = await gitRepo(); - const commits = await gitCommits(['First'], {cwd}); - await gitTagVersion('prefix/v1.0.0', undefined, {cwd}); - await gitTagVersion('prefix/v2.0.0', undefined, {cwd}); - 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 => { - // 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}); - await gitCommits(['Second'], {cwd}); - await gitTagVersion('v2.0.x', undefined, {cwd}); - await gitCommits(['Third'], {cwd}); - await gitTagVersion('v3.0', undefined, {cwd}); - - const result = await getLastRelease({cwd, options: {tagFormat: `v\${version}`}, logger: t.context.logger}); +test('Get the highest non-prerelease valid tag', t => { + const result = getLastRelease({ + branch: { + name: 'master', + tags: [ + {version: '2.0.0', gitTag: 'v2.0.0', gitHead: '222'}, + {version: '1.0.0', gitTag: 'v1.0.0', gitHead: '111'}, + {version: '3.0.0-beta.1', gitTag: 'v3.0.0-beta.1@beta', gitHead: '333'}, + ], + type: 'release', + }, + options: {tagFormat: `v\${version}`}, + logger: t.context.logger, + }); - t.deepEqual(result, {}); - t.is(t.context.log.args[0][0], 'No git tag version found'); + t.deepEqual(result, {version: '2.0.0', gitTag: 'v2.0.0', name: 'v2.0.0', gitHead: '222', channel: undefined}); + t.deepEqual(t.context.log.args[0][0], 'Found git tag v2.0.0 associated with version 2.0.0 on branch master'); }); -test('Return empty object if no valid tag is found in history', async t => { - // Create a git repository, set the current working directory at the root of the repo - const {cwd} = await gitRepo(); - await gitCommits(['First'], {cwd}); - await gitCheckout('other-branch', true, {cwd}); - await gitCommits(['Second'], {cwd}); - await gitTagVersion('v1.0.0', undefined, {cwd}); - await gitTagVersion('v2.0.0', undefined, {cwd}); - await gitTagVersion('v3.0.0', undefined, {cwd}); - await gitCheckout('master', false, {cwd}); - - const result = await getLastRelease({cwd, options: {tagFormat: `v\${version}`}, logger: t.context.logger}); +test('Return empty object if no valid tag is found', t => { + const result = getLastRelease({ + branch: { + name: 'master', + tags: [{version: '3.0.0-beta.1', gitTag: 'v3.0.0-beta.1@beta', gitHead: '111'}], + type: 'release', + }, + options: {tagFormat: `v\${version}`}, + logger: t.context.logger, + }); t.deepEqual(result, {}); - t.is(t.context.log.args[0][0], 'No git tag version found'); + t.deepEqual(t.context.log.args[0][0], 'No git tag version found on branch master'); }); -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', - }); +test('Get the highest non-prerelease valid tag before a certain version', t => { + const result = getLastRelease( + { + branch: { + name: 'master', + channel: undefined, + tags: [ + {version: '2.0.0', gitTag: 'v2.0.0', gitHead: '333'}, + {version: '1.0.0', gitTag: 'v1.0.0', gitHead: '111'}, + {version: '2.0.0-beta.1', gitTag: 'v2.0.0-beta.1@beta', gitHead: '222'}, + {version: '2.1.0', gitTag: 'v2.1.0', gitHead: '444'}, + {version: '2.1.1', gitTag: 'v2.1.1', gitHead: '555'}, + ], + type: 'release', + }, + options: {tagFormat: `v\${version}`}, + logger: t.context.logger, + }, + {before: '2.1.0'} + ); + + t.deepEqual(result, {version: '2.0.0', gitTag: 'v2.0.0', name: 'v2.0.0', gitHead: '333', channel: undefined}); + t.deepEqual(t.context.log.args[0][0], 'Found git tag v2.0.0 associated with version 2.0.0 on branch master'); }); diff --git a/test/get-next-version.test.js b/test/get-next-version.test.js index ecbaee889b..476d5e9fbb 100644 --- a/test/get-next-version.test.js +++ b/test/get-next-version.test.js @@ -9,33 +9,127 @@ test.beforeEach(t => { }); test('Increase version for patch release', t => { - const version = getNextVersion({ - nextRelease: {type: 'patch'}, - lastRelease: {version: '1.0.0'}, - logger: t.context.logger, - }); - t.is(version, '1.0.1'); + t.is( + getNextVersion({ + branch: {name: 'master', type: 'release'}, + nextRelease: {type: 'patch'}, + lastRelease: {version: '1.0.0'}, + logger: t.context.logger, + }), + '1.0.1' + ); }); test('Increase version for minor release', t => { - const version = getNextVersion({ - nextRelease: {type: 'minor'}, - lastRelease: {version: '1.0.0'}, - logger: t.context.logger, - }); - t.is(version, '1.1.0'); + t.is( + getNextVersion({ + branch: {name: 'master', type: 'release'}, + nextRelease: {type: 'minor'}, + lastRelease: {version: '1.0.0'}, + logger: t.context.logger, + }), + '1.1.0' + ); }); test('Increase version for major release', t => { - const version = getNextVersion({ - nextRelease: {type: 'major'}, - lastRelease: {version: '1.0.0'}, - logger: t.context.logger, - }); - t.is(version, '2.0.0'); + t.is( + getNextVersion({ + branch: {name: 'master', type: 'release'}, + nextRelease: {type: 'major'}, + lastRelease: {version: '1.0.0'}, + logger: t.context.logger, + }), + '2.0.0' + ); }); 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(version, '1.0.0'); + t.is( + getNextVersion({ + branch: {name: 'master', type: 'release'}, + 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'}, + nextRelease: {type: 'patch'}, + lastRelease: {version: '1.0.0'}, + logger: t.context.logger, + }), + '1.0.1-beta.1' + ); + + t.is( + getNextVersion({ + branch: {name: 'beta', type: 'prerelease', prerelease: 'beta'}, + nextRelease: {type: 'patch'}, + lastRelease: {version: '1.0.0-beta.1'}, + logger: t.context.logger, + }), + '1.0.0-beta.2' + ); +}); + +test('Increase version for minor release on prerelease branch', t => { + t.is( + getNextVersion({ + branch: {name: 'beta', type: 'prerelease', prerelease: 'beta'}, + nextRelease: {type: 'minor'}, + lastRelease: {version: '1.0.0'}, + logger: t.context.logger, + }), + '1.1.0-beta.1' + ); + + t.is( + getNextVersion({ + branch: {name: 'beta', type: 'prerelease', prerelease: 'beta'}, + nextRelease: {type: 'minor'}, + lastRelease: {version: '1.0.0-beta.1'}, + logger: t.context.logger, + }), + '1.0.0-beta.2' + ); +}); + +test('Increase version for major release on prerelease branch', t => { + t.is( + getNextVersion({ + branch: {name: 'beta', type: 'prerelease', prerelease: 'beta'}, + nextRelease: {type: 'major'}, + lastRelease: {version: '1.0.0'}, + logger: t.context.logger, + }), + '2.0.0-beta.1' + ); + + t.is( + getNextVersion({ + branch: {name: 'beta', type: 'prerelease', prerelease: 'beta'}, + nextRelease: {type: 'major'}, + lastRelease: {version: '1.0.0-beta.1'}, + logger: t.context.logger, + }), + '1.0.0-beta.2' + ); +}); + +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'}, + nextRelease: {type: 'minor'}, + lastRelease: {}, + logger: t.context.logger, + }), + '1.0.0-beta.1' + ); }); diff --git a/test/get-releases-to-add.test.js b/test/get-releases-to-add.test.js new file mode 100644 index 0000000000..e4c28ac4a9 --- /dev/null +++ b/test/get-releases-to-add.test.js @@ -0,0 +1,258 @@ +import test from 'ava'; +import {stub} from 'sinon'; +import getReleasesToAdd from '../lib/get-releases-to-add'; + +test.beforeEach(t => { + // Stub the logger functions + t.context.log = stub(); + t.context.logger = {log: t.context.log}; +}); + +test('Return versions merged from release to maintenance branch', t => { + const result = getReleasesToAdd({ + branch: { + name: '1.x', + channel: '1.x', + tags: [ + {gitTag: 'v1.0.0@1.x', version: '1.0.0', channel: '1.x', gitHead: '111'}, + {gitTag: 'v1.0.0', version: '1.0.0', gitHead: '111'}, + {gitTag: 'v1.1.0', version: '1.1.0', gitHead: '222'}, + {gitTag: 'v1.1.1', version: '1.1.1', gitHead: '333'}, + ], + }, + branches: [{name: '1.x', channel: '1.x'}, {name: 'master'}], + options: {tagFormat: `v\${version}`}, + logger: t.context.logger, + }); + + t.deepEqual(result, [ + { + lastRelease: {version: '1.0.0', channel: '1.x', gitTag: 'v1.0.0@1.x', name: 'v1.0.0', gitHead: '111'}, + currentRelease: { + type: 'minor', + version: '1.1.0', + channel: undefined, + gitTag: 'v1.1.0', + name: 'v1.1.0', + gitHead: '222', + }, + nextRelease: { + type: 'minor', + version: '1.1.0', + channel: '1.x', + gitTag: 'v1.1.0@1.x', + name: 'v1.1.0', + gitHead: '222', + }, + }, + { + lastRelease: {version: '1.1.0', channel: undefined, gitTag: 'v1.1.0', name: 'v1.1.0', gitHead: '222'}, + currentRelease: { + type: 'patch', + version: '1.1.1', + channel: undefined, + gitTag: 'v1.1.1', + name: 'v1.1.1', + gitHead: '333', + }, + nextRelease: { + type: 'patch', + version: '1.1.1', + channel: '1.x', + gitTag: 'v1.1.1@1.x', + name: 'v1.1.1', + gitHead: '333', + }, + }, + ]); +}); + +test('Return versions merged from future branch to release branch', t => { + const result = getReleasesToAdd({ + branch: { + name: 'master', + tags: [ + {gitTag: 'v1.0.0', version: '1.0.0', gitHead: '111'}, + {gitTag: 'v1.0.0@next', version: '1.0.0', channel: 'next', gitHead: '111'}, + {gitTag: 'v1.1.0@next', version: '1.1.0', channel: 'next', gitHead: '222'}, + {gitTag: 'v2.0.0@next-major', version: '2.0.0', channel: 'next-major', gitHead: '333'}, + ], + }, + branches: [{name: 'master'}, {name: 'next', channel: 'next'}, {name: 'next-major', channel: 'next-major'}], + options: {tagFormat: `v\${version}`}, + logger: t.context.logger, + }); + + t.deepEqual(result, [ + { + lastRelease: {version: '1.0.0', channel: undefined, gitTag: 'v1.0.0', name: 'v1.0.0', gitHead: '111'}, + currentRelease: { + type: 'minor', + version: '1.1.0', + channel: 'next', + gitTag: 'v1.1.0@next', + name: 'v1.1.0', + gitHead: '222', + }, + nextRelease: { + type: 'minor', + version: '1.1.0', + channel: undefined, + gitTag: 'v1.1.0', + name: 'v1.1.0', + gitHead: '222', + }, + }, + { + lastRelease: {version: '1.1.0', gitTag: 'v1.1.0@next', name: 'v1.1.0', gitHead: '222', channel: 'next'}, + currentRelease: { + type: 'major', + version: '2.0.0', + channel: 'next-major', + gitTag: 'v2.0.0@next-major', + name: 'v2.0.0', + gitHead: '333', + }, + nextRelease: { + type: 'major', + version: '2.0.0', + channel: undefined, + gitTag: 'v2.0.0', + name: 'v2.0.0', + gitHead: '333', + }, + }, + ]); +}); + +test('Return releases sorted by ascending order', t => { + const result = getReleasesToAdd({ + branch: { + name: 'master', + tags: [ + {gitTag: 'v2.0.0@next-major', version: '2.0.0', channel: 'next-major', gitHead: '333'}, + {gitTag: 'v1.1.0@next', version: '1.1.0', channel: 'next', gitHead: '222'}, + {gitTag: 'v1.0.0', version: '1.0.0', gitHead: '111'}, + {gitTag: 'v1.0.0@next', version: '1.0.0', channel: 'next', gitHead: '111'}, + ], + }, + branches: [{name: 'master'}, {name: 'next', channel: 'next'}, {name: 'next-major', channel: 'next-major'}], + options: {tagFormat: `v\${version}`}, + logger: t.context.logger, + }); + + t.deepEqual(result, [ + { + lastRelease: {version: '1.0.0', channel: undefined, gitTag: 'v1.0.0', name: 'v1.0.0', gitHead: '111'}, + currentRelease: { + type: 'minor', + version: '1.1.0', + channel: 'next', + gitTag: 'v1.1.0@next', + name: 'v1.1.0', + gitHead: '222', + }, + nextRelease: { + type: 'minor', + version: '1.1.0', + channel: undefined, + gitTag: 'v1.1.0', + name: 'v1.1.0', + gitHead: '222', + }, + }, + { + lastRelease: {version: '1.1.0', gitTag: 'v1.1.0@next', name: 'v1.1.0', gitHead: '222', channel: 'next'}, + currentRelease: { + type: 'major', + version: '2.0.0', + channel: 'next-major', + gitTag: 'v2.0.0@next-major', + name: 'v2.0.0', + gitHead: '333', + }, + nextRelease: { + type: 'major', + version: '2.0.0', + channel: undefined, + gitTag: 'v2.0.0', + name: 'v2.0.0', + gitHead: '333', + }, + }, + ]); +}); + +test('no lastRelease', t => { + const result = getReleasesToAdd({ + branch: {name: 'master', tags: [{gitTag: 'v1.0.0@next', version: '1.0.0', channel: 'next', gitHead: '111'}]}, + branches: [{name: 'master'}, {name: 'next', channel: 'next'}], + options: {tagFormat: `v\${version}`}, + logger: t.context.logger, + }); + + t.deepEqual(result, [ + { + lastRelease: {}, + currentRelease: { + type: 'major', + version: '1.0.0', + channel: 'next', + gitTag: 'v1.0.0@next', + name: 'v1.0.0', + gitHead: '111', + }, + nextRelease: { + type: 'major', + version: '1.0.0', + channel: undefined, + gitTag: 'v1.0.0', + name: 'v1.0.0', + gitHead: '111', + }, + }, + ]); +}); + +test('Ignore pre-release versions', t => { + const result = getReleasesToAdd({ + branch: { + name: 'master', + tags: [ + {gitTag: 'v1.0.0', version: '1.0.0', gitHead: '111'}, + {gitTag: 'v1.0.0@next', version: '1.0.0', channel: 'next', gitHead: '111'}, + {gitTag: 'v1.1.0@next', version: '1.1.0', channel: 'next', gitHead: '222'}, + {gitTag: 'v2.0.0-alpha.1@alpha', version: '2.0.0', channel: 'alpha', gitHead: '333'}, + ], + }, + branches: [ + {name: 'master'}, + {name: 'next', channel: 'next'}, + {name: 'alpha', type: 'prerelease', channel: 'alpha'}, + ], + options: {tagFormat: `v\${version}`}, + logger: t.context.logger, + }); + + t.deepEqual(result, [ + { + lastRelease: {version: '1.0.0', channel: undefined, gitTag: 'v1.0.0', name: 'v1.0.0', gitHead: '111'}, + currentRelease: { + type: 'minor', + version: '1.1.0', + channel: 'next', + gitTag: 'v1.1.0@next', + name: 'v1.1.0', + gitHead: '222', + }, + nextRelease: { + type: 'minor', + version: '1.1.0', + channel: undefined, + gitTag: 'v1.1.0', + name: 'v1.1.0', + gitHead: '222', + }, + }, + ]); +}); diff --git a/test/git.test.js b/test/git.test.js index 82d4b0b196..68c97645bb 100644 --- a/test/git.test.js +++ b/test/git.test.js @@ -3,12 +3,14 @@ import tempy from 'tempy'; import { getTagHead, isRefInHistory, + isRefExists, fetch, getGitHead, repoUrl, tag, push, getTags, + getBranches, isGitRepo, verifyTagName, isBranchUpToDate, @@ -56,7 +58,7 @@ test('Unshallow and fetch repository', async t => { // Verify the shallow clone contains only one commit t.is((await gitGetCommits(undefined, {cwd})).length, 1); - await fetch(repositoryUrl, {cwd}); + await fetch({cwd}); // Verify the shallow clone contains all the commits t.is((await gitGetCommits(undefined, {cwd})).length, 2); @@ -64,10 +66,10 @@ test('Unshallow and fetch 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 - const {cwd, repositoryUrl} = await gitRepo(); + const {cwd} = await gitRepo(true); // Add commits to the master branch await gitCommits(['First'], {cwd}); - await t.notThrows(fetch(repositoryUrl, {cwd})); + await t.notThrows(fetch({cwd})); }); test('Fetch all tags on a detached head repository', async t => { @@ -82,7 +84,7 @@ test('Fetch all tags on a detached head repository', async t => { await gitPush(repositoryUrl, 'master', {cwd}); cwd = await gitDetachedHead(repositoryUrl, commit.hash); - await fetch(repositoryUrl, {cwd}); + await fetch({cwd}); t.deepEqual((await getTags({cwd})).sort(), ['v1.0.0', 'v1.0.1', 'v1.1.0'].sort()); }); @@ -98,9 +100,36 @@ test('Verify if the commit `sha` is in the direct history of the current branch' const otherCommits = await gitCommits(['Second'], {cwd}); await gitCheckout('master', false, {cwd}); - t.true(await isRefInHistory(commits[0].hash, {cwd})); - t.falsy(await isRefInHistory(otherCommits[0].hash, {cwd})); - await t.throws(isRefInHistory('non-existant-sha', {cwd})); + t.true(await isRefInHistory(commits[0].hash, 'master', false, {cwd})); + t.falsy(await isRefInHistory(otherCommits[0].hash, 'master', false, {cwd})); + t.falsy(await isRefInHistory(otherCommits[0].hash, 'missing-branch', false, {cwd})); + await t.throws(isRefInHistory('non-existant-sha', 'master', false, {cwd})); +}); + +test('Verify if a branch exists', 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 + await gitCommits(['First'], {cwd}); + // Create the new branch 'other-branch' from master + await gitCheckout('other-branch', true, {cwd}); + // Add commits to the 'other-branch' branch + await gitCommits(['Second'], {cwd}); + + t.true(await isRefExists('master', {cwd})); + t.true(await isRefExists('other-branch', {cwd})); + t.falsy(await isRefExists('next', {cwd})); +}); + +test('Get all branches', async t => { + const {cwd} = await gitRepo(); + await gitCommits(['First'], {cwd}); + await gitCheckout('second-branch', true, {cwd}); + await gitCommits(['Second'], {cwd}); + await gitCheckout('third-branch', true, {cwd}); + await gitCommits(['Third'], {cwd}); + + t.deepEqual((await getBranches({cwd})).sort(), ['master', 'second-branch', 'third-branch'].sort()); }); test('Get the commit sha for a given tag or falsy if the tag does not exists', async t => { @@ -146,7 +175,7 @@ test('Add tag on head commit', async t => { const {cwd} = await gitRepo(); 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'); }); @@ -156,13 +185,13 @@ test('Push tag to remote repository', async t => { const {cwd, repositoryUrl} = await gitRepo(true); const commits = await gitCommits(['Test commit'], {cwd}); - await tag('tag_name', {cwd}); + await tag('tag_name', 'HEAD', {cwd}); await push(repositoryUrl, 'master', {cwd}); 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 commits = await gitCommits(['First'], {cwd}); await gitPush(repositoryUrl, 'master', {cwd}); @@ -170,7 +199,7 @@ test('Push tag to remote repository with remote branch ahaed', async t => { await gitCommits(['Second'], {cwd: tmpRepo}); await gitPush('origin', 'master', {cwd: tmpRepo}); - await tag('tag_name', {cwd}); + await tag('tag_name', 'HEAD', {cwd}); await push(repositoryUrl, 'master', {cwd}); t.is(await gitRemoteTagHead(repositoryUrl, 'tag_name', {cwd}), commits[0].hash); diff --git a/test/helpers/git-utils.js b/test/helpers/git-utils.js index 38b464bc90..7240fe1d13 100644 --- a/test/helpers/git-utils.js +++ b/test/helpers/git-utils.js @@ -1,7 +1,7 @@ import tempy from 'tempy'; import execa from 'execa'; import fileUrl from 'file-url'; -import pReduce from 'p-reduce'; +import pEachSeries from 'p-each-series'; import gitLogParser from 'git-log-parser'; import getStream from 'get-stream'; @@ -69,7 +69,7 @@ export async function initBareRepo(repositoryUrl, branch = 'master') { * @returns {Array} The created commits, in reverse order (to match `git log` order). */ export async function gitCommits(messages, execaOpts) { - await pReduce(messages, (_, message) => + await pEachSeries(messages, message => execa.stdout('git', ['commit', '-m', message, '--allow-empty', '--no-gpg-sign'], execaOpts) ); return (await gitGetCommits(undefined, execaOpts)).slice(0, messages.length); @@ -225,3 +225,46 @@ export function gitCommitTag(gitHead, execaOpts) { export async function gitPush(repositoryUrl = 'origin', branch = 'master', 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); +} + +export async function changeAuthor(sha, execaOpts) { + await execa( + 'git', + [ + 'filter-branch', + '-f', + '--env-filter', + `if [[ "$GIT_COMMIT" = "${sha}" ]]; then export GIT_COMMITTER_NAME="New Author" GIT_COMMITTER_EMAIL="author@test.com"; fi`, + ], + execaOpts + ); +} diff --git a/test/helpers/npm-utils.js b/test/helpers/npm-utils.js new file mode 100644 index 0000000000..b690c92769 --- /dev/null +++ b/test/helpers/npm-utils.js @@ -0,0 +1,5 @@ +import execa from 'execa'; + +export async function npmView(packageName, env) { + return JSON.parse(await execa.stdout('npm', ['view', packageName, '--json'], {env})); +} diff --git a/test/index.test.js b/test/index.test.js index 046d316e53..8b342ebee8 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -8,6 +8,7 @@ import SemanticReleaseError from '@semantic-release/error'; import {COMMIT_NAME, COMMIT_EMAIL, SECRET_REPLACEMENT} from '../lib/definitions/constants'; import { gitHead as getGitHead, + gitCheckout, gitTagHead, gitRepo, gitCommits, @@ -15,6 +16,9 @@ import { gitRemoteTagHead, gitPush, gitShallowClone, + merge, + mergeFf, + rebase, } from './helpers/git-utils'; const requireNoCache = proxyquire.noPreserveCache(); @@ -41,13 +45,28 @@ test('Plugins are called with expected values', async t => { // Add commits to the master branch let commits = await gitCommits(['First'], {cwd}); // Create the tag corresponding to version 1.0.0 - await gitTagVersion('v1.0.0', undefined, {cwd}); - // Add new commits to the master branch + await gitTagVersion('v1.0.0@next', undefined, {cwd}); commits = (await gitCommits(['Second'], {cwd})).concat(commits); + await gitCheckout('next', true, {cwd}); + await gitPush(repositoryUrl, 'next', {cwd}); + await gitCheckout('master', false, {cwd}); await gitPush(repositoryUrl, 'master', {cwd}); - const lastRelease = {version: '1.0.0', gitHead: commits[commits.length - 1].hash, gitTag: 'v1.0.0'}; - const nextRelease = {type: 'major', version: '2.0.0', gitHead: await getGitHead({cwd}), gitTag: 'v2.0.0'}; + const lastRelease = { + version: '1.0.0', + gitHead: commits[commits.length - 1].hash, + gitTag: 'v1.0.0@next', + name: 'v1.0.0', + channel: 'next', + }; + const nextRelease = { + name: 'v1.1.0', + type: 'minor', + version: '1.1.0', + gitHead: await getGitHead({cwd}), + gitTag: 'v1.1.0', + channel: undefined, + }; const notes1 = 'Release notes 1'; const notes2 = 'Release notes 2'; const notes3 = 'Release notes 3'; @@ -59,23 +78,65 @@ test('Plugins are called with expected values', async t => { const generateNotes2 = stub().resolves(notes2); const generateNotes3 = stub().resolves(notes3); const release1 = {name: 'Release 1', url: 'https://release1.com'}; + const release2 = {name: 'Release 2', url: 'https://release2.com'}; + const addChannel = stub().resolves(release1); const prepare = stub().resolves(); - const publish1 = stub().resolves(release1); + const publish = stub().resolves(release2); const success = stub().resolves(); const env = {...process.env}; - const config = {branch: 'master', repositoryUrl, globalOpt: 'global', tagFormat: `v\${version}`}; + const config = { + branches: [{name: 'master'}, {name: 'next'}], + repositoryUrl, + globalOpt: 'global', + tagFormat: `v\${version}`, + }; + const branches = [ + { + channel: undefined, + name: 'master', + range: '>=1.0.0 <2.0.0', + accept: ['patch', 'minor'], + tags: [{channel: 'next', gitTag: 'v1.0.0@next', version: '1.0.0', gitHead: commits[commits.length - 1].hash}], + type: 'release', + }, + { + channel: 'next', + name: 'next', + range: '>=2.0.0', + accept: ['patch', 'minor', 'major'], + tags: [{channel: 'next', gitHead: commits[commits.length - 1].hash, gitTag: 'v1.0.0@next', version: '1.0.0'}], + type: 'release', + }, + ]; + const branch = branches[0]; const options = { ...config, plugins: false, verifyConditions: [verifyConditions1, verifyConditions2], analyzeCommits, verifyRelease, + addChannel, generateNotes: [generateNotes1, generateNotes2, generateNotes3], prepare, - publish: [publish1, pluginNoop], + publish: [publish, pluginNoop], success, }; + const releases = [ + { + ...lastRelease, + ...release1, + type: 'major', + version: '1.0.0', + channel: undefined, + gitTag: 'v1.0.0', + notes: `${notes1}\n\n${notes2}\n\n${notes3}`, + pluginName: '[Function: proxy]', + }, + {...nextRelease, ...release2, notes: `${notes1}\n\n${notes2}\n\n${notes3}`, pluginName: '[Function: proxy]'}, + {...nextRelease, notes: `${notes1}\n\n${notes2}\n\n${notes3}`, pluginName: pluginNoop}, + ]; + const semanticRelease = requireNoCache('..', { './lib/get-logger': () => t.context.logger, 'env-ci': () => ({isCi: true, branch: 'master', isPr: false}), @@ -91,16 +152,106 @@ test('Plugins are called with expected values', async t => { t.deepEqual(verifyConditions1.args[0][0], config); t.deepEqual(verifyConditions1.args[0][1].cwd, cwd); t.deepEqual(verifyConditions1.args[0][1].options, options); + t.deepEqual(verifyConditions1.args[0][1].branch, branch); + t.deepEqual(verifyConditions1.args[0][1].branches, branches); t.deepEqual(verifyConditions1.args[0][1].logger, t.context.logger); t.is(verifyConditions2.callCount, 1); t.deepEqual(verifyConditions2.args[0][0], config); t.deepEqual(verifyConditions2.args[0][1].cwd, cwd); t.deepEqual(verifyConditions2.args[0][1].options, options); + t.deepEqual(verifyConditions2.args[0][1].branch, branch); + t.deepEqual(verifyConditions2.args[0][1].branches, branches); t.deepEqual(verifyConditions2.args[0][1].logger, t.context.logger); + t.is(generateNotes1.callCount, 2); + t.is(generateNotes2.callCount, 2); + t.is(generateNotes3.callCount, 2); + + t.deepEqual(generateNotes1.args[0][0], config); + t.deepEqual(generateNotes1.args[0][1].options, options); + t.deepEqual(generateNotes1.args[0][1].branch, branch); + t.deepEqual(generateNotes1.args[0][1].branches, branches); + t.deepEqual(generateNotes1.args[0][1].logger, t.context.logger); + t.deepEqual(generateNotes1.args[0][1].lastRelease, {}); + t.deepEqual(generateNotes1.args[0][1].commits[0].hash, commits[1].hash); + t.deepEqual(generateNotes1.args[0][1].commits[0].message, commits[1].message); + t.deepEqual(generateNotes1.args[0][1].nextRelease, { + ...lastRelease, + type: 'major', + version: '1.0.0', + channel: undefined, + gitTag: 'v1.0.0', + name: 'v1.0.0', + }); + + t.deepEqual(generateNotes2.args[0][0], config); + t.deepEqual(generateNotes2.args[0][1].options, options); + t.deepEqual(generateNotes2.args[0][1].branch, branch); + t.deepEqual(generateNotes2.args[0][1].branches, branches); + t.deepEqual(generateNotes2.args[0][1].logger, t.context.logger); + t.deepEqual(generateNotes2.args[0][1].lastRelease, {}); + t.deepEqual(generateNotes2.args[0][1].commits[0].hash, commits[1].hash); + t.deepEqual(generateNotes2.args[0][1].commits[0].message, commits[1].message); + t.deepEqual(generateNotes2.args[0][1].nextRelease, { + ...lastRelease, + type: 'major', + version: '1.0.0', + channel: undefined, + gitTag: 'v1.0.0', + name: 'v1.0.0', + notes: notes1, + }); + + t.deepEqual(generateNotes3.args[0][0], config); + t.deepEqual(generateNotes3.args[0][1].options, options); + t.deepEqual(generateNotes3.args[0][1].branch, branch); + t.deepEqual(generateNotes3.args[0][1].branches, branches); + t.deepEqual(generateNotes3.args[0][1].logger, t.context.logger); + t.deepEqual(generateNotes3.args[0][1].lastRelease, {}); + t.deepEqual(generateNotes3.args[0][1].commits[0].hash, commits[1].hash); + t.deepEqual(generateNotes3.args[0][1].commits[0].message, commits[1].message); + t.deepEqual(generateNotes3.args[0][1].nextRelease, { + ...lastRelease, + type: 'major', + version: '1.0.0', + channel: undefined, + gitTag: 'v1.0.0', + name: 'v1.0.0', + notes: `${notes1}\n\n${notes2}`, + }); + + branch.tags.push({ + version: '1.0.0', + channel: undefined, + gitTag: 'v1.0.0', + gitHead: commits[commits.length - 1].hash, + }); + + t.is(addChannel.callCount, 1); + t.deepEqual(addChannel.args[0][0], config); + t.deepEqual(addChannel.args[0][1].options, options); + t.deepEqual(addChannel.args[0][1].branch, branch); + t.deepEqual(addChannel.args[0][1].branches, branches); + t.deepEqual(addChannel.args[0][1].logger, t.context.logger); + t.deepEqual(addChannel.args[0][1].lastRelease, {}); + t.deepEqual(addChannel.args[0][1].currentRelease, {...lastRelease, type: 'major'}); + t.deepEqual(addChannel.args[0][1].nextRelease, { + ...lastRelease, + type: 'major', + version: '1.0.0', + channel: undefined, + gitTag: 'v1.0.0', + name: 'v1.0.0', + notes: `${notes1}\n\n${notes2}\n\n${notes3}`, + }); + t.deepEqual(addChannel.args[0][1].commits[0].hash, commits[1].hash); + t.deepEqual(addChannel.args[0][1].commits[0].message, commits[1].message); + t.is(analyzeCommits.callCount, 1); t.deepEqual(analyzeCommits.args[0][0], config); t.deepEqual(analyzeCommits.args[0][1].options, options); + t.deepEqual(analyzeCommits.args[0][1].branch, branch); + t.deepEqual(analyzeCommits.args[0][1].branches, branches); t.deepEqual(analyzeCommits.args[0][1].logger, t.context.logger); t.deepEqual(analyzeCommits.args[0][1].lastRelease, lastRelease); t.deepEqual(analyzeCommits.args[0][1].commits[0].hash, commits[0].hash); @@ -109,78 +260,102 @@ test('Plugins are called with expected values', async t => { t.is(verifyRelease.callCount, 1); t.deepEqual(verifyRelease.args[0][0], config); t.deepEqual(verifyRelease.args[0][1].options, options); + t.deepEqual(verifyRelease.args[0][1].branch, branch); + t.deepEqual(verifyRelease.args[0][1].branches, branches); t.deepEqual(verifyRelease.args[0][1].logger, t.context.logger); t.deepEqual(verifyRelease.args[0][1].lastRelease, lastRelease); t.deepEqual(verifyRelease.args[0][1].commits[0].hash, commits[0].hash); t.deepEqual(verifyRelease.args[0][1].commits[0].message, commits[0].message); t.deepEqual(verifyRelease.args[0][1].nextRelease, nextRelease); - t.is(generateNotes1.callCount, 1); - t.deepEqual(generateNotes1.args[0][0], config); - t.deepEqual(generateNotes1.args[0][1].options, options); - t.deepEqual(generateNotes1.args[0][1].logger, t.context.logger); - t.deepEqual(generateNotes1.args[0][1].lastRelease, lastRelease); - t.deepEqual(generateNotes1.args[0][1].commits[0].hash, commits[0].hash); - t.deepEqual(generateNotes1.args[0][1].commits[0].message, commits[0].message); - t.deepEqual(generateNotes1.args[0][1].nextRelease, nextRelease); - - t.is(generateNotes2.callCount, 1); - t.deepEqual(generateNotes2.args[0][0], config); - t.deepEqual(generateNotes2.args[0][1].options, options); - t.deepEqual(generateNotes2.args[0][1].logger, t.context.logger); - t.deepEqual(generateNotes2.args[0][1].lastRelease, lastRelease); - t.deepEqual(generateNotes2.args[0][1].commits[0].hash, commits[0].hash); - t.deepEqual(generateNotes2.args[0][1].commits[0].message, commits[0].message); - t.deepEqual(generateNotes2.args[0][1].nextRelease, {...nextRelease, notes: notes1}); - - t.is(generateNotes3.callCount, 1); - t.deepEqual(generateNotes3.args[0][0], config); - t.deepEqual(generateNotes3.args[0][1].options, options); - t.deepEqual(generateNotes3.args[0][1].logger, t.context.logger); - t.deepEqual(generateNotes3.args[0][1].lastRelease, lastRelease); - t.deepEqual(generateNotes3.args[0][1].commits[0].hash, commits[0].hash); - t.deepEqual(generateNotes3.args[0][1].commits[0].message, commits[0].message); - t.deepEqual(generateNotes3.args[0][1].nextRelease, {...nextRelease, notes: `${notes1}\n\n${notes2}`}); + t.deepEqual(generateNotes1.args[1][0], config); + t.deepEqual(generateNotes1.args[1][1].options, options); + t.deepEqual(generateNotes1.args[1][1].branch, branch); + t.deepEqual(generateNotes1.args[1][1].branches, branches); + t.deepEqual(generateNotes1.args[1][1].logger, t.context.logger); + t.deepEqual(generateNotes1.args[1][1].lastRelease, lastRelease); + t.deepEqual(generateNotes1.args[1][1].commits[0].hash, commits[0].hash); + t.deepEqual(generateNotes1.args[1][1].commits[0].message, commits[0].message); + t.deepEqual(generateNotes1.args[1][1].nextRelease, nextRelease); + + t.deepEqual(generateNotes2.args[1][0], config); + t.deepEqual(generateNotes2.args[1][1].options, options); + t.deepEqual(generateNotes2.args[1][1].branch, branch); + t.deepEqual(generateNotes2.args[1][1].branches, branches); + t.deepEqual(generateNotes2.args[1][1].logger, t.context.logger); + t.deepEqual(generateNotes2.args[1][1].lastRelease, lastRelease); + t.deepEqual(generateNotes2.args[1][1].commits[0].hash, commits[0].hash); + t.deepEqual(generateNotes2.args[1][1].commits[0].message, commits[0].message); + t.deepEqual(generateNotes2.args[1][1].nextRelease, {...nextRelease, notes: notes1}); + + t.deepEqual(generateNotes3.args[1][0], config); + t.deepEqual(generateNotes3.args[1][1].options, options); + t.deepEqual(generateNotes3.args[1][1].branch, branch); + t.deepEqual(generateNotes3.args[1][1].branches, branches); + t.deepEqual(generateNotes3.args[1][1].logger, t.context.logger); + t.deepEqual(generateNotes3.args[1][1].lastRelease, lastRelease); + t.deepEqual(generateNotes3.args[1][1].commits[0].hash, commits[0].hash); + t.deepEqual(generateNotes3.args[1][1].commits[0].message, commits[0].message); + t.deepEqual(generateNotes3.args[1][1].nextRelease, {...nextRelease, notes: `${notes1}\n\n${notes2}`}); t.is(prepare.callCount, 1); t.deepEqual(prepare.args[0][0], config); t.deepEqual(prepare.args[0][1].options, options); + t.deepEqual(prepare.args[0][1].branch, branch); + t.deepEqual(prepare.args[0][1].branches, branches); t.deepEqual(prepare.args[0][1].logger, t.context.logger); t.deepEqual(prepare.args[0][1].lastRelease, lastRelease); t.deepEqual(prepare.args[0][1].commits[0].hash, commits[0].hash); t.deepEqual(prepare.args[0][1].commits[0].message, commits[0].message); t.deepEqual(prepare.args[0][1].nextRelease, {...nextRelease, notes: `${notes1}\n\n${notes2}\n\n${notes3}`}); - t.is(publish1.callCount, 1); - t.deepEqual(publish1.args[0][0], config); - t.deepEqual(publish1.args[0][1].options, options); - t.deepEqual(publish1.args[0][1].logger, t.context.logger); - t.deepEqual(publish1.args[0][1].lastRelease, lastRelease); - t.deepEqual(publish1.args[0][1].commits[0].hash, commits[0].hash); - t.deepEqual(publish1.args[0][1].commits[0].message, commits[0].message); - t.deepEqual(publish1.args[0][1].nextRelease, {...nextRelease, notes: `${notes1}\n\n${notes2}\n\n${notes3}`}); + t.is(publish.callCount, 1); + t.deepEqual(publish.args[0][0], config); + t.deepEqual(publish.args[0][1].options, options); + t.deepEqual(publish.args[0][1].branch, branch); + t.deepEqual(publish.args[0][1].branches, branches); + t.deepEqual(publish.args[0][1].logger, t.context.logger); + t.deepEqual(publish.args[0][1].lastRelease, lastRelease); + t.deepEqual(publish.args[0][1].commits[0].hash, commits[0].hash); + t.deepEqual(publish.args[0][1].commits[0].message, commits[0].message); + t.deepEqual(publish.args[0][1].nextRelease, {...nextRelease, notes: `${notes1}\n\n${notes2}\n\n${notes3}`}); - t.is(success.callCount, 1); + t.is(success.callCount, 2); t.deepEqual(success.args[0][0], config); t.deepEqual(success.args[0][1].options, options); + t.deepEqual(success.args[0][1].branch, branch); + t.deepEqual(success.args[0][1].branches, branches); t.deepEqual(success.args[0][1].logger, t.context.logger); - t.deepEqual(success.args[0][1].lastRelease, lastRelease); - t.deepEqual(success.args[0][1].commits[0].hash, commits[0].hash); - t.deepEqual(success.args[0][1].commits[0].message, commits[0].message); - t.deepEqual(success.args[0][1].nextRelease, {...nextRelease, notes: `${notes1}\n\n${notes2}\n\n${notes3}`}); - t.deepEqual(success.args[0][1].releases, [ - {...release1, ...nextRelease, notes: `${notes1}\n\n${notes2}\n\n${notes3}`, pluginName: '[Function: proxy]'}, - {...nextRelease, notes: `${notes1}\n\n${notes2}\n\n${notes3}`, pluginName: pluginNoop}, - ]); + t.deepEqual(success.args[0][1].lastRelease, {}); + t.deepEqual(success.args[0][1].commits[0].hash, commits[1].hash); + t.deepEqual(success.args[0][1].commits[0].message, commits[1].message); + t.deepEqual(success.args[0][1].nextRelease, { + ...lastRelease, + type: 'major', + version: '1.0.0', + channel: undefined, + gitTag: 'v1.0.0', + name: 'v1.0.0', + notes: `${notes1}\n\n${notes2}\n\n${notes3}`, + }); + t.deepEqual(success.args[0][1].releases, [releases[0]]); + + t.deepEqual(success.args[1][0], config); + t.deepEqual(success.args[1][1].options, options); + t.deepEqual(success.args[0][1].branch, branch); + t.deepEqual(success.args[0][1].branches, branches); + t.deepEqual(success.args[1][1].logger, t.context.logger); + t.deepEqual(success.args[1][1].lastRelease, lastRelease); + t.deepEqual(success.args[1][1].commits[0].hash, commits[0].hash); + t.deepEqual(success.args[1][1].commits[0].message, commits[0].message); + t.deepEqual(success.args[1][1].nextRelease, {...nextRelease, notes: `${notes1}\n\n${notes2}\n\n${notes3}`}); + t.deepEqual(success.args[1][1].releases, releases); t.deepEqual(result, { lastRelease, - commits: [commits[0]], + commits: [{...commits[0], gitTags: '(HEAD -> master, origin/master, origin/HEAD, next)'}], nextRelease: {...nextRelease, notes: `${notes1}\n\n${notes2}\n\n${notes3}`}, - releases: [ - {...release1, ...nextRelease, notes: `${notes1}\n\n${notes2}\n\n${notes3}`, pluginName: '[Function: proxy]'}, - {...nextRelease, notes: `${notes1}\n\n${notes2}\n\n${notes3}`, pluginName: pluginNoop}, - ], + releases, }); // Verify the tag has been created on the local and remote repo and reference the gitHead @@ -201,15 +376,22 @@ test('Use custom tag format', async t => { await gitCommits(['Second'], {cwd}); await gitPush(repositoryUrl, 'master', {cwd}); - const nextRelease = {type: 'major', version: '2.0.0', gitHead: await getGitHead({cwd}), gitTag: 'test-2.0.0'}; + const nextRelease = { + name: 'test-2.0.0', + type: 'major', + version: '2.0.0', + gitHead: await getGitHead({cwd}), + gitTag: 'test-2.0.0', + }; const notes = 'Release notes'; - const config = {branch: 'master', repositoryUrl, globalOpt: 'global', tagFormat: `test-\${version}`}; + const config = {branches: 'master', repositoryUrl, globalOpt: 'global', tagFormat: `test-\${version}`}; const options = { ...config, verifyConditions: stub().resolves(), analyzeCommits: stub().resolves(nextRelease.type), verifyRelease: stub().resolves(), generateNotes: stub().resolves(notes), + addChannel: stub().resolves(), prepare: stub().resolves(), publish: stub().resolves(), success: stub().resolves(), @@ -245,7 +427,14 @@ test('Use new gitHead, and recreate release notes if a prepare plugin create a c commits = (await gitCommits(['Second'], {cwd})).concat(commits); await gitPush(repositoryUrl, 'master', {cwd}); - const nextRelease = {type: 'major', version: '2.0.0', gitHead: await getGitHead({cwd}), gitTag: 'v2.0.0'}; + const nextRelease = { + name: 'v2.0.0', + type: 'major', + version: '2.0.0', + gitHead: await getGitHead({cwd}), + gitTag: 'v2.0.0', + channel: undefined, + }; const notes = 'Release notes'; const generateNotes = stub().resolves(notes); @@ -255,12 +444,13 @@ test('Use new gitHead, and recreate release notes if a prepare plugin create a c const prepare2 = stub().resolves(); const publish = stub().resolves(); const options = { - branch: 'master', + branches: ['master'], repositoryUrl, verifyConditions: stub().resolves(), analyzeCommits: stub().resolves(nextRelease.type), verifyRelease: stub().resolves(), generateNotes, + addChannel: stub().resolves(), prepare: [prepare1, prepare2], publish, success: stub().resolves(), @@ -300,6 +490,229 @@ test('Use new gitHead, and recreate release notes if a prepare plugin create a c t.is(await gitRemoteTagHead(repositoryUrl, nextRelease.gitTag, {cwd}), commits[0].hash); }); +test('Make a new release when a commit is forward-ported to an upper branch', async t => { + const {cwd, repositoryUrl} = await gitRepo(true); + const commits = await gitCommits(['feat: initial release'], {cwd}); + await gitTagVersion('v1.0.0', undefined, {cwd}); + await gitTagVersion('v1.0.0@1.0.x', undefined, {cwd}); + await gitCheckout('1.0.x', true, {cwd}); + commits.push(...(await gitCommits(['fix: fix on maintenance version 1.0.x'], {cwd}))); + await gitTagVersion('v1.0.1@1.0.x', undefined, {cwd}); + await gitPush('origin', '1.0.x', {cwd}); + await gitCheckout('master', false, {cwd}); + commits.push(...(await gitCommits(['feat: new feature on master'], {cwd}))); + await gitTagVersion('v1.1.0', undefined, {cwd}); + await merge('1.0.x', {cwd}); + await gitPush('origin', 'master', {cwd}); + + const verifyConditions = stub().resolves(); + const verifyRelease = stub().resolves(); + const addChannel = stub().resolves(); + const prepare = stub().resolves(); + const publish = stub().resolves(); + const success = stub().resolves(); + + const config = {branches: [{name: '1.0.x'}, {name: 'master'}], repositoryUrl, tagFormat: `v\${version}`}; + const options = { + ...config, + verifyConditions, + verifyRelease, + addChannel, + prepare, + publish, + success, + }; + + const semanticRelease = proxyquire('..', { + './lib/logger': t.context.logger, + 'env-ci': () => ({isCi: true, branch: 'master', isPr: false}), + }); + t.truthy(await semanticRelease(options, {cwd, env: {}, stdout: {write: () => {}}, stderr: {write: () => {}}})); + + t.is(addChannel.callCount, 0); + t.is(publish.callCount, 1); + // The release 1.1.1, triggered by the forward-port of "fix: fix on maintenance version 1.0.x" has been published from master + t.is(publish.args[0][1].nextRelease.version, '1.1.1'); + t.is(success.callCount, 1); +}); + +test('Publish a pre-release version', async t => { + const {cwd, repositoryUrl} = await gitRepo(true); + await gitCommits(['feat: initial commit'], {cwd}); + await gitTagVersion('v1.0.0', undefined, {cwd}); + await gitPush(repositoryUrl, 'master', {cwd}); + await gitCheckout('beta', true, {cwd}); + await gitCommits(['feat: a feature'], {cwd}); + await gitPush(repositoryUrl, 'beta', {cwd}); + + const config = {branches: ['master', {name: 'beta', prerelease: true}], repositoryUrl}; + const options = { + ...config, + verifyConditions: stub().resolves(), + verifyRelease: stub().resolves(), + generateNotes: stub().resolves(''), + addChannel: false, + prepare: stub().resolves(), + publish: stub().resolves(), + success: stub().resolves(), + fail: stub().resolves(), + }; + + const semanticRelease = requireNoCache('..', { + './lib/get-logger': () => t.context.logger, + 'env-ci': () => ({isCi: true, branch: 'beta', isPr: false}), + }); + let {releases} = await semanticRelease(options, {cwd, stdout: {write: () => {}}, stderr: {write: () => {}}}); + + t.is(releases.length, 1); + t.is(releases[0].version, '1.1.0-beta.1'); + t.is(releases[0].gitTag, 'v1.1.0-beta.1@beta'); + + await gitCommits(['fix: a fix'], {cwd}); + ({releases} = await semanticRelease(options, { + cwd, + stdout: {write: () => {}}, + stderr: {write: () => {}}, + })); + + t.is(releases.length, 1); + t.is(releases[0].version, '1.1.0-beta.2'); + t.is(releases[0].gitTag, 'v1.1.0-beta.2@beta'); +}); + +test('Do not add pre-releases to a different channel', async t => { + const {cwd, repositoryUrl} = await gitRepo(true); + const commits = await gitCommits(['feat: initial release'], {cwd}); + await gitTagVersion('v1.0.0', undefined, {cwd}); + await gitTagVersion('v1.0.0@beta', undefined, {cwd}); + await gitCheckout('beta', true, {cwd}); + commits.push(...(await gitCommits(['feat: breaking change/n/nBREAKING CHANGE: break something'], {cwd}))); + await gitTagVersion('v2.0.0-beta.1@beta', undefined, {cwd}); + commits.push(...(await gitCommits(['fix: a fix'], {cwd}))); + await gitTagVersion('v2.0.0-beta.2@beta', undefined, {cwd}); + await gitPush('origin', 'beta', {cwd}); + await gitCheckout('master', false, {cwd}); + await merge('beta', {cwd}); + await gitPush('origin', 'master', {cwd}); + + const verifyConditions = stub().resolves(); + const verifyRelease = stub().resolves(); + const generateNotes = stub().resolves('Release notes'); + const release1 = {name: 'Release 1', url: 'https://release1.com'}; + const addChannel = stub().resolves(release1); + const prepare = stub().resolves(); + const publish = stub().resolves(); + const success = stub().resolves(); + + const config = { + branches: [{name: 'master'}, {name: 'beta', prerelease: 'beta'}], + repositoryUrl, + tagFormat: `v\${version}`, + }; + + const options = { + ...config, + verifyConditions, + verifyRelease, + addChannel, + generateNotes, + prepare, + publish, + success, + }; + + const semanticRelease = proxyquire('..', { + './lib/logger': t.context.logger, + 'env-ci': () => ({isCi: true, branch: 'master', isPr: false}), + }); + t.truthy(await semanticRelease(options, {cwd, env: {}, stdout: {write: () => {}}, stderr: {write: () => {}}})); + + t.is(addChannel.callCount, 0); +}); + +async function addChannelMacro(t, mergeFunction) { + const {cwd, repositoryUrl} = await gitRepo(true); + const commits = await gitCommits(['feat: initial release'], {cwd}); + await gitTagVersion('v1.0.0', undefined, {cwd}); + await gitTagVersion('v1.0.0@next', undefined, {cwd}); + await gitCheckout('next', true, {cwd}); + commits.push(...(await gitCommits(['feat: breaking change/n/nBREAKING CHANGE: break something'], {cwd}))); + await gitTagVersion('v2.0.0@next', undefined, {cwd}); + commits.push(...(await gitCommits(['fix: a fix'], {cwd}))); + await gitTagVersion('v2.0.1@next', undefined, {cwd}); + commits.push(...(await gitCommits(['feat: a feature'], {cwd}))); + await gitTagVersion('v2.1.0@next', undefined, {cwd}); + await gitPush('origin', 'next', {cwd}); + await gitCheckout('master', false, {cwd}); + // Merge all commits but last one from next to master + await mergeFunction('next~1', {cwd}); + await gitPush('origin', 'master', {cwd}); + + const notes = 'Release notes'; + const verifyConditions = stub().resolves(); + const verifyRelease = stub().resolves(); + const generateNotes = stub().resolves(notes); + const release1 = {name: 'Release 1', url: 'https://release1.com'}; + const addChannel1 = stub().resolves(release1); + const addChannel2 = stub().resolves(); + const prepare = stub().resolves(); + const publish = stub().resolves(); + const success = stub().resolves(); + + const config = {branches: [{name: 'master'}, {name: 'next'}], repositoryUrl, tagFormat: `v\${version}`}; + const options = { + ...config, + verifyConditions, + verifyRelease, + addChannel: [addChannel1, addChannel2], + generateNotes, + prepare, + publish, + success, + }; + const nextRelease1 = { + name: 'v2.0.0', + type: 'major', + version: '2.0.0', + channel: undefined, + gitTag: 'v2.0.0', + gitHead: commits[1].hash, + }; + const nextRelease2 = { + name: 'v2.0.1', + type: 'patch', + version: '2.0.1', + channel: undefined, + gitTag: 'v2.0.1', + gitHead: commits[2].hash, + }; + + const semanticRelease = proxyquire('..', { + './lib/logger': t.context.logger, + 'env-ci': () => ({isCi: true, branch: 'master', isPr: false}), + }); + const result = await semanticRelease(options, {cwd, env: {}, stdout: {write: () => {}}, stderr: {write: () => {}}}); + + t.deepEqual(result.releases, [ + {...nextRelease1, ...release1, notes, pluginName: '[Function: proxy]'}, + {...nextRelease1, notes, pluginName: '[Function: proxy]'}, + {...nextRelease2, ...release1, notes, pluginName: '[Function: proxy]'}, + {...nextRelease2, notes, pluginName: '[Function: proxy]'}, + ]); + + // Verify the tag has been created on the local and remote repo and reference + t.is(await gitTagHead(nextRelease1.gitTag, {cwd}), nextRelease1.gitHead); + t.is(await gitRemoteTagHead(repositoryUrl, nextRelease1.gitTag, {cwd}), nextRelease1.gitHead); + t.is(await gitTagHead(nextRelease2.gitTag, {cwd}), nextRelease2.gitHead); + t.is(await gitRemoteTagHead(repositoryUrl, nextRelease2.gitTag, {cwd}), nextRelease2.gitHead); +} + +addChannelMacro.title = providedTitle => `Add version to a channel after a merge (${providedTitle})`; + +test('fast-forward', addChannelMacro, mergeFf); +test('non fast-forward', addChannelMacro, merge); +test('rebase', addChannelMacro, rebase); + test('Call all "success" plugins even if one errors out', async t => { // Create a git repository, set the current working directory at the root of the repo const {cwd, repositoryUrl} = await gitRepo(true); @@ -311,7 +724,14 @@ test('Call all "success" plugins even if one errors out', async t => { await gitCommits(['Second'], {cwd}); await gitPush(repositoryUrl, 'master', {cwd}); - const nextRelease = {type: 'major', version: '2.0.0', gitHead: await getGitHead({cwd}), gitTag: 'v2.0.0'}; + const nextRelease = { + name: 'v2.0.0', + type: 'major', + version: '2.0.0', + gitHead: await getGitHead({cwd}), + gitTag: 'v2.0.0', + channel: undefined, + }; const notes = 'Release notes'; const verifyConditions1 = stub().resolves(); const verifyConditions2 = stub().resolves(); @@ -321,12 +741,18 @@ test('Call all "success" plugins even if one errors out', async t => { const publish = stub().resolves(release); const success1 = stub().rejects(); const success2 = stub().resolves(); - const config = {branch: 'master', repositoryUrl, globalOpt: 'global', tagFormat: `v\${version}`}; + const config = { + branches: [{name: 'master'}], + repositoryUrl, + globalOpt: 'global', + tagFormat: `v\${version}`, + }; const options = { ...config, verifyConditions: [verifyConditions1, verifyConditions2], analyzeCommits, generateNotes, + addChannel: stub().resolves(), prepare: stub().resolves(), publish, success: [success1, success2], @@ -342,10 +768,11 @@ test('Call all "success" plugins even if one errors out', async t => { ); t.is(success1.callCount, 1); - t.deepEqual(success1.args[0][1].releases, [{...release, ...nextRelease, notes, pluginName: '[Function: proxy]'}]); + t.deepEqual(success1.args[0][0], config); + t.deepEqual(success1.args[0][1].releases, [{...nextRelease, ...release, notes, pluginName: '[Function: proxy]'}]); t.is(success2.callCount, 1); - t.deepEqual(success2.args[0][1].releases, [{...release, ...nextRelease, notes, pluginName: '[Function: proxy]'}]); + t.deepEqual(success2.args[0][1].releases, [{...nextRelease, ...release, notes, pluginName: '[Function: proxy]'}]); }); test('Log all "verifyConditions" errors', async t => { @@ -359,7 +786,7 @@ test('Log all "verifyConditions" errors', async t => { const error2 = new SemanticReleaseError('error 2', 'ERR2'); const error3 = new SemanticReleaseError('error 3', 'ERR3'); const fail = stub().resolves(); - const config = {branch: 'master', repositoryUrl, tagFormat: `v\${version}`}; + const config = {branches: [{name: 'master'}], repositoryUrl, tagFormat: `v\${version}`}; const options = { ...config, plugins: false, @@ -403,7 +830,7 @@ test('Log all "verifyRelease" errors', async t => { const error1 = new SemanticReleaseError('error 1', 'ERR1'); const error2 = new SemanticReleaseError('error 2', 'ERR2'); const fail = stub().resolves(); - const config = {branch: 'master', repositoryUrl, tagFormat: `v\${version}`}; + const config = {branches: [{name: 'master'}], repositoryUrl, tagFormat: `v\${version}`}; const options = { ...config, verifyConditions: stub().resolves(), @@ -430,36 +857,35 @@ test('Log all "verifyRelease" errors', async t => { t.deepEqual(fail.args[0][1].errors, [error1, error2]); }); -test('Dry-run skips prepare, publish and success', async t => { - // Create a git repository, set the current working directory at the root of the repo +test('Dry-run skips addChannel, prepare, publish and success', async t => { const {cwd, repositoryUrl} = await gitRepo(true); - // Add commits to the master branch await gitCommits(['First'], {cwd}); - // Create the tag corresponding to version 1.0.0 await gitTagVersion('v1.0.0', undefined, {cwd}); - // Add new commits to the master branch + await gitTagVersion('v1.0.0@next', undefined, {cwd}); + await gitTagVersion('v1.1.0@next', undefined, {cwd}); await gitCommits(['Second'], {cwd}); await gitPush(repositoryUrl, 'master', {cwd}); - - const nextRelease = {type: 'major', version: '2.0.0', gitHead: await getGitHead({cwd}), gitTag: 'v2.0.0'}; - const notes = 'Release notes'; + await gitCheckout('next', true, {cwd}); + await gitPush('origin', 'next', {cwd}); const verifyConditions = stub().resolves(); - const analyzeCommits = stub().resolves(nextRelease.type); + const analyzeCommits = stub().resolves('minor'); const verifyRelease = stub().resolves(); - const generateNotes = stub().resolves(notes); + const generateNotes = stub().resolves(); + const addChannel = stub().resolves(); const prepare = stub().resolves(); const publish = stub().resolves(); const success = stub().resolves(); const options = { dryRun: true, - branch: 'master', + branches: ['master', 'next'], repositoryUrl, verifyConditions, analyzeCommits, verifyRelease, generateNotes, + addChannel, prepare, publish, success, @@ -482,7 +908,11 @@ test('Dry-run skips prepare, publish and success', async t => { t.is(verifyConditions.callCount, 1); t.is(analyzeCommits.callCount, 1); t.is(verifyRelease.callCount, 1); - t.is(generateNotes.callCount, 1); + t.is(generateNotes.callCount, 2); + t.is(addChannel.callCount, 0); + t.true( + t.context.warn.calledWith(`Skip step "addChannel" of plugin "[Function: ${addChannel.name}]" in dry-run mode`) + ); t.is(prepare.callCount, 0); t.true(t.context.warn.calledWith(`Skip step "prepare" of plugin "[Function: ${prepare.name}]" in dry-run mode`)); t.is(publish.callCount, 0); @@ -508,7 +938,7 @@ test('Dry-run skips fail', async t => { const options = { dryRun: true, - branch: 'master', + branches: ['master'], repositoryUrl, verifyConditions: [stub().rejects(error1), stub().rejects(error2)], fail, @@ -542,7 +972,14 @@ test('Force a dry-run if not on a CI and "noCi" is not explicitly set', async t await gitCommits(['Second'], {cwd}); await gitPush(repositoryUrl, 'master', {cwd}); - const nextRelease = {type: 'major', version: '2.0.0', gitHead: await getGitHead({cwd}), gitTag: 'v2.0.0'}; + const nextRelease = { + name: 'v2.0.0', + type: 'major', + version: '2.0.0', + gitHead: await getGitHead({cwd}), + gitTag: 'v2.0.0', + channel: undefined, + }; const notes = 'Release notes'; const verifyConditions = stub().resolves(); @@ -554,12 +991,13 @@ test('Force a dry-run if not on a CI and "noCi" is not explicitly set', async t const options = { dryRun: false, - branch: 'master', + branches: ['master'], repositoryUrl, verifyConditions, analyzeCommits, verifyRelease, generateNotes, + addChannel: stub().resolves(), prepare: stub().resolves(), publish, success, @@ -605,7 +1043,7 @@ test('Dry-run does not print changelog if "generateNotes" return "undefined"', a const options = { dryRun: true, - branch: 'master', + branches: ['master'], repositoryUrl, verifyConditions: false, analyzeCommits, @@ -643,7 +1081,14 @@ test('Allow local releases with "noCi" option', async t => { await gitCommits(['Second'], {cwd}); await gitPush(repositoryUrl, 'master', {cwd}); - const nextRelease = {type: 'major', version: '2.0.0', gitHead: await getGitHead({cwd}), gitTag: 'v2.0.0'}; + const nextRelease = { + name: 'v2.0.0', + type: 'major', + version: '2.0.0', + gitHead: await getGitHead({cwd}), + gitTag: 'v2.0.0', + channel: undefined, + }; const notes = 'Release notes'; const verifyConditions = stub().resolves(); @@ -655,12 +1100,13 @@ test('Allow local releases with "noCi" option', async t => { const options = { noCi: true, - branch: 'master', + branches: ['master'], repositoryUrl, verifyConditions, analyzeCommits, verifyRelease, generateNotes, + addChannel: stub().resolves(), prepare: stub().resolves(), publish, success, @@ -704,8 +1150,21 @@ test('Accept "undefined" value returned by the "generateNotes" plugins', async t commits = (await gitCommits(['Second'], {cwd})).concat(commits); await gitPush(repositoryUrl, 'master', {cwd}); - const lastRelease = {version: '1.0.0', gitHead: commits[commits.length - 1].hash, gitTag: 'v1.0.0'}; - const nextRelease = {type: 'major', version: '2.0.0', gitHead: await getGitHead({cwd}), gitTag: 'v2.0.0'}; + const lastRelease = { + name: 'v1.0.0', + version: '1.0.0', + gitHead: commits[commits.length - 1].hash, + gitTag: 'v1.0.0', + channel: undefined, + }; + const nextRelease = { + name: 'v2.0.0', + type: 'major', + version: '2.0.0', + gitHead: await getGitHead({cwd}), + gitTag: 'v2.0.0', + channel: undefined, + }; const analyzeCommits = stub().resolves(nextRelease.type); const verifyRelease = stub().resolves(); const generateNotes1 = stub().resolves(); @@ -714,12 +1173,13 @@ test('Accept "undefined" value returned by the "generateNotes" plugins', async t const publish = stub().resolves(); const options = { - branch: 'master', + branches: ['master'], repositoryUrl, verifyConditions: stub().resolves(), analyzeCommits, verifyRelease, generateNotes: [generateNotes1, generateNotes2], + addChannel: stub().resolves(), prepare: stub().resolves(), publish, success: stub().resolves(), @@ -777,7 +1237,188 @@ test('Returns false if triggered by a PR', async t => { ); }); -test('Returns false if triggered on an outdated clone', async t => { +test('Throws "EINVALIDNEXTVERSION" if next release is out of range of the current maintenance branch', async t => { + const {cwd, repositoryUrl} = await gitRepo(true); + const commits = await gitCommits(['feat: initial commit'], {cwd}); + await gitTagVersion('v1.0.0', undefined, {cwd}); + await gitTagVersion('v1.0.0@1.x', undefined, {cwd}); + await gitCheckout('1.x', true, {cwd}); + await gitPush('origin', '1.x', {cwd}); + await gitCheckout('master', false, {cwd}); + commits.push(...(await gitCommits(['feat: new feature on master'], {cwd}))); + await gitTagVersion('v1.1.0', undefined, {cwd}); + await gitCheckout('1.x', false, {cwd}); + commits.push(...(await gitCommits(['feat: feature on maintenance version 1.x'], {cwd}))); + await gitPush('origin', 'master', {cwd}); + + const verifyConditions = stub().resolves(); + const verifyRelease = stub().resolves(); + const addChannel = stub().resolves(); + const prepare = stub().resolves(); + const publish = stub().resolves(); + const success = stub().resolves(); + + const config = { + branches: [{name: '1.x'}, {name: 'master'}], + repositoryUrl, + tagFormat: `v\${version}`, + }; + const options = { + ...config, + verifyConditions, + verifyRelease, + addChannel, + prepare, + publish, + success, + }; + + const semanticRelease = proxyquire('..', { + './lib/logger': t.context.logger, + 'env-ci': () => ({isCi: true, branch: '1.x', isPr: false}), + }); + + const error = await t.throws( + semanticRelease(options, {cwd, env: {}, stdout: {write: () => {}}, stderr: {write: () => {}}}) + ); + + t.is(error.code, 'EINVALIDNEXTVERSION'); + t.is(error.name, 'SemanticReleaseError'); + t.is(error.message, 'The release `1.1.0` on branch `1.x` cannot be published as it is out of range.'); + t.regex(error.details, /A valid branch could be `master`./); +}); + +test('Throws "EINVALIDNEXTVERSION" if next release is out of range of the current release branch', async t => { + const {cwd, repositoryUrl} = await gitRepo(true); + const commits = await gitCommits(['feat: initial commit'], {cwd}); + await gitTagVersion('v1.0.0', undefined, {cwd}); + await gitCheckout('next', true, {cwd}); + commits.push(...(await gitCommits(['feat: new feature on next'], {cwd}))); + await gitTagVersion('v1.1.0@next', undefined, {cwd}); + await gitPush('origin', 'next', {cwd}); + await gitCheckout('next-major', true, {cwd}); + await gitPush('origin', 'next-major', {cwd}); + await gitCheckout('master', false, {cwd}); + commits.push(...(await gitCommits(['feat: new feature on master', 'fix: new fix on master'], {cwd}))); + await gitPush('origin', 'master', {cwd}); + + const verifyConditions = stub().resolves(); + const verifyRelease = stub().resolves(); + const addChannel = stub().resolves(); + const prepare = stub().resolves(); + const publish = stub().resolves(); + const success = stub().resolves(); + + const config = { + branches: [{name: 'master'}, {name: 'next'}, {name: 'next-major'}], + repositoryUrl, + tagFormat: `v\${version}`, + }; + const options = { + ...config, + verifyConditions, + verifyRelease, + addChannel, + prepare, + publish, + success, + }; + + const semanticRelease = proxyquire('..', { + './lib/logger': t.context.logger, + 'env-ci': () => ({isCi: true, branch: 'master', isPr: false}), + }); + + const error = await t.throws( + semanticRelease(options, {cwd, env: {}, stdout: {write: () => {}}, stderr: {write: () => {}}}) + ); + + t.is(error.code, 'EINVALIDNEXTVERSION'); + t.is(error.name, 'SemanticReleaseError'); + t.is(error.message, 'The release `1.1.0` on branch `master` cannot be published as it is out of range.'); + t.regex(error.details, /A valid branch could be `next` or `next-major`./); +}); + +test('Throws "EINVALIDMAINTENANCEMERGE" if merge an out of range release in a maintenance branch', async t => { + const {cwd, repositoryUrl} = await gitRepo(true); + const commits = await gitCommits(['First'], {cwd}); + await gitTagVersion('v1.0.0', undefined, {cwd}); + await gitTagVersion('v1.0.0@1.1.x', undefined, {cwd}); + commits.push(...(await gitCommits(['Second'], {cwd}))); + await gitTagVersion('v1.1.0', undefined, {cwd}); + await gitTagVersion('v1.1.0@1.1.x', undefined, {cwd}); + await gitCheckout('1.1.x', 'master', {cwd}); + await gitPush('origin', '1.1.x', {cwd}); + await gitCheckout('master', false, {cwd}); + commits.push(...(await gitCommits(['Third'], {cwd}))); + await gitTagVersion('v1.1.1', undefined, {cwd}); + commits.push(...(await gitCommits(['Fourth'], {cwd}))); + await gitTagVersion('v1.2.0', undefined, {cwd}); + await gitPush('origin', 'master', {cwd}); + await gitCheckout('1.1.x', false, {cwd}); + await merge('master', {cwd}); + await gitPush('origin', '1.1.x', {cwd}); + + const notes = 'Release notes'; + const verifyConditions = stub().resolves(); + const analyzeCommits = stub().resolves(); + const verifyRelease = stub().resolves(); + const generateNotes = stub().resolves(notes); + const addChannel = stub().resolves(); + const prepare = stub().resolves(); + const publish = stub().resolves(); + const success = stub().resolves(); + const fail = stub().resolves(); + + const config = {branches: [{name: 'master'}, {name: '1.1.x'}], repositoryUrl, tagFormat: `v\${version}`}; + const options = { + ...config, + verifyConditions, + analyzeCommits, + verifyRelease, + addChannel, + generateNotes, + prepare, + publish, + success, + fail, + }; + + const nextRelease = { + type: 'patch', + version: '1.1.1', + channel: '1.1.x', + gitTag: 'v1.1.1@1.1.x', + name: 'v1.1.1', + gitHead: commits[2].hash, + }; + + const semanticRelease = proxyquire('..', { + './lib/logger': t.context.logger, + 'env-ci': () => ({isCi: true, branch: '1.1.x', isPr: false}), + }); + const errors = [ + ...(await t.throws(semanticRelease(options, {cwd, env: {}, stdout: {write: () => {}}, stderr: {write: () => {}}}))), + ]; + + t.is(addChannel.callCount, 1); + t.deepEqual(addChannel.args[0][1].nextRelease, {...nextRelease, notes}); + + t.is(publish.callCount, 0); + + t.is(success.callCount, 1); + t.deepEqual(success.args[0][1].releases, [{...nextRelease, notes, pluginName: '[Function: proxy]'}]); + + t.is(fail.callCount, 1); + t.deepEqual(fail.args[0][1].errors, errors); + + t.is(errors[0].code, 'EINVALIDMAINTENANCEMERGE'); + t.is(errors[0].name, 'SemanticReleaseError'); + t.truthy(errors[0].message); + t.truthy(errors[0].details); +}); + +test('Returns false value if triggered on an outdated clone', async t => { // Create a git repository, set the current working directory at the root of the repo let {cwd, repositoryUrl} = await gitRepo(true); const repoDir = cwd; @@ -809,12 +1450,13 @@ test('Returns false if not running from the configured branch', async t => { // Create a git repository, set the current working directory at the root of the repo const {cwd, repositoryUrl} = await gitRepo(true); const options = { - branch: 'master', + branches: ['master'], repositoryUrl, verifyConditions: stub().resolves(), analyzeCommits: stub().resolves(), verifyRelease: stub().resolves(), generateNotes: stub().resolves(), + addChannel: stub().resolves(), prepare: stub().resolves(), publish: stub().resolves(), success: stub().resolves(), @@ -853,12 +1495,13 @@ test('Returns false if there is no relevant changes', async t => { const publish = stub().resolves(); const options = { - branch: 'master', + branches: ['master'], repositoryUrl, verifyConditions: [stub().resolves()], analyzeCommits, verifyRelease, generateNotes, + addChannel: stub().resolves(), prepare: stub().resolves(), publish, success: stub().resolves(), @@ -907,13 +1550,14 @@ test('Exclude commits with [skip release] or [release skip] from analysis', asyn ); await gitPush(repositoryUrl, 'master', {cwd}); const analyzeCommits = stub().resolves(); - const config = {branch: 'master', repositoryUrl, globalOpt: 'global'}; + const config = {branches: ['master'], repositoryUrl, globalOpt: 'global'}; const options = { ...config, verifyConditions: [stub().resolves(), stub().resolves()], analyzeCommits, verifyRelease: stub().resolves(), generateNotes: stub().resolves(), + addChannel: stub().resolves(), prepare: stub().resolves(), publish: stub().resolves(), success: stub().resolves(), @@ -943,7 +1587,7 @@ test('Log both plugins errors and errors thrown by "fail" plugin', async t => { const failError2 = new Error('Fail error 2'); const options = { - branch: 'master', + branches: ['master'], repositoryUrl, verifyConditions: stub().rejects(pluginError), fail: [stub().rejects(failError1), stub().rejects(failError2)], @@ -968,7 +1612,7 @@ test('Call "fail" only if a plugin returns a SemanticReleaseError', async t => { const fail = stub().resolves(); const options = { - branch: 'master', + branches: ['master'], repositoryUrl, verifyConditions: stub().rejects(pluginError), fail, @@ -1003,6 +1647,8 @@ test('Throw SemanticReleaseError if repositoryUrl is not set and cannot be found // Verify error code and type t.is(errors[0].code, 'ENOREPOURL'); t.is(errors[0].name, 'SemanticReleaseError'); + t.truthy(errors[0].message); + t.truthy(errors[0].details); }); test('Throw an Error if plugin returns an unexpected value', async t => { @@ -1020,7 +1666,7 @@ test('Throw an Error if plugin returns an unexpected value', async t => { const analyzeCommits = stub().resolves('string'); const options = { - branch: 'master', + branches: ['master'], repositoryUrl, verifyConditions: [verifyConditions], analyzeCommits, @@ -1099,6 +1745,7 @@ test('Hide sensitive information passed to "success" plugin', async t => { name: `Name: Exposing token ${env.MY_TOKEN}`, url: `URL: Exposing token ${env.MY_TOKEN}`, }), + addChannel: false, success, fail: stub().resolves(), }; @@ -1129,11 +1776,18 @@ test('Get all commits including the ones not in the shallow clone', async t => { cwd = await gitShallowClone(repositoryUrl); - const nextRelease = {type: 'major', version: '2.0.0', gitHead: await getGitHead({cwd}), gitTag: 'v2.0.0'}; + const nextRelease = { + name: 'v2.0.0', + type: 'major', + version: '2.0.0', + gitHead: await getGitHead({cwd}), + gitTag: 'v2.0.0', + channel: undefined, + }; const notes = 'Release notes'; const analyzeCommits = stub().resolves(nextRelease.type); - const config = {branch: 'master', repositoryUrl, globalOpt: 'global'}; + const config = {branches: ['master'], repositoryUrl, globalOpt: 'global'}; const options = { ...config, verifyConditions: stub().resolves(), diff --git a/test/integration.test.js b/test/integration.test.js index ecbf704fa0..485bd74082 100644 --- a/test/integration.test.js +++ b/test/integration.test.js @@ -5,8 +5,19 @@ import {escapeRegExp} from 'lodash'; import {writeJson, readJson} from 'fs-extra'; import execa from 'execa'; import {WritableStreamBuffer} from 'stream-buffers'; +import delay from 'delay'; 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, +} from './helpers/git-utils'; +import {npmView} from './helpers/npm-utils'; import gitbox from './helpers/gitbox'; import mockServer from './helpers/mockserver'; import npmRegistry from './helpers/npm-registry'; @@ -58,7 +69,7 @@ test('Release patch, minor and major versions', async t => { version: '0.0.0-dev', repository: {url: repositoryUrl}, publishConfig: {registry: npmRegistry.url}, - release: {success: false, fail: false}, + release: {branches: ['master', 'next'], success: false, fail: false}, }); // Create a npm-shrinkwrap.json file await execa('npm', ['shrinkwrap'], {env: testEnv, cwd}); @@ -86,7 +97,7 @@ test('Release patch, minor and major versions', async t => { let createReleaseMock = await mockServer.mock( `/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}`]}], }, {body: {html_url: `release-url/${version}`}} @@ -105,15 +116,14 @@ test('Release patch, minor and major versions', async t => { t.is((await readJson(path.resolve(cwd, 'npm-shrinkwrap.json'))).version, version); // Retrieve the published package from the registry and check version and gitHead - let [, releasedVersion, releasedGitHead] = /^version = '(.+)'\s+gitHead = '(.+)'$/.exec( - (await execa('npm', ['show', packageName, 'version', 'gitHead'], {env: testEnv, cwd})).stdout - ); + let { + 'dist-tags': {latest: releasedVersion}, + } = await npmView(packageName, testEnv); let head = await gitHead({cwd}); t.is(releasedVersion, version); - t.is(releasedGitHead, head); t.is(await gitTagHead(`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(createReleaseMock); @@ -128,7 +138,7 @@ test('Release patch, minor and major versions', async t => { createReleaseMock = await mockServer.mock( `/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}`]}], }, {body: {html_url: `release-url/${version}`}} @@ -147,15 +157,14 @@ test('Release patch, minor and major versions', async t => { t.is((await readJson(path.resolve(cwd, 'npm-shrinkwrap.json'))).version, version); // 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}); t.is(releasedVersion, version); - t.is(releasedGitHead, head); t.is(await gitTagHead(`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(createReleaseMock); @@ -170,7 +179,7 @@ test('Release patch, minor and major versions', async t => { createReleaseMock = await mockServer.mock( `/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}`]}], }, {body: {html_url: `release-url/${version}`}} @@ -189,20 +198,19 @@ test('Release patch, minor and major versions', async t => { t.is((await readJson(path.resolve(cwd, 'npm-shrinkwrap.json'))).version, version); // 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}); t.is(releasedVersion, version); - t.is(releasedGitHead, head); t.is(await gitTagHead(`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(createReleaseMock); - /* Major release */ + /* Major release on next */ version = '2.0.0'; verifyMock = await mockServer.mock( `/repos/${owner}/${packageName}`, @@ -212,16 +220,18 @@ test('Release patch, minor and major versions', async t => { createReleaseMock = await mockServer.mock( `/repos/${owner}/${packageName}/releases`, { - body: {tag_name: `v${version}`, target_commitish: 'master', name: `v${version}`}, + body: {tag_name: `v${version}@next`, name: `v${version}`}, headers: [{name: 'Authorization', values: [`token ${env.GH_TOKEN}`]}], }, {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}); t.log('$ semantic-release'); - ({stdout, code} = await execa(cli, [], {env, cwd})); + ({stdout, code} = 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(`Publishing version ${version} to npm registry`)); t.is(code, 0); @@ -231,18 +241,67 @@ test('Release patch, minor and major versions', async t => { t.is((await readJson(path.resolve(cwd, 'npm-shrinkwrap.json'))).version, version); // 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}); t.is(releasedVersion, version); - t.is(releasedGitHead, head); - t.is(await gitTagHead(`v${version}`, {cwd}), head); - t.is(await gitRemoteTagHead(authUrl, `v${version}`, {cwd}), head); - t.log(`+ released ${releasedVersion} with head ${releasedGitHead}`); + t.is(await gitTagHead(`v${version}@next`, {cwd}), head); + t.is(await gitRemoteTagHead(authUrl, `v${version}@next`, {cwd}), head); + t.log(`+ released ${releasedVersion} on @next`); await mockServer.verify(verifyMock); 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@next`, + {headers: [{name: 'Authorization', values: [`token ${env.GH_TOKEN}`]}]}, + {body: {id: releaseId}, method: 'GET'} + ); + const updateReleaseMock = await mockServer.mock( + `/repos/${owner}/${packageName}/releases/${releaseId}`, + { + body: {tag_name: `v${version}`, 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, code} = 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(code, 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 gitTagHead(`v${version}`, {cwd}), await gitTagHead(`v${version}@next`, {cwd})); + t.is( + await gitRemoteTagHead(authUrl, `v${version}`, {cwd}), + await gitRemoteTagHead(authUrl, `v${version}@next`, {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 => { @@ -366,7 +425,7 @@ test('Allow local releases with "noCi" option', async t => { const createReleaseMock = await mockServer.mock( `/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}`]}], }, {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); // Retrieve the published package from the registry and check version and gitHead - const [, releasedVersion, releasedGitHead] = /^version = '(.+)'\s+gitHead = '(.+)'$/.exec( - (await execa('npm', ['show', packageName, 'version', 'gitHead'], {env: testEnv, cwd})).stdout - ); + const {version: releasedVersion, gitHead: releasedGitHead} = await npmView(packageName, testEnv); const head = await gitHead({cwd}); 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); // Retrieve the published package from the registry and check version and gitHead - const [, releasedVersion, releasedGitHead] = /^version = '(.+)'\s+gitHead = '(.+)'$/.exec( - (await execa('npm', ['show', packageName, 'version', 'gitHead'], {env: testEnv, cwd})).stdout - ); + const {version: releasedVersion, gitHead: releasedGitHead} = await npmView(packageName, testEnv); const head = await gitHead({cwd}); t.is(releasedVersion, version); t.is(releasedGitHead, head); @@ -482,7 +537,7 @@ test('Run via JS API', async t => { const createReleaseMock = await mockServer.mock( `/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}`]}], }, {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); // Retrieve the published package from the registry and check version and gitHead - const [, releasedVersion, releasedGitHead] = /^version = '(.+)'\s+gitHead = '(.+)'$/.exec( - (await execa('npm', ['show', packageName, 'version', 'gitHead'], {env: testEnv, cwd})).stdout - ); + const {version: releasedVersion, gitHead: releasedGitHead} = await npmView(packageName, testEnv); const head = await gitHead({cwd}); t.is(releasedVersion, version); t.is(releasedGitHead, head); diff --git a/test/plugins/normalize.test.js b/test/plugins/normalize.test.js index d42ae4792e..8965af8923 100644 --- a/test/plugins/normalize.test.js +++ b/test/plugins/normalize.test.js @@ -152,6 +152,24 @@ test('Wrap "publish" plugin in a function that validate the output of the plugin 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.throws(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 => { const pluginFunction = stub().resolves(); const pluginConf = {path: pluginFunction, conf: 'confValue'}; diff --git a/test/utils.test.js b/test/utils.test.js new file mode 100644 index 0000000000..9a973508dd --- /dev/null +++ b/test/utils.test.js @@ -0,0 +1,153 @@ +import test from 'ava'; +import AggregateError from 'aggregate-error'; +import { + extractErrors, + tagsToVersions, + isMajorRange, + isMaintenanceRange, + getUpperBound, + getLowerBound, + highest, + lowest, + getLatestVersion, + getEarliestVersion, + getFirstVersion, + getRange, + makeTag, +} 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.1.X')); + t.false(isMajorRange('1.1.0')); + + t.true(isMajorRange('1.x.x')); + t.true(isMajorRange('1.X.X')); + t.true(isMajorRange('1.x')); + t.true(isMajorRange('1.X')); +}); + +test('isMaintenanceRange', t => { + t.true(isMaintenanceRange('1.1.x')); + t.true(isMaintenanceRange('1.x.x')); + t.true(isMaintenanceRange('1.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('~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'), '2.0.0'); + t.is(getUpperBound('1.0.x'), '1.1.0'); + t.is(getUpperBound('1.0.0'), '1.0.0'); + + t.is(getUpperBound('foo'), undefined); +}); + +test('getLowerBound', t => { + t.is(getLowerBound('1.x.x'), '1.0.0'); + t.is(getLowerBound('1.x'), '1.0.0'); + t.is(getLowerBound('1.0.x'), '1.0.0'); + t.is(getLowerBound('1.0.0'), '1.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'); + t.is(makeTag(`v\${version}`, '1.0.0', 'next'), 'v1.0.0@next'); + t.is(makeTag(`v\${version}@test`, '1.0.0', 'next'), 'v1.0.0@next@test'); +}); diff --git a/test/verify.test.js b/test/verify.test.js index 3bf1e1009d..dba1818b85 100644 --- a/test/verify.test.js +++ b/test/verify.test.js @@ -5,7 +5,7 @@ import {gitRepo} from './helpers/git-utils'; test('Throw a AggregateError', async t => { const {cwd} = await gitRepo(); - const options = {}; + const options = {branches: [{name: 'master'}, {name: ''}]}; const errors = [...(await t.throws(verify({cwd, options})))]; @@ -21,11 +21,15 @@ test('Throw a AggregateError', async t => { t.is(errors[2].code, 'ETAGNOVERSION'); 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); }); test('Throw a SemanticReleaseError if does not run on a git repository', async t => { const cwd = tempy.directory(); - const options = {}; + const options = {branches: []}; const errors = [...(await t.throws(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 => { const {cwd, repositoryUrl} = await gitRepo(true); - const options = {repositoryUrl, tagFormat: `?\${version}`}; + const options = {repositoryUrl, tagFormat: `?\${version}`, branches: []}; const errors = [...(await t.throws(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 => { const {cwd, repositoryUrl} = await gitRepo(true); - const options = {repositoryUrl, tagFormat: 'test'}; + const options = {repositoryUrl, tagFormat: 'test', branches: []}; const errors = [...(await t.throws(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 => { 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.throws(verify({cwd, options})))]; @@ -71,9 +75,43 @@ test('Throw a SemanticReleaseError if the "tagFormat" contains multiple "version 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.throws(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 => { const {cwd, repositoryUrl} = await gitRepo(true); - const options = {repositoryUrl, tagFormat: `v\${version}`}; + const options = {repositoryUrl, tagFormat: `v\${version}`, branches: [{name: 'master'}]}; await t.notThrows(verify({cwd, options})); }); From e63e753cf09b2c3b51db00097bceade0893d3eaf Mon Sep 17 00:00:00 2001 From: Pierre Vanduynslager Date: Thu, 29 Nov 2018 13:29:47 -0500 Subject: [PATCH 002/107] feat(package): update @semantic-release/commit-analyzer to version 7.0.0 BREAKING CHANGE: Regexp are not supported anymore for property matching in the `releaseRules` option. Regex are replaced by [globs](https://github.com/micromatch/micromatch#matching-features). For example `/core-.*/` should be changed to `'core-*'`. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index dd076f8fea..b0af43ed1d 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ "Pierre Vanduynslager (https://twitter.com/@pvdlg_)" ], "dependencies": { - "@semantic-release/commit-analyzer": "^6.1.0", + "@semantic-release/commit-analyzer": "^7.0.0-beta.2", "@semantic-release/error": "^2.2.0", "@semantic-release/github": "^5.3.0-beta.1", "@semantic-release/npm": "^5.2.0-beta.1", From b729183b4af2818c713634746628f68d06e3a8bc Mon Sep 17 00:00:00 2001 From: Pierre Vanduynslager Date: Thu, 29 Nov 2018 19:55:19 -0500 Subject: [PATCH 003/107] fix: fetch all release branches on CI --- index.js | 4 +--- lib/branches/index.js | 17 +++++++++++------ lib/git.js | 31 ++++++++++++++++++++++++------- test/branches/branches.test.js | 8 ++++---- test/branches/expand.test.js | 12 ++++++++++-- test/git.test.js | 20 ++++++++++++++------ 6 files changed, 64 insertions(+), 28 deletions(-) diff --git a/index.js b/index.js index a9ccf47e5d..7d41184b5b 100644 --- a/index.js +++ b/index.js @@ -18,7 +18,7 @@ const {extractErrors, makeTag} = require('./lib/utils'); const getGitAuthUrl = require('./lib/get-git-auth-url'); const getBranches = require('./lib/branches'); const getLogger = require('./lib/get-logger'); -const {fetch, verifyAuth, isBranchUpToDate, getGitHead, tag, push} = require('./lib/git'); +const {verifyAuth, isBranchUpToDate, getGitHead, tag, push} = require('./lib/git'); const getError = require('./lib/get-error'); const {COMMIT_NAME, COMMIT_EMAIL} = require('./lib/definitions/constants'); @@ -53,8 +53,6 @@ async function run(context, plugins) { // Verify config await verify(context); - await fetch({cwd, env}); - context.branches = await getBranches(context); context.branch = context.branches.find(({name}) => name === ciBranch); diff --git a/lib/branches/index.js b/lib/branches/index.js index b039a3ee80..8f586f692b 100644 --- a/lib/branches/index.js +++ b/lib/branches/index.js @@ -3,20 +3,25 @@ const AggregateError = require('aggregate-error'); const pEachSeries = require('p-each-series'); const DEFINITIONS = require('../definitions/branches'); const getError = require('../get-error'); -const {verifyBranchName} = require('../git'); +const {fetch, verifyBranchName} = require('../git'); const expand = require('./expand'); const getTags = require('./get-tags'); const normalize = require('./normalize'); module.exports = async context => { - const branches = await getTags( + const {cwd, env} = context; + + const remoteBranches = await expand( context, - await expand( - context, - context.options.branches.map(branch => (isString(branch) || isRegExp(branch) ? {name: branch} : branch)) - ) + context.options.branches.map(branch => (isString(branch) || isRegExp(branch) ? {name: branch} : branch)) ); + await pEachSeries(remoteBranches, async ({name}) => { + await fetch(name, {cwd, env}); + }); + + const branches = await getTags(context, remoteBranches); + const errors = []; const branchesByType = Object.entries(DEFINITIONS).reduce( (branchesByType, [type, {filter}]) => ({[type]: branches.filter(filter), ...branchesByType}), diff --git a/lib/git.js b/lib/git.js index 62b285a5a0..63ec5112c3 100644 --- a/lib/git.js +++ b/lib/git.js @@ -1,4 +1,4 @@ -const {trimStart, matches, pick, memoize} = require('lodash'); +const {matches, pick, memoize} = require('lodash'); const gitLogParser = require('git-log-parser'); const getStream = require('get-stream'); const execa = require('execa'); @@ -63,9 +63,9 @@ async function getCommits(from, to, execaOpts) { * @throws {Error} If the `git` command fails. */ async function getBranches(execaOpts) { - return (await execa.stdout('git', ['branch', '--list', '--no-color'], execaOpts)) + return (await execa.stdout('git', ['ls-remote', '--heads', 'origin'], execaOpts)) .split('\n') - .map(branch => trimStart(branch, '*').trim()) + .map(branch => branch.match(/^.+refs\/heads\/(.+)$/)[1]) .filter(Boolean); } @@ -126,13 +126,30 @@ async function isRefExists(ref, execaOpts) { /** * Unshallow the git repository if necessary and fetch all the tags. * + * @param {String} branch The repository branch to fetch. * @param {Object} [execaOpts] Options to pass to `execa`. */ -async function fetch(execaOpts) { +async function fetch(branch, execaOpts) { + const isLocalExists = + (await execa('git', ['rev-parse', '--verify', branch], {...execaOpts, reject: false})).code === 0; + try { - await execa('git', ['fetch', '--unshallow', '--tags'], execaOpts); + await execa( + 'git', + [ + 'fetch', + '--unshallow', + '--tags', + ...(isLocalExists ? [] : ['origin', `+refs/heads/${branch}:refs/heads/${branch}`]), + ], + execaOpts + ); } catch (error) { - await execa('git', ['fetch', '--tags'], execaOpts); + await execa( + 'git', + ['fetch', '--tags', ...(isLocalExists ? [] : ['origin', `+refs/heads/${branch}:refs/heads/${branch}`])], + execaOpts + ); } } @@ -181,7 +198,7 @@ async function isGitRepo(execaOpts) { * Verify the write access authorization to remote repository with push dry-run. * * @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`. * * @throws {Error} if not authorized to push. diff --git a/test/branches/branches.test.js b/test/branches/branches.test.js index 31c19c36b4..a8f4c3cbbe 100644 --- a/test/branches/branches.test.js +++ b/test/branches/branches.test.js @@ -22,7 +22,7 @@ test('Enforce ranges with branching release workflow', async t => { {name: 'beta', prerelease: true, tags: []}, {name: 'alpha', prerelease: true, tags: []}, ]; - const getBranches = proxyquire('../../lib/branches', {'./get-tags': () => branches}); + const getBranches = proxyquire('../../lib/branches', {'./get-tags': () => branches, './expand': () => []}); let result = (await getBranches({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'); @@ -145,7 +145,7 @@ test('Throw SemanticReleaseError for invalid configurations', async t => { {name: 'alpha', prerelease: 'alpha', tags: []}, {name: 'preview', prerelease: 'alpha', tags: []}, ]; - const getBranches = proxyquire('../../lib/branches', {'./get-tags': () => branches}); + const getBranches = proxyquire('../../lib/branches', {'./get-tags': () => branches, './expand': () => []}); const errors = [...(await t.throws(getBranches({options: {branches}})))]; t.is(errors[0].name, 'SemanticReleaseError'); @@ -172,7 +172,7 @@ test('Throw SemanticReleaseError for invalid configurations', async t => { 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}); + const getBranches = proxyquire('../../lib/branches', {'./get-tags': () => branches, './expand': () => []}); const errors = [...(await t.throws(getBranches({options: {branches}})))]; @@ -184,7 +184,7 @@ test('Throw a SemanticReleaseError if there is duplicate branches', async t => { 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}); + const getBranches = proxyquire('../../lib/branches', {'./get-tags': () => branches, './expand': () => []}); const errors = [...(await t.throws(getBranches({options: {branches}})))]; diff --git a/test/branches/expand.test.js b/test/branches/expand.test.js index ec0f3853e2..889ac6ed77 100644 --- a/test/branches/expand.test.js +++ b/test/branches/expand.test.js @@ -1,24 +1,32 @@ import test from 'ava'; import expand from '../../lib/branches/expand'; -import {gitRepo, gitCommits, gitCheckout} from '../helpers/git-utils'; +import {gitRepo, gitCommits, gitCheckout, gitPush} from '../helpers/git-utils'; test('Expand branches defined with globs', async t => { - const {cwd} = await gitRepo(); + const {cwd, repositoryUrl} = await gitRepo(true); await gitCommits(['First'], {cwd}); + await gitPush(repositoryUrl, 'master', {cwd}); await gitCheckout('1.1.x', true, {cwd}); await gitCommits(['Second'], {cwd}); + await gitPush(repositoryUrl, '1.1.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 diff --git a/test/git.test.js b/test/git.test.js index 68c97645bb..82288b10a2 100644 --- a/test/git.test.js +++ b/test/git.test.js @@ -58,7 +58,7 @@ test('Unshallow and fetch repository', async t => { // Verify the shallow clone contains only one commit t.is((await gitGetCommits(undefined, {cwd})).length, 1); - await fetch({cwd}); + await fetch('master', {cwd}); // Verify the shallow clone contains all the commits t.is((await gitGetCommits(undefined, {cwd})).length, 2); @@ -66,10 +66,15 @@ test('Unshallow and fetch 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 - const {cwd} = await gitRepo(true); - // Add commits to the master branch + const {cwd, repositoryUrl} = await gitRepo(true); await gitCommits(['First'], {cwd}); - await t.notThrows(fetch({cwd})); + await gitPush(repositoryUrl, 'master', {cwd}); + await gitCheckout('second-branch', true, {cwd}); + await gitCommits(['Second'], {cwd}); + await gitPush(repositoryUrl, 'second-branch', {cwd}); + + await t.notThrows(fetch('master', {cwd})); + await t.notThrows(fetch('second-branch', {cwd})); }); test('Fetch all tags on a detached head repository', async t => { @@ -84,7 +89,7 @@ test('Fetch all tags on a detached head repository', async t => { await gitPush(repositoryUrl, 'master', {cwd}); cwd = await gitDetachedHead(repositoryUrl, commit.hash); - await fetch({cwd}); + await fetch('master', {cwd}); t.deepEqual((await getTags({cwd})).sort(), ['v1.0.0', 'v1.0.1', 'v1.1.0'].sort()); }); @@ -122,12 +127,15 @@ test('Verify if a branch exists', async t => { }); test('Get all branches', async t => { - const {cwd} = await gitRepo(); + 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({cwd})).sort(), ['master', 'second-branch', 'third-branch'].sort()); }); From 968b9968a1a4dba8c638be071d0af59205257279 Mon Sep 17 00:00:00 2001 From: Pierre Vanduynslager Date: Thu, 29 Nov 2018 20:00:01 -0500 Subject: [PATCH 004/107] fix: remove unnecessary `branch` parameter from `push` function --- index.js | 4 ++-- lib/git.js | 3 +-- test/git.test.js | 4 ++-- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index 7d41184b5b..40dbf27080 100644 --- a/index.js +++ b/index.js @@ -108,7 +108,7 @@ async function run(context, plugins) { logger.log('Create tag %s', nextRelease.gitTag); await tag(nextRelease.gitTag, nextRelease.gitHead, {cwd, env}); - await push(options.repositoryUrl, context.branch.name, {cwd, env}); + await push(options.repositoryUrl, {cwd, env}); context.branch.tags.push({ version: nextRelease.version, channel: nextRelease.channel, @@ -164,7 +164,7 @@ async function run(context, plugins) { } else { // Create the tag before calling the publish plugins as some require the tag to exists await tag(nextRelease.gitTag, nextRelease.gitHead, {cwd, env}); - await push(options.repositoryUrl, context.branch.name, {cwd, env}); + await push(options.repositoryUrl, {cwd, env}); logger.success(`Created tag ${nextRelease.gitTag}`); } diff --git a/lib/git.js b/lib/git.js index 63ec5112c3..c50308758f 100644 --- a/lib/git.js +++ b/lib/git.js @@ -229,12 +229,11 @@ async function tag(tagName, ref, execaOpts) { * Push to the remote repository. * * @param {String} repositoryUrl The remote repository URL. - * @param {String} branch The branch to push. * @param {Object} [execaOpts] Options to pass to `execa`. * * @throws {Error} if the push failed. */ -async function push(repositoryUrl, branch, execaOpts) { +async function push(repositoryUrl, execaOpts) { await execa('git', ['push', '--tags', repositoryUrl], execaOpts); } diff --git a/test/git.test.js b/test/git.test.js index 82288b10a2..c0ab6e97ef 100644 --- a/test/git.test.js +++ b/test/git.test.js @@ -194,7 +194,7 @@ test('Push tag to remote repository', async t => { const commits = await gitCommits(['Test commit'], {cwd}); await tag('tag_name', 'HEAD', {cwd}); - await push(repositoryUrl, 'master', {cwd}); + await push(repositoryUrl, {cwd}); t.is(await gitRemoteTagHead(repositoryUrl, 'tag_name', {cwd}), commits[0].hash); }); @@ -208,7 +208,7 @@ test('Push tag to remote repository with remote branch ahead', async t => { await gitPush('origin', 'master', {cwd: tmpRepo}); await tag('tag_name', 'HEAD', {cwd}); - await push(repositoryUrl, 'master', {cwd}); + await push(repositoryUrl, {cwd}); t.is(await gitRemoteTagHead(repositoryUrl, 'tag_name', {cwd}), commits[0].hash); }); From 687fea28f1fc62149b09ae4b9db0b7e2bb81e468 Mon Sep 17 00:00:00 2001 From: Pierre Vanduynslager Date: Tue, 11 Dec 2018 19:54:10 -0500 Subject: [PATCH 005/107] docs: new `branches` option in JS API example --- docs/developer-guide/js-api.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/docs/developer-guide/js-api.md b/docs/developer-guide/js-api.md index 4f6bd1ac89..cbce75127f 100644 --- a/docs/developer-guide/js-api.md +++ b/docs/developer-guide/js-api.md @@ -12,7 +12,14 @@ const stderrBuffer = WritableStreamBuffer(); try { const result = await semanticRelease({ // Core options - branch: 'master', + branches: [ + '+([1-9])?(.{+([1-9]),x}).x', + 'master', + 'next', + 'next-major', + {name: 'beta', prerelease: true}, + {name: 'alpha', prerelease: true} + ], repositoryUrl: 'https://github.com/me/my-package.git', // Shareable config extends: 'my-shareable-config', From a31dd9c873e9f8714570c613434ceaed1e3b9640 Mon Sep 17 00:00:00 2001 From: Pierre Vanduynslager Date: Fri, 30 Nov 2018 01:11:00 -0500 Subject: [PATCH 006/107] test: delete unused test helper file --- test/helpers/mock-github.js | 16 ---------------- 1 file changed, 16 deletions(-) delete mode 100644 test/helpers/mock-github.js diff --git a/test/helpers/mock-github.js b/test/helpers/mock-github.js deleted file mode 100644 index e0a62040d4..0000000000 --- a/test/helpers/mock-github.js +++ /dev/null @@ -1,16 +0,0 @@ -import nock from 'nock'; - -/** - * Retun a `nock` object setup to respond to a github authentication request. Other expectation and responses can be chained. - * - * @param {String} [githubToken='GH_TOKEN'] The github token to return in the authentication response. - * @param {String} [githubUrl='https://api.github.com'] The url on which to intercept http requests. - * @return {Object} A `nock` object ready to respond to a github authentication request. - */ -export default function authenticate({ - githubToken = 'GH_TOKEN', - githubUrl = 'https://api.github.com', - githubApiPathPrefix = '', -} = {}) { - return nock(`${githubUrl}/${githubApiPathPrefix}`, {reqheaders: {Authorization: `token ${githubToken}`}}); -} From b874017458a520191be78f40d6db8e111e873a96 Mon Sep 17 00:00:00 2001 From: Pierre Vanduynslager Date: Fri, 30 Nov 2018 01:44:10 -0500 Subject: [PATCH 007/107] chore(package): update nyc and sinon --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index b0af43ed1d..4b6a111e93 100644 --- a/package.json +++ b/package.json @@ -62,10 +62,10 @@ "js-yaml": "^3.10.0", "mockserver-client": "^5.1.1", "nock": "^10.0.0", - "nyc": "^12.0.1", + "nyc": "^13.1.0", "p-retry": "^2.0.0", "proxyquire": "^2.0.0", - "sinon": "^6.0.0", + "sinon": "^7.1.1", "stream-buffers": "^3.0.2", "tempy": "^0.2.1", "xo": "^0.23.0" From 1f6d8e3ee1b16f9733302be40968930f80a7b484 Mon Sep 17 00:00:00 2001 From: Evan Siroky Date: Fri, 23 Nov 2018 13:46:06 -0800 Subject: [PATCH 008/107] docs: add maven-semantic-release to list of community plugins --- docs/extending/plugins-list.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/extending/plugins-list.md b/docs/extending/plugins-list.md index 3d1bcfff0b..3320f1ad88 100644 --- a/docs/extending/plugins-list.md +++ b/docs/extending/plugins-list.md @@ -62,3 +62,8 @@ - [semantic-release-expo](https://github.com/bycedric/semantic-release-expo) - `verifyConditions`: Verify Expo manifest(s) are readable and valid. - `prepare`: Update version, ios build number and android version code in the Expo manifest(s). +- [maven-semantic-release](https://github.com/conveyal/maven-semantic-release) + - `verifyConditions`: Verifies that the pom.xml file and other files exist and are setup to allow releases + - `verifyRelease`: Checks and warns (does not error by default) if the version numbers found on maven central and within the Git project differ by quite a bit + - `prepare`: Changes the version number in the pom.xml (or all pom.xml files in maven projects with multiple pom.xml files). Optionally creates a commit with this version number and pushes it to master + - `publish`: Runs `mvn deploy` to deploy to maven central. Optionally will update to next snapshot version and merge changes to development branch From 862ffbe51232f89fbd7e4276ab188c24fa4d6bf3 Mon Sep 17 00:00:00 2001 From: Pierre Vanduynslager Date: Fri, 30 Nov 2018 03:11:45 -0500 Subject: [PATCH 009/107] docs: add `@semantic-release/apm` to plugins list --- docs/extending/plugins-list.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/extending/plugins-list.md b/docs/extending/plugins-list.md index 3320f1ad88..dcda42179f 100644 --- a/docs/extending/plugins-list.md +++ b/docs/extending/plugins-list.md @@ -32,6 +32,10 @@ - `publish`: Execute a shell command to publish the release - `success`: Execute a shell command to notify of a new release - `fail`: Execute a shell command to notify of a failed release +- [@semantic-release/apm](https://github.com/semantic-release/apm) + - `verifyConditions`: Verify the presence of the ATOM_ACCESS_TOKEN environment variable and the apm CLI + - `prepare`: Update the package.json version with npm version + - `publish`: Publish the Atom package ## Community plugins From 708bca38427a1d5ea7dae73bf2f0061d49c13fdb Mon Sep 17 00:00:00 2001 From: Pierre Vanduynslager Date: Fri, 30 Nov 2018 03:18:09 -0500 Subject: [PATCH 010/107] docs: syntax fixes in plugins list --- docs/extending/plugins-list.md | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/docs/extending/plugins-list.md b/docs/extending/plugins-list.md index dcda42179f..838f12f9a0 100644 --- a/docs/extending/plugins-list.md +++ b/docs/extending/plugins-list.md @@ -26,16 +26,16 @@ - [@semantic-release/exec](https://github.com/semantic-release/exec) - `verifyConditions`: Execute a shell command to verify if the release should happen - `analyzeCommits`: Execute a shell command to determine the type of release - - `verifyRelease`: Execute a shell command to verifying a release that was determined before and is about to be published. + - `verifyRelease`: Execute a shell command to verifying a release that was determined before and is about to be published - `generateNotes`: Execute a shell command to generate the release note - `prepare`: Execute a shell command to prepare the release - `publish`: Execute a shell command to publish the release - `success`: Execute a shell command to notify of a new release - `fail`: Execute a shell command to notify of a failed release - [@semantic-release/apm](https://github.com/semantic-release/apm) - - `verifyConditions`: Verify the presence of the ATOM_ACCESS_TOKEN environment variable and the apm CLI - - `prepare`: Update the package.json version with npm version - - `publish`: Publish the Atom package + - `verifyConditions`: Verify the presence of the `ATOM_ACCESS_TOKEN` environment variable and the [`apm`](https://github.com/atom/apm) CLI + - `prepare`: Update the `package.json` version with [`npm version`](https://docs.npmjs.com/cli/version) + - `publish`: Publish the [Atom package](https://flight-manual.atom.io/hacking-atom/sections/publishing) ## Community plugins @@ -43,10 +43,10 @@ - [semantic-release-docker](https://github.com/felixfbecker/semantic-release-docker) - `verifyConditions`: Verify that all needed configuration is present and login to the Docker registry. - - `publish`: Tag the image specified by `name` with the new version, push it to Docker Hub and update the latest tag. + - `publish`: Tag the image specified by `name` with the new version, push it to Docker Hub and update the latest tag - [semantic-release-gcr](https://github.com/carlos-cubas/semantic-release-gcr) - - `verifyConditions`: Verify that all needed configuration is present and login to the Docker registry. - - `publish`: Tag the image specified by `name` with the new version, push it to Docker Hub and update the latest tag. + - `verifyConditions`: Verify that all needed configuration is present and login to the Docker registry + - `publish`: Tag the image specified by `name` with the new version, push it to Docker Hub and update the latest tag - [semantic-release-vsce](https://github.com/raix/semantic-release-vsce) - `verifyConditions`: Verify the presence and the validity of the vsce authentication and release configuration - `prepare`: Create a `.vsix` for distribution @@ -55,11 +55,11 @@ - `verifyConditions`: Check the dependencies format against a regexp before a release - [semantic-release-chrome](https://github.com/GabrielDuarteM/semantic-release-chrome) - `verifyConditions`: Verify the presence of the authentication (set via environment variables) - - `prepare`: Write the correct version to the manifest.json and creates a zip file of the whole dist folder + - `prepare`: Write the correct version to the `manifest.json` and creates a zip file of the whole dist folder - `publish`: Uploads the generated zip file to the webstore, and publish the item - [semantic-release-firefox](https://github.com/felixfbecker/semantic-release-firefox) - `verifyConditions`: Verify the presence of the authentication (set via environment variables) - - `prepare`: Write the correct version to the manifest.json, creates a xpi file of the dist folder and a zip of the sources + - `prepare`: Write the correct version to the `manifest.json`, creates a `xpi` file of the dist folder and a zip of the sources - `publish`: Submit the generated archives to the webstore for review, and publish the item including release notes - [semantic-release-gerrit](https://github.com/pascalMN/semantic-release-gerrit) - `generateNotes`: Generate release notes with Gerrit reviews URL @@ -67,7 +67,7 @@ - `verifyConditions`: Verify Expo manifest(s) are readable and valid. - `prepare`: Update version, ios build number and android version code in the Expo manifest(s). - [maven-semantic-release](https://github.com/conveyal/maven-semantic-release) - - `verifyConditions`: Verifies that the pom.xml file and other files exist and are setup to allow releases + - `verifyConditions`: Verifies that the `pom.xml` file and other files exist and are setup to allow releases - `verifyRelease`: Checks and warns (does not error by default) if the version numbers found on maven central and within the Git project differ by quite a bit - - `prepare`: Changes the version number in the pom.xml (or all pom.xml files in maven projects with multiple pom.xml files). Optionally creates a commit with this version number and pushes it to master - - `publish`: Runs `mvn deploy` to deploy to maven central. Optionally will update to next snapshot version and merge changes to development branch + - `prepare`: Changes the version number in the `pom.xml` (or all `pom.xml` files in maven projects with multiple `pom.xml` files) and optionally creates a commit with this version number and pushes it to `master` + - `publish`: Runs `mvn deploy` to deploy to maven central and optionally will update to next snapshot version and merge changes to development branch From 635406c4c8f175b8c351363cfcb8d8213e7a5974 Mon Sep 17 00:00:00 2001 From: Pierre Vanduynslager Date: Fri, 23 Nov 2018 22:59:55 -0500 Subject: [PATCH 011/107] docs: switch to spectrum.chat --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 4c62f904e1..1899fa3b71 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@

📦🚀 semantic-release

Fully automated version management and package publishing

- - Gitter + + Join the community on Spectrum Travis @@ -128,7 +128,7 @@ After running the tests, the command `semantic-release` will execute the followi ## Get help - [Stack Overflow](https://stackoverflow.com/questions/tagged/semantic-release) -- [Gitter chat](https://gitter.im/semantic-release/semantic-release) +- [Spectrum community](https://spectrum.chat/semantic-release) - [Twitter](https://twitter.com/SemanticRelease) ## Badge From 2faff2637f49e3caf6e08c5b0de5e53f99e29ac7 Mon Sep 17 00:00:00 2001 From: Pierre Vanduynslager Date: Tue, 11 Dec 2018 13:25:12 -0500 Subject: [PATCH 012/107] fix: allow to set `ci` option via API and config file --- cli.js | 5 ----- lib/get-config.js | 3 +++ test/cli.test.js | 12 ------------ test/get-config.test.js | 12 ++++++++++++ 4 files changed, 15 insertions(+), 17 deletions(-) diff --git a/cli.js b/cli.js index 2767c49e19..39549a2808 100755 --- a/cli.js +++ b/cli.js @@ -47,11 +47,6 @@ Usage: return 0; } - // Set the `noCi` options as yargs sets the `ci` options instead (because arg starts with `--no`) - if (opts.ci === false) { - opts.noCi = true; - } - if (opts.debug) { // Debug must be enabled before other requires in order to work require('debug').enable('semantic-release:*'); diff --git a/lib/get-config.js b/lib/get-config.js index 1ee2abb688..3b1864b630 100644 --- a/lib/get-config.js +++ b/lib/get-config.js @@ -27,6 +27,9 @@ module.exports = async (context, opts) => { // Merge config file options and CLI/API options let options = {...config, ...opts}; + if (options.ci === false) { + options.noCi = true; + } const pluginsPath = {}; let extendPaths; ({extends: extendPaths, ...options} = options); diff --git a/test/cli.test.js b/test/cli.test.js index aca4d03ffb..7d7961c4fb 100644 --- a/test/cli.test.js +++ b/test/cli.test.js @@ -164,18 +164,6 @@ test.serial('Do not set properties in option for which arg is not in command lin t.false('e' in run.args[0][0]); }); -test.serial('Set "noCi" options to "true" with "--no-ci"', async t => { - const run = stub().resolves(true); - const argv = ['', '', '--no-ci']; - const cli = requireNoCache('../cli', {'.': run, process: {...process, argv}}); - - const exitCode = await cli(); - - t.is(run.args[0][0].noCi, true); - - t.is(exitCode, 0); -}); - test.serial('Display help', async t => { const run = stub().resolves(true); const argv = ['', '', '--help']; diff --git a/test/get-config.test.js b/test/get-config.test.js index 6978723598..1df49e602f 100644 --- a/test/get-config.test.js +++ b/test/get-config.test.js @@ -90,6 +90,18 @@ test('Default values, reading repositoryUrl (http url) from package.json if not t.is(result.tagFormat, `v\${version}`); }); +test('Convert "ci" option to "noCi"', async t => { + const pkg = {repository: 'https://host.null/owner/module.git', release: {ci: false}}; + // Create a git repository, set the current working directory at the root of the repo + const {cwd} = await gitRepo(); + // Create package.json in repository root + await outputJson(path.resolve(cwd, 'package.json'), pkg); + + const {options: result} = await t.context.getConfig({cwd}); + + t.is(result.noCi, true); +}); + test('Read options from package.json', async t => { // Create a git repository, set the current working directory at the root of the repo const {cwd} = await gitRepo(); From d51254f465b069b6919c1db9abba858d5cd2d5cc Mon Sep 17 00:00:00 2001 From: Pierre Vanduynslager Date: Tue, 11 Dec 2018 13:25:36 -0500 Subject: [PATCH 013/107] docs: mention that `debug` option is CLI only --- docs/usage/configuration.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/usage/configuration.md b/docs/usage/configuration.md index 4004f32caa..0c67e698eb 100644 --- a/docs/usage/configuration.md +++ b/docs/usage/configuration.md @@ -143,6 +143,8 @@ CLI argument: `--debug` Output debugging information. This can also be enabled by setting the `DEBUG` environment variable to `semantic-release:*`. +**Note**: The `debug` is used only supported via CLI argument. To enable debug mode from the [JS API](../developer-guide/js-api.md#javascript-api) use `require('debug').enable('semantic-release:*')`. + ## Git environment variables | Variable | Description | Default | From 5d99e022548a37e9b8e284096aea0d227ebee88f Mon Sep 17 00:00:00 2001 From: Gregor Martynus Date: Thu, 13 Dec 2018 09:18:04 -0800 Subject: [PATCH 014/107] docs(workflow-configuration): typo --- docs/usage/workflow-configuration.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/usage/workflow-configuration.md b/docs/usage/workflow-configuration.md index 022920311e..81797f3d6c 100644 --- a/docs/usage/workflow-configuration.md +++ b/docs/usage/workflow-configuration.md @@ -3,7 +3,7 @@ **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 parrallel +- 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. From 52ca0b391ccd7e31df0f2d7a125efd38e1b71b79 Mon Sep 17 00:00:00 2001 From: Pierre Vanduynslager Date: Thu, 13 Dec 2018 15:06:54 -0500 Subject: [PATCH 015/107] fix: fix branch type regexp to handle version with multiple digits --- lib/utils.js | 4 ++-- test/utils.test.js | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/utils.js b/lib/utils.js index 697b00a5ac..bd330d4580 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -23,11 +23,11 @@ function tagsToVersions(tags) { } function isMajorRange(range) { - return /^\d\.x(?:\.x)?$/i.test(range); + return /^\d+\.x(?:\.x)?$/i.test(range); } function isMaintenanceRange(range) { - return /^\d\.[\dx](?:\.x)?$/i.test(range); + return /^\d+\.(?:\d+|x)(?:\.x)?$/i.test(range); } function getUpperBound(range) { diff --git a/test/utils.test.js b/test/utils.test.js index 9a973508dd..3afa8c7148 100644 --- a/test/utils.test.js +++ b/test/utils.test.js @@ -33,24 +33,37 @@ test('tagsToVersions', t => { 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')); }); From 28c21fbc937f751baa1c204b8fe0bdfe8c0666e2 Mon Sep 17 00:00:00 2001 From: "greenkeeper[bot]" Date: Wed, 12 Dec 2018 15:15:35 +0000 Subject: [PATCH 016/107] chore(package): update p-retry to version 3.0.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4b6a111e93..4439355a14 100644 --- a/package.json +++ b/package.json @@ -63,7 +63,7 @@ "mockserver-client": "^5.1.1", "nock": "^10.0.0", "nyc": "^13.1.0", - "p-retry": "^2.0.0", + "p-retry": "^3.0.0", "proxyquire": "^2.0.0", "sinon": "^7.1.1", "stream-buffers": "^3.0.2", From 0bfc7a974e9620ce469ee90fd3a23bb4af330563 Mon Sep 17 00:00:00 2001 From: Pierre Vanduynslager Date: Fri, 14 Dec 2018 12:27:37 -0500 Subject: [PATCH 017/107] docs: remove mentions of `travis-deploy-once` --- docs/recipes/README.md | 1 - docs/recipes/travis-build-stages.md | 95 ------------------------ docs/recipes/travis.md | 110 ++++++++++------------------ docs/usage/ci-configuration.md | 2 +- 4 files changed, 39 insertions(+), 169 deletions(-) delete mode 100644 docs/recipes/travis-build-stages.md diff --git a/docs/recipes/README.md b/docs/recipes/README.md index 28d381ffc3..4c782f8bf2 100644 --- a/docs/recipes/README.md +++ b/docs/recipes/README.md @@ -3,7 +3,6 @@ ## CI configurations - [CircleCI 2.0 workflows](circleci-workflows.md) - [Travis CI](travis.md) -- [Travis CI with build stages](travis-build-stages.md) - [GitLab CI](gitlab-ci.md) ## Git hosted services diff --git a/docs/recipes/travis-build-stages.md b/docs/recipes/travis-build-stages.md deleted file mode 100644 index b23d0b7d8d..0000000000 --- a/docs/recipes/travis-build-stages.md +++ /dev/null @@ -1,95 +0,0 @@ -# Using semantic-release with [Travis CI build stages](https://docs.travis-ci.com/user/build-stages) - -## Environment variables - -The [Authentication](../usage/ci-configuration.md#authentication) environment variables can be configured in [Travis Repository Settings](https://docs.travis-ci.com/user/environment-variables/#defining-variables-in-repository-Settings) or with the [travis env set CLI](https://github.com/travis-ci/travis.rb#env). - -Alternatively, the default `NPM_TOKEN` and `GH_TOKEN` can be easily [setup with semantic-release-cli](../usage/ci-configuration.md#automatic-setup-with-semantic-release-cli). - -## Multiple Node jobs configuration - -### `.travis.yml` configuration for multiple Node jobs - -This example is a minimal configuration for **semantic-release** with a build running Node 6 and 8. See [Travis - Customizing the Build](https://docs.travis-ci.com/user/customizing-the-build) for additional configuration options. - -This example creates a `release` [build stage](https://docs.travis-ci.com/user/build-stages) that [runs `semantic-release` only after all test jobs are successful](../usage/ci-configuration.md#run-semantic-release-only-after-all-tests-succeeded). - -It's recommended to run the `semantic-release` command in the [Travis `deploy` step](https://docs.travis-ci.com/user/customizing-the-build/#The-Build-Lifecycle) so if an error occurs the build will fail and Travis will send a notification. - -**Note**: It's not recommended to run the `semantic-release` command in the Travis `script` step as each script in this step will be executed regardless of the outcome of the previous one. See [travis-ci/travis-ci#1066](https://github.com/travis-ci/travis-ci/issues/1066). - -**Advanced configuration**: Running the tests in the `script` step of the `release` stage is not necessary as the previous stage(s) already ran them. To increase speed, the `script` step of the `release` stage can be overwritten to skip the tests. Note that other commands such as build or compilation might still be required. - -```yaml -language: node_js - -node_js: - - 8 - - 6 - -jobs: - include: - # Define the release stage that runs semantic-release - - stage: release - node_js: lts/* - # Advanced: optionally overwrite your default `script` step to skip the tests - # script: skip - deploy: - provider: script - skip_cleanup: true - script: - - npx semantic-release -``` - -### `package.json` configuration for multiple Node jobs - -A `package.json` is required only for [local](../usage/installation.md#local-installation) **semantic-release** installation. - -```json -{ - "devDependencies": { - "semantic-release": "^15.0.0" - } -} -``` - -## Non-JavaScript projects configuration - -For projects that require to be tested with one or multiple version of a Non-JavaScript [language](https://docs.travis-ci.com/user/languages), optionally on multiple [Operating Systems](https://docs.travis-ci.com/user/multi-os). - -This recipe cover the Travis specifics only. See [Non JavaScript projects recipe](../support/FAQ.md#can-i-use-semantic-release-to-publish-non-javascript-packages) for more information on the **semantic-release** configuration. - -### `.travis.yml` configuration for non-JavaScript projects - -This example is a minimal configuration for **semantic-release** with a build running [Go 1.6 and 1.7](https://docs.travis-ci.com/user/languages/go). See [Travis - Customizing the Build](https://docs.travis-ci.com/user/customizing-the-build) for additional configuration options. - -This example creates a `release` [build stage](https://docs.travis-ci.com/user/build-stages) that [runs `semantic-release` only after all test jobs are successful](../usage/ci-configuration.md#run-semantic-release-only-after-all-tests-succeeded). - -It's recommended to run the `semantic-release` command in the [Travis `deploy` step](https://docs.travis-ci.com/user/customizing-the-build/#The-Build-Lifecycle) so if an error occurs the build will fail and Travis will send a notification. - -**Note**: It's not recommended to run the `semantic-release` command in the Travis `script` step as each script in this step will be executed regardless of the outcome of the previous one. See [travis-ci/travis-ci#1066](https://github.com/travis-ci/travis-ci/issues/1066). - -**Advanced configuration**: Running the tests in the `script` step of the `release` stage is not necessary as the previous stage(s) already ran them. To increase speed, the `script` step of the `release` stage can be overwritten to skip the tests. Note that other commands such as build or compilation might still be required. - -```yaml -language: go - -go: - - 1.6 - - 1.7 - -jobs: - include: - # Define the release stage that runs semantic-release - - stage: release - # Advanced: optionally overwrite your default `script` step to skip the tests - # script: - # - make - deploy: - provider: script - skip_cleanup: true - script: - # Use nvm to install and use the Node LTS version (nvm is installed on all Travis images) - - nvm install lts/* - - npx semantic-release -``` diff --git a/docs/recipes/travis.md b/docs/recipes/travis.md index 1b60fee438..02ac8356ba 100644 --- a/docs/recipes/travis.md +++ b/docs/recipes/travis.md @@ -4,62 +4,22 @@ The [Authentication](../usage/ci-configuration.md#authentication) environment variables can be configured in [Travis Repository Settings](https://docs.travis-ci.com/user/environment-variables/#defining-variables-in-repository-Settings) or with the [travis env set CLI](https://github.com/travis-ci/travis.rb#env). -Alternatively, the default `NPM_TOKEN` and `GH_TOKEN` can be easily [setup with semantic-release-cli](../usage/ci-configuration.md#automatic-setup-with-semantic-release-cli). +Alternatively, the default `NPM_TOKEN` and `GH_TOKEN` can be easily [setup with semantic-release-cli](../usage/getting-started.md#getting-started). -## Single Node job configuration +## Node.js projects configuration -For projects that require to be tested only with a single [Node version](https://docs.travis-ci.com/user/getting-started/#Selecting-a-different-programming-language) on [one Operating System](https://docs.travis-ci.com/user/getting-started/#Selecting-infrastructure-(optional)). - -**Note**: [Node 8 is the minimal version required](../support/FAQ.md#why-does-semantic-release-require-node-version--83). - -### `.travis.yml` configuration for single Node job - -This example is a minimal configuration for semantic-release with a build running Node 8 on Linux. See [Travis - Customizing the Build](https://docs.travis-ci.com/user/customizing-the-build) for additional configuration options. - -It's recommended to run the `semantic-release` command in the [Travis `deploy` step](https://docs.travis-ci.com/user/customizing-the-build/#The-Build-Lifecycle) so if an error occurs the build will fail and Travis will send a notification. - -**Note**: It's not recommended to run the `semantic-release` command in the Travis `script` step as each script in this step will be executed regardless of the outcome of the previous one. See [travis-ci/travis-ci#1066](https://github.com/travis-ci/travis-ci/issues/1066). - -```yaml -language: node_js - -node_js: 8 - -deploy: - provider: script - skip_cleanup: true - script: - - npx semantic-release -``` - -### `package.json` configuration for single Node job - -A `package.json` is required only for [local](../usage/installation.md#local-installation) **semantic-release** installation. - -```json -{ - "devDependencies": { - "semantic-release": "^11.0.0" - } -} -``` - -## Multiple Node jobs configuration - -For projects that require to be tested with multiple [Node versions](https://docs.travis-ci.com/user/languages/javascript-with-nodejs/#Specifying-Node.js-versions) and/or on multiple [Operating Systems](https://docs.travis-ci.com/user/multi-os). - -**Note**: At least one job must run a [Node >= 8 version](../support/FAQ.md#why-does-semantic-release-require-node-version--83). - -### `.travis.yml` configuration for multiple Node jobs +### `.travis.yml` configuration for multiple Node.js jobs This example is a minimal configuration for **semantic-release** with a build running Node 6 and 8. See [Travis - Customizing the Build](https://docs.travis-ci.com/user/customizing-the-build) for additional configuration options. -This example uses [`travis-deploy-once`](https://github.com/semantic-release/travis-deploy-once) in order to [Run `semantic-release` only after all tests succeeded](../usage/ci-configuration.md#run-semantic-release-only-after-all-tests-succeeded). Alternatively you can use [Travis CI Build Stages recipe](travis-build-stages.md). +This example creates a `release` [build stage](https://docs.travis-ci.com/user/build-stages) that [runs `semantic-release` only after all test jobs are successful](../usage/ci-configuration.md#run-semantic-release-only-after-all-tests-succeeded). It's recommended to run the `semantic-release` command in the [Travis `deploy` step](https://docs.travis-ci.com/user/customizing-the-build/#The-Build-Lifecycle) so if an error occurs the build will fail and Travis will send a notification. **Note**: It's not recommended to run the `semantic-release` command in the Travis `script` step as each script in this step will be executed regardless of the outcome of the previous one. See [travis-ci/travis-ci#1066](https://github.com/travis-ci/travis-ci/issues/1066). +**Advanced configuration**: Running the tests in the `script` step of the `release` stage is not necessary as the previous stage(s) already ran them. To increase speed, the `script` step of the `release` stage can be overwritten to skip the tests. Note that other commands such as build or compilation might still be required. + ```yaml language: node_js @@ -67,15 +27,20 @@ node_js: - 8 - 6 -deploy: - provider: script - skip_cleanup: true - script: - - npx travis-deploy-once "npx semantic-release" +jobs: + include: + # Define the release stage that runs semantic-release + - stage: release + node_js: lts/* + # Advanced: optionally overwrite your default `script` step to skip the tests + # script: skip + deploy: + provider: script + skip_cleanup: true + script: + - npx semantic-release ``` -**Note**: See the `travis-deploy-once` [`pro`](https://github.com/semantic-release/travis-deploy-once#-p---pro) and [`travis-url`](https://github.com/semantic-release/travis-deploy-once#-u---travis-url) options for using with [Travis Pro](https://docs.travis-ci.com/user/travis-pro) and [Travis Enterprise](https://enterprise.travis-ci.com). - ### `package.json` configuration for multiple Node jobs A `package.json` is required only for [local](../usage/installation.md#local-installation) **semantic-release** installation. @@ -83,13 +48,12 @@ A `package.json` is required only for [local](../usage/installation.md#local-ins ```json { "devDependencies": { - "semantic-release": "^15.0.0", - "travis-deploy-once": "^5.0.0" + "semantic-release": "^15.0.0" } } ``` -## Non-JavaScript projects configuration +## Non-Node.js projects configuration For projects that require to be tested with one or multiple version of a Non-JavaScript [language](https://docs.travis-ci.com/user/languages), optionally on multiple [Operating Systems](https://docs.travis-ci.com/user/multi-os). @@ -97,14 +61,16 @@ This recipe cover the Travis specifics only. See [Non JavaScript projects recipe ### `.travis.yml` configuration for non-JavaScript projects -This example is a minimal configuration for **semantic-release** with a build running [Go 1.6 and 1.7](https://docs.travis-ci.com/user/languages/go) on Linux and OSX. See [Travis - Customizing the Build](https://docs.travis-ci.com/user/customizing-the-build) for additional configuration options. +This example is a minimal configuration for **semantic-release** with a build running [Go 1.6 and 1.7](https://docs.travis-ci.com/user/languages/go). See [Travis - Customizing the Build](https://docs.travis-ci.com/user/customizing-the-build) for additional configuration options. -This example uses [`travis-deploy-once`](https://github.com/semantic-release/travis-deploy-once) in order to [run `semantic-release` only after all tests succeeded](../usage/ci-configuration.md#run-semantic-release-only-after-all-tests-succeeded). Alternatively you can use [Travis CI Build Stages recipe](travis-build-stages.md). +This example creates a `release` [build stage](https://docs.travis-ci.com/user/build-stages) that [runs `semantic-release` only after all test jobs are successful](../usage/ci-configuration.md#run-semantic-release-only-after-all-tests-succeeded). It's recommended to run the `semantic-release` command in the [Travis `deploy` step](https://docs.travis-ci.com/user/customizing-the-build/#The-Build-Lifecycle) so if an error occurs the build will fail and Travis will send a notification. **Note**: It's not recommended to run the `semantic-release` command in the Travis `script` step as each script in this step will be executed regardless of the outcome of the previous one. See [travis-ci/travis-ci#1066](https://github.com/travis-ci/travis-ci/issues/1066). +**Advanced configuration**: Running the tests in the `script` step of the `release` stage is not necessary as the previous stage(s) already ran them. To increase speed, the `script` step of the `release` stage can be overwritten to skip the tests. Note that other commands such as build or compilation might still be required. + ```yaml language: go @@ -112,18 +78,18 @@ go: - 1.6 - 1.7 -os: - - linux - - osx - -deploy: - provider: script - skip_cleanup: true - script: - # Use nvm to install and use the Node LTS version (nvm is installed on all Travis images) - - nvm install lts/* - # Run semantic-release only on one job, after all other are successful - - npx travis-deploy-once "npx semantic-release" +jobs: + include: + # Define the release stage that runs semantic-release + - stage: release + # Advanced: optionally overwrite your default `script` step to skip the tests + # script: + # - make + deploy: + provider: script + skip_cleanup: true + script: + # Use nvm to install and use the Node LTS version (nvm is installed on all Travis images) + - nvm install lts/* + - npx semantic-release ``` - -**Note**: See the `travis-deploy-once` [`pro`](https://github.com/semantic-release/travis-deploy-once#-p---pro) and [`travis-url`](https://github.com/semantic-release/travis-deploy-once#-u---travis-url) options for using with [Travis Pro](https://docs.travis-ci.com/user/travis-pro) and [Travis Enterprise](https://enterprise.travis-ci.com). diff --git a/docs/usage/ci-configuration.md b/docs/usage/ci-configuration.md index 0d0d4e3516..940d8f6d0c 100644 --- a/docs/usage/ci-configuration.md +++ b/docs/usage/ci-configuration.md @@ -2,7 +2,7 @@ ## Run `semantic-release` only after all tests succeeded -The `semantic-release` command must be executed only after all the tests in the CI build pass. If the build runs multiple jobs (for example to test on multiple Operating Systems or Node versions) the CI has to be configured to guarantee that the `semantic-release` command is executed only after all jobs are successful. This can be achieved with [Travis Build Stages](https://docs.travis-ci.com/user/build-stages), [CircleCI Workflows](https://circleci.com/docs/2.0/workflows), [Codeship Deployment Pipelines](https://documentation.codeship.com/basic/builds-and-configuration/deployment-pipelines), [GitLab Pipelines](https://docs.gitlab.com/ee/ci/pipelines.html#introduction-to-pipelines-and-jobs), [Codefresh Pipelines](https://codefresh.io/docs/docs/configure-ci-cd-pipeline/introduction-to-codefresh-pipelines), [Wercker Workflows](http://devcenter.wercker.com/docs/workflows), [GoCD Pipelines](https://docs.gocd.org/current/introduction/concepts_in_go.html#pipeline) or specific tools like [`travis-deploy-once`](https://github.com/semantic-release/travis-deploy-once). +The `semantic-release` command must be executed only after all the tests in the CI build pass. If the build runs multiple jobs (for example to test on multiple Operating Systems or Node versions) the CI has to be configured to guarantee that the `semantic-release` command is executed only after all jobs are successful. This can be achieved with [Travis Build Stages](https://docs.travis-ci.com/user/build-stages), [CircleCI Workflows](https://circleci.com/docs/2.0/workflows), [Codeship Deployment Pipelines](https://documentation.codeship.com/basic/builds-and-configuration/deployment-pipelines), [GitLab Pipelines](https://docs.gitlab.com/ee/ci/pipelines.html#introduction-to-pipelines-and-jobs), [Codefresh Pipelines](https://codefresh.io/docs/docs/configure-ci-cd-pipeline/introduction-to-codefresh-pipelines), [Wercker Workflows](http://devcenter.wercker.com/docs/workflows) or [GoCD Pipelines](https://docs.gocd.org/current/introduction/concepts_in_go.html#pipeline). See [CI configuration recipes](../recipes/README.md#ci-configurations) for more details. From 2aa65ad668b5f171a4e6b987d813be76e9a5b647 Mon Sep 17 00:00:00 2001 From: Pierre Vanduynslager Date: Fri, 14 Dec 2018 12:28:01 -0500 Subject: [PATCH 018/107] docs: fix broken link in CircleCI recipe --- docs/recipes/circleci-workflows.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/recipes/circleci-workflows.md b/docs/recipes/circleci-workflows.md index 73bd5156fd..a83a2a31d4 100644 --- a/docs/recipes/circleci-workflows.md +++ b/docs/recipes/circleci-workflows.md @@ -4,7 +4,7 @@ The [Authentication](../usage/ci-configuration.md#authentication) environment variables can be configured in [CircleCi Project Settings](https://circleci.com/docs/2.0/env-vars/#adding-environment-variables-in-the-app).. -Alternatively, the default `NPM_TOKEN` and `GH_TOKEN` can be easily [setup with semantic-release-cli](../usage/ci-configuration.md#automatic-setup-with-semantic-release-cli). +Alternatively, the default `NPM_TOKEN` and `GH_TOKEN` can be easily [setup with semantic-release-cli](../usage/getting-started.md#getting-started). ## Multiple Node jobs configuration From 47484f5eb2fa330cbbbb03bffadba524ad642081 Mon Sep 17 00:00:00 2001 From: Pierre Vanduynslager Date: Fri, 14 Dec 2018 15:58:58 -0500 Subject: [PATCH 019/107] feat: allow `publish` plugins to return `false` in order to signify no release was done --- lib/definitions/plugins.js | 2 +- test/definitions/plugins.test.js | 3 ++- test/index.test.js | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/definitions/plugins.js b/lib/definitions/plugins.js index f3516c33e7..23b49890c7 100644 --- a/lib/definitions/plugins.js +++ b/lib/definitions/plugins.js @@ -73,7 +73,7 @@ module.exports = { transform: (release, step, {nextRelease}) => ({ ...nextRelease, ...(release || {}), - ...step, + ...(release === false ? {} : step), }), }), }, diff --git a/test/definitions/plugins.test.js b/test/definitions/plugins.test.js index effca5c08c..0a6de485df 100644 --- a/test/definitions/plugins.test.js +++ b/test/definitions/plugins.test.js @@ -22,7 +22,7 @@ test('The "generateNotes" plugin output, if defined, must be a string', t => { t.true(plugins.generateNotes.outputValidator('string')); }); -test('The "publish" plugin output, if defined, must be an object', t => { +test('The "publish" plugin output, if defined, must be an object or "false"', t => { t.false(plugins.publish.outputValidator(1)); t.false(plugins.publish.outputValidator('string')); @@ -30,6 +30,7 @@ test('The "publish" plugin output, if defined, must be an object', t => { t.true(plugins.publish.outputValidator()); t.true(plugins.publish.outputValidator(null)); t.true(plugins.publish.outputValidator('')); + t.true(plugins.publish.outputValidator(false)); }); test('The "addChannel" plugin output, if defined, must be an object', t => { diff --git a/test/index.test.js b/test/index.test.js index 8b342ebee8..96185f9406 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -1139,7 +1139,7 @@ test('Allow local releases with "noCi" option', async t => { t.is(success.callCount, 1); }); -test('Accept "undefined" value returned by the "generateNotes" plugins', async t => { +test('Accept "undefined" value returned by "generateNotes" and "false" by "publish"', async t => { // Create a git repository, set the current working directory at the root of the repo const {cwd, repositoryUrl} = await gitRepo(true); // Add commits to the master branch @@ -1170,7 +1170,7 @@ test('Accept "undefined" value returned by the "generateNotes" plugins', async t const generateNotes1 = stub().resolves(); const notes2 = 'Release notes 2'; const generateNotes2 = stub().resolves(notes2); - const publish = stub().resolves(); + const publish = stub().resolves(false); const options = { branches: ['master'], From aa48514f85249abaac1029f4213b6c3dae606e40 Mon Sep 17 00:00:00 2001 From: Pierre Vanduynslager Date: Fri, 14 Dec 2018 18:24:47 -0500 Subject: [PATCH 020/107] refactor: remove unnecessary `default` of `addChannel` plugin --- lib/definitions/plugins.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/definitions/plugins.js b/lib/definitions/plugins.js index 23b49890c7..e8f0351b5f 100644 --- a/lib/definitions/plugins.js +++ b/lib/definitions/plugins.js @@ -78,7 +78,6 @@ module.exports = { }), }, addChannel: { - default: ['@semantic-release/npm', '@semantic-release/github'], required: false, dryRun: false, outputValidator: output => !output || isPlainObject(output), From e1c7269cb3af0d84c28fd3c4a5ce61ae4b625924 Mon Sep 17 00:00:00 2001 From: Pierre Vanduynslager Date: Fri, 14 Dec 2018 18:24:59 -0500 Subject: [PATCH 021/107] feat: allow `addChannel` plugins to return `false` in order to signify no release was done --- lib/definitions/plugins.js | 2 +- test/index.test.js | 50 ++++++++++++++------------------------ 2 files changed, 19 insertions(+), 33 deletions(-) diff --git a/lib/definitions/plugins.js b/lib/definitions/plugins.js index e8f0351b5f..8fc5f143d6 100644 --- a/lib/definitions/plugins.js +++ b/lib/definitions/plugins.js @@ -86,7 +86,7 @@ module.exports = { transform: (release, step, {nextRelease}) => ({ ...nextRelease, ...(release || {}), - ...step, + ...(release === false ? {} : step), }), }), }, diff --git a/test/index.test.js b/test/index.test.js index 96185f9406..d1099d4b5a 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -1139,30 +1139,23 @@ test('Allow local releases with "noCi" option', async t => { t.is(success.callCount, 1); }); -test('Accept "undefined" value returned by "generateNotes" and "false" by "publish"', async t => { - // Create a git repository, set the current working directory at the root of the repo +test('Accept "undefined" value returned by "generateNotes" and "false" by "publish" and "addChannel"', async t => { const {cwd, repositoryUrl} = await gitRepo(true); - // Add commits to the master branch - let commits = await gitCommits(['First'], {cwd}); - // Create the tag corresponding to version 1.0.0 + await gitCommits(['First'], {cwd}); await gitTagVersion('v1.0.0', undefined, {cwd}); - // Add new commits to the master branch - commits = (await gitCommits(['Second'], {cwd})).concat(commits); + await gitTagVersion('v1.0.0@next', undefined, {cwd}); + await gitTagVersion('v1.1.0@next', undefined, {cwd}); await gitPush(repositoryUrl, 'master', {cwd}); + await gitCheckout('next', true, {cwd}); + await gitPush('origin', 'next', {cwd}); + await gitCheckout('master', false, {cwd}); - const lastRelease = { - name: 'v1.0.0', - version: '1.0.0', - gitHead: commits[commits.length - 1].hash, - gitTag: 'v1.0.0', - channel: undefined, - }; const nextRelease = { - name: 'v2.0.0', - type: 'major', - version: '2.0.0', + name: 'v1.2.0', + type: 'minor', + version: '1.2.0', gitHead: await getGitHead({cwd}), - gitTag: 'v2.0.0', + gitTag: 'v1.2.0', channel: undefined, }; const analyzeCommits = stub().resolves(nextRelease.type); @@ -1171,15 +1164,16 @@ test('Accept "undefined" value returned by "generateNotes" and "false" by "publi const notes2 = 'Release notes 2'; const generateNotes2 = stub().resolves(notes2); const publish = stub().resolves(false); + const addChannel = stub().resolves(false); const options = { - branches: ['master'], + branches: ['master', 'next'], repositoryUrl, verifyConditions: stub().resolves(), analyzeCommits, verifyRelease, generateNotes: [generateNotes1, generateNotes2], - addChannel: stub().resolves(), + addChannel, prepare: stub().resolves(), publish, success: stub().resolves(), @@ -1200,20 +1194,12 @@ test('Accept "undefined" value returned by "generateNotes" and "false" by "publi ); t.is(analyzeCommits.callCount, 1); - t.deepEqual(analyzeCommits.args[0][1].lastRelease, lastRelease); - t.is(verifyRelease.callCount, 1); - t.deepEqual(verifyRelease.args[0][1].lastRelease, lastRelease); - - t.is(generateNotes1.callCount, 1); - t.deepEqual(generateNotes1.args[0][1].lastRelease, lastRelease); - - t.is(generateNotes2.callCount, 1); - t.deepEqual(generateNotes2.args[0][1].lastRelease, lastRelease); - + t.is(generateNotes1.callCount, 2); + t.is(generateNotes2.callCount, 2); + t.is(addChannel.callCount, 1); t.is(publish.callCount, 1); - t.deepEqual(publish.args[0][1].lastRelease, lastRelease); - t.is(publish.args[0][1].nextRelease.notes, notes2); + t.deepEqual(publish.args[0][1].nextRelease, {...nextRelease, notes: notes2}); }); test('Returns false if triggered by a PR', async t => { From d6731b9b274bb9cbae379f56766a3d4a4b48c0e3 Mon Sep 17 00:00:00 2001 From: Pierre Vanduynslager Date: Fri, 14 Dec 2018 19:00:51 -0500 Subject: [PATCH 022/107] fix(package): update `@semantic-release/npm` and `@semantic-release/github` --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 4439355a14..dee7a6dcea 100644 --- a/package.json +++ b/package.json @@ -21,8 +21,8 @@ "dependencies": { "@semantic-release/commit-analyzer": "^7.0.0-beta.2", "@semantic-release/error": "^2.2.0", - "@semantic-release/github": "^5.3.0-beta.1", - "@semantic-release/npm": "^5.2.0-beta.1", + "@semantic-release/github": "^5.3.0-beta.2", + "@semantic-release/npm": "^5.2.0-beta.2", "@semantic-release/release-notes-generator": "^7.1.2", "aggregate-error": "^1.0.0", "cosmiconfig": "^5.0.1", From 9a30f3542c8c29d452565c6a43a852a93912c483 Mon Sep 17 00:00:00 2001 From: Pierre Vanduynslager Date: Fri, 14 Dec 2018 22:21:28 -0500 Subject: [PATCH 023/107] fix(package): update `@semantic-release/github` --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index dee7a6dcea..b45823d6c5 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ "dependencies": { "@semantic-release/commit-analyzer": "^7.0.0-beta.2", "@semantic-release/error": "^2.2.0", - "@semantic-release/github": "^5.3.0-beta.2", + "@semantic-release/github": "^5.3.0-beta.3", "@semantic-release/npm": "^5.2.0-beta.2", "@semantic-release/release-notes-generator": "^7.1.2", "aggregate-error": "^1.0.0", From e1b418d0b55f419b3444379a9ae4082f3d86f869 Mon Sep 17 00:00:00 2001 From: Pierre Vanduynslager Date: Fri, 14 Dec 2018 23:31:39 -0500 Subject: [PATCH 024/107] build: fix Travis maintenance branch regexp --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 3661cbb942..9b5b8bff23 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,7 +14,7 @@ branches: - master - next - beta - - /^\d+(.\d+)?.x$/ + - /^\d+\.(\d+|x)(\.x)?$/ - /^greenkeeper.*$/ # Retry install on fail to avoid failing a build on network/disk/external errors From 89663d3fcfed34923289b12d4b2b5c509f4db321 Mon Sep 17 00:00:00 2001 From: Pierre Vanduynslager Date: Sun, 16 Dec 2018 15:54:21 -0500 Subject: [PATCH 025/107] fix: correctly handle skipped releases --- lib/definitions/plugins.js | 12 ++++++------ test/index.test.js | 6 +++++- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/lib/definitions/plugins.js b/lib/definitions/plugins.js index 8fc5f143d6..69651eb20f 100644 --- a/lib/definitions/plugins.js +++ b/lib/definitions/plugins.js @@ -71,9 +71,9 @@ module.exports = { pipelineConfig: () => ({ // Add `nextRelease` and plugin properties to published release transform: (release, step, {nextRelease}) => ({ - ...nextRelease, - ...(release || {}), - ...(release === false ? {} : step), + ...(release === false ? {} : nextRelease), + ...release, + ...step, }), }), }, @@ -84,9 +84,9 @@ module.exports = { pipelineConfig: () => ({ // Add `nextRelease` and plugin properties to published release transform: (release, step, {nextRelease}) => ({ - ...nextRelease, - ...(release || {}), - ...(release === false ? {} : step), + ...(release === false ? {} : nextRelease), + ...release, + ...step, }), }), }, diff --git a/test/index.test.js b/test/index.test.js index d1099d4b5a..0afdfe5392 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -1165,6 +1165,7 @@ test('Accept "undefined" value returned by "generateNotes" and "false" by "publi const generateNotes2 = stub().resolves(notes2); const publish = stub().resolves(false); const addChannel = stub().resolves(false); + const success = stub().resolves(); const options = { branches: ['master', 'next'], @@ -1176,7 +1177,7 @@ test('Accept "undefined" value returned by "generateNotes" and "false" by "publi addChannel, prepare: stub().resolves(), publish, - success: stub().resolves(), + success, fail: stub().resolves(), }; @@ -1199,7 +1200,10 @@ test('Accept "undefined" value returned by "generateNotes" and "false" by "publi t.is(generateNotes2.callCount, 2); t.is(addChannel.callCount, 1); t.is(publish.callCount, 1); + t.is(success.callCount, 2); t.deepEqual(publish.args[0][1].nextRelease, {...nextRelease, notes: notes2}); + t.deepEqual(success.args[0][1].releases, [{pluginName: '[Function: proxy]'}]); + t.deepEqual(success.args[1][1].releases, [{pluginName: '[Function: proxy]'}, {pluginName: '[Function: proxy]'}]); }); test('Returns false if triggered by a PR', async t => { From 9a04e64fab3ac8d7c6ea203ff29acb6d73e25246 Mon Sep 17 00:00:00 2001 From: Pierre Vanduynslager Date: Sun, 16 Dec 2018 18:55:39 -0500 Subject: [PATCH 026/107] fix: fix range regexp to handle version with multiple digits --- lib/utils.js | 4 ++-- test/utils.test.js | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/utils.js b/lib/utils.js index bd330d4580..f2ca198c1b 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -31,11 +31,11 @@ function isMaintenanceRange(range) { } function getUpperBound(range) { - return semver.valid(range) ? range : ((semver.validRange(range) || '').match(/<(\d\.\d\.\d)$/) || [])[1]; + return semver.valid(range) ? range : ((semver.validRange(range) || '').match(/<(\d+\.\d+\.\d+)$/) || [])[1]; } function getLowerBound(range) { - return ((semver.validRange(range) || '').match(/(\d\.\d\.\d)/) || [])[1]; + return ((semver.validRange(range) || '').match(/(\d+\.\d+\.\d+)/) || [])[1]; } function highest(version1, version2) { diff --git a/test/utils.test.js b/test/utils.test.js index 3afa8c7148..8d5c630028 100644 --- a/test/utils.test.js +++ b/test/utils.test.js @@ -70,18 +70,30 @@ test('isMaintenanceRange', t => { 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); }); From 162b4b9e3bea940c63014d045e80b8fc21227ac1 Mon Sep 17 00:00:00 2001 From: Pierre Vanduynslager Date: Sun, 16 Dec 2018 21:41:54 -0500 Subject: [PATCH 027/107] fix: remove confusing logs when searching for releases to add to a channel --- index.js | 10 ++++++++++ lib/get-last-release.js | 4 +--- test/get-last-release.test.js | 13 ------------- test/get-releases-to-add.test.js | 12 ------------ 4 files changed, 11 insertions(+), 28 deletions(-) diff --git a/index.js b/index.js index 40dbf27080..1b426acf6f 100644 --- a/index.js +++ b/index.js @@ -127,6 +127,16 @@ async function run(context, plugins) { context.lastRelease = await getLastRelease(context); + 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.commits = await getCommits(context); const nextRelease = { diff --git a/lib/get-last-release.js b/lib/get-last-release.js index 1fbf4a7e04..10557184fc 100644 --- a/lib/get-last-release.js +++ b/lib/get-last-release.js @@ -23,17 +23,15 @@ const {makeTag} = require('./utils'); * * @return {LastRelease} The last tagged release or empty object if none is found. */ -module.exports = ({branch: {name, tags, type}, options: {tagFormat}, logger}, {before} = {}) => { +module.exports = ({branch: {tags, type}, options: {tagFormat}}, {before} = {}) => { const [{version, gitTag, gitHead, channel} = {}] = tags .filter(tag => type === 'prerelease' || !semver.prerelease(tag.version)) .filter(tag => isUndefined(before) || semver.lt(tag.version, before)) .sort((a, b) => semver.rcompare(a.version, b.version)); if (gitTag) { - logger.log(`Found git tag ${gitTag} associated with version ${version} on branch ${name}`); return {version, gitTag, gitHead, channel, name: makeTag(tagFormat, version)}; } - logger.log(`No git tag version found on branch ${name}`); return {}; }; diff --git a/test/get-last-release.test.js b/test/get-last-release.test.js index f61200f297..08d54f4685 100644 --- a/test/get-last-release.test.js +++ b/test/get-last-release.test.js @@ -1,13 +1,6 @@ import test from 'ava'; -import {stub} from 'sinon'; import getLastRelease from '../lib/get-last-release'; -test.beforeEach(t => { - // Stub the logger functions - t.context.log = stub(); - t.context.logger = {log: t.context.log}; -}); - test('Get the highest non-prerelease valid tag', t => { const result = getLastRelease({ branch: { @@ -20,11 +13,9 @@ test('Get the highest non-prerelease valid tag', t => { type: 'release', }, options: {tagFormat: `v\${version}`}, - logger: t.context.logger, }); t.deepEqual(result, {version: '2.0.0', gitTag: 'v2.0.0', name: 'v2.0.0', gitHead: '222', channel: undefined}); - t.deepEqual(t.context.log.args[0][0], 'Found git tag v2.0.0 associated with version 2.0.0 on branch master'); }); test('Return empty object if no valid tag is found', t => { @@ -35,11 +26,9 @@ test('Return empty object if no valid tag is found', t => { type: 'release', }, options: {tagFormat: `v\${version}`}, - logger: t.context.logger, }); t.deepEqual(result, {}); - t.deepEqual(t.context.log.args[0][0], 'No git tag version found on branch master'); }); test('Get the highest non-prerelease valid tag before a certain version', t => { @@ -58,11 +47,9 @@ test('Get the highest non-prerelease valid tag before a certain version', t => { type: 'release', }, options: {tagFormat: `v\${version}`}, - logger: t.context.logger, }, {before: '2.1.0'} ); t.deepEqual(result, {version: '2.0.0', gitTag: 'v2.0.0', name: 'v2.0.0', gitHead: '333', channel: undefined}); - t.deepEqual(t.context.log.args[0][0], 'Found git tag v2.0.0 associated with version 2.0.0 on branch master'); }); diff --git a/test/get-releases-to-add.test.js b/test/get-releases-to-add.test.js index e4c28ac4a9..65c83fc5bc 100644 --- a/test/get-releases-to-add.test.js +++ b/test/get-releases-to-add.test.js @@ -1,13 +1,6 @@ import test from 'ava'; -import {stub} from 'sinon'; import getReleasesToAdd from '../lib/get-releases-to-add'; -test.beforeEach(t => { - // Stub the logger functions - t.context.log = stub(); - t.context.logger = {log: t.context.log}; -}); - test('Return versions merged from release to maintenance branch', t => { const result = getReleasesToAdd({ branch: { @@ -22,7 +15,6 @@ test('Return versions merged from release to maintenance branch', t => { }, branches: [{name: '1.x', channel: '1.x'}, {name: 'master'}], options: {tagFormat: `v\${version}`}, - logger: t.context.logger, }); t.deepEqual(result, [ @@ -80,7 +72,6 @@ test('Return versions merged from future branch to release branch', t => { }, branches: [{name: 'master'}, {name: 'next', channel: 'next'}, {name: 'next-major', channel: 'next-major'}], options: {tagFormat: `v\${version}`}, - logger: t.context.logger, }); t.deepEqual(result, [ @@ -138,7 +129,6 @@ test('Return releases sorted by ascending order', t => { }, branches: [{name: 'master'}, {name: 'next', channel: 'next'}, {name: 'next-major', channel: 'next-major'}], options: {tagFormat: `v\${version}`}, - logger: t.context.logger, }); t.deepEqual(result, [ @@ -188,7 +178,6 @@ test('no lastRelease', t => { branch: {name: 'master', tags: [{gitTag: 'v1.0.0@next', version: '1.0.0', channel: 'next', gitHead: '111'}]}, branches: [{name: 'master'}, {name: 'next', channel: 'next'}], options: {tagFormat: `v\${version}`}, - logger: t.context.logger, }); t.deepEqual(result, [ @@ -231,7 +220,6 @@ test('Ignore pre-release versions', t => { {name: 'alpha', type: 'prerelease', channel: 'alpha'}, ], options: {tagFormat: `v\${version}`}, - logger: t.context.logger, }); t.deepEqual(result, [ From c22ae17a9b10534ef87b66ae08a5c0c6d95e1269 Mon Sep 17 00:00:00 2001 From: Pierre Vanduynslager Date: Mon, 17 Dec 2018 14:35:48 -0500 Subject: [PATCH 028/107] fix: on maintenance branch add to channel only version >= to start range --- lib/get-releases-to-add.js | 12 ++++++-- test/get-releases-to-add.test.js | 52 +++++++++++++++++--------------- 2 files changed, 37 insertions(+), 27 deletions(-) diff --git a/lib/get-releases-to-add.js b/lib/get-releases-to-add.js index a800dcebd1..8b6237dbfb 100644 --- a/lib/get-releases-to-add.js +++ b/lib/get-releases-to-add.js @@ -2,7 +2,7 @@ const {uniq} = require('lodash'); const semver = require('semver'); const semverDiff = require('semver-diff'); const getLastRelease = require('./get-last-release'); -const {makeTag} = require('./utils'); +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. @@ -28,8 +28,14 @@ module.exports = context => { .reduce( (releases, higherBranch) => [ ...releases, - // For all unique release version of the higher branch merged on current branch - ...uniq(branch.tags.filter(({channel}) => channel === higherBranch.channel)) + // For all unique release version of the higher branch merged on current branch, excluding lower than start range version for maintenance branches + ...uniq( + branch.tags.filter( + ({channel, version}) => + channel === higherBranch.channel && + (branch.type !== 'maintenance' || semver.gte(version, getLowerBound(branch['merge-range']))) + ) + ) // Find ones that are not released on the building branch channel .filter(tag => branch.tags.every( diff --git a/test/get-releases-to-add.test.js b/test/get-releases-to-add.test.js index 65c83fc5bc..5c78187e0a 100644 --- a/test/get-releases-to-add.test.js +++ b/test/get-releases-to-add.test.js @@ -1,58 +1,62 @@ import test from 'ava'; import getReleasesToAdd from '../lib/get-releases-to-add'; -test('Return versions merged from release to maintenance branch', t => { +test('Return versions merged from release to maintenance branch, excluding lower than branch start range', t => { const result = getReleasesToAdd({ branch: { - name: '1.x', - channel: '1.x', + name: '2.x', + channel: '2.x', + type: 'maintenance', + 'merge-range': '>=2.0.0 <3.0.0', tags: [ - {gitTag: 'v1.0.0@1.x', version: '1.0.0', channel: '1.x', gitHead: '111'}, - {gitTag: 'v1.0.0', version: '1.0.0', gitHead: '111'}, - {gitTag: 'v1.1.0', version: '1.1.0', gitHead: '222'}, - {gitTag: 'v1.1.1', version: '1.1.1', gitHead: '333'}, + {gitTag: 'v2.0.0@2.x', version: '2.0.0', channel: '2.x', gitHead: '111'}, + {gitTag: 'v2.0.0', version: '2.0.0', gitHead: '111'}, + {gitTag: 'v2.1.0', version: '2.1.0', gitHead: '222'}, + {gitTag: 'v2.1.1', version: '2.1.1', gitHead: '333'}, + {gitTag: 'v1.0.0', version: '1.0.0', gitHead: '444'}, + {gitTag: 'v1.1.0', version: '1.1.0', gitHead: '555'}, ], }, - branches: [{name: '1.x', channel: '1.x'}, {name: 'master'}], + branches: [{name: '2.x', channel: '2.x'}, {name: 'master'}], options: {tagFormat: `v\${version}`}, }); t.deepEqual(result, [ { - lastRelease: {version: '1.0.0', channel: '1.x', gitTag: 'v1.0.0@1.x', name: 'v1.0.0', gitHead: '111'}, + lastRelease: {version: '2.0.0', channel: '2.x', gitTag: 'v2.0.0@2.x', name: 'v2.0.0', gitHead: '111'}, currentRelease: { type: 'minor', - version: '1.1.0', + version: '2.1.0', channel: undefined, - gitTag: 'v1.1.0', - name: 'v1.1.0', + gitTag: 'v2.1.0', + name: 'v2.1.0', gitHead: '222', }, nextRelease: { type: 'minor', - version: '1.1.0', - channel: '1.x', - gitTag: 'v1.1.0@1.x', - name: 'v1.1.0', + version: '2.1.0', + channel: '2.x', + gitTag: 'v2.1.0@2.x', + name: 'v2.1.0', gitHead: '222', }, }, { - lastRelease: {version: '1.1.0', channel: undefined, gitTag: 'v1.1.0', name: 'v1.1.0', gitHead: '222'}, + lastRelease: {version: '2.1.0', channel: undefined, gitTag: 'v2.1.0', name: 'v2.1.0', gitHead: '222'}, currentRelease: { type: 'patch', - version: '1.1.1', + version: '2.1.1', channel: undefined, - gitTag: 'v1.1.1', - name: 'v1.1.1', + gitTag: 'v2.1.1', + name: 'v2.1.1', gitHead: '333', }, nextRelease: { type: 'patch', - version: '1.1.1', - channel: '1.x', - gitTag: 'v1.1.1@1.x', - name: 'v1.1.1', + version: '2.1.1', + channel: '2.x', + gitTag: 'v2.1.1@2.x', + name: 'v2.1.1', gitHead: '333', }, }, From 9a023b40883d5eb825a36c540c57f71713a670c0 Mon Sep 17 00:00:00 2001 From: Pierre Vanduynslager Date: Mon, 17 Dec 2018 14:52:22 -0500 Subject: [PATCH 029/107] fix: call `success` plugin only once for releases added to a channel --- index.js | 5 +++-- test/index.test.js | 8 ++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index 1b426acf6f..ff16524548 100644 --- a/index.js +++ b/index.js @@ -178,9 +178,10 @@ async function run(context, plugins) { logger.success(`Created tag ${nextRelease.gitTag}`); } - context.releases.push(...(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}`); diff --git a/test/index.test.js b/test/index.test.js index 0afdfe5392..6984331eac 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -342,14 +342,14 @@ test('Plugins are called with expected values', async t => { t.deepEqual(success.args[1][0], config); t.deepEqual(success.args[1][1].options, options); - t.deepEqual(success.args[0][1].branch, branch); - t.deepEqual(success.args[0][1].branches, branches); + t.deepEqual(success.args[1][1].branch, branch); + t.deepEqual(success.args[1][1].branches, branches); t.deepEqual(success.args[1][1].logger, t.context.logger); t.deepEqual(success.args[1][1].lastRelease, lastRelease); t.deepEqual(success.args[1][1].commits[0].hash, commits[0].hash); t.deepEqual(success.args[1][1].commits[0].message, commits[0].message); t.deepEqual(success.args[1][1].nextRelease, {...nextRelease, notes: `${notes1}\n\n${notes2}\n\n${notes3}`}); - t.deepEqual(success.args[1][1].releases, releases); + t.deepEqual(success.args[1][1].releases, [releases[1], releases[2]]); t.deepEqual(result, { lastRelease, @@ -1203,7 +1203,7 @@ test('Accept "undefined" value returned by "generateNotes" and "false" by "publi t.is(success.callCount, 2); t.deepEqual(publish.args[0][1].nextRelease, {...nextRelease, notes: notes2}); t.deepEqual(success.args[0][1].releases, [{pluginName: '[Function: proxy]'}]); - t.deepEqual(success.args[1][1].releases, [{pluginName: '[Function: proxy]'}, {pluginName: '[Function: proxy]'}]); + t.deepEqual(success.args[1][1].releases, [{pluginName: '[Function: proxy]'}]); }); test('Returns false if triggered by a PR', async t => { From 725780bf0ac9e2726628dd8e526622ab6a5d5a49 Mon Sep 17 00:00:00 2001 From: Pierre Vanduynslager Date: Mon, 17 Dec 2018 14:55:08 -0500 Subject: [PATCH 030/107] fix(package): update @semantic-release/commit-analyzer to version 7.0.0-beta.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b45823d6c5..cb3d171949 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ "Pierre Vanduynslager (https://twitter.com/@pvdlg_)" ], "dependencies": { - "@semantic-release/commit-analyzer": "^7.0.0-beta.2", + "@semantic-release/commit-analyzer": "^7.0.0-beta.1", "@semantic-release/error": "^2.2.0", "@semantic-release/github": "^5.3.0-beta.3", "@semantic-release/npm": "^5.2.0-beta.2", From c1c96a87a3b60b267ebc9b46a636bcaa469ca76a Mon Sep 17 00:00:00 2001 From: Pierre Vanduynslager Date: Mon, 17 Dec 2018 14:56:06 -0500 Subject: [PATCH 031/107] fix(package): update @semantic-release/github to version 5.3.0-beta.5 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index cb3d171949..b445b0ee98 100644 --- a/package.json +++ b/package.json @@ -21,8 +21,8 @@ "dependencies": { "@semantic-release/commit-analyzer": "^7.0.0-beta.1", "@semantic-release/error": "^2.2.0", - "@semantic-release/github": "^5.3.0-beta.3", "@semantic-release/npm": "^5.2.0-beta.2", + "@semantic-release/github": "^5.3.0-beta.5", "@semantic-release/release-notes-generator": "^7.1.2", "aggregate-error": "^1.0.0", "cosmiconfig": "^5.0.1", From 390e966341ceb9c0baf7be2d42ea21aff11c7a4e Mon Sep 17 00:00:00 2001 From: Pierre Vanduynslager Date: Mon, 17 Dec 2018 14:56:35 -0500 Subject: [PATCH 032/107] fix(package): update @semantic-release/npm to version 5.2.0-beta.3 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b445b0ee98..aaef95c273 100644 --- a/package.json +++ b/package.json @@ -21,8 +21,8 @@ "dependencies": { "@semantic-release/commit-analyzer": "^7.0.0-beta.1", "@semantic-release/error": "^2.2.0", - "@semantic-release/npm": "^5.2.0-beta.2", "@semantic-release/github": "^5.3.0-beta.5", + "@semantic-release/npm": "^5.2.0-beta.4", "@semantic-release/release-notes-generator": "^7.1.2", "aggregate-error": "^1.0.0", "cosmiconfig": "^5.0.1", From 4aad9cd49031a849216e71a1ce358ad0668e4d54 Mon Sep 17 00:00:00 2001 From: Pierre Vanduynslager Date: Tue, 18 Dec 2018 01:53:09 -0500 Subject: [PATCH 033/107] fix: do not call `addChannel`for 2 merged branches configured with the same channel --- docs/usage/workflow-configuration.md | 12 ++--- lib/branches/normalize.js | 8 ++-- lib/get-releases-to-add.js | 1 + test/branches/normalize.test.js | 29 ++++++++++-- test/get-releases-to-add.test.js | 67 +++++++++++++++++++++++++++- test/utils.test.js | 2 + 6 files changed, 104 insertions(+), 15 deletions(-) diff --git a/docs/usage/workflow-configuration.md b/docs/usage/workflow-configuration.md index 81797f3d6c..eef0a826f9 100644 --- a/docs/usage/workflow-configuration.md +++ b/docs/usage/workflow-configuration.md @@ -20,12 +20,12 @@ The type of the branch is automatically determined based on naming convention an ## 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. 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). | - | +| 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 diff --git a/lib/branches/normalize.js b/lib/branches/normalize.js index 34e4049e0b..dfd4ef86c4 100644 --- a/lib/branches/normalize.js +++ b/lib/branches/normalize.js @@ -1,4 +1,4 @@ -const {sortBy} = require('lodash'); +const {sortBy, isNil} = require('lodash'); const semver = require('semver'); const semverDiff = require('semver-diff'); const {FIRST_RELEASE, RELEASE_TYPE} = require('../definitions/constants'); @@ -20,7 +20,7 @@ function maintenance({maintenance, release}) { ...rest, name, range: range || name, - channel: channel || name, + channel: isNil(channel) ? name : channel, })), 'range' ).map(({name, range, tags, ...rest}, idx, branches) => { @@ -83,7 +83,7 @@ function release({release}) { const diff = bound ? semverDiff(min, bound) : null; return { ...rest, - channel: idx === 0 ? channel : channel || name, + channel: idx === 0 ? channel : isNil(channel) ? name : channel, tags, type: 'release', name, @@ -98,7 +98,7 @@ function prerelease({prerelease}) { const preid = prerelease === true ? name : prerelease; return { ...rest, - channel: channel || name, + channel: isNil(channel) ? name : channel, type: 'prerelease', name, prerelease: preid, diff --git a/lib/get-releases-to-add.js b/lib/get-releases-to-add.js index 8b6237dbfb..5bedcb1227 100644 --- a/lib/get-releases-to-add.js +++ b/lib/get-releases-to-add.js @@ -33,6 +33,7 @@ module.exports = context => { branch.tags.filter( ({channel, version}) => channel === higherBranch.channel && + channel !== branch.channel && (branch.type !== 'maintenance' || semver.gte(version, getLowerBound(branch['merge-range']))) ) ) diff --git a/test/branches/normalize.test.js b/test/branches/normalize.test.js index cb4a7b36b9..c77c7babf5 100644 --- a/test/branches/normalize.test.js +++ b/test/branches/normalize.test.js @@ -4,7 +4,7 @@ import normalize from '../../lib/branches/normalize'; const toTags = versions => versions.map(version => ({version})); test('Maintenance branches - initial state', t => { - const maintenance = [{name: '1.x', tags: []}, {name: '1.1.x', tags: []}, {name: '1.2.x', tags: []}]; + 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 @@ -148,7 +148,11 @@ test('Maintenance branches - cap range to default branch last release if all rel }); test('Release branches - initial state', t => { - const release = [{name: 'master', tags: []}, {name: 'next', tags: []}, {name: 'next-major', tags: []}]; + 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}) => ({type, name, range, accept, channel})), @@ -298,10 +302,29 @@ test('Release branches - limit releases on 2nd and 3rd branche based on 1st bran }); test('Prerelease branches', t => { - const prerelease = [{name: 'beta', prerelease: true, tags: []}, {name: 'alpha', prerelease: 'preview', tags: []}]; + 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}, + ]); +}); diff --git a/test/get-releases-to-add.test.js b/test/get-releases-to-add.test.js index 5c78187e0a..521b099e6c 100644 --- a/test/get-releases-to-add.test.js +++ b/test/get-releases-to-add.test.js @@ -63,7 +63,7 @@ test('Return versions merged from release to maintenance branch, excluding lower ]); }); -test('Return versions merged from future branch to release branch', t => { +test('Return versions merged between release branches', t => { const result = getReleasesToAdd({ branch: { name: 'master', @@ -177,7 +177,7 @@ test('Return releases sorted by ascending order', t => { ]); }); -test('no lastRelease', t => { +test('No lastRelease', t => { const result = getReleasesToAdd({ branch: {name: 'master', tags: [{gitTag: 'v1.0.0@next', version: '1.0.0', channel: 'next', gitHead: '111'}]}, branches: [{name: 'master'}, {name: 'next', channel: 'next'}], @@ -248,3 +248,66 @@ test('Ignore pre-release versions', t => { }, ]); }); + +test('Exclude versions merged from release to maintenance branch if they have the same "channel"', t => { + const result = getReleasesToAdd({ + branch: { + name: '2.x', + channel: 'latest', + type: 'maintenance', + 'merge-range': '>=2.0.0 <3.0.0', + tags: [ + {gitTag: 'v2.0.0', version: '2.0.0', gitHead: '111'}, + {gitTag: 'v2.0.0', version: '2.0.0', gitHead: '111'}, + {gitTag: 'v2.1.0', version: '2.1.0', gitHead: '222'}, + {gitTag: 'v2.1.1', version: '2.1.1', gitHead: '333'}, + {gitTag: 'v1.0.0', version: '1.0.0', gitHead: '444'}, + {gitTag: 'v1.1.0', version: '1.1.0', gitHead: '555'}, + ], + }, + branches: [{name: '2.x', channel: 'latest'}, {name: 'master', channel: 'latest'}], + options: {tagFormat: `v\${version}`}, + }); + + t.deepEqual(result, []); +}); + +test('Exclude versions merged between release branches if they have the same "channel"', t => { + const result = getReleasesToAdd({ + branch: { + name: 'master', + channel: 'latest', + tags: [ + {gitTag: 'v1.0.0', channel: 'latest', version: '1.0.0', gitHead: '111'}, + {gitTag: 'v1.1.0', channel: 'latest', version: '1.1.0', gitHead: '222'}, + {gitTag: 'v2.0.0', channel: 'latest', version: '2.0.0', gitHead: '333'}, + ], + }, + branches: [ + {name: 'master', channel: 'latest'}, + {name: 'next', channel: 'latest'}, + {name: 'next-major', channel: 'latest'}, + ], + options: {tagFormat: `v\${version}`}, + }); + + t.deepEqual(result, []); +}); + +test('Exclude versions merged between release branches if they all have "channel" set to "false"', t => { + const result = getReleasesToAdd({ + branch: { + name: 'master', + channel: false, + tags: [ + {gitTag: 'v1.0.0', version: '1.0.0', gitHead: '111'}, + {gitTag: 'v1.1.0', version: '1.1.0', gitHead: '222'}, + {gitTag: 'v2.0.0', version: '2.0.0', gitHead: '333'}, + ], + }, + branches: [{name: 'master', channel: false}, {name: 'next', channel: false}, {name: 'next-major', channel: false}], + options: {tagFormat: `v\${version}`}, + }); + + t.deepEqual(result, []); +}); diff --git a/test/utils.test.js b/test/utils.test.js index 8d5c630028..08b4ebd97c 100644 --- a/test/utils.test.js +++ b/test/utils.test.js @@ -173,6 +173,8 @@ test('getRange', t => { test('makeTag', t => { t.is(makeTag(`v\${version}`, '1.0.0'), 'v1.0.0'); + t.is(makeTag(`v\${version}`, '1.0.0', false), 'v1.0.0'); + t.is(makeTag(`v\${version}`, '1.0.0', null), 'v1.0.0'); t.is(makeTag(`v\${version}`, '1.0.0', 'next'), 'v1.0.0@next'); t.is(makeTag(`v\${version}@test`, '1.0.0', 'next'), 'v1.0.0@next@test'); }); From f96c660c1b22fec29d87965838ef1493b87de114 Mon Sep 17 00:00:00 2001 From: Pierre Vanduynslager Date: Tue, 18 Dec 2018 17:34:06 -0500 Subject: [PATCH 034/107] fix: harmonize parameters passed to `getError` --- index.js | 6 ++-- lib/branches/normalize.js | 2 +- lib/definitions/errors.js | 42 +++++++---------------- lib/get-releases-to-add.js | 2 +- lib/verify.js | 11 ++++-- test/branches/normalize.test.js | 58 +++++++++++++++----------------- test/get-releases-to-add.test.js | 4 +-- 7 files changed, 55 insertions(+), 70 deletions(-) diff --git a/index.js b/index.js index ff16524548..9303f01ca2 100644 --- a/index.js +++ b/index.js @@ -86,7 +86,7 @@ async function run(context, plugins) { } } catch (error) { logger.error(`The command "${error.cmd}" failed with the error message ${error.stderr}.`); - throw getError('EGITNOPERMISSION', {options}); + throw getError('EGITNOPERMISSION', context); } logger.success(`Allowed to push to the Git repository`); @@ -98,8 +98,8 @@ async function run(context, plugins) { context.releases = []; await pEachSeries(releasesToAdd, async ({lastRelease, currentRelease, nextRelease}) => { - if (context.branch['merge-range'] && !semver.satisfies(nextRelease.version, context.branch['merge-range'])) { - errors.push(getError('EINVALIDMAINTENANCEMERGE', {nextRelease, branch: context.branch})); + if (context.branch.mergeRange && !semver.satisfies(nextRelease.version, context.branch.mergeRange)) { + errors.push(getError('EINVALIDMAINTENANCEMERGE', {...context, nextRelease})); return; } diff --git a/lib/branches/normalize.js b/lib/branches/normalize.js index dfd4ef86c4..54c1722cfb 100644 --- a/lib/branches/normalize.js +++ b/lib/branches/normalize.js @@ -51,7 +51,7 @@ function maintenance({maintenance, release}) { tags, range: getRange(min, max), accept: diff ? RELEASE_TYPE.slice(0, RELEASE_TYPE.indexOf(diff)) : [], - 'merge-range': getRange(maintenanceMin, getUpperBound(range)), + mergeRange: getRange(maintenanceMin, getUpperBound(range)), }; }); } diff --git a/lib/definitions/errors.js b/lib/definitions/errors.js index 9c0be3100b..4d0b6bcdc4 100644 --- a/lib/definitions/errors.js +++ b/lib/definitions/errors.js @@ -29,11 +29,9 @@ Please make sure to add the \`repositoryUrl\` to the [semantic-release configura 'docs/usage/configuration.md' )}).`, }), - EGITNOPERMISSION: ({options}) => ({ + EGITNOPERMISSION: ({options: {repositoryUrl}, branch: {name}}) => ({ message: 'The push permission to the Git repository is required.', - details: `**semantic-release** cannot push the version tag to the branch \`${ - options.branch - }\` on remote Git repository with URL \`${options.repositoryUrl}\`. + details: `**semantic-release** cannot push the version tag to the branch \`${name}\` on remote Git repository with URL \`${repositoryUrl}\`. Please refer to the [authentication configuration documentation](${linkify( 'docs/usage/ci-configuration.md#authentication' @@ -41,7 +39,7 @@ Please refer to the [authentication configuration documentation](${linkify( 'docs/usage/configuration.md#repositoryurl' )}) is configured with a [valid Git URL](https://git-scm.com/book/en/v2/Git-on-the-Server-The-Protocols).`, }), - EINVALIDTAGFORMAT: ({tagFormat}) => ({ + EINVALIDTAGFORMAT: ({options: {tagFormat}}) => ({ message: 'Invalid `tagFormat` option.', details: `The [tagFormat](${linkify( 'docs/usage/configuration.md#tagformat' @@ -49,7 +47,7 @@ Please refer to the [authentication configuration documentation](${linkify( Your configuration for the \`tagFormat\` option is \`${stringify(tagFormat)}\`.`, }), - ETAGNOVERSION: ({tagFormat}) => ({ + ETAGNOVERSION: ({options: {tagFormat}}) => ({ message: 'Invalid `tagFormat` option.', details: `The [tagFormat](${linkify( 'docs/usage/configuration.md#tagformat' @@ -205,40 +203,26 @@ Your configuration for the problematic branch is \`${stringify(branch)}\`.`, Your configuration for the problematic branches is \`${stringify(branches)}\`.`, }), - EINVALIDNEXTVERSION: ({nextRelease, branch, commits, validBranches}) => ({ - message: `The release \`${nextRelease.version}\` on branch \`${ - 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 \`${ - branch.range - }\` can be published from branch \`${branch.name}\`. + 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 \`${ - branch.name - }\` with [git revert](https://git-scm.com/docs/git-revert) or [git reset](https://git-scm.com/docs/git-reset). + } 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, branch}) => ({ - message: `The release \`${nextRelease.version}\` on branch \`${ - branch.name - }\` cannot be published as it is out of range.`, - details: `Only releases within the range \`${branch['merge-range']}\` can be merged into the maintenance branch \`${ - branch.name - }\` and published to the \`${nextRelease.channel}\` distribution channel. - -The branch \`${ - branch.name - }\` head should be [reset](https://git-scm.com/docs/git-reset) to a previous commit so the commit with tag \`${ - nextRelease.gitTag - }\` is removed from the branch history. + 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.`, }), diff --git a/lib/get-releases-to-add.js b/lib/get-releases-to-add.js index 5bedcb1227..5f27933215 100644 --- a/lib/get-releases-to-add.js +++ b/lib/get-releases-to-add.js @@ -34,7 +34,7 @@ module.exports = context => { ({channel, version}) => channel === higherBranch.channel && channel !== branch.channel && - (branch.type !== 'maintenance' || semver.gte(version, getLowerBound(branch['merge-range']))) + (branch.type !== 'maintenance' || semver.gte(version, getLowerBound(branch.mergeRange))) ) ) // Find ones that are not released on the building branch channel diff --git a/lib/verify.js b/lib/verify.js index a4eaf727d0..c789191146 100644 --- a/lib/verify.js +++ b/lib/verify.js @@ -3,7 +3,12 @@ const AggregateError = require('aggregate-error'); const {isGitRepo, verifyTagName} = require('./git'); const getError = require('./get-error'); -module.exports = async ({cwd, env, options: {repositoryUrl, tagFormat, branches}}) => { +module.exports = async context => { + const { + cwd, + env, + options: {repositoryUrl, tagFormat, branches}, + } = context; const errors = []; if (!(await isGitRepo({cwd, env}))) { @@ -14,14 +19,14 @@ module.exports = async ({cwd, env, options: {repositoryUrl, tagFormat, branches} // Verify that compiling the `tagFormat` produce a valid Git tag 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 // 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`. if ((template(tagFormat)({version: ' '}).match(/ /g) || []).length !== 1) { - errors.push(getError('ETAGNOVERSION', {tagFormat})); + errors.push(getError('ETAGNOVERSION', context)); } branches.forEach(branch => { diff --git a/test/branches/normalize.test.js b/test/branches/normalize.test.js index c77c7babf5..0316206039 100644 --- a/test/branches/normalize.test.js +++ b/test/branches/normalize.test.js @@ -7,16 +7,14 @@ 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, 'merge-range': maintenanceRange}) => ({ - type, - name, - range, - accept, - channel, - 'merge-range': maintenanceRange, - })), + normalize.maintenance({maintenance, release}).map(({type, name, range, accept, channel, mergeRange}) => ({ + type, + name, + range, + accept, + channel, + mergeRange, + })), [ { type: 'maintenance', @@ -24,7 +22,7 @@ test('Maintenance branches - initial state', t => { range: '>=1.1.0 <1.0.0', accept: [], channel: '1.1.x', - 'merge-range': '>=1.1.0 <1.2.0', + mergeRange: '>=1.1.0 <1.2.0', }, { type: 'maintenance', @@ -32,7 +30,7 @@ test('Maintenance branches - initial state', t => { range: '>=1.2.0 <1.0.0', accept: [], channel: '1.2.x', - 'merge-range': '>=1.2.0 <1.3.0', + mergeRange: '>=1.2.0 <1.3.0', }, { type: 'maintenance', @@ -40,7 +38,7 @@ test('Maintenance branches - initial state', t => { range: '>=1.3.0 <1.0.0', accept: [], channel: '1.x', - 'merge-range': '>=1.3.0 <2.0.0', + mergeRange: '>=1.3.0 <2.0.0', }, ] ); @@ -63,13 +61,13 @@ test('Maintenance branches - cap range to first release present on default branc t.deepEqual( normalize .maintenance({maintenance, release}) - .map(({type, name, range, accept, channel, 'merge-range': maintenanceRange}) => ({ + .map(({type, name, range, accept, channel, mergeRange: maintenanceRange}) => ({ type, name, range, accept, channel, - 'merge-range': maintenanceRange, + mergeRange: maintenanceRange, })), [ { @@ -78,7 +76,7 @@ test('Maintenance branches - cap range to first release present on default branc range: '>=1.1.1 <1.2.0', accept: ['patch'], channel: 'name', - 'merge-range': '>=1.1.0 <1.2.0', + mergeRange: '>=1.1.0 <1.2.0', }, { type: 'maintenance', @@ -86,7 +84,7 @@ test('Maintenance branches - cap range to first release present on default branc range: '>=1.2.1 <1.3.0', accept: ['patch'], channel: '1.2.x', - 'merge-range': '>=1.2.0 <1.3.0', + mergeRange: '>=1.2.0 <1.3.0', }, { type: 'maintenance', @@ -94,7 +92,7 @@ test('Maintenance branches - cap range to first release present on default branc range: '>=1.5.0 <1.6.0', accept: ['patch'], channel: '1.x', - 'merge-range': '>=1.3.0 <2.0.0', + mergeRange: '>=1.3.0 <2.0.0', }, { type: 'maintenance', @@ -102,7 +100,7 @@ test('Maintenance branches - cap range to first release present on default branc range: '>=2.0.0 <1.6.0', accept: [], channel: '2.x.x', - 'merge-range': '>=2.0.0 <3.0.0', + mergeRange: '>=2.0.0 <3.0.0', }, ] ); @@ -116,16 +114,14 @@ test('Maintenance branches - cap range to default branch last release if all rel 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, 'merge-range': maintenanceRange}) => ({ - type, - name, - range, - accept, - channel, - 'merge-range': maintenanceRange, - })), + normalize.maintenance({maintenance, release}).map(({type, name, range, accept, channel, mergeRange}) => ({ + type, + name, + range, + accept, + channel, + mergeRange, + })), [ { type: 'maintenance', @@ -133,7 +129,7 @@ test('Maintenance branches - cap range to default branch last release if all rel range: '>=1.3.0 <2.0.0', accept: ['patch', 'minor'], channel: '1.x', - 'merge-range': '>=1.0.0 <2.0.0', + mergeRange: '>=1.0.0 <2.0.0', }, { type: 'maintenance', @@ -141,7 +137,7 @@ test('Maintenance branches - cap range to default branch last release if all rel range: '>=2.0.0 <2.0.0', accept: [], channel: '2.x.x', - 'merge-range': '>=2.0.0 <3.0.0', + mergeRange: '>=2.0.0 <3.0.0', }, ] ); diff --git a/test/get-releases-to-add.test.js b/test/get-releases-to-add.test.js index 521b099e6c..3e3dc5fe72 100644 --- a/test/get-releases-to-add.test.js +++ b/test/get-releases-to-add.test.js @@ -7,7 +7,7 @@ test('Return versions merged from release to maintenance branch, excluding lower name: '2.x', channel: '2.x', type: 'maintenance', - 'merge-range': '>=2.0.0 <3.0.0', + mergeRange: '>=2.0.0 <3.0.0', tags: [ {gitTag: 'v2.0.0@2.x', version: '2.0.0', channel: '2.x', gitHead: '111'}, {gitTag: 'v2.0.0', version: '2.0.0', gitHead: '111'}, @@ -255,7 +255,7 @@ test('Exclude versions merged from release to maintenance branch if they have th name: '2.x', channel: 'latest', type: 'maintenance', - 'merge-range': '>=2.0.0 <3.0.0', + mergeRange: '>=2.0.0 <3.0.0', tags: [ {gitTag: 'v2.0.0', version: '2.0.0', gitHead: '111'}, {gitTag: 'v2.0.0', version: '2.0.0', gitHead: '111'}, From 5d6fd7c1cd4190ebef36118826b81229f1df7d8f Mon Sep 17 00:00:00 2001 From: "greenkeeper[bot]" Date: Wed, 26 Dec 2018 17:02:31 +0000 Subject: [PATCH 035/107] fix(package): update aggregate-error to version 2.0.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index aaef95c273..b1d9f7a4ef 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ "@semantic-release/github": "^5.3.0-beta.5", "@semantic-release/npm": "^5.2.0-beta.4", "@semantic-release/release-notes-generator": "^7.1.2", - "aggregate-error": "^1.0.0", + "aggregate-error": "^2.0.0", "cosmiconfig": "^5.0.1", "debug": "^4.0.0", "env-ci": "^3.0.0", From ba00e16f43148a82f86c6ce6394f13d96089101e Mon Sep 17 00:00:00 2001 From: "greenkeeper[bot]" Date: Sat, 15 Dec 2018 13:36:43 +0000 Subject: [PATCH 036/107] chore(package): update ava to version 1.0.1 --- package.json | 2 +- test/branches/branches.test.js | 6 +++--- test/get-config.test.js | 2 +- test/git.test.js | 10 +++++----- test/index.test.js | 26 ++++++++++++++------------ test/integration.test.js | 6 +++--- test/plugins/normalize.test.js | 12 ++++++------ test/plugins/pipeline.test.js | 10 +++++----- test/verify.test.js | 14 +++++++------- 9 files changed, 45 insertions(+), 43 deletions(-) diff --git a/package.json b/package.json index b1d9f7a4ef..4c2a224256 100644 --- a/package.json +++ b/package.json @@ -49,7 +49,7 @@ "yargs": "^12.0.0" }, "devDependencies": { - "ava": "^0.25.0", + "ava": "^1.0.1", "clear-module": "^3.0.0", "codecov": "^3.0.0", "commitizen": "^3.0.0", diff --git a/test/branches/branches.test.js b/test/branches/branches.test.js index a8f4c3cbbe..0bddf703d3 100644 --- a/test/branches/branches.test.js +++ b/test/branches/branches.test.js @@ -146,7 +146,7 @@ test('Throw SemanticReleaseError for invalid configurations', async t => { {name: 'preview', prerelease: 'alpha', tags: []}, ]; const getBranches = proxyquire('../../lib/branches', {'./get-tags': () => branches, './expand': () => []}); - const errors = [...(await t.throws(getBranches({options: {branches}})))]; + const errors = [...(await t.throwsAsync(getBranches({options: {branches}})))]; t.is(errors[0].name, 'SemanticReleaseError'); t.is(errors[0].code, 'EMAINTENANCEBRANCH'); @@ -174,7 +174,7 @@ 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.throws(getBranches({options: {branches}})))]; + const errors = [...(await t.throwsAsync(getBranches({options: {branches}})))]; t.is(errors[0].name, 'SemanticReleaseError'); t.is(errors[0].code, 'EDUPLICATEBRANCHES'); @@ -186,7 +186,7 @@ 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.throws(getBranches({options: {branches}})))]; + const errors = [...(await t.throwsAsync(getBranches({options: {branches}})))]; t.is(errors[0].name, 'SemanticReleaseError'); t.is(errors[0].code, 'EINVALIDBRANCHNAME'); diff --git a/test/get-config.test.js b/test/get-config.test.js index 1df49e602f..32866464d1 100644 --- a/test/get-config.test.js +++ b/test/get-config.test.js @@ -511,7 +511,7 @@ test('Throw an Error if one of the shareable config cannot be found', async t => await outputJson(path.resolve(cwd, 'package.json'), {release: pkhOptions}); await outputJson(path.resolve(cwd, 'shareable1.json'), options1); - const error = await t.throws(t.context.getConfig({cwd}), Error); + const error = await t.throwsAsync(t.context.getConfig({cwd}), Error); t.is(error.message, "Cannot find module 'non-existing-path'"); t.is(error.code, 'MODULE_NOT_FOUND'); diff --git a/test/git.test.js b/test/git.test.js index c0ab6e97ef..37e48b8023 100644 --- a/test/git.test.js +++ b/test/git.test.js @@ -44,7 +44,7 @@ test('Throw error if the last commit sha cannot be found', async t => { // Create a git repository, set the current working directory at the root of the repo const {cwd} = await gitRepo(); - await t.throws(getGitHead({cwd}), Error); + await t.throwsAsync(getGitHead({cwd}), Error); }); test('Unshallow and fetch repository', async t => { @@ -73,8 +73,8 @@ test('Do not throw error when unshallow a complete repository', async t => { await gitCommits(['Second'], {cwd}); await gitPush(repositoryUrl, 'second-branch', {cwd}); - await t.notThrows(fetch('master', {cwd})); - await t.notThrows(fetch('second-branch', {cwd})); + await t.notThrowsAsync(fetch('master', {cwd})); + await t.notThrowsAsync(fetch('second-branch', {cwd})); }); test('Fetch all tags on a detached head repository', async t => { @@ -108,7 +108,7 @@ test('Verify if the commit `sha` is in the direct history of the current branch' t.true(await isRefInHistory(commits[0].hash, 'master', false, {cwd})); t.falsy(await isRefInHistory(otherCommits[0].hash, 'master', false, {cwd})); t.falsy(await isRefInHistory(otherCommits[0].hash, 'missing-branch', false, {cwd})); - await t.throws(isRefInHistory('non-existant-sha', 'master', false, {cwd})); + await t.throwsAsync(isRefInHistory('non-existant-sha', 'master', false, {cwd})); }); test('Verify if a branch exists', async t => { @@ -243,7 +243,7 @@ test('Return falsy for invalid tag names', async t => { test('Throws error if obtaining the tags fails', async t => { const cwd = tempy.directory(); - await t.throws(getTags({cwd})); + await t.throwsAsync(getTags({cwd})); }); test('Return "true" if repository is up to date', async t => { diff --git a/test/index.test.js b/test/index.test.js index 6984331eac..e00bc7f611 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -763,7 +763,7 @@ test('Call all "success" plugins even if one errors out', async t => { 'env-ci': () => ({isCi: true, branch: 'master', isPr: false}), }); - await t.throws( + await t.throwsAsync( semanticRelease(options, {cwd, env: {}, stdout: new WritableStreamBuffer(), stderr: new WritableStreamBuffer()}) ); @@ -799,7 +799,7 @@ test('Log all "verifyConditions" errors', async t => { 'env-ci': () => ({isCi: true, branch: 'master', isPr: false}), }); const errors = [ - ...(await t.throws( + ...(await t.throwsAsync( semanticRelease(options, {cwd, env: {}, stdout: new WritableStreamBuffer(), stderr: new WritableStreamBuffer()}) )), ]; @@ -844,7 +844,7 @@ test('Log all "verifyRelease" errors', async t => { 'env-ci': () => ({isCi: true, branch: 'master', isPr: false}), }); const errors = [ - ...(await t.throws( + ...(await t.throwsAsync( semanticRelease(options, {cwd, env: {}, stdout: new WritableStreamBuffer(), stderr: new WritableStreamBuffer()}) )), ]; @@ -949,7 +949,7 @@ test('Dry-run skips fail', async t => { 'env-ci': () => ({isCi: true, branch: 'master', isPr: false}), }); const errors = [ - ...(await t.throws( + ...(await t.throwsAsync( semanticRelease(options, {cwd, env: {}, stdout: new WritableStreamBuffer(), stderr: new WritableStreamBuffer()}) )), ]; @@ -1268,7 +1268,7 @@ test('Throws "EINVALIDNEXTVERSION" if next release is out of range of the curren 'env-ci': () => ({isCi: true, branch: '1.x', isPr: false}), }); - const error = await t.throws( + const error = await t.throwsAsync( semanticRelease(options, {cwd, env: {}, stdout: {write: () => {}}, stderr: {write: () => {}}}) ); @@ -1319,7 +1319,7 @@ test('Throws "EINVALIDNEXTVERSION" if next release is out of range of the curren 'env-ci': () => ({isCi: true, branch: 'master', isPr: false}), }); - const error = await t.throws( + const error = await t.throwsAsync( semanticRelease(options, {cwd, env: {}, stdout: {write: () => {}}, stderr: {write: () => {}}}) ); @@ -1388,7 +1388,9 @@ test('Throws "EINVALIDMAINTENANCEMERGE" if merge an out of range release in a ma 'env-ci': () => ({isCi: true, branch: '1.1.x', isPr: false}), }); const errors = [ - ...(await t.throws(semanticRelease(options, {cwd, env: {}, stdout: {write: () => {}}, stderr: {write: () => {}}}))), + ...(await t.throwsAsync( + semanticRelease(options, {cwd, env: {}, stdout: {write: () => {}}, stderr: {write: () => {}}}) + )), ]; t.is(addChannel.callCount, 1); @@ -1587,7 +1589,7 @@ test('Log both plugins errors and errors thrown by "fail" plugin', async t => { 'env-ci': () => ({isCi: true, branch: 'master', isPr: false}), }); - await t.throws( + await t.throwsAsync( semanticRelease(options, {cwd, env: {}, stdout: new WritableStreamBuffer(), stderr: new WritableStreamBuffer()}) ); @@ -1612,7 +1614,7 @@ test('Call "fail" only if a plugin returns a SemanticReleaseError', async t => { 'env-ci': () => ({isCi: true, branch: 'master', isPr: false}), }); - await t.throws( + await t.throwsAsync( semanticRelease(options, {cwd, env: {}, stdout: new WritableStreamBuffer(), stderr: new WritableStreamBuffer()}) ); @@ -1629,7 +1631,7 @@ test('Throw SemanticReleaseError if repositoryUrl is not set and cannot be found 'env-ci': () => ({isCi: true, branch: 'master', isPr: false}), }); const errors = [ - ...(await t.throws( + ...(await t.throwsAsync( semanticRelease({}, {cwd, env: {}, stdout: new WritableStreamBuffer(), stderr: new WritableStreamBuffer()}) )), ]; @@ -1668,7 +1670,7 @@ test('Throw an Error if plugin returns an unexpected value', async t => { './lib/get-logger': () => t.context.logger, 'env-ci': () => ({isCi: true, branch: 'master', isPr: false}), }); - const error = await t.throws( + const error = await t.throwsAsync( semanticRelease(options, {cwd, env: {}, stdout: new WritableStreamBuffer(), stderr: new WritableStreamBuffer()}), Error ); @@ -1698,7 +1700,7 @@ test('Hide sensitive information passed to "fail" plugin', async t => { './lib/get-logger': () => t.context.logger, 'env-ci': () => ({isCi: true, branch: 'master', isPr: false}), }); - await t.throws( + await t.throwsAsync( semanticRelease(options, {cwd, env, stdout: new WritableStreamBuffer(), stderr: new WritableStreamBuffer()}), Error ); diff --git a/test/integration.test.js b/test/integration.test.js index 485bd74082..ee61a8eaa4 100644 --- a/test/integration.test.js +++ b/test/integration.test.js @@ -317,7 +317,7 @@ test('Exit with 1 if a plugin is not found', async t => { release: {analyzeCommits: 'non-existing-path', success: false, fail: false}, }); - const {code, stderr} = await t.throws(execa(cli, [], {env, cwd})); + const {code, stderr} = await t.throwsAsync(execa(cli, [], {env, cwd})); t.is(code, 1); t.regex(stderr, /Cannot find module/); }); @@ -335,7 +335,7 @@ test('Exit with 1 if a shareable config is not found', async t => { release: {extends: 'non-existing-path', success: false, fail: false}, }); - const {code, stderr} = await t.throws(execa(cli, [], {env, cwd})); + const {code, stderr} = await t.throwsAsync(execa(cli, [], {env, cwd})); t.is(code, 1); t.regex(stderr, /Cannot find module/); }); @@ -356,7 +356,7 @@ test('Exit with 1 if a shareable config reference a not found plugin', async t = }); await writeJson(path.resolve(cwd, 'shareable.json'), shareable); - const {code, stderr} = await t.throws(execa(cli, [], {env, cwd})); + const {code, stderr} = await t.throwsAsync(execa(cli, [], {env, cwd})); t.is(code, 1); t.regex(stderr, /Cannot find module/); }); diff --git a/test/plugins/normalize.test.js b/test/plugins/normalize.test.js index 8965af8923..9c5f212532 100644 --- a/test/plugins/normalize.test.js +++ b/test/plugins/normalize.test.js @@ -62,7 +62,7 @@ test('Wrap plugin in a function that add the "pluginName" to the error"', async './plugin-error': './test/fixtures', }); - const error = await t.throws(plugin({options: {}})); + const error = await t.throwsAsync(plugin({options: {}})); t.is(error.pluginName, './plugin-error'); }); @@ -72,7 +72,7 @@ test('Wrap plugin in a function that add the "pluginName" to multiple errors"', './plugin-errors': './test/fixtures', }); - const errors = [...(await t.throws(plugin({options: {}})))]; + const errors = [...(await t.throwsAsync(plugin({options: {}})))]; for (const error of errors) { t.is(error.pluginName, './plugin-errors'); } @@ -107,7 +107,7 @@ test('Wrap "analyzeCommits" plugin in a function that validate the output of the {} ); - const error = await t.throws(plugin({options: {}})); + const error = await t.throwsAsync(plugin({options: {}})); t.is(error.code, 'EANALYZECOMMITSOUTPUT'); t.is(error.name, 'SemanticReleaseError'); @@ -125,7 +125,7 @@ test('Wrap "generateNotes" plugin in a function that validate the output of the {} ); - const error = await t.throws(plugin({options: {}})); + const error = await t.throwsAsync(plugin({options: {}})); t.is(error.code, 'EGENERATENOTESOUTPUT'); t.is(error.name, 'SemanticReleaseError'); @@ -143,7 +143,7 @@ test('Wrap "publish" plugin in a function that validate the output of the plugin {} ); - const error = await t.throws(plugin({options: {}})); + const error = await t.throwsAsync(plugin({options: {}})); t.is(error.code, 'EPUBLISHOUTPUT'); t.is(error.name, 'SemanticReleaseError'); @@ -161,7 +161,7 @@ test('Wrap "addChannel" plugin in a function that validate the output of the plu {} ); - const error = await t.throws(plugin({options: {}})); + const error = await t.throwsAsync(plugin({options: {}})); t.is(error.code, 'EADDCHANNELOUTPUT'); t.is(error.name, 'SemanticReleaseError'); diff --git a/test/plugins/pipeline.test.js b/test/plugins/pipeline.test.js index 2a67394196..6c58129e30 100644 --- a/test/plugins/pipeline.test.js +++ b/test/plugins/pipeline.test.js @@ -83,7 +83,7 @@ test('Stop execution and throw error if a step rejects', async t => { const step2 = stub().rejects(new Error('test error')); const step3 = stub().resolves(3); - const error = await t.throws(pipeline([step1, step2, step3])(0), Error); + const error = await t.throwsAsync(pipeline([step1, step2, step3])(0), Error); t.is(error.message, 'test error'); t.true(step1.calledWith(0)); t.true(step2.calledWith(0)); @@ -98,7 +98,7 @@ test('Throw all errors from the first step throwing an AggregateError', async t const step2 = stub().rejects(new AggregateError([error1, error2])); const step3 = stub().resolves(3); - const errors = await t.throws(pipeline([step1, step2, step3])(0)); + const errors = await t.throwsAsync(pipeline([step1, step2, step3])(0)); t.deepEqual([...errors], [error1, error2]); t.true(step1.calledWith(0)); @@ -113,7 +113,7 @@ test('Execute all even if a Promise rejects', async t => { const step2 = stub().rejects(error1); const step3 = stub().rejects(error2); - const errors = await t.throws(pipeline([step1, step2, step3], {settleAll: true})(0)); + const errors = await t.throwsAsync(pipeline([step1, step2, step3], {settleAll: true})(0)); t.deepEqual([...errors], [error1, error2]); t.true(step1.calledWith(0)); @@ -129,7 +129,7 @@ test('Throw all errors from all steps throwing an AggregateError', async t => { const step1 = stub().rejects(new AggregateError([error1, error2])); const step2 = stub().rejects(new AggregateError([error3, error4])); - const errors = await t.throws(pipeline([step1, step2], {settleAll: true})(0)); + const errors = await t.throwsAsync(pipeline([step1, step2], {settleAll: true})(0)); t.deepEqual([...errors], [error1, error2, error3, error4]); t.true(step1.calledWith(0)); @@ -145,7 +145,7 @@ test('Execute each function in series passing a transformed input even if a step const step4 = stub().resolves(4); const getNextInput = (prevResult, result) => prevResult + result; - const errors = await t.throws(pipeline([step1, step2, step3, step4], {settleAll: true, getNextInput})(0)); + const errors = await t.throwsAsync(pipeline([step1, step2, step3, step4], {settleAll: true, getNextInput})(0)); t.deepEqual([...errors], [error2, error3]); t.true(step1.calledWith(0)); diff --git a/test/verify.test.js b/test/verify.test.js index dba1818b85..09d882850d 100644 --- a/test/verify.test.js +++ b/test/verify.test.js @@ -7,7 +7,7 @@ test('Throw a AggregateError', async t => { const {cwd} = await gitRepo(); const options = {branches: [{name: 'master'}, {name: ''}]}; - const errors = [...(await t.throws(verify({cwd, options})))]; + const errors = [...(await t.throwsAsync(verify({cwd, options})))]; t.is(errors[0].name, 'SemanticReleaseError'); t.is(errors[0].code, 'ENOREPOURL'); @@ -31,7 +31,7 @@ test('Throw a SemanticReleaseError if does not run on a git repository', async t const cwd = tempy.directory(); const options = {branches: []}; - const errors = [...(await t.throws(verify({cwd, options})))]; + const errors = [...(await t.throwsAsync(verify({cwd, options})))]; t.is(errors[0].name, 'SemanticReleaseError'); t.is(errors[0].code, 'ENOGITREPO'); @@ -43,7 +43,7 @@ test('Throw a SemanticReleaseError if the "tagFormat" is not valid', async t => const {cwd, repositoryUrl} = await gitRepo(true); const options = {repositoryUrl, tagFormat: `?\${version}`, branches: []}; - const errors = [...(await t.throws(verify({cwd, options})))]; + const errors = [...(await t.throwsAsync(verify({cwd, options})))]; t.is(errors[0].name, 'SemanticReleaseError'); t.is(errors[0].code, 'EINVALIDTAGFORMAT'); @@ -55,7 +55,7 @@ test('Throw a SemanticReleaseError if the "tagFormat" does not contains the "ver const {cwd, repositoryUrl} = await gitRepo(true); const options = {repositoryUrl, tagFormat: 'test', branches: []}; - const errors = [...(await t.throws(verify({cwd, options})))]; + const errors = [...(await t.throwsAsync(verify({cwd, options})))]; t.is(errors[0].name, 'SemanticReleaseError'); t.is(errors[0].code, 'ETAGNOVERSION'); @@ -67,7 +67,7 @@ test('Throw a SemanticReleaseError if the "tagFormat" contains multiple "version const {cwd, repositoryUrl} = await gitRepo(true); const options = {repositoryUrl, tagFormat: `\${version}v\${version}`, branches: []}; - const errors = [...(await t.throws(verify({cwd, options})))]; + const errors = [...(await t.throwsAsync(verify({cwd, options})))]; t.is(errors[0].name, 'SemanticReleaseError'); t.is(errors[0].code, 'ETAGNOVERSION'); @@ -83,7 +83,7 @@ test('Throw a SemanticReleaseError for each invalid branch', async t => { branches: [{name: ''}, {name: ' '}, {name: 1}, {}, {name: ''}, 1, 'master'], }; - const errors = [...(await t.throws(verify({cwd, options})))]; + const errors = [...(await t.throwsAsync(verify({cwd, options})))]; t.is(errors[0].name, 'SemanticReleaseError'); t.is(errors[0].code, 'EINVALIDBRANCH'); @@ -113,5 +113,5 @@ test('Return "true" if all verification pass', async t => { const {cwd, repositoryUrl} = await gitRepo(true); const options = {repositoryUrl, tagFormat: `v\${version}`, branches: [{name: 'master'}]}; - await t.notThrows(verify({cwd, options})); + await t.notThrowsAsync(verify({cwd, options})); }); From d55fda3306df2955448b92a9f4a352f22759f4b0 Mon Sep 17 00:00:00 2001 From: Pierre Vanduynslager Date: Thu, 27 Dec 2018 15:28:05 -0500 Subject: [PATCH 037/107] fix(pacjage): update `@semantic-release/github` and `@semantic-release/npm` --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 4c2a224256..8b1df87d02 100644 --- a/package.json +++ b/package.json @@ -21,8 +21,8 @@ "dependencies": { "@semantic-release/commit-analyzer": "^7.0.0-beta.1", "@semantic-release/error": "^2.2.0", - "@semantic-release/github": "^5.3.0-beta.5", - "@semantic-release/npm": "^5.2.0-beta.4", + "@semantic-release/github": "^5.3.0-beta.6", + "@semantic-release/npm": "^5.2.0-beta.5", "@semantic-release/release-notes-generator": "^7.1.2", "aggregate-error": "^2.0.0", "cosmiconfig": "^5.0.1", From 2144f2064f3603309ee91df00a33c7f5b4819898 Mon Sep 17 00:00:00 2001 From: Pierre Vanduynslager Date: Mon, 31 Dec 2018 03:19:18 -0500 Subject: [PATCH 038/107] docs: add missing recipes link in README --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 1899fa3b71..a50b090e58 100644 --- a/README.md +++ b/README.md @@ -113,6 +113,8 @@ After running the tests, the command `semantic-release` will execute the followi - [Shareable configuration](docs/extending/shareable-configurations-list.md) - Recipes - [CI configurations](docs/recipes/README.md) + - [Git hosted services](docs/recipes/README.md) + - [Release workflow](docs/recipes/README.md) - [Package managers and languages](docs/recipes/README.md) - Developer guide - [JavaScript API](docs/developer-guide/js-api.md) From 0d91027e9f4e655de95cb3b5b1f71b87f07308d8 Mon Sep 17 00:00:00 2001 From: Pierre Vanduynslager Date: Mon, 31 Dec 2018 03:20:13 -0500 Subject: [PATCH 039/107] docs: update release triggering section in README --- README.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index a50b090e58..c8aa2ec563 100644 --- a/README.md +++ b/README.md @@ -77,11 +77,12 @@ Here is an example of the release type that will be done based on a commit messa ### 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: -- 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. -- 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. +**semantic-release** offers various ways to control the timing, the content and the audience of published releases. See example workflows in the following recipes: +- [Using distribution channels](docs/recipes/distribution-channels.md#publishing-on-distribution-channels) +- [Maintenance releases](docs/recipes/maintenance-releases.md#publishing-maintenance-releases) +- [Pre-releases](docs/recipes/pre-releases.md#publishing-pre-releases) ### Release steps From 1d8c35d889acd12ad16fa20e6dfee075ae8b2101 Mon Sep 17 00:00:00 2001 From: Pierre Vanduynslager Date: Mon, 31 Dec 2018 03:20:36 -0500 Subject: [PATCH 040/107] docs: update FAQ regarding initial release version --- docs/support/FAQ.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/support/FAQ.md b/docs/support/FAQ.md index 74ea3135a5..7bbac18c3f 100644 --- a/docs/support/FAQ.md +++ b/docs/support/FAQ.md @@ -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. -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`. From 0457a074e7694ec95e4e8a24a27f15658a339489 Mon Sep 17 00:00:00 2001 From: Pierre Vanduynslager Date: Mon, 7 Jan 2019 17:28:08 -0500 Subject: [PATCH 041/107] fix: correctly determine next pre-release version --- lib/get-next-version.js | 7 ++++--- test/get-next-version.test.js | 30 ++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/lib/get-next-version.js b/lib/get-next-version.js index f4c4439e50..19b9e2991c 100644 --- a/lib/get-next-version.js +++ b/lib/get-next-version.js @@ -1,14 +1,15 @@ const semver = require('semver'); const {FIRST_RELEASE, FIRSTPRERELEASE} = require('./definitions/constants'); -module.exports = ({branch, nextRelease: {type}, lastRelease, logger}) => { +module.exports = ({branch, nextRelease: {type, channel}, lastRelease, logger}) => { let version; if (lastRelease.version) { + const {major, minor, patch} = semver.parse(lastRelease.version); version = branch.type === 'prerelease' - ? semver.prerelease(lastRelease.version) + ? semver.prerelease(lastRelease.version) && lastRelease.channel === channel ? semver.inc(lastRelease.version, 'prerelease') - : `${semver.inc(lastRelease.version, type)}-${branch.prerelease}.${FIRSTPRERELEASE}` + : `${semver.inc(`${major}.${minor}.${patch}`, type)}-${branch.prerelease}.${FIRSTPRERELEASE}` : semver.inc(lastRelease.version, type); logger.log('The next release version is %s', version); } else { diff --git a/test/get-next-version.test.js b/test/get-next-version.test.js index 476d5e9fbb..a3212a5fb1 100644 --- a/test/get-next-version.test.js +++ b/test/get-next-version.test.js @@ -76,6 +76,16 @@ test('Increase version for patch release on prerelease branch', t => { }), '1.0.0-beta.2' ); + + t.is( + getNextVersion({ + branch: {name: 'alpha', type: 'prerelease', prerelease: 'alpha'}, + nextRelease: {type: 'patch', channel: 'alpha'}, + lastRelease: {version: '1.0.0-beta.1', channel: 'beta'}, + logger: t.context.logger, + }), + '1.0.1-alpha.1' + ); }); test('Increase version for minor release on prerelease branch', t => { @@ -98,6 +108,16 @@ test('Increase version for minor release on prerelease branch', t => { }), '1.0.0-beta.2' ); + + t.is( + getNextVersion({ + branch: {name: 'alpha', type: 'prerelease', prerelease: 'alpha'}, + nextRelease: {type: 'minor', channel: 'alpha'}, + lastRelease: {version: '1.0.0-beta.1', channel: 'beta'}, + logger: t.context.logger, + }), + '1.1.0-alpha.1' + ); }); test('Increase version for major release on prerelease branch', t => { @@ -120,6 +140,16 @@ test('Increase version for major release on prerelease branch', t => { }), '1.0.0-beta.2' ); + + t.is( + getNextVersion({ + branch: {name: 'alpha', type: 'prerelease', prerelease: 'alpha'}, + nextRelease: {type: 'major', channel: 'alpha'}, + lastRelease: {version: '1.0.0-beta.1', channel: 'beta'}, + logger: t.context.logger, + }), + '2.0.0-alpha.1' + ); }); test('Return 1.0.0 if there is no previous release on prerelease branch', t => { From 990e85f069d35d87b78292119f37e27b6031b56c Mon Sep 17 00:00:00 2001 From: Pierre Vanduynslager Date: Mon, 14 Jan 2019 12:47:14 -0500 Subject: [PATCH 042/107] fix: ignore lasst release only if pre-release on the same channel as current branch --- lib/get-last-release.js | 6 +++--- test/get-last-release.test.js | 25 +++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/lib/get-last-release.js b/lib/get-last-release.js index 10557184fc..7ac63c3b89 100644 --- a/lib/get-last-release.js +++ b/lib/get-last-release.js @@ -23,9 +23,9 @@ const {makeTag} = require('./utils'); * * @return {LastRelease} The last tagged release or empty object if none is found. */ -module.exports = ({branch: {tags, type}, options: {tagFormat}}, {before} = {}) => { - const [{version, gitTag, gitHead, channel} = {}] = tags - .filter(tag => type === 'prerelease' || !semver.prerelease(tag.version)) +module.exports = ({branch, options: {tagFormat}}, {before} = {}) => { + const [{version, gitTag, gitHead, channel} = {}] = branch.tags + .filter(tag => (branch.type === 'prerelease' && branch.channel === tag.channel) || !semver.prerelease(tag.version)) .filter(tag => isUndefined(before) || semver.lt(tag.version, before)) .sort((a, b) => semver.rcompare(a.version, b.version)); diff --git a/test/get-last-release.test.js b/test/get-last-release.test.js index 08d54f4685..759739ab67 100644 --- a/test/get-last-release.test.js +++ b/test/get-last-release.test.js @@ -18,6 +18,31 @@ test('Get the highest non-prerelease valid tag', t => { t.deepEqual(result, {version: '2.0.0', gitTag: 'v2.0.0', name: 'v2.0.0', gitHead: '222', channel: undefined}); }); +test('Get the highest prerelease valid tag, ignoring other tags from other prerelease channels', t => { + const result = getLastRelease({ + branch: { + name: 'beta', + prerelease: 'beta', + channel: 'beta', + tags: [ + {version: '1.0.0-beta.1', gitTag: 'v1.0.0-beta.1@beta', gitHead: '111', channel: 'beta'}, + {version: '1.0.0-beta.2', gitTag: 'v1.0.0-beta.2@beta', gitHead: '222', channel: 'beta'}, + {version: '1.0.0-alpha.1', gitTag: 'v1.0.0-alpha.1@alpha', gitHead: '333', channel: 'alpha'}, + ], + type: 'prerelease', + }, + options: {tagFormat: `v\${version}`}, + }); + + t.deepEqual(result, { + version: '1.0.0-beta.2', + gitTag: 'v1.0.0-beta.2@beta', + name: 'v1.0.0-beta.2', + gitHead: '222', + channel: 'beta', + }); +}); + test('Return empty object if no valid tag is found', t => { const result = getLastRelease({ branch: { From d0891bf037c73e12af7e5f56a4235279abdbd1cf Mon Sep 17 00:00:00 2001 From: "greenkeeper[bot]" Date: Tue, 1 Jan 2019 00:51:39 +0000 Subject: [PATCH 043/107] fix(package): update marked to version 0.6.0 --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 8b1df87d02..c0594ae6b0 100644 --- a/package.json +++ b/package.json @@ -36,8 +36,8 @@ "hook-std": "^1.1.0", "hosted-git-info": "^2.7.1", "lodash": "^4.17.4", - "marked": "^0.5.0", - "marked-terminal": "^3.0.0", + "marked": "^0.6.0", + "marked-terminal": "^3.2.0", "micromatch": "3.1.5", "p-each-series": "^1.0.0", "p-reduce": "^1.0.0", From 7f90b7b69143b52eb08d19a82be40d9eed2bd3e4 Mon Sep 17 00:00:00 2001 From: David Aghassi <3680126+Aghassi@users.noreply.github.com> Date: Sat, 12 Jan 2019 09:46:20 -0800 Subject: [PATCH 044/107] docs: corrected typos in jsdocs --- lib/get-git-auth-url.js | 2 +- lib/plugins/pipeline.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/get-git-auth-url.js b/lib/get-git-auth-url.js index 421d19d1f5..6f130bcb0a 100644 --- a/lib/get-git-auth-url.js +++ b/lib/get-git-auth-url.js @@ -44,7 +44,7 @@ module.exports = async ({cwd, env, branch, options: {repositoryUrl}}) => { const gitCredentials = `${GIT_TOKENS[envVar] || ''}${env[envVar] || ''}`; if (gitCredentials) { - // If credentials are set via anvironment 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) || []; return format({ ...parse(match ? `ssh://${auth ? `${auth}@` : ''}${host}/${path}` : repositoryUrl), diff --git a/lib/plugins/pipeline.js b/lib/plugins/pipeline.js index 4ed7f0cf1f..d36c8608be 100644 --- a/lib/plugins/pipeline.js +++ b/lib/plugins/pipeline.js @@ -4,7 +4,7 @@ const AggregateError = require('aggregate-error'); const {extractErrors} = require('../utils'); /** - * A Function that execute a list of function sequencially. If at least one Function ins the pipeline throw an Error or rejects, the pipeline function rejects as well. + * A Function that execute a list of function sequencially. If at least one Function ins the pipeline throws an Error or rejects, the pipeline function rejects as well. * * @typedef {Function} Pipeline * @param {Any} input Argument to pass to the first step in the pipeline. From 2977462c5bf526202c4ab531efeba9aafb3f23a9 Mon Sep 17 00:00:00 2001 From: David Aghassi <3680126+Aghassi@users.noreply.github.com> Date: Sat, 12 Jan 2019 09:47:19 -0800 Subject: [PATCH 045/107] docs: cleaned up wording and typos in docs --- docs/support/FAQ.md | 2 +- docs/support/troubleshooting.md | 2 +- docs/usage/ci-configuration.md | 2 +- docs/usage/shareable-configurations.md | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/support/FAQ.md b/docs/support/FAQ.md index 7bbac18c3f..96deeaedb6 100644 --- a/docs/support/FAQ.md +++ b/docs/support/FAQ.md @@ -145,7 +145,7 @@ If you have introduced a breaking bug in a release you have 2 options: In both cases **semantic-release** will publish a new release, so your package users' will get the fixed/reverted version. -Depending on the package manager you are using, you might be able to un-publish or deprecate a release, in order to prevent users to download it by accident. For example npm allows you to [un-publish](https://docs.npmjs.com/cli/unpublish) in [next 72 hours](https://www.npmjs.com/policies/unpublish) after releasing or to [deprecate](https://docs.npmjs.com/cli/deprecate) a release. +Depending on the package manager you are using, you might be able to un-publish or deprecate a release, in order to prevent users from downloading it by accident. For example npm allows you to [un-publish](https://docs.npmjs.com/cli/unpublish) [within 72 hours](https://www.npmjs.com/policies/unpublish) after releasing. You may also [deprecate](https://docs.npmjs.com/cli/deprecate) a release if you would rather avoid un-publishing. In any case **do not remove the Git tag associated with the buggy version**, otherwise **semantic-release** will later try to republish that version. Publishing a version after un-publishing is not supported by most package managers. diff --git a/docs/support/troubleshooting.md b/docs/support/troubleshooting.md index d6e7a9de9e..75e7aafa9a 100644 --- a/docs/support/troubleshooting.md +++ b/docs/support/troubleshooting.md @@ -12,7 +12,7 @@ npm ERR! You do not have permission to publish "". Are you logged This is most likely related to a misconfiguration of the [npm registry authentication](https://github.com/semantic-release/npm#npm-registry-authentication) or to your user [missing permission](https://docs.npmjs.com/cli/team) for publishing. -It might also happen if the package name you are trying to publish already exists (in such case npm consider you are trying to publish a new version of a package that is not yours, hence the permission error). +It might also happen if the package name you are trying to publish already exists (in the case of npm, you may be trying to publish a new version of a package that is not yours, hence the permission error). To verify if your package name is available you can use [npm-name-cli](https://github.com/sindresorhus/npm-name-cli): ```bash diff --git a/docs/usage/ci-configuration.md b/docs/usage/ci-configuration.md index 940d8f6d0c..ef2c72927e 100644 --- a/docs/usage/ci-configuration.md +++ b/docs/usage/ci-configuration.md @@ -26,7 +26,7 @@ Most **semantic-release** [plugins](plugins.md) require setting up authenticatio | `NPM_TOKEN` | npm token created via [npm token create](https://docs.npmjs.com/getting-started/working_with_tokens#how-to-create-new-tokens).
**Note**: Only the `auth-only` [level of npm two-factor authentication](https://docs.npmjs.com/getting-started/using-two-factor-authentication#levels-of-authentication) is supported. | | `GH_TOKEN` | GitHub authentication token.
**Note**: Only the [personal token](https://help.github.com/articles/creating-a-personal-access-token-for-the-command-line) authentication is supported. | -See each plugin documentation for the environment variables to set up. +See each plugin's documentation for the environment variables required. The authentication token/credentials have to be made available in the CI service via environment variables. diff --git a/docs/usage/shareable-configurations.md b/docs/usage/shareable-configurations.md index 18e7e3e5a1..bfaf3bab08 100644 --- a/docs/usage/shareable-configurations.md +++ b/docs/usage/shareable-configurations.md @@ -1,6 +1,6 @@ # Shareable configurations -A sharable configuration is an [npm](https://www.npmjs.com/) package that exports a **semantic-release** configuration object. It allows for use of the same configuration across several projects. +A shareable configuration is an [npm](https://www.npmjs.com/) package that exports a **semantic-release** configuration object. It allows for use of the same configuration across several projects. The shareable configurations to use can be set with the [extends](configuration.md#extends) option. From d7299395d556d336e442fdc7be161c136ef5c814 Mon Sep 17 00:00:00 2001 From: Austin Cawley-Edwards Date: Tue, 22 Jan 2019 11:32:41 -0500 Subject: [PATCH 046/107] docs: fix typo in CircleCI recipe --- docs/recipes/git-auth-ssh-keys.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/recipes/git-auth-ssh-keys.md b/docs/recipes/git-auth-ssh-keys.md index 15337a07fc..9bd27d6109 100644 --- a/docs/recipes/git-auth-ssh-keys.md +++ b/docs/recipes/git-auth-ssh-keys.md @@ -158,6 +158,6 @@ Commit the encrypted private key and the `.circleci/config.yml` file to your rep ```bash $ git add git_deploy_key.enc .circleci/config.yml -$ git commit -m "ci(cicle): Add the encrypted private ssh key" +$ git commit -m "ci(circle): Add the encrypted private ssh key" $ git push ``` From 9d310c958ba49a8bfd52e6b7498c90abede4e8d5 Mon Sep 17 00:00:00 2001 From: Kevin Lluch Date: Tue, 29 Jan 2019 22:15:23 +0100 Subject: [PATCH 047/107] docs: add semantic-release-ado to community plugins --- docs/extending/plugins-list.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/extending/plugins-list.md b/docs/extending/plugins-list.md index 838f12f9a0..e91ee1bbe1 100644 --- a/docs/extending/plugins-list.md +++ b/docs/extending/plugins-list.md @@ -71,3 +71,5 @@ - `verifyRelease`: Checks and warns (does not error by default) if the version numbers found on maven central and within the Git project differ by quite a bit - `prepare`: Changes the version number in the `pom.xml` (or all `pom.xml` files in maven projects with multiple `pom.xml` files) and optionally creates a commit with this version number and pushes it to `master` - `publish`: Runs `mvn deploy` to deploy to maven central and optionally will update to next snapshot version and merge changes to development branch +- [semantic-release-ado](https://github.com/lluchmk/semantic-release-ado) + - `prepare`: Stores the version number as an Azure DevOps pipeline variable availabe to downstream steps on the job \ No newline at end of file From d10268a8fa6a76967ea07ea2473dee32fd953cfb Mon Sep 17 00:00:00 2001 From: "greenkeeper[bot]" Date: Mon, 14 Jan 2019 06:16:30 +0000 Subject: [PATCH 048/107] chore(package): update xo to version 0.24.0 --- bin/semantic-release.js | 2 +- cli.js | 4 +++- index.js | 2 ++ lib/branches/normalize.js | 2 ++ lib/definitions/errors.js | 7 +++---- lib/definitions/plugins.js | 1 + lib/get-config.js | 1 + lib/get-git-auth-url.js | 2 +- lib/git.js | 1 + lib/plugins/index.js | 2 ++ lib/plugins/normalize.js | 2 ++ lib/plugins/pipeline.js | 2 ++ lib/plugins/utils.js | 3 +++ lib/utils.js | 1 + package.json | 2 +- 15 files changed, 26 insertions(+), 8 deletions(-) diff --git a/bin/semantic-release.js b/bin/semantic-release.js index cbd697e96e..407475dac3 100755 --- a/bin/semantic-release.js +++ b/bin/semantic-release.js @@ -3,7 +3,7 @@ // Bad news: We have to write plain ES5 in this file // Good news: It's the only file of the entire project -/* eslint-disable no-var, promise/prefer-await-to-then, prefer-destructuring */ +/* eslint-disable no-var */ var semver = require('semver'); var execa = require('execa'); diff --git a/cli.js b/cli.js index 39549a2808..58c14bc4d1 100755 --- a/cli.js +++ b/cli.js @@ -1,4 +1,4 @@ -const {argv, env, stderr} = require('process'); +const {argv, env, stderr} = require('process'); // eslint-disable-line node/prefer-global/process const util = require('util'); const hideSensitive = require('./lib/hide-sensitive'); @@ -51,12 +51,14 @@ Usage: // Debug must be enabled before other requires in order to work require('debug').enable('semantic-release:*'); } + await require('.')(opts); return 0; } catch (error) { if (error.name !== 'YError') { stderr.write(hideSensitive(env)(util.inspect(error, {colors: true}))); } + return 1; } }; diff --git a/index.js b/index.js index 9303f01ca2..309741539c 100644 --- a/index.js +++ b/index.js @@ -64,6 +64,7 @@ async function run(context, plugins) { ); return false; } + logger[options.dryRun ? 'warn' : 'success']( `Run automated release from branch ${ciBranch}${options.dryRun ? ' in dry-run mode' : ''}` ); @@ -82,6 +83,7 @@ async function run(context, plugins) { ); return false; } + throw error; } } catch (error) { diff --git a/lib/branches/normalize.js b/lib/branches/normalize.js index 54c1722cfb..4e3e9b01f0 100644 --- a/lib/branches/normalize.js +++ b/lib/branches/normalize.js @@ -60,6 +60,7 @@ function release({release}) { if (release.length === 0) { return release; } + const breakpoints = release.length > 2 ? ['minor', 'major'] : ['major']; // The intial bound is the last release from the base branch of `FIRST_RELEASE` (1.0.0) @@ -80,6 +81,7 @@ function release({release}) { // The upper bound is the lowest version between `nextFirstVersion` and the default upper bound bound = lowest(nextFirstVersion, upperBound); } + const diff = bound ? semverDiff(min, bound) : null; return { ...rest, diff --git a/lib/definitions/errors.js b/lib/definitions/errors.js index 4d0b6bcdc4..6f04eb7244 100644 --- a/lib/definitions/errors.js +++ b/lib/definitions/errors.js @@ -1,10 +1,9 @@ -const url = require('url'); const {inspect} = require('util'); const {toLower, isString, trim} = require('lodash'); const pkg = require('../../package.json'); const {RELEASE_TYPE} = require('./constants'); -const homepage = url.format({...url.parse(pkg.homepage), hash: null}); +const [homepage] = pkg.homepage.split('#'); const stringify = obj => (isString(obj) ? obj : inspect(obj, {breakLength: Infinity, depth: 2, maxArrayLength: 5})); const linkify = file => `${homepage}/blob/master/${file}`; const wordsList = words => @@ -211,8 +210,8 @@ The following commit${commits.length > 1 ? 's are' : ' is'} responsible for the ${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). + 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}\``))}. diff --git a/lib/definitions/plugins.js b/lib/definitions/plugins.js index 69651eb20f..d77c230f1d 100644 --- a/lib/definitions/plugins.js +++ b/lib/definitions/plugins.js @@ -59,6 +59,7 @@ module.exports = { // Regenerate the release notes context.nextRelease.notes = await generateNotes(context); } + // Call the next prepare plugin with the updated `nextRelease` return context; }, diff --git a/lib/get-config.js b/lib/get-config.js index 3b1864b630..e4812088a0 100644 --- a/lib/get-config.js +++ b/lib/get-config.js @@ -30,6 +30,7 @@ module.exports = async (context, opts) => { if (options.ci === false) { options.noCi = true; } + const pluginsPath = {}; let extendPaths; ({extends: extendPaths, ...options} = options); diff --git a/lib/get-git-auth-url.js b/lib/get-git-auth-url.js index 6f130bcb0a..5206db0203 100644 --- a/lib/get-git-auth-url.js +++ b/lib/get-git-auth-url.js @@ -1,4 +1,4 @@ -const {parse, format} = require('url'); +const {parse, format} = require('url'); // eslint-disable-line node/no-deprecated-api const {isNil} = require('lodash'); const hostedGitInfo = require('hosted-git-info'); const {verifyAuth} = require('./git'); diff --git a/lib/git.js b/lib/git.js index c50308758f..896a5daf76 100644 --- a/lib/git.js +++ b/lib/git.js @@ -99,6 +99,7 @@ async function isRefInHistory(ref, branch, findRebasedTags, execaOpts) { ); return (await getBranchCommits(branch, execaOpts)).some(matches(pick(tagCommit, ['message', 'author']))); } + return false; } diff --git a/lib/plugins/index.js b/lib/plugins/index.js index abbc754cfe..51b080d10a 100644 --- a/lib/plugins/index.js +++ b/lib/plugins/index.js @@ -57,10 +57,12 @@ module.exports = (context, pluginsPath) => { plugin ? [plugin[0], Object.assign(plugin[1], options[type])] : plugin ); } + if (!validateStep({required}, options[type])) { errors.push(getError('EPLUGINCONF', {type, required, pluginConf: options[type]})); return pluginsConf; } + pluginOpts = options[type]; } diff --git a/lib/plugins/normalize.js b/lib/plugins/normalize.js index 56af5b68f0..b35f337056 100644 --- a/lib/plugins/normalize.js +++ b/lib/plugins/normalize.js @@ -40,9 +40,11 @@ module.exports = (context, type, pluginOpt, pluginsPath) => { if (outputValidator && !outputValidator(result)) { throw getError(`E${type.toUpperCase()}OUTPUT`, {result, pluginName}); } + logger.success(`Completed step "${type}" of plugin "${pluginName}"`); return result; } + logger.warn(`Skip step "${type}" of plugin "${pluginName}" in dry-run mode`); } catch (error) { logger.error(`Failed step "${type}" of plugin "${pluginName}"`); diff --git a/lib/plugins/pipeline.js b/lib/plugins/pipeline.js index d36c8608be..b12f264ec6 100644 --- a/lib/plugins/pipeline.js +++ b/lib/plugins/pipeline.js @@ -44,6 +44,7 @@ module.exports = (steps, {settleAll = false, getNextInput = identity, transform throw error; } } + // Prepare input for the next step, passing the input of the last iteration (or initial parameter for the first iteration) and the result of the current one return getNextInput(lastInput, result); }, @@ -52,5 +53,6 @@ module.exports = (steps, {settleAll = false, getNextInput = identity, transform if (errors.length > 0) { throw new AggregateError(errors); } + return results; }; diff --git a/lib/plugins/utils.js b/lib/plugins/utils.js index 2a213400ad..e0cf759f25 100644 --- a/lib/plugins/utils.js +++ b/lib/plugins/utils.js @@ -12,6 +12,7 @@ const validateSteps = conf => { ) { return true; } + conf = castArray(conf); if (conf.length !== 1) { @@ -39,6 +40,7 @@ function validateStep({required}, conf) { if (required) { return conf.length >= 1 && validateSteps(conf); } + return conf.length === 0 || validateSteps(conf); } @@ -59,6 +61,7 @@ function parseConfig(plugin) { } else { path = plugin; } + return [path, config || {}]; } diff --git a/lib/utils.js b/lib/utils.js index f2ca198c1b..9497026bdd 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -59,6 +59,7 @@ function getFirstVersion(versions, lowerBranches) { if (lowerVersion[0]) { return versions.sort(semver.compare).find(version => semver.gt(version, lowerVersion[0])); } + return getEarliestVersion(versions); } diff --git a/package.json b/package.json index c0594ae6b0..65d45f5955 100644 --- a/package.json +++ b/package.json @@ -68,7 +68,7 @@ "sinon": "^7.1.1", "stream-buffers": "^3.0.2", "tempy": "^0.2.1", - "xo": "^0.23.0" + "xo": "^0.24.0" }, "engines": { "node": ">=8.3" From a0229962ceac2c9eb05499373c153c7b3dced382 Mon Sep 17 00:00:00 2001 From: Pierre Vanduynslager Date: Wed, 8 May 2019 16:11:37 -0400 Subject: [PATCH 049/107] fix: fix maintenance branch regex --- docs/developer-guide/js-api.md | 2 +- docs/recipes/distribution-channels.md | 2 +- docs/recipes/maintenance-releases.md | 2 +- docs/recipes/pre-releases.md | 2 +- docs/usage/configuration.md | 2 +- docs/usage/workflow-configuration.md | 2 +- lib/get-config.js | 2 +- test/branches/expand.test.js | 8 ++++---- test/get-config.test.js | 6 +++--- 9 files changed, 14 insertions(+), 14 deletions(-) diff --git a/docs/developer-guide/js-api.md b/docs/developer-guide/js-api.md index cbce75127f..4d08625eab 100644 --- a/docs/developer-guide/js-api.md +++ b/docs/developer-guide/js-api.md @@ -13,7 +13,7 @@ try { const result = await semanticRelease({ // Core options branches: [ - '+([1-9])?(.{+([1-9]),x}).x', + '+([0-9])?(.{+([0-9]),x}).x', 'master', 'next', 'next-major', diff --git a/docs/recipes/distribution-channels.md b/docs/recipes/distribution-channels.md index 0d9abafa27..db55e68001 100644 --- a/docs/recipes/distribution-channels.md +++ b/docs/recipes/distribution-channels.md @@ -3,7 +3,7 @@ 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): `['+([1-9])?(.{+([1-9]),x}).x', 'master', 'next', 'next-major', {name: 'beta', prerelease: true}, {name: 'alpha', prerelease: true}]` +- [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 diff --git a/docs/recipes/maintenance-releases.md b/docs/recipes/maintenance-releases.md index 0eb93ee2d7..01d46fb0e7 100644 --- a/docs/recipes/maintenance-releases.md +++ b/docs/recipes/maintenance-releases.md @@ -3,7 +3,7 @@ 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): `['+([1-9])?(.{+([1-9]),x}).x', 'master', 'next', 'next-major', {name: 'beta', prerelease: true}, {name: 'alpha', prerelease: true}]` +- [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 diff --git a/docs/recipes/pre-releases.md b/docs/recipes/pre-releases.md index 1f7891858b..7bfb1ff4cb 100644 --- a/docs/recipes/pre-releases.md +++ b/docs/recipes/pre-releases.md @@ -3,7 +3,7 @@ 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): `['+([1-9])?(.{+([1-9]),x}).x', 'master', 'next', 'next-major', {name: 'beta', prerelease: true}, {name: 'alpha', prerelease: true}]` +- [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 diff --git a/docs/usage/configuration.md b/docs/usage/configuration.md index 0c67e698eb..235c7aaf91 100644 --- a/docs/usage/configuration.md +++ b/docs/usage/configuration.md @@ -70,7 +70,7 @@ List of modules or file paths containing a [shareable configuration](shareable-c ### branches Type: `Array`, `String`, `Object`
-Default: `['+([1-9])?(.{+([1-9]),x}).x', 'master', 'next', 'next-major', {name: 'beta', prerelease: true}, {name: 'alpha', prerelease: true}]`
+Default: `['+([0-9])?(.{+([0-9]),x}).x', 'master', 'next', 'next-major', {name: 'beta', prerelease: true}, {name: 'alpha', prerelease: true}]`
CLI arguments: `--branches` The branches on which releases should happen. By default **semantic-release** will release: diff --git a/docs/usage/workflow-configuration.md b/docs/usage/workflow-configuration.md index eef0a826f9..aee88c614f 100644 --- a/docs/usage/workflow-configuration.md +++ b/docs/usage/workflow-configuration.md @@ -34,7 +34,7 @@ It can be defined as a [glob](https://github.com/micromatch/micromatch#matching- 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 `['+([1-9])?(.{+([1-9]),x}).x', 'master', 'next']` will be expanded as: +For example the configuration `['+([0-9])?(.{+([0-9]),x}).x', 'master', 'next']` will be expanded as: ```js { branches: [ diff --git a/lib/get-config.js b/lib/get-config.js index e4812088a0..ba0a8f25f3 100644 --- a/lib/get-config.js +++ b/lib/get-config.js @@ -67,7 +67,7 @@ module.exports = async (context, opts) => { // Set default options values if not defined yet options = { branches: [ - '+([1-9])?(.{+([1-9]),x}).x', + '+([0-9])?(.{+([0-9]),x}).x', 'master', 'next', 'next-major', diff --git a/test/branches/expand.test.js b/test/branches/expand.test.js index 889ac6ed77..285aaac061 100644 --- a/test/branches/expand.test.js +++ b/test/branches/expand.test.js @@ -6,9 +6,9 @@ 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.1.x', true, {cwd}); + await gitCheckout('1.0.x', true, {cwd}); await gitCommits(['Second'], {cwd}); - await gitPush(repositoryUrl, '1.1.x', {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}); @@ -30,7 +30,7 @@ test('Expand branches defined with globs', async t => { const branches = [ // Should match all maintenance type branches - {name: '+([1-9])?(.{+([1-9]),x}).x'}, + {name: '+([0-9])?(.{+([0-9]),x}).x'}, {name: 'master', channel: 'latest'}, {name: 'next'}, {name: 'pre/{foo,bar}', channel: `\${name.replace(/^pre\\//g, '')}`, prerelease: true}, @@ -42,7 +42,7 @@ test('Expand branches defined with globs', async t => { ]; t.deepEqual(await expand({cwd}, branches), [ - {name: '1.1.x'}, + {name: '1.0.x'}, {name: '1.x.x'}, {name: '2.x'}, {name: 'master', channel: 'latest'}, diff --git a/test/get-config.test.js b/test/get-config.test.js index 32866464d1..c243c91bcb 100644 --- a/test/get-config.test.js +++ b/test/get-config.test.js @@ -36,7 +36,7 @@ test('Default values, reading repositoryUrl from package.json', async t => { // Verify the default options are set t.deepEqual(result.branches, [ - '+([1-9])?(.{+([1-9]),x}).x', + '+([0-9])?(.{+([0-9]),x}).x', 'master', 'next', 'next-major', @@ -57,7 +57,7 @@ test('Default values, reading repositoryUrl from repo if not set in package.json // Verify the default options are set t.deepEqual(result.branches, [ - '+([1-9])?(.{+([1-9]),x}).x', + '+([0-9])?(.{+([0-9]),x}).x', 'master', 'next', 'next-major', @@ -79,7 +79,7 @@ test('Default values, reading repositoryUrl (http url) from package.json if not // Verify the default options are set t.deepEqual(result.branches, [ - '+([1-9])?(.{+([1-9]),x}).x', + '+([0-9])?(.{+([0-9]),x}).x', 'master', 'next', 'next-major', From b60fef83cb19f5432f8d79185b7c929930cdc27a Mon Sep 17 00:00:00 2001 From: Pierre Vanduynslager Date: Thu, 9 May 2019 10:23:40 -0400 Subject: [PATCH 050/107] chore(package): update @semantic-release/github to version 5.4.0-beta.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 65d45f5955..841e763dd7 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ "dependencies": { "@semantic-release/commit-analyzer": "^7.0.0-beta.1", "@semantic-release/error": "^2.2.0", - "@semantic-release/github": "^5.3.0-beta.6", + "@semantic-release/github": "^5.4.0-beta.1", "@semantic-release/npm": "^5.2.0-beta.5", "@semantic-release/release-notes-generator": "^7.1.2", "aggregate-error": "^2.0.0", From 8576f49e54bd0e72f60a7bba7026dc00f6eba84f Mon Sep 17 00:00:00 2001 From: Pierre Vanduynslager Date: Thu, 9 May 2019 10:24:29 -0400 Subject: [PATCH 051/107] test: update test to new sinon version --- test/index.test.js | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/test/index.test.js b/test/index.test.js index e00bc7f611..3144446198 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -131,9 +131,9 @@ test('Plugins are called with expected values', async t => { channel: undefined, gitTag: 'v1.0.0', notes: `${notes1}\n\n${notes2}\n\n${notes3}`, - pluginName: '[Function: proxy]', + pluginName: '[Function: functionStub]', }, - {...nextRelease, ...release2, notes: `${notes1}\n\n${notes2}\n\n${notes3}`, pluginName: '[Function: proxy]'}, + {...nextRelease, ...release2, notes: `${notes1}\n\n${notes2}\n\n${notes3}`, pluginName: '[Function: functionStub]'}, {...nextRelease, notes: `${notes1}\n\n${notes2}\n\n${notes3}`, pluginName: pluginNoop}, ]; @@ -694,10 +694,10 @@ async function addChannelMacro(t, mergeFunction) { const result = await semanticRelease(options, {cwd, env: {}, stdout: {write: () => {}}, stderr: {write: () => {}}}); t.deepEqual(result.releases, [ - {...nextRelease1, ...release1, notes, pluginName: '[Function: proxy]'}, - {...nextRelease1, notes, pluginName: '[Function: proxy]'}, - {...nextRelease2, ...release1, notes, pluginName: '[Function: proxy]'}, - {...nextRelease2, notes, pluginName: '[Function: proxy]'}, + {...nextRelease1, ...release1, notes, pluginName: '[Function: functionStub]'}, + {...nextRelease1, notes, pluginName: '[Function: functionStub]'}, + {...nextRelease2, ...release1, notes, pluginName: '[Function: functionStub]'}, + {...nextRelease2, notes, pluginName: '[Function: functionStub]'}, ]); // Verify the tag has been created on the local and remote repo and reference @@ -769,10 +769,14 @@ test('Call all "success" plugins even if one errors out', async t => { t.is(success1.callCount, 1); t.deepEqual(success1.args[0][0], config); - t.deepEqual(success1.args[0][1].releases, [{...nextRelease, ...release, notes, pluginName: '[Function: proxy]'}]); + t.deepEqual(success1.args[0][1].releases, [ + {...nextRelease, ...release, notes, pluginName: '[Function: functionStub]'}, + ]); t.is(success2.callCount, 1); - t.deepEqual(success2.args[0][1].releases, [{...nextRelease, ...release, notes, pluginName: '[Function: proxy]'}]); + t.deepEqual(success2.args[0][1].releases, [ + {...nextRelease, ...release, notes, pluginName: '[Function: functionStub]'}, + ]); }); test('Log all "verifyConditions" errors', async t => { @@ -1202,8 +1206,8 @@ test('Accept "undefined" value returned by "generateNotes" and "false" by "publi t.is(publish.callCount, 1); t.is(success.callCount, 2); t.deepEqual(publish.args[0][1].nextRelease, {...nextRelease, notes: notes2}); - t.deepEqual(success.args[0][1].releases, [{pluginName: '[Function: proxy]'}]); - t.deepEqual(success.args[1][1].releases, [{pluginName: '[Function: proxy]'}]); + t.deepEqual(success.args[0][1].releases, [{pluginName: '[Function: functionStub]'}]); + t.deepEqual(success.args[1][1].releases, [{pluginName: '[Function: functionStub]'}]); }); test('Returns false if triggered by a PR', async t => { @@ -1399,7 +1403,7 @@ test('Throws "EINVALIDMAINTENANCEMERGE" if merge an out of range release in a ma t.is(publish.callCount, 0); t.is(success.callCount, 1); - t.deepEqual(success.args[0][1].releases, [{...nextRelease, notes, pluginName: '[Function: proxy]'}]); + t.deepEqual(success.args[0][1].releases, [{...nextRelease, notes, pluginName: '[Function: functionStub]'}]); t.is(fail.callCount, 1); t.deepEqual(fail.args[0][1].errors, errors); From 37bcc9e51536bccdfe47c6cbf911234a65b32787 Mon Sep 17 00:00:00 2001 From: Ryan Kennedy Date: Thu, 23 May 2019 15:21:17 -0400 Subject: [PATCH 052/107] fix: Add helpful detail to `ERELEASEBRANCHES` error message (#1188) --- docs/usage/configuration.md | 2 ++ lib/definitions/errors.js | 2 ++ 2 files changed, 4 insertions(+) diff --git a/docs/usage/configuration.md b/docs/usage/configuration.md index 235c7aaf91..feb7cd3699 100644 --- a/docs/usage/configuration.md +++ b/docs/usage/configuration.md @@ -81,6 +81,8 @@ The branches on which releases should happen. By default **semantic-release** wi - 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 [Plugins configuration](plugins.md#plugins) for more details. diff --git a/lib/definitions/errors.js b/lib/definitions/errors.js index 6f04eb7244..c99ee91c1a 100644 --- a/lib/definitions/errors.js +++ b/lib/definitions/errors.js @@ -183,6 +183,8 @@ Your configuration for the problematic branches is \`${stringify(branches)}\`.`, 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)}\`.`, }), From 36104229593c167e9086bc5fd8a533117ee3b579 Mon Sep 17 00:00:00 2001 From: jmodjeski75 <13580368+jmodjeski75@users.noreply.github.com> Date: Wed, 5 Jun 2019 13:33:54 -0500 Subject: [PATCH 053/107] fix(repositoryUrl): on beta repositoryUrl needs auth for pre-release flows (#1186) --- index.js | 7 +++---- lib/branches/expand.js | 4 ++-- lib/branches/index.js | 5 +++-- lib/git.js | 21 +++++++++++++------- test/branches/branches.test.js | 36 +++++++++++++++++----------------- test/branches/expand.test.js | 2 +- test/git.test.js | 18 ++++++++--------- test/index.test.js | 2 +- 8 files changed, 51 insertions(+), 44 deletions(-) diff --git a/index.js b/index.js index 309741539c..9bad0aca62 100644 --- a/index.js +++ b/index.js @@ -53,7 +53,8 @@ async function run(context, plugins) { // Verify config await verify(context); - context.branches = await getBranches(context); + options.repositoryUrl = await getGitAuthUrl(context); + context.branches = await getBranches(options.repositoryUrl, context); context.branch = context.branches.find(({name}) => name === ciBranch); if (!context.branch) { @@ -69,13 +70,11 @@ async function run(context, plugins) { `Run automated release from branch ${ciBranch}${options.dryRun ? ' in dry-run mode' : ''}` ); - options.repositoryUrl = await getGitAuthUrl(context); - try { try { await verifyAuth(options.repositoryUrl, context.branch.name, {cwd, env}); } catch (error) { - if (!(await isBranchUpToDate(context.branch.name, {cwd, env}))) { + if (!(await isBranchUpToDate(options.repositoryUrl, context.branch.name, {cwd, env}))) { logger.log( `The local branch ${ context.branch.name diff --git a/lib/branches/expand.js b/lib/branches/expand.js index c40632acb2..bf0d1da12a 100644 --- a/lib/branches/expand.js +++ b/lib/branches/expand.js @@ -2,8 +2,8 @@ const {isString, remove, omit, mapValues, template} = require('lodash'); const micromatch = require('micromatch'); const {getBranches} = require('../git'); -module.exports = async ({cwd}, branches) => { - const gitBranches = await getBranches({cwd}); +module.exports = async (repositoryUrl, {cwd}, branches) => { + const gitBranches = await getBranches(repositoryUrl, {cwd}); return branches.reduce( (branches, branch) => [ diff --git a/lib/branches/index.js b/lib/branches/index.js index 8f586f692b..044289e821 100644 --- a/lib/branches/index.js +++ b/lib/branches/index.js @@ -8,16 +8,17 @@ const expand = require('./expand'); const getTags = require('./get-tags'); const normalize = require('./normalize'); -module.exports = async context => { +module.exports = async (repositoryUrl, 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(name, {cwd, env}); + await fetch(repositoryUrl, name, {cwd, env}); }); const branches = await getTags(context, remoteBranches); diff --git a/lib/git.js b/lib/git.js index 896a5daf76..905f953fca 100644 --- a/lib/git.js +++ b/lib/git.js @@ -57,13 +57,14 @@ async function getCommits(from, to, execaOpts) { /** * Get all the repository branches. * + * @param {String} repositoryUrl The remote repository URL. * @param {Object} [execaOpts] Options to pass to `execa`. * * @return {Array} List of git branches. * @throws {Error} If the `git` command fails. */ -async function getBranches(execaOpts) { - return (await execa.stdout('git', ['ls-remote', '--heads', 'origin'], execaOpts)) +async function getBranches(repositoryUrl, execaOpts) { + return (await execa.stdout('git', ['ls-remote', '--heads', repositoryUrl], execaOpts)) .split('\n') .map(branch => branch.match(/^.+refs\/heads\/(.+)$/)[1]) .filter(Boolean); @@ -127,10 +128,11 @@ async function isRefExists(ref, execaOpts) { /** * Unshallow the git repository if necessary and fetch all the tags. * + * @param {String} repositoryUrl The remote repository URL. * @param {String} branch The repository branch to fetch. * @param {Object} [execaOpts] Options to pass to `execa`. */ -async function fetch(branch, execaOpts) { +async function fetch(repositoryUrl, branch, execaOpts) { const isLocalExists = (await execa('git', ['rev-parse', '--verify', branch], {...execaOpts, reject: false})).code === 0; @@ -141,14 +143,18 @@ async function fetch(branch, execaOpts) { 'fetch', '--unshallow', '--tags', - ...(isLocalExists ? [] : ['origin', `+refs/heads/${branch}:refs/heads/${branch}`]), + ...(isLocalExists ? [repositoryUrl] : [repositoryUrl, `+refs/heads/${branch}:refs/remotes/upstream/${branch}`]), ], execaOpts ); } catch (error) { await execa( 'git', - ['fetch', '--tags', ...(isLocalExists ? [] : ['origin', `+refs/heads/${branch}:refs/heads/${branch}`])], + [ + 'fetch', + '--tags', + ...(isLocalExists ? [repositoryUrl] : [repositoryUrl, `+refs/heads/${branch}:refs/remotes/upstream/${branch}`]), + ], execaOpts ); } @@ -273,13 +279,14 @@ async function verifyBranchName(branch, execaOpts) { /** * Verify the local branch is up to date with the remote one. * + * @param {String} repositoryUrl The remote repository URL. * @param {String} branch The repository branch for which to verify status. * @param {Object} [execaOpts] Options to pass to `execa`. * * @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(branch, execaOpts) { - const remoteHead = await execa.stdout('git', ['ls-remote', '--heads', 'origin', branch], execaOpts); +async function isBranchUpToDate(repositoryUrl, branch, execaOpts) { + const remoteHead = await execa.stdout('git', ['ls-remote', '--heads', repositoryUrl, branch], execaOpts); try { return await isRefInHistory(remoteHead.match(/^(\w+)?/)[1], branch, false, execaOpts); } catch (error) { diff --git a/test/branches/branches.test.js b/test/branches/branches.test.js index 0bddf703d3..339099ef91 100644 --- a/test/branches/branches.test.js +++ b/test/branches/branches.test.js @@ -24,7 +24,7 @@ test('Enforce ranges with branching release workflow', async t => { ]; const getBranches = proxyquire('../../lib/branches', {'./get-tags': () => branches, './expand': () => []}); - let result = (await getBranches({options: {branches}})).map(({name, range}) => ({name, range})); + let result = (await getBranches('repositoryUrl', {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 <1.1.0', 'Can release only patch on master'); @@ -32,43 +32,43 @@ test('Enforce ranges with branching release workflow', async t => { t.is(getBranch(result, 'next-major').range, '>=2.0.0', 'Can release only major on next-major'); release(branches, 'master', '1.0.0'); - result = (await getBranches({options: {branches}})).map(({name, range}) => ({name, range})); + result = (await getBranches('repositoryUrl', {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 <1.1.0', 'Can release only patch on master'); release(branches, 'master', '1.0.1'); - result = (await getBranches({options: {branches}})).map(({name, range}) => ({name, range})); + result = (await getBranches('repositoryUrl', {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'); merge(branches, 'master', 'next'); merge(branches, 'master', 'next-major'); - result = (await getBranches({options: {branches}})).map(({name, range}) => ({name, range})); + result = (await getBranches('repositoryUrl', {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.0 <2.0.0', 'Can release only minor on next'); t.is(getBranch(result, 'next-major').range, '>=2.0.0', 'Can release only major on next-major'); release(branches, 'next', '1.1.0'); release(branches, 'next', '1.1.1'); - result = (await getBranches({options: {branches}})).map(({name, range}) => ({name, range})); + result = (await getBranches('repositoryUrl', {options: {branches}})).map(({name, range}) => ({name, range})); t.is(getBranch(result, 'next').range, '>=1.1.1 <2.0.0', 'Can release only patch or minor, > than 1.1.0 on next'); release(branches, 'next-major', '2.0.0'); release(branches, 'next-major', '2.0.1'); - result = (await getBranches({options: {branches}})).map(({name, range}) => ({name, range})); + result = (await getBranches('repositoryUrl', {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, '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({options: {branches}})).map(({name, range}) => ({name, range})); + result = (await getBranches('repositoryUrl', {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'); release(branches, 'master', '1.0.1'); - result = (await getBranches({options: {branches}})).map(({name, range}) => ({name, range})); + result = (await getBranches('repositoryUrl', {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, @@ -80,7 +80,7 @@ test('Enforce ranges with branching release workflow', async t => { release(branches, 'master', '1.0.2'); release(branches, 'master', '1.0.3'); release(branches, 'master', '1.0.4'); - result = (await getBranches({options: {branches}})).map(({name, range}) => ({name, range})); + result = (await getBranches('repositoryUrl', {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, @@ -90,7 +90,7 @@ test('Enforce ranges with branching release workflow', async t => { 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({options: {branches}})).map(({name, range}) => ({name, range})); + result = (await getBranches('repositoryUrl', {options: {branches}})).map(({name, range}) => ({name, range})); t.is(getBranch(result, 'master').range, '>=1.1.1 <1.2.0', 'Can release only patch, > than 1.1.1 on master'); t.is(getBranch(result, 'next').range, '>=1.2.0 <2.0.0', 'Can release only patch or minor, > than 1.2.0 on next'); t.is(getBranch(result, 'next-major').range, '>=2.0.1', 'Can release any version, > than 2.0.1 on next-major'); @@ -102,34 +102,34 @@ test('Enforce ranges with branching release workflow', async t => { 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({options: {branches}})).map(({name, range}) => ({name, range})); + result = (await getBranches('repositoryUrl', {options: {branches}})).map(({name, range}) => ({name, range})); t.is(getBranch(result, 'master').range, '>=1.1.1 <1.2.0', 'Can release only patch, > 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({options: {branches}})).map(({name, range}) => ({name, range})); + result = (await getBranches('repositoryUrl', {options: {branches}})).map(({name, range}) => ({name, range})); t.is(getBranch(result, 'master').range, '>=1.1.1 <1.2.0', 'Can release only patch, > 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({options: {branches}})).map(({name, range}) => ({name, range})); + result = (await getBranches('repositoryUrl', {options: {branches}})).map(({name, range}) => ({name, range})); t.is(getBranch(result, 'master').range, '>=2.0.1 <2.1.0', 'Can release only patch, > than 2.0.1 on master'); t.is(getBranch(result, 'next').range, '>=2.1.0 <3.0.0', 'Can release only minor on next'); t.is(getBranch(result, 'next-major').range, '>=3.0.0', 'Can release only major 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'); - result = (await getBranches({options: {branches}})).map(({name, range}) => ({name, range})); + result = (await getBranches('repositoryUrl', {options: {branches}})).map(({name, range}) => ({name, range})); t.is(getBranch(result, 'master').range, '>=2.0.1 <2.1.0', 'Can release only patch, > than 2.0.1 on master'); t.is(getBranch(result, 'next').range, '>=2.1.0 <3.0.0', 'Can release only minor on next'); t.is(getBranch(result, 'next-major').range, '>=3.0.0', 'Can release only major on next-major'); branches.push({name: '1.1.x', tags: []}); merge(branches, '1.x', '1.1.x'); - result = (await getBranches({options: {branches}})).map(({name, range}) => ({name, range})); + result = (await getBranches('repositoryUrl', {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'); @@ -146,7 +146,7 @@ test('Throw SemanticReleaseError for invalid configurations', async t => { {name: 'preview', prerelease: 'alpha', tags: []}, ]; const getBranches = proxyquire('../../lib/branches', {'./get-tags': () => branches, './expand': () => []}); - const errors = [...(await t.throwsAsync(getBranches({options: {branches}})))]; + const errors = [...(await t.throwsAsync(getBranches('repositoryUrl', {options: {branches}})))]; t.is(errors[0].name, 'SemanticReleaseError'); t.is(errors[0].code, 'EMAINTENANCEBRANCH'); @@ -174,7 +174,7 @@ 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({options: {branches}})))]; + const errors = [...(await t.throwsAsync(getBranches('repositoryUrl', {options: {branches}})))]; t.is(errors[0].name, 'SemanticReleaseError'); t.is(errors[0].code, 'EDUPLICATEBRANCHES'); @@ -186,7 +186,7 @@ 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({options: {branches}})))]; + const errors = [...(await t.throwsAsync(getBranches('repositoryUrl', {options: {branches}})))]; t.is(errors[0].name, 'SemanticReleaseError'); t.is(errors[0].code, 'EINVALIDBRANCHNAME'); diff --git a/test/branches/expand.test.js b/test/branches/expand.test.js index 285aaac061..a912e193da 100644 --- a/test/branches/expand.test.js +++ b/test/branches/expand.test.js @@ -41,7 +41,7 @@ test('Expand branches defined with globs', async t => { {name: 'beta', channel: `channel-\${name}`, prerelease: true}, ]; - t.deepEqual(await expand({cwd}, branches), [ + t.deepEqual(await expand(repositoryUrl, {cwd}, branches), [ {name: '1.0.x'}, {name: '1.x.x'}, {name: '2.x'}, diff --git a/test/git.test.js b/test/git.test.js index 37e48b8023..d804966d81 100644 --- a/test/git.test.js +++ b/test/git.test.js @@ -58,7 +58,7 @@ test('Unshallow and fetch repository', async t => { // Verify the shallow clone contains only one commit t.is((await gitGetCommits(undefined, {cwd})).length, 1); - await fetch('master', {cwd}); + await fetch(repositoryUrl, 'master', {cwd}); // Verify the shallow clone contains all the commits t.is((await gitGetCommits(undefined, {cwd})).length, 2); @@ -73,8 +73,8 @@ test('Do not throw error when unshallow a complete repository', async t => { await gitCommits(['Second'], {cwd}); await gitPush(repositoryUrl, 'second-branch', {cwd}); - await t.notThrowsAsync(fetch('master', {cwd})); - await t.notThrowsAsync(fetch('second-branch', {cwd})); + await t.notThrowsAsync(fetch(repositoryUrl, 'master', {cwd})); + await t.notThrowsAsync(fetch(repositoryUrl, 'second-branch', {cwd})); }); test('Fetch all tags on a detached head repository', async t => { @@ -89,7 +89,7 @@ test('Fetch all tags on a detached head repository', async t => { await gitPush(repositoryUrl, 'master', {cwd}); cwd = await gitDetachedHead(repositoryUrl, commit.hash); - await fetch('master', {cwd}); + await fetch(repositoryUrl, 'master', {cwd}); t.deepEqual((await getTags({cwd})).sort(), ['v1.0.0', 'v1.0.1', 'v1.1.0'].sort()); }); @@ -137,7 +137,7 @@ test('Get all branches', async t => { await gitCommits(['Third'], {cwd}); await gitPush(repositoryUrl, 'third-branch', {cwd}); - t.deepEqual((await getBranches({cwd})).sort(), ['master', 'second-branch', 'third-branch'].sort()); + t.deepEqual((await getBranches(repositoryUrl, {cwd})).sort(), ['master', 'second-branch', 'third-branch'].sort()); }); test('Get the commit sha for a given tag or falsy if the tag does not exists', async t => { @@ -251,7 +251,7 @@ test('Return "true" if repository is up to date', async t => { await gitCommits(['First'], {cwd}); await gitPush(repositoryUrl, 'master', {cwd}); - t.true(await isBranchUpToDate('master', {cwd})); + t.true(await isBranchUpToDate(repositoryUrl, 'master', {cwd})); }); test('Return falsy if repository is not up to date', async t => { @@ -260,13 +260,13 @@ test('Return falsy if repository is not up to date', async t => { await gitCommits(['Second'], {cwd}); await gitPush(repositoryUrl, 'master', {cwd}); - t.true(await isBranchUpToDate('master', {cwd})); + t.true(await isBranchUpToDate(repositoryUrl, 'master', {cwd})); const tmpRepo = await gitShallowClone(repositoryUrl); await gitCommits(['Third'], {cwd: tmpRepo}); await gitPush('origin', 'master', {cwd: tmpRepo}); - t.falsy(await isBranchUpToDate('master', {cwd})); + t.falsy(await isBranchUpToDate(repositoryUrl, 'master', {cwd})); }); test('Return "true" if local repository is ahead', async t => { @@ -275,5 +275,5 @@ test('Return "true" if local repository is ahead', async t => { await gitPush(repositoryUrl, 'master', {cwd}); await gitCommits(['Second'], {cwd}); - t.true(await isBranchUpToDate('master', {cwd})); + t.true(await isBranchUpToDate(repositoryUrl, 'master', {cwd})); }); diff --git a/test/index.test.js b/test/index.test.js index 3144446198..92b8e677ef 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -353,7 +353,7 @@ test('Plugins are called with expected values', async t => { t.deepEqual(result, { lastRelease, - commits: [{...commits[0], gitTags: '(HEAD -> master, origin/master, origin/HEAD, next)'}], + commits: [{...commits[0], gitTags: '(HEAD -> master, next)'}], nextRelease: {...nextRelease, notes: `${notes1}\n\n${notes2}\n\n${notes3}`}, releases, }); From d4f28abd470879b8ba56ca3427ec91b345a1fc40 Mon Sep 17 00:00:00 2001 From: Pierre Vanduynslager Date: Wed, 5 Jun 2019 16:05:27 -0400 Subject: [PATCH 054/107] test: fix parsing of `MODULE_NOT_FOUND` errors message in unit tests --- test/get-config.test.js | 2 +- test/plugins/normalize.test.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/get-config.test.js b/test/get-config.test.js index c243c91bcb..80fd72d064 100644 --- a/test/get-config.test.js +++ b/test/get-config.test.js @@ -513,6 +513,6 @@ test('Throw an Error if one of the shareable config cannot be found', async t => const error = await t.throwsAsync(t.context.getConfig({cwd}), Error); - t.is(error.message, "Cannot find module 'non-existing-path'"); + t.regex(error.message, /Cannot find module 'non-existing-path'/); t.is(error.code, 'MODULE_NOT_FOUND'); }); diff --git a/test/plugins/normalize.test.js b/test/plugins/normalize.test.js index 9c5f212532..dd93467ed5 100644 --- a/test/plugins/normalize.test.js +++ b/test/plugins/normalize.test.js @@ -273,6 +273,6 @@ test('Throws an error if the plugin is not found', t => { Error ); - t.is(error.message, "Cannot find module 'non-existing-path'"); + t.regex(error.message, /Cannot find module 'non-existing-path'/); t.is(error.code, 'MODULE_NOT_FOUND'); }); From 113157f42a8adb6523579ad2c82c930f8234eb0a Mon Sep 17 00:00:00 2001 From: Pierre Vanduynslager Date: Wed, 5 Jun 2019 16:17:47 -0400 Subject: [PATCH 055/107] test: fix parsing of test repo URL on Travis in unit tests --- test/index.test.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/index.test.js b/test/index.test.js index 92b8e677ef..e620058b95 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -83,7 +83,7 @@ test('Plugins are called with expected values', async t => { const prepare = stub().resolves(); const publish = stub().resolves(release2); const success = stub().resolves(); - const env = {...process.env}; + const env = {}; const config = { branches: [{name: 'master'}, {name: 'next'}], repositoryUrl, @@ -562,7 +562,7 @@ test('Publish a pre-release version', async t => { './lib/get-logger': () => t.context.logger, 'env-ci': () => ({isCi: true, branch: 'beta', isPr: false}), }); - let {releases} = await semanticRelease(options, {cwd, stdout: {write: () => {}}, stderr: {write: () => {}}}); + let {releases} = await semanticRelease(options, {cwd, env: {}, stdout: {write: () => {}}, stderr: {write: () => {}}}); t.is(releases.length, 1); t.is(releases[0].version, '1.1.0-beta.1'); @@ -571,6 +571,7 @@ test('Publish a pre-release version', async t => { await gitCommits(['fix: a fix'], {cwd}); ({releases} = await semanticRelease(options, { cwd, + env: {}, stdout: {write: () => {}}, stderr: {write: () => {}}, })); From 9948a74347704b9a0bdd601ffc0ab08aaa4ae97a Mon Sep 17 00:00:00 2001 From: Pierre Vanduynslager Date: Thu, 6 Jun 2019 11:43:42 -0400 Subject: [PATCH 056/107] fix: revert to the correct refspec in fetch function --- lib/git.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/git.js b/lib/git.js index 905f953fca..4f53ed788b 100644 --- a/lib/git.js +++ b/lib/git.js @@ -143,7 +143,7 @@ async function fetch(repositoryUrl, branch, execaOpts) { 'fetch', '--unshallow', '--tags', - ...(isLocalExists ? [repositoryUrl] : [repositoryUrl, `+refs/heads/${branch}:refs/remotes/upstream/${branch}`]), + ...(isLocalExists ? [repositoryUrl] : [repositoryUrl, `+refs/heads/${branch}:refs/heads/${branch}`]), ], execaOpts ); @@ -153,7 +153,7 @@ async function fetch(repositoryUrl, branch, execaOpts) { [ 'fetch', '--tags', - ...(isLocalExists ? [repositoryUrl] : [repositoryUrl, `+refs/heads/${branch}:refs/remotes/upstream/${branch}`]), + ...(isLocalExists ? [repositoryUrl] : [repositoryUrl, `+refs/heads/${branch}:refs/heads/${branch}`]), ], execaOpts ); From 4d581fc140dda99065542872d125cf27fb24798f Mon Sep 17 00:00:00 2001 From: Pierre Vanduynslager Date: Wed, 5 Jun 2019 18:06:26 -0400 Subject: [PATCH 057/107] feat: create annotated tags --- index.js | 4 ++-- lib/definitions/constants.js | 3 +++ lib/git.js | 14 +++++++++----- test/git.test.js | 6 +++--- test/helpers/git-utils.js | 2 +- 5 files changed, 18 insertions(+), 11 deletions(-) diff --git a/index.js b/index.js index 9bad0aca62..0a7b7edebe 100644 --- a/index.js +++ b/index.js @@ -108,7 +108,7 @@ async function run(context, plugins) { nextRelease.notes = await plugins.generateNotes({...context, commits, lastRelease, nextRelease}); logger.log('Create tag %s', nextRelease.gitTag); - await tag(nextRelease.gitTag, nextRelease.gitHead, {cwd, env}); + await tag(nextRelease, {cwd, env}); await push(options.repositoryUrl, {cwd, env}); context.branch.tags.push({ version: nextRelease.version, @@ -174,7 +174,7 @@ async function run(context, plugins) { logger.warn(`Skip ${nextRelease.gitTag} tag creation in dry-run mode`); } else { // Create the tag before calling the publish plugins as some require the tag to exists - await tag(nextRelease.gitTag, nextRelease.gitHead, {cwd, env}); + await tag(nextRelease, {cwd, env}); await push(options.repositoryUrl, {cwd, env}); logger.success(`Created tag ${nextRelease.gitTag}`); } diff --git a/lib/definitions/constants.js b/lib/definitions/constants.js index 491a1a71a3..9de9d9579f 100644 --- a/lib/definitions/constants.js +++ b/lib/definitions/constants.js @@ -14,6 +14,8 @@ const SECRET_REPLACEMENT = '[secure]'; const SECRET_MIN_SIZE = 5; +const TAG_MESSAGE_FORMAT = `release \${version}`; + module.exports = { RELEASE_TYPE, FIRST_RELEASE, @@ -23,4 +25,5 @@ module.exports = { RELEASE_NOTES_SEPARATOR, SECRET_REPLACEMENT, SECRET_MIN_SIZE, + TAG_MESSAGE_FORMAT, }; diff --git a/lib/git.js b/lib/git.js index 4f53ed788b..ef7ac9e24c 100644 --- a/lib/git.js +++ b/lib/git.js @@ -1,8 +1,9 @@ -const {matches, pick, memoize} = require('lodash'); +const {matches, pick, memoize, template} = require('lodash'); const gitLogParser = require('git-log-parser'); const getStream = require('get-stream'); const execa = require('execa'); const debug = require('debug')('semantic-release:git'); +const {TAG_MESSAGE_FORMAT} = require('./definitions/constants'); Object.assign(gitLogParser.fields, {hash: 'H', message: 'B', gitTags: 'd', committerDate: {key: 'ci', type: Date}}); @@ -222,14 +223,17 @@ async function verifyAuth(repositoryUrl, branch, execaOpts) { /** * Tag the commit head on the local repository. * - * @param {String} tagName The name of the tag. - * @param {String} ref The Git reference to tag. + * @param {Object} release The release associated with the tag. * @param {Object} [execaOpts] Options to pass to `execa`. * * @throws {Error} if the tag creation failed. */ -async function tag(tagName, ref, execaOpts) { - await execa('git', ['tag', tagName, ref], execaOpts); +async function tag(release, execaOpts) { + await execa( + 'git', + ['tag', release.gitTag, release.gitHead, '-a', '-m', template(TAG_MESSAGE_FORMAT)(release)], + execaOpts + ); } /** diff --git a/test/git.test.js b/test/git.test.js index d804966d81..994a68dc60 100644 --- a/test/git.test.js +++ b/test/git.test.js @@ -183,7 +183,7 @@ test('Add tag on head commit', async t => { const {cwd} = await gitRepo(); const commits = await gitCommits(['Test commit'], {cwd}); - await tag('tag_name', 'HEAD', {cwd}); + await tag({gitTag: 'tag_name', gitHead: 'HEAD', version: '1.0.0'}, {cwd}); await t.is(await gitCommitTag(commits[0].hash, {cwd}), 'tag_name'); }); @@ -193,7 +193,7 @@ test('Push tag to remote repository', async t => { const {cwd, repositoryUrl} = await gitRepo(true); const commits = await gitCommits(['Test commit'], {cwd}); - await tag('tag_name', 'HEAD', {cwd}); + await tag({gitTag: 'tag_name', gitHead: 'HEAD', version: '1.0.0'}, {cwd}); await push(repositoryUrl, {cwd}); t.is(await gitRemoteTagHead(repositoryUrl, 'tag_name', {cwd}), commits[0].hash); @@ -207,7 +207,7 @@ test('Push tag to remote repository with remote branch ahead', async t => { await gitCommits(['Second'], {cwd: tmpRepo}); await gitPush('origin', 'master', {cwd: tmpRepo}); - await tag('tag_name', 'HEAD', {cwd}); + await tag({gitTag: 'tag_name', gitHead: 'HEAD', version: '1.0.0'}, {cwd}); await push(repositoryUrl, {cwd}); t.is(await gitRemoteTagHead(repositoryUrl, 'tag_name', {cwd}), commits[0].hash); diff --git a/test/helpers/git-utils.js b/test/helpers/git-utils.js index 7240fe1d13..ba3673588d 100644 --- a/test/helpers/git-utils.js +++ b/test/helpers/git-utils.js @@ -195,7 +195,7 @@ export function gitTagHead(tagName, execaOpts) { * @return {String} The sha of the commit associated with `tagName` on the remote repository. */ export async function gitRemoteTagHead(repositoryUrl, tagName, execaOpts) { - return (await execa.stdout('git', ['ls-remote', '--tags', repositoryUrl, tagName], execaOpts)) + return (await execa.stdout('git', ['ls-remote', repositoryUrl, `${tagName}^{}`], execaOpts)) .split('\n') .filter(tag => Boolean(tag)) .map(tag => tag.match(/^(\S+)/)[1])[0]; From 3e4bb40990c4849912ff7eddf595d0823cdfcbb1 Mon Sep 17 00:00:00 2001 From: Pierre Vanduynslager Date: Fri, 7 Jun 2019 13:35:34 -0400 Subject: [PATCH 058/107] style: fix prettier style --- index.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index 0a7b7edebe..985c915930 100644 --- a/index.js +++ b/index.js @@ -76,9 +76,7 @@ async function run(context, plugins) { } catch (error) { if (!(await isBranchUpToDate(options.repositoryUrl, context.branch.name, {cwd, env}))) { logger.log( - `The local branch ${ - context.branch.name - } 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; } @@ -130,9 +128,7 @@ async function run(context, plugins) { if (context.lastRelease.gitTag) { logger.log( - `Found git tag ${context.lastRelease.gitTag} associated with version ${context.lastRelease.version} on branch ${ - context.branch.name - }` + `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}`); From cb2c506d8b6545b90587b6b5b7bf979c3f2b40b6 Mon Sep 17 00:00:00 2001 From: Scott Willeke Date: Tue, 20 Aug 2019 23:33:32 -0700 Subject: [PATCH 059/107] fix: prefix git auth url with "x-access-token:" when run in a GitHub Action --- lib/get-git-auth-url.js | 22 ++++++++++++---------- test/get-git-auth-url.test.js | 13 +++++++++++++ 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/lib/get-git-auth-url.js b/lib/get-git-auth-url.js index 5206db0203..baa4aa2bf3 100644 --- a/lib/get-git-auth-url.js +++ b/lib/get-git-auth-url.js @@ -3,16 +3,6 @@ const {isNil} = require('lodash'); const hostedGitInfo = require('hosted-git-info'); const {verifyAuth} = require('./git'); -const GIT_TOKENS = { - GIT_CREDENTIALS: undefined, - GH_TOKEN: undefined, - GITHUB_TOKEN: undefined, - GL_TOKEN: 'gitlab-ci-token:', - GITLAB_TOKEN: 'gitlab-ci-token:', - BB_TOKEN: 'x-token-auth:', - BITBUCKET_TOKEN: 'x-token-auth:', -}; - /** * Determine the the git repository URL to use to push, either: * - The `repositoryUrl` as is if allowed to push @@ -25,6 +15,18 @@ const GIT_TOKENS = { * @return {String} The formatted Git repository URL. */ module.exports = async ({cwd, env, branch, options: {repositoryUrl}}) => { + const GIT_TOKENS = { + GIT_CREDENTIALS: undefined, + GH_TOKEN: undefined, + // GitHub Actions require the "x-access-token:" prefix for git access + // https://developer.github.com/apps/building-github-apps/authenticating-with-github-apps/#http-based-git-access-by-an-installation + GITHUB_TOKEN: isNil(env.GITHUB_ACTION) ? undefined : 'x-access-token:', + GL_TOKEN: 'gitlab-ci-token:', + GITLAB_TOKEN: 'gitlab-ci-token:', + BB_TOKEN: 'x-token-auth:', + BITBUCKET_TOKEN: 'x-token-auth:', + }; + const info = hostedGitInfo.fromUrl(repositoryUrl, {noGitPlus: true}); const {protocol, ...parsed} = parse(repositoryUrl); diff --git a/test/get-git-auth-url.test.js b/test/get-git-auth-url.test.js index f4b2633624..aa2c2ce35d 100644 --- a/test/get-git-auth-url.test.js +++ b/test/get-git-auth-url.test.js @@ -273,6 +273,19 @@ test('Return the "https" formatted URL if "gitCredentials" is defined with "BITB ); }); +test('Return the "https" formatted URL if "GITHUB_ACTION" is set', async t => { + const {cwd} = await gitRepo(); + + t.is( + await getAuthUrl({ + cwd, + env: {...env, GITHUB_ACTION: 'foo', GITHUB_TOKEN: 'token'}, + options: {branch: 'master', repositoryUrl: 'git@host.null:owner/repo.git'}, + }), + 'https://x-access-token:token@host.null/owner/repo.git' + ); +}); + test('Handle "https" URL with group and subgroup, with "GIT_CREDENTIALS"', async t => { const {cwd} = await gitRepo(); From 3f0a37944db9324381f779b93ae4115b59c3e13b Mon Sep 17 00:00:00 2001 From: Scott Willeke Date: Sat, 7 Sep 2019 21:59:25 -0700 Subject: [PATCH 060/107] fix(package): update @semantic-release/github back to a build from the beta branch * Only the beta channel that is compatible with semantic-release v16 * 5.4.0-beta.1 worked, but subsequently v5.4.3 was released from master but didn't include the changes from the beta branch and 5.4.0-beta.1. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 841e763dd7..27f729f14b 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ "dependencies": { "@semantic-release/commit-analyzer": "^7.0.0-beta.1", "@semantic-release/error": "^2.2.0", - "@semantic-release/github": "^5.4.0-beta.1", + "@semantic-release/github": "=5.5.0-beta.1", "@semantic-release/npm": "^5.2.0-beta.5", "@semantic-release/release-notes-generator": "^7.1.2", "aggregate-error": "^2.0.0", From f67a667bcb9564025ebbdc4a09bb66f847c4fa15 Mon Sep 17 00:00:00 2001 From: Pierre Vanduynslager Date: Fri, 13 Sep 2019 14:44:56 -0400 Subject: [PATCH 061/107] revert: fix: prefix git auth url with "x-access-token:" when run in a GitHub Action This reverts commit cb2c506d8b6545b90587b6b5b7bf979c3f2b40b6. --- lib/get-git-auth-url.js | 22 ++++++++++------------ test/get-git-auth-url.test.js | 13 ------------- 2 files changed, 10 insertions(+), 25 deletions(-) diff --git a/lib/get-git-auth-url.js b/lib/get-git-auth-url.js index baa4aa2bf3..5206db0203 100644 --- a/lib/get-git-auth-url.js +++ b/lib/get-git-auth-url.js @@ -3,6 +3,16 @@ const {isNil} = require('lodash'); const hostedGitInfo = require('hosted-git-info'); const {verifyAuth} = require('./git'); +const GIT_TOKENS = { + GIT_CREDENTIALS: undefined, + GH_TOKEN: undefined, + GITHUB_TOKEN: undefined, + GL_TOKEN: 'gitlab-ci-token:', + GITLAB_TOKEN: 'gitlab-ci-token:', + BB_TOKEN: 'x-token-auth:', + BITBUCKET_TOKEN: 'x-token-auth:', +}; + /** * Determine the the git repository URL to use to push, either: * - The `repositoryUrl` as is if allowed to push @@ -15,18 +25,6 @@ const {verifyAuth} = require('./git'); * @return {String} The formatted Git repository URL. */ module.exports = async ({cwd, env, branch, options: {repositoryUrl}}) => { - const GIT_TOKENS = { - GIT_CREDENTIALS: undefined, - GH_TOKEN: undefined, - // GitHub Actions require the "x-access-token:" prefix for git access - // https://developer.github.com/apps/building-github-apps/authenticating-with-github-apps/#http-based-git-access-by-an-installation - GITHUB_TOKEN: isNil(env.GITHUB_ACTION) ? undefined : 'x-access-token:', - GL_TOKEN: 'gitlab-ci-token:', - GITLAB_TOKEN: 'gitlab-ci-token:', - BB_TOKEN: 'x-token-auth:', - BITBUCKET_TOKEN: 'x-token-auth:', - }; - const info = hostedGitInfo.fromUrl(repositoryUrl, {noGitPlus: true}); const {protocol, ...parsed} = parse(repositoryUrl); diff --git a/test/get-git-auth-url.test.js b/test/get-git-auth-url.test.js index aa2c2ce35d..f4b2633624 100644 --- a/test/get-git-auth-url.test.js +++ b/test/get-git-auth-url.test.js @@ -273,19 +273,6 @@ test('Return the "https" formatted URL if "gitCredentials" is defined with "BITB ); }); -test('Return the "https" formatted URL if "GITHUB_ACTION" is set', async t => { - const {cwd} = await gitRepo(); - - t.is( - await getAuthUrl({ - cwd, - env: {...env, GITHUB_ACTION: 'foo', GITHUB_TOKEN: 'token'}, - options: {branch: 'master', repositoryUrl: 'git@host.null:owner/repo.git'}, - }), - 'https://x-access-token:token@host.null/owner/repo.git' - ); -}); - test('Handle "https" URL with group and subgroup, with "GIT_CREDENTIALS"', async t => { const {cwd} = await gitRepo(); From d120eaea8b2ea4dbeb27499be5a82b4336e04c70 Mon Sep 17 00:00:00 2001 From: Pierre Vanduynslager Date: Fri, 13 Sep 2019 14:45:00 -0400 Subject: [PATCH 062/107] revert: fix(package): update @semantic-release/github back to a build from the beta branch This reverts commit 3f0a37944db9324381f779b93ae4115b59c3e13b. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 27f729f14b..841e763dd7 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ "dependencies": { "@semantic-release/commit-analyzer": "^7.0.0-beta.1", "@semantic-release/error": "^2.2.0", - "@semantic-release/github": "=5.5.0-beta.1", + "@semantic-release/github": "^5.4.0-beta.1", "@semantic-release/npm": "^5.2.0-beta.5", "@semantic-release/release-notes-generator": "^7.1.2", "aggregate-error": "^2.0.0", From 0629f3cd8af8068a0f6daedc1312c37d1936d87f Mon Sep 17 00:00:00 2001 From: Pierre Vanduynslager Date: Fri, 13 Sep 2019 14:46:30 -0400 Subject: [PATCH 063/107] revert: feat: create annotated tags This reverts commit 4d581fc140dda99065542872d125cf27fb24798f. --- index.js | 4 ++-- lib/definitions/constants.js | 3 --- lib/git.js | 14 +++++--------- test/git.test.js | 6 +++--- test/helpers/git-utils.js | 2 +- 5 files changed, 11 insertions(+), 18 deletions(-) diff --git a/index.js b/index.js index 985c915930..4116759c06 100644 --- a/index.js +++ b/index.js @@ -106,7 +106,7 @@ async function run(context, plugins) { nextRelease.notes = await plugins.generateNotes({...context, commits, lastRelease, nextRelease}); logger.log('Create tag %s', nextRelease.gitTag); - await tag(nextRelease, {cwd, env}); + await tag(nextRelease.gitTag, nextRelease.gitHead, {cwd, env}); await push(options.repositoryUrl, {cwd, env}); context.branch.tags.push({ version: nextRelease.version, @@ -170,7 +170,7 @@ async function run(context, plugins) { logger.warn(`Skip ${nextRelease.gitTag} tag creation in dry-run mode`); } else { // Create the tag before calling the publish plugins as some require the tag to exists - await tag(nextRelease, {cwd, env}); + await tag(nextRelease.gitTag, nextRelease.gitHead, {cwd, env}); await push(options.repositoryUrl, {cwd, env}); logger.success(`Created tag ${nextRelease.gitTag}`); } diff --git a/lib/definitions/constants.js b/lib/definitions/constants.js index 9de9d9579f..491a1a71a3 100644 --- a/lib/definitions/constants.js +++ b/lib/definitions/constants.js @@ -14,8 +14,6 @@ const SECRET_REPLACEMENT = '[secure]'; const SECRET_MIN_SIZE = 5; -const TAG_MESSAGE_FORMAT = `release \${version}`; - module.exports = { RELEASE_TYPE, FIRST_RELEASE, @@ -25,5 +23,4 @@ module.exports = { RELEASE_NOTES_SEPARATOR, SECRET_REPLACEMENT, SECRET_MIN_SIZE, - TAG_MESSAGE_FORMAT, }; diff --git a/lib/git.js b/lib/git.js index ef7ac9e24c..4f53ed788b 100644 --- a/lib/git.js +++ b/lib/git.js @@ -1,9 +1,8 @@ -const {matches, pick, memoize, template} = require('lodash'); +const {matches, pick, memoize} = require('lodash'); const gitLogParser = require('git-log-parser'); const getStream = require('get-stream'); const execa = require('execa'); const debug = require('debug')('semantic-release:git'); -const {TAG_MESSAGE_FORMAT} = require('./definitions/constants'); Object.assign(gitLogParser.fields, {hash: 'H', message: 'B', gitTags: 'd', committerDate: {key: 'ci', type: Date}}); @@ -223,17 +222,14 @@ async function verifyAuth(repositoryUrl, branch, execaOpts) { /** * Tag the commit head on the local repository. * - * @param {Object} release The release associated with 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`. * * @throws {Error} if the tag creation failed. */ -async function tag(release, execaOpts) { - await execa( - 'git', - ['tag', release.gitTag, release.gitHead, '-a', '-m', template(TAG_MESSAGE_FORMAT)(release)], - execaOpts - ); +async function tag(tagName, ref, execaOpts) { + await execa('git', ['tag', tagName, ref], execaOpts); } /** diff --git a/test/git.test.js b/test/git.test.js index 994a68dc60..d804966d81 100644 --- a/test/git.test.js +++ b/test/git.test.js @@ -183,7 +183,7 @@ test('Add tag on head commit', async t => { const {cwd} = await gitRepo(); const commits = await gitCommits(['Test commit'], {cwd}); - await tag({gitTag: 'tag_name', gitHead: 'HEAD', version: '1.0.0'}, {cwd}); + await tag('tag_name', 'HEAD', {cwd}); await t.is(await gitCommitTag(commits[0].hash, {cwd}), 'tag_name'); }); @@ -193,7 +193,7 @@ test('Push tag to remote repository', async t => { const {cwd, repositoryUrl} = await gitRepo(true); const commits = await gitCommits(['Test commit'], {cwd}); - await tag({gitTag: 'tag_name', gitHead: 'HEAD', version: '1.0.0'}, {cwd}); + await tag('tag_name', 'HEAD', {cwd}); await push(repositoryUrl, {cwd}); t.is(await gitRemoteTagHead(repositoryUrl, 'tag_name', {cwd}), commits[0].hash); @@ -207,7 +207,7 @@ test('Push tag to remote repository with remote branch ahead', async t => { await gitCommits(['Second'], {cwd: tmpRepo}); await gitPush('origin', 'master', {cwd: tmpRepo}); - await tag({gitTag: 'tag_name', gitHead: 'HEAD', version: '1.0.0'}, {cwd}); + await tag('tag_name', 'HEAD', {cwd}); await push(repositoryUrl, {cwd}); t.is(await gitRemoteTagHead(repositoryUrl, 'tag_name', {cwd}), commits[0].hash); diff --git a/test/helpers/git-utils.js b/test/helpers/git-utils.js index ba3673588d..7240fe1d13 100644 --- a/test/helpers/git-utils.js +++ b/test/helpers/git-utils.js @@ -195,7 +195,7 @@ export function gitTagHead(tagName, execaOpts) { * @return {String} The sha of the commit associated with `tagName` on the remote repository. */ export async function gitRemoteTagHead(repositoryUrl, tagName, execaOpts) { - return (await execa.stdout('git', ['ls-remote', repositoryUrl, `${tagName}^{}`], execaOpts)) + return (await execa.stdout('git', ['ls-remote', '--tags', repositoryUrl, tagName], execaOpts)) .split('\n') .filter(tag => Boolean(tag)) .map(tag => tag.match(/^(\S+)/)[1])[0]; From f1d983ddb005f4808ecf4da26363dde1175cbc74 Mon Sep 17 00:00:00 2001 From: Pierre Vanduynslager Date: Fri, 13 Sep 2019 16:25:09 -0400 Subject: [PATCH 064/107] feat: require Node.js >=8.15 BREAKING CHANGE: Require Node.js => 8.15 --- .travis.yml | 2 +- docs/support/FAQ.md | 8 ++++---- docs/support/node-version.md | 6 +++--- package.json | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/.travis.yml b/.travis.yml index 8d81eed247..b3f3e263b4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,7 +6,7 @@ services: node_js: - 12 - 10 - - 8.3 + - 8.15 # Trigger a push build on release and greenkeeper branches + PRs build on every branches # Avoid double build on PRs (See https://github.com/travis-ci/travis-ci/issues/1147) diff --git a/docs/support/FAQ.md b/docs/support/FAQ.md index e051b1ad5f..0c82d6999c 100644 --- a/docs/support/FAQ.md +++ b/docs/support/FAQ.md @@ -38,7 +38,7 @@ Yes with the [dry-run options](../usage/configuration.md#dryrun) which prints to ## 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.3](#why-does-semantic-release-require-node-version--83) 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 >= 8.15](#why-does-semantic-release-require-node-version--815) 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: @@ -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`. -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.3. +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.15. 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: @@ -232,9 +232,9 @@ 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). -## Why does semantic-release require Node version >= 8.3? +## Why does semantic-release require Node version >= 8.15? -**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.3 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 8.15 or higher**. See [Node version requirement](./node-version.md#node-version-requirement) for more details and solutions. diff --git a/docs/support/node-version.md b/docs/support/node-version.md index 542af90b4b..bc0625016c 100644 --- a/docs/support/node-version.md +++ b/docs/support/node-version.md @@ -1,6 +1,6 @@ # 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.3 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 8.15 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 -### Run at least one CI job with Node >= 8.3 +### Run at least one CI job with Node >= 8.15 -The recommended approach is to run the `semantic-release` command from a CI job running on Node 8.3 or higher. This can either be a job used by your project to test on Node >= 8.3 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 8.15 or higher. This can either be a job used by your project to test on Node >= 8.15 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. diff --git a/package.json b/package.json index a57f106bfb..c7bbacc9cb 100644 --- a/package.json +++ b/package.json @@ -72,7 +72,7 @@ "xo": "^0.24.0" }, "engines": { - "node": ">=8.3" + "node": ">=8.15" }, "files": [ "bin", From fa62d0ba0bacece609399bbfe6cb4347f5141e51 Mon Sep 17 00:00:00 2001 From: Pierre Vanduynslager Date: Fri, 13 Sep 2019 16:33:09 -0400 Subject: [PATCH 065/107] revert: fix: revert to execa `^1.0.0` This reverts commit 6b3adf6bbe72d5c32335118e91ca32ec043bbc9e. --- lib/git.js | 14 ++++----- package.json | 2 +- test/cli.test.js | 36 +++++++++++------------ test/helpers/npm-utils.js | 2 +- test/integration.test.js | 60 +++++++++++++++++++-------------------- 5 files changed, 57 insertions(+), 57 deletions(-) diff --git a/lib/git.js b/lib/git.js index 4278ea5bfa..c0971f33a5 100644 --- a/lib/git.js +++ b/lib/git.js @@ -64,7 +64,7 @@ async function getCommits(from, to, execaOpts) { * @throws {Error} If the `git` command fails. */ async function getBranches(repositoryUrl, execaOpts) { - return (await execa.stdout('git', ['ls-remote', '--heads', repositoryUrl], execaOpts)) + return (await execa('git', ['ls-remote', '--heads', repositoryUrl], execaOpts)).stdout .split('\n') .map(branch => branch.match(/^.+refs\/heads\/(.+)$/)[1]) .filter(Boolean); @@ -93,7 +93,7 @@ async function isRefInHistory(ref, branch, findRebasedTags, execaOpts) { await execa('git', ['merge-base', '--is-ancestor', ref, branch], execaOpts); return true; } catch (error) { - if (error.code === 1) { + if (error.exitCode === 1) { if (findRebasedTags) { const [tagCommit] = await getStream.array( gitLogParser.parse({_: ref, n: '1'}, {cwd: execaOpts.cwd, env: {...process.env, ...execaOpts.env}}) @@ -119,7 +119,7 @@ async function isRefInHistory(ref, branch, findRebasedTags, execaOpts) { */ async function isRefExists(ref, execaOpts) { try { - return (await execa('git', ['rev-parse', '--verify', ref], execaOpts)).code === 0; + return (await execa('git', ['rev-parse', '--verify', ref], execaOpts)).exitCode === 0; } catch (error) { debug(error); } @@ -134,7 +134,7 @@ async function isRefExists(ref, execaOpts) { */ async function fetch(repositoryUrl, branch, execaOpts) { const isLocalExists = - (await execa('git', ['rev-parse', '--verify', branch], {...execaOpts, reject: false})).code === 0; + (await execa('git', ['rev-parse', '--verify', branch], {...execaOpts, reject: false})).exitCode === 0; try { await execa( @@ -195,7 +195,7 @@ async function repoUrl(execaOpts) { */ async function isGitRepo(execaOpts) { try { - return (await execa('git', ['rev-parse', '--git-dir'], execaOpts)).code === 0; + return (await execa('git', ['rev-parse', '--git-dir'], execaOpts)).exitCode === 0; } catch (error) { debug(error); } @@ -254,7 +254,7 @@ async function push(repositoryUrl, execaOpts) { */ async function verifyTagName(tagName, execaOpts) { try { - return (await execa('git', ['check-ref-format', `refs/tags/${tagName}`], execaOpts)).code === 0; + return (await execa('git', ['check-ref-format', `refs/tags/${tagName}`], execaOpts)).exitCode === 0; } catch (error) { debug(error); } @@ -270,7 +270,7 @@ async function verifyTagName(tagName, execaOpts) { */ async function verifyBranchName(branch, execaOpts) { try { - return (await execa('git', ['check-ref-format', `refs/heads/${branch}`], execaOpts)).code === 0; + return (await execa('git', ['check-ref-format', `refs/heads/${branch}`], execaOpts)).exitCode === 0; } catch (error) { debug(error); } diff --git a/package.json b/package.json index c7bbacc9cb..acc60c9960 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,7 @@ "cosmiconfig": "^5.0.1", "debug": "^4.0.0", "env-ci": "^4.0.0", - "execa": "^1.0.0", + "execa": "^2.0.0", "figures": "^3.0.0", "find-versions": "^3.0.0", "get-stream": "^5.0.0", diff --git a/test/cli.test.js b/test/cli.test.js index a0f4e29e77..7d7961c4fb 100644 --- a/test/cli.test.js +++ b/test/cli.test.js @@ -67,7 +67,7 @@ test.serial('Pass options to semantic-release API', async t => { ]; const cli = requireNoCache('../cli', {'.': run, process: {...process, argv}}); - const code = await cli(); + const exitCode = await cli(); t.deepEqual(run.args[0][0].branches, ['master', 'next']); t.is(run.args[0][0].repositoryUrl, 'https://github/com/owner/repo.git'); @@ -85,7 +85,7 @@ test.serial('Pass options to semantic-release API', async t => { t.is(run.args[0][0].debug, true); t.is(run.args[0][0].dryRun, true); - t.is(code, 0); + t.is(exitCode, 0); }); test.serial('Pass options to semantic-release API with alias arguments', async t => { @@ -109,7 +109,7 @@ test.serial('Pass options to semantic-release API with alias arguments', async t ]; const cli = requireNoCache('../cli', {'.': run, process: {...process, argv}}); - const code = await cli(); + const exitCode = await cli(); t.deepEqual(run.args[0][0].branches, ['master']); t.is(run.args[0][0].repositoryUrl, 'https://github/com/owner/repo.git'); @@ -118,7 +118,7 @@ test.serial('Pass options to semantic-release API with alias arguments', async t t.deepEqual(run.args[0][0].extends, ['config1', 'config2']); t.is(run.args[0][0].dryRun, true); - t.is(code, 0); + t.is(exitCode, 0); }); test.serial('Pass unknown options to semantic-release API', async t => { @@ -126,13 +126,13 @@ test.serial('Pass unknown options to semantic-release API', async t => { const argv = ['', '', '--bool', '--first-option', 'value1', '--second-option', 'value2', '--second-option', 'value3']; const cli = requireNoCache('../cli', {'.': run, process: {...process, argv}}); - const code = await cli(); + const exitCode = await cli(); t.is(run.args[0][0].bool, true); t.is(run.args[0][0].firstOption, 'value1'); t.deepEqual(run.args[0][0].secondOption, ['value2', 'value3']); - t.is(code, 0); + t.is(exitCode, 0); }); test.serial('Pass empty Array to semantic-release API for list option set to "false"', async t => { @@ -140,11 +140,11 @@ test.serial('Pass empty Array to semantic-release API for list option set to "fa const argv = ['', '', '--publish', 'false']; const cli = requireNoCache('../cli', {'.': run, process: {...process, argv}}); - const code = await cli(); + const exitCode = await cli(); t.deepEqual(run.args[0][0].publish, []); - t.is(code, 0); + t.is(exitCode, 0); }); test.serial('Do not set properties in option for which arg is not in command line', async t => { @@ -169,10 +169,10 @@ test.serial('Display help', async t => { const argv = ['', '', '--help']; const cli = requireNoCache('../cli', {'.': run, process: {...process, argv}}); - const code = await cli(); + const exitCode = await cli(); t.regex(t.context.logs, /Run automated package publishing/); - t.is(code, 0); + t.is(exitCode, 0); }); test.serial('Return error code and prints help if called with a command', async t => { @@ -180,11 +180,11 @@ test.serial('Return error code and prints help if called with a command', async const argv = ['', '', 'pre']; const cli = requireNoCache('../cli', {'.': run, process: {...process, argv}}); - const code = await cli(); + const exitCode = await cli(); t.regex(t.context.errors, /Run automated package publishing/); t.regex(t.context.errors, /Too many non-option arguments/); - t.is(code, 1); + t.is(exitCode, 1); }); test.serial('Return error code if multiple plugin are set for single plugin', async t => { @@ -192,11 +192,11 @@ test.serial('Return error code if multiple plugin are set for single plugin', as const argv = ['', '', '--analyze-commits', 'analyze1', 'analyze2']; const cli = requireNoCache('../cli', {'.': run, process: {...process, argv}}); - const code = await cli(); + const exitCode = await cli(); t.regex(t.context.errors, /Run automated package publishing/); t.regex(t.context.errors, /Too many non-option arguments/); - t.is(code, 1); + t.is(exitCode, 1); }); test.serial('Return error code if semantic-release throw error', async t => { @@ -204,10 +204,10 @@ test.serial('Return error code if semantic-release throw error', async t => { const argv = ['', '']; const cli = requireNoCache('../cli', {'.': run, process: {...process, argv}}); - const code = await cli(); + const exitCode = await cli(); t.regex(t.context.errors, /semantic-release error/); - t.is(code, 1); + t.is(exitCode, 1); }); test.serial('Hide sensitive environment variable values from the logs', async t => { @@ -216,8 +216,8 @@ test.serial('Hide sensitive environment variable values from the logs', async t const argv = ['', '']; const cli = requireNoCache('../cli', {'.': run, process: {...process, argv, env: {...process.env, ...env}}}); - const code = await cli(); + const exitCode = await cli(); t.regex(t.context.errors, new RegExp(`Throw error: Exposing token ${escapeRegExp(SECRET_REPLACEMENT)}`)); - t.is(code, 1); + t.is(exitCode, 1); }); diff --git a/test/helpers/npm-utils.js b/test/helpers/npm-utils.js index b690c92769..ea0192a85d 100644 --- a/test/helpers/npm-utils.js +++ b/test/helpers/npm-utils.js @@ -1,5 +1,5 @@ import execa from 'execa'; export async function npmView(packageName, env) { - return JSON.parse(await execa.stdout('npm', ['view', packageName, '--json'], {env})); + return JSON.parse((await execa('npm', ['view', packageName, '--json'], {env})).stdout); } diff --git a/test/integration.test.js b/test/integration.test.js index ee61a8eaa4..3b0d4d66bd 100644 --- a/test/integration.test.js +++ b/test/integration.test.js @@ -83,9 +83,9 @@ test('Release patch, minor and major versions', async t => { t.log('Commit a chore'); await gitCommits(['chore: Init repository'], {cwd}); t.log('$ semantic-release'); - let {stdout, code} = await execa(cli, [], {env, cwd}); + let {stdout, exitCode} = await execa(cli, [], {env, cwd}); t.regex(stdout, /There are no relevant changes, so no new version is released/); - t.is(code, 0); + t.is(exitCode, 0); /* Initial release */ let version = '1.0.0'; @@ -106,10 +106,10 @@ test('Release patch, minor and major versions', async t => { t.log('Commit a feature'); await gitCommits(['feat: Initial commit'], {cwd}); t.log('$ semantic-release'); - ({stdout, code} = await execa(cli, [], {env, cwd})); + ({stdout, exitCode} = await execa(cli, [], {env, cwd})); t.regex(stdout, new RegExp(`Published GitHub release: release-url/${version}`)); t.regex(stdout, new RegExp(`Publishing version ${version} to npm registry`)); - t.is(code, 0); + t.is(exitCode, 0); // Verify package.json and npm-shrinkwrap.json have been updated t.is((await readJson(path.resolve(cwd, 'package.json'))).version, version); @@ -147,10 +147,10 @@ test('Release patch, minor and major versions', async t => { t.log('Commit a fix'); await gitCommits(['fix: bar'], {cwd}); t.log('$ semantic-release'); - ({stdout, code} = await execa(cli, [], {env, cwd})); + ({stdout, exitCode} = await execa(cli, [], {env, cwd})); t.regex(stdout, new RegExp(`Published GitHub release: release-url/${version}`)); t.regex(stdout, new RegExp(`Publishing version ${version} to npm registry`)); - t.is(code, 0); + t.is(exitCode, 0); // Verify package.json and npm-shrinkwrap.json have been updated t.is((await readJson(path.resolve(cwd, 'package.json'))).version, version); @@ -188,10 +188,10 @@ test('Release patch, minor and major versions', async t => { t.log('Commit a feature'); await gitCommits(['feat: baz'], {cwd}); t.log('$ semantic-release'); - ({stdout, code} = await execa(cli, [], {env, cwd})); + ({stdout, exitCode} = await execa(cli, [], {env, cwd})); t.regex(stdout, new RegExp(`Published GitHub release: release-url/${version}`)); t.regex(stdout, new RegExp(`Publishing version ${version} to npm registry`)); - t.is(code, 0); + t.is(exitCode, 0); // Verify package.json and npm-shrinkwrap.json have been updated t.is((await readJson(path.resolve(cwd, 'package.json'))).version, version); @@ -231,10 +231,10 @@ test('Release patch, minor and major versions', async t => { await gitPush('origin', 'next', {cwd}); await gitCommits(['feat: foo\n\n BREAKING CHANGE: bar'], {cwd}); t.log('$ semantic-release'); - ({stdout, code} = await execa(cli, [], {env: {...env, TRAVIS_BRANCH: 'next'}, 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(`Publishing version ${version} to npm registry`)); - t.is(code, 0); + t.is(exitCode, 0); // Verify package.json and npm-shrinkwrap.json have been updated t.is((await readJson(path.resolve(cwd, 'package.json'))).version, version); @@ -280,10 +280,10 @@ test('Release patch, minor and major versions', async t => { await merge('next', {cwd}); await gitPush('origin', 'master', {cwd}); t.log('$ semantic-release'); - ({stdout, code} = await execa(cli, [], {env, cwd})); + ({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(code, 0); + t.is(exitCode, 0); // Wait for 3s as the change of dist-tag takes time to be reflected in the registry await delay(3000); @@ -317,8 +317,8 @@ test('Exit with 1 if a plugin is not found', async t => { release: {analyzeCommits: 'non-existing-path', success: false, fail: false}, }); - const {code, stderr} = await t.throwsAsync(execa(cli, [], {env, cwd})); - t.is(code, 1); + const {exitCode, stderr} = await t.throwsAsync(execa(cli, [], {env, cwd})); + t.is(exitCode, 1); t.regex(stderr, /Cannot find module/); }); @@ -335,8 +335,8 @@ test('Exit with 1 if a shareable config is not found', async t => { release: {extends: 'non-existing-path', success: false, fail: false}, }); - const {code, stderr} = await t.throwsAsync(execa(cli, [], {env, cwd})); - t.is(code, 1); + const {exitCode, stderr} = await t.throwsAsync(execa(cli, [], {env, cwd})); + t.is(exitCode, 1); t.regex(stderr, /Cannot find module/); }); @@ -356,8 +356,8 @@ test('Exit with 1 if a shareable config reference a not found plugin', async t = }); await writeJson(path.resolve(cwd, 'shareable.json'), shareable); - const {code, stderr} = await t.throwsAsync(execa(cli, [], {env, cwd})); - t.is(code, 1); + const {exitCode, stderr} = await t.throwsAsync(execa(cli, [], {env, cwd})); + t.is(exitCode, 1); t.regex(stderr, /Cannot find module/); }); @@ -386,11 +386,11 @@ test('Dry-run', async t => { t.log('Commit a feature'); await gitCommits(['feat: Initial commit'], {cwd}); t.log('$ semantic-release -d'); - const {stdout, code} = await execa(cli, ['-d'], {env, cwd}); + const {stdout, exitCode} = await execa(cli, ['-d'], {env, cwd}); t.regex(stdout, new RegExp(`There is no previous release, the next release version is ${version}`)); t.regex(stdout, new RegExp(`Release note for version ${version}`)); t.regex(stdout, /Initial commit/); - t.is(code, 0); + t.is(exitCode, 0); // Verify package.json and has not been modified t.is((await readJson(path.resolve(cwd, 'package.json'))).version, '0.0.0-dev'); @@ -434,10 +434,10 @@ test('Allow local releases with "noCi" option', async t => { t.log('Commit a feature'); await gitCommits(['feat: Initial commit'], {cwd}); t.log('$ semantic-release --no-ci'); - const {stdout, code} = await execa(cli, ['--no-ci'], {env: envNoCi, cwd}); + const {stdout, exitCode} = await execa(cli, ['--no-ci'], {env: envNoCi, cwd}); t.regex(stdout, new RegExp(`Published GitHub release: release-url/${version}`)); t.regex(stdout, new RegExp(`Publishing version ${version} to npm registry`)); - t.is(code, 0); + t.is(exitCode, 0); // Verify package.json and has been updated t.is((await readJson(path.resolve(cwd, 'package.json'))).version, version); @@ -474,7 +474,7 @@ test('Pass options via CLI arguments', async t => { t.log('Commit a feature'); await gitCommits(['feat: Initial commit'], {cwd}); t.log('$ semantic-release'); - const {stdout, code} = await execa( + const {stdout, exitCode} = await execa( cli, [ '--verify-conditions', @@ -490,7 +490,7 @@ test('Pass options via CLI arguments', async t => { {env, cwd} ); t.regex(stdout, new RegExp(`Publishing version ${version} to npm registry`)); - t.is(code, 0); + t.is(exitCode, 0); // Verify package.json and has been updated t.is((await readJson(path.resolve(cwd, 'package.json'))).version, version); @@ -581,14 +581,14 @@ test('Log unexpected errors from plugins and exit with 1', async t => { t.log('Commit a feature'); await gitCommits(['feat: Initial commit'], {cwd}); t.log('$ semantic-release'); - const {stderr, code} = await execa(cli, [], {env, cwd, reject: false}); + const {stderr, exitCode} = await execa(cli, [], {env, cwd, reject: false}); // Verify the type and message are logged t.regex(stderr, /Error: a/); // Verify the the stacktrace is logged t.regex(stderr, new RegExp(pluginError)); // Verify the Error properties are logged t.regex(stderr, /errorProperty: 'errorProperty'/); - t.is(code, 1); + t.is(exitCode, 1); }); test('Log errors inheriting SemanticReleaseError and exit with 1', async t => { @@ -608,10 +608,10 @@ test('Log errors inheriting SemanticReleaseError and exit with 1', async t => { t.log('Commit a feature'); await gitCommits(['feat: Initial commit'], {cwd}); t.log('$ semantic-release'); - const {stderr, code} = await execa(cli, [], {env, cwd, reject: false}); + const {stderr, exitCode} = await execa(cli, [], {env, cwd, reject: false}); // Verify the type and message are logged t.regex(stderr, /EINHERITED Inherited error/); - t.is(code, 1); + t.is(exitCode, 1); }); test('Exit with 1 if missing permission to push to the remote repository', async t => { @@ -626,14 +626,14 @@ test('Exit with 1 if missing permission to push to the remote repository', async await gitCommits(['feat: Initial commit'], {cwd}); await gitPush('origin', 'master', {cwd}); t.log('$ semantic-release'); - const {stderr, code} = await execa( + const {stderr, exitCode} = await execa( cli, ['--repository-url', 'http://user:wrong_pass@localhost:2080/git/unauthorized.git'], {env: {...env, GH_TOKEN: 'user:wrong_pass'}, cwd, reject: false} ); // Verify the type and message are logged t.regex(stderr, /EGITNOPERMISSION/); - t.is(code, 1); + t.is(exitCode, 1); }); test('Hide sensitive environment variable values from the logs', async t => { From 8b2bb688f9f7b15f0e0d3ebc5776391f2aa29566 Mon Sep 17 00:00:00 2001 From: Pierre Vanduynslager Date: Thu, 26 Sep 2019 14:36:14 -0700 Subject: [PATCH 066/107] docs: fix link to FAQ node minimum version --- docs/recipes/gitlab-ci.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/recipes/gitlab-ci.md b/docs/recipes/gitlab-ci.md index 6671ecef8b..6a5c4be5b3 100644 --- a/docs/recipes/gitlab-ci.md +++ b/docs/recipes/gitlab-ci.md @@ -8,7 +8,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. -**Note**: The publish pipeline must run a [Node >= 8 version](../support/FAQ.md#why-does-semantic-release-require-node-version--83). +**Note**: The publish pipeline must run a [Node >= 8 version](../support/FAQ.md#why-does-semantic-release-require-node-version--815). ### `.gitlab-ci.yml` configuration for Node projects From 53c85701df5efd8bbd9cfe08954821d70b5e82d9 Mon Sep 17 00:00:00 2001 From: Pierre Vanduynslager Date: Thu, 26 Sep 2019 14:36:39 -0700 Subject: [PATCH 067/107] docs: fix links in configuration doc --- docs/usage/configuration.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/usage/configuration.md b/docs/usage/configuration.md index 1aecdaf345..21ad6d2bd4 100644 --- a/docs/usage/configuration.md +++ b/docs/usage/configuration.md @@ -1,7 +1,7 @@ # Configuration **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 - Run mode ([debug](#debug), [dry run](#dryrun) and [local (no CI)](#ci)) @@ -76,7 +76,7 @@ The branches on which releases should happen. By default **semantic-release** wi **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 [Plugins configuration](plugins.md#plugins) for more details. +See [Plugins configuration](workflow-configuration.md#workflow-configuration) for more details. ### repositoryUrl @@ -150,7 +150,7 @@ Output debugging information. This can also be enabled by setting the `DEBUG` en ## 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. -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. From 2769a5057ddc4d3817f0aab54e96e63fbf63732a Mon Sep 17 00:00:00 2001 From: Pierre Vanduynslager Date: Thu, 26 Sep 2019 14:36:56 -0700 Subject: [PATCH 068/107] docs: add links to workflow configuration --- README.md | 1 + SUMMARY.md | 1 + docs/usage/README.md | 1 + 3 files changed, 3 insertions(+) diff --git a/README.md b/README.md index e1fd8471ac..3e5e98aab1 100644 --- a/README.md +++ b/README.md @@ -103,6 +103,7 @@ After running the tests, the command `semantic-release` will execute the followi - [CI Configuration](docs/usage/ci-configuration.md#ci-configuration) - [Configuration](docs/usage/configuration.md#configuration) - [Plugins](docs/usage/plugins.md) + - [Workflow configuration](docs/usage/workflow-configuration.md) - [Shareable configurations](docs/usage/shareable-configurations.md) - Extending - [Plugins](docs/extending/plugins-list.md) diff --git a/SUMMARY.md b/SUMMARY.md index e6ce15b072..a28efb45a1 100644 --- a/SUMMARY.md +++ b/SUMMARY.md @@ -6,6 +6,7 @@ - [CI Configuration](docs/usage/ci-configuration.md#ci-configuration) - [Configuration](docs/usage/configuration.md#configuration) - [Plugins](docs/usage/plugins.md) +- [Workflow configuration](docs/usage/workflow-configuration.md) - [Shareable configurations](docs/usage/shareable-configurations.md) ## Extending diff --git a/docs/usage/README.md b/docs/usage/README.md index 636326ff04..758b34a35d 100644 --- a/docs/usage/README.md +++ b/docs/usage/README.md @@ -5,4 +5,5 @@ - [CI Configuration](ci-configuration.md#ci-configuration) - [Configuration](configuration.md#configuration) - [Plugins](plugins.md) +- [Workflow configuration](workflow-configuration.md) - [Shareable configurations](shareable-configurations.md) From 73f0c775daf1167a0577425bb06149b4c7e3819f Mon Sep 17 00:00:00 2001 From: Pierre Vanduynslager Date: Fri, 4 Oct 2019 17:58:49 -0400 Subject: [PATCH 069/107] fix: update plugins dependencies --- package.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index acc60c9960..f7f5f19c1a 100644 --- a/package.json +++ b/package.json @@ -22,10 +22,10 @@ "Pierre Vanduynslager (https://twitter.com/@pvdlg_)" ], "dependencies": { - "@semantic-release/commit-analyzer": "^7.0.0-beta.3", + "@semantic-release/commit-analyzer": "7.0.0-beta.4", "@semantic-release/error": "^2.2.0", - "@semantic-release/github": "^5.5.0-beta.1", - "@semantic-release/npm": "^5.2.0-beta.8", + "@semantic-release/github": "5.6.0-beta.1", + "@semantic-release/npm": "6.0.0-beta.1", "@semantic-release/release-notes-generator": "^7.1.2", "aggregate-error": "^3.0.0", "cosmiconfig": "^5.0.1", From 4b66303d2f1868b3b454c1ef5b9cac7d588094d7 Mon Sep 17 00:00:00 2001 From: Pierre Vanduynslager Date: Wed, 9 Oct 2019 16:23:12 -0400 Subject: [PATCH 070/107] docs: typo is link to workflow config --- docs/usage/configuration.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/usage/configuration.md b/docs/usage/configuration.md index 21ad6d2bd4..4c9ff1e898 100644 --- a/docs/usage/configuration.md +++ b/docs/usage/configuration.md @@ -76,7 +76,7 @@ The branches on which releases should happen. By default **semantic-release** wi **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 [Plugins configuration](workflow-configuration.md#workflow-configuration) for more details. +See [Workflow configuration](workflow-configuration.md#workflow-configuration) for more details. ### repositoryUrl From ff60ac594c6a3b4870a6c0424f5b385a1eaf7bcf Mon Sep 17 00:00:00 2001 From: Pierre Vanduynslager Date: Thu, 10 Oct 2019 11:50:30 -0400 Subject: [PATCH 071/107] test: specify version of gitbox image --- test/helpers/gitbox.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/helpers/gitbox.js b/test/helpers/gitbox.js index 2dba7c2059..6ddd586fb7 100644 --- a/test/helpers/gitbox.js +++ b/test/helpers/gitbox.js @@ -3,7 +3,7 @@ import getStream from 'get-stream'; import pRetry from 'p-retry'; import {initBareRepo, gitShallowClone} from './git-utils'; -const IMAGE = 'pvdlg/docker-gitbox'; +const IMAGE = 'pvdlg/docker-gitbox:latest'; const SERVER_PORT = 80; const HOST_PORT = 2080; const SERVER_HOST = 'localhost'; From 95379270d6383357c9c18cfc882ba21e6497db29 Mon Sep 17 00:00:00 2001 From: Pierre Vanduynslager Date: Mon, 14 Oct 2019 12:49:59 -0400 Subject: [PATCH 072/107] fix(package): update execa to version 3.0.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f7f5f19c1a..0e9d10fde2 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,7 @@ "cosmiconfig": "^5.0.1", "debug": "^4.0.0", "env-ci": "^4.0.0", - "execa": "^2.0.0", + "execa": "^3.0.0", "figures": "^3.0.0", "find-versions": "^3.0.0", "get-stream": "^5.0.0", From 6053b89af300baba0b9cf9931f39415c7f487e27 Mon Sep 17 00:00:00 2001 From: Pierre Vanduynslager Date: Tue, 29 Oct 2019 12:01:33 -0400 Subject: [PATCH 073/107] fix(package): update @semantic-release/github to version 5.6.0-beta.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 0623e15eeb..576e3fe0e6 100644 --- a/package.json +++ b/package.json @@ -24,8 +24,8 @@ "dependencies": { "@semantic-release/commit-analyzer": "7.0.0-beta.4", "@semantic-release/error": "^2.2.0", - "@semantic-release/github": "5.6.0-beta.1", "@semantic-release/npm": "6.0.0-beta.1", + "@semantic-release/github": "5.6.0-beta.2", "@semantic-release/release-notes-generator": "^7.1.2", "aggregate-error": "^3.0.0", "cosmiconfig": "^5.0.1", From 65c412293e940d51818fc1286a77d7dc6855dbbf Mon Sep 17 00:00:00 2001 From: Pierre Vanduynslager Date: Tue, 29 Oct 2019 12:01:59 -0400 Subject: [PATCH 074/107] fix(package): update @semantic-release/npm to version 6.0.0-beta.3 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 576e3fe0e6..2420ab2764 100644 --- a/package.json +++ b/package.json @@ -24,8 +24,8 @@ "dependencies": { "@semantic-release/commit-analyzer": "7.0.0-beta.4", "@semantic-release/error": "^2.2.0", - "@semantic-release/npm": "6.0.0-beta.1", "@semantic-release/github": "5.6.0-beta.2", + "@semantic-release/npm": "6.0.0-beta.3", "@semantic-release/release-notes-generator": "^7.1.2", "aggregate-error": "^3.0.0", "cosmiconfig": "^5.0.1", From 581998cff075e31ab3c4b2a99b84984b9900228b Mon Sep 17 00:00:00 2001 From: Pierre Vanduynslager Date: Tue, 29 Oct 2019 12:42:31 -0400 Subject: [PATCH 075/107] fix(package): update semver-diff to version 3.1.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 2420ab2764..6f0bf39c6b 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "read-pkg-up": "^7.0.0", "resolve-from": "^5.0.0", "semver": "^6.0.0", - "semver-diff": "^2.1.0", + "semver-diff": "^3.1.1", "signale": "^1.2.1", "yargs": "^14.0.0" }, From 2c655b23285621e6c4f8dcae8846c954e00d8b14 Mon Sep 17 00:00:00 2001 From: Pierre Vanduynslager Date: Tue, 29 Oct 2019 13:26:08 -0400 Subject: [PATCH 076/107] fix(package): update p-each-series to version 2.1.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 6f0bf39c6b..53dad9517c 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,7 @@ "marked": "^0.7.0", "marked-terminal": "^3.2.0", "micromatch": "3.1.5", - "p-each-series": "^1.0.0", + "p-each-series": "^2.1.0", "p-reduce": "^2.0.0", "read-pkg-up": "^7.0.0", "resolve-from": "^5.0.0", From e5344cd89bc47a3a8608f0d62353cd9c660a1bd9 Mon Sep 17 00:00:00 2001 From: Pierre Vanduynslager Date: Tue, 29 Oct 2019 13:26:41 -0400 Subject: [PATCH 077/107] fix(package): update micromatch to version 3.1.10 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 53dad9517c..1ab79d3317 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "lodash": "^4.17.15", "marked": "^0.7.0", "marked-terminal": "^3.2.0", - "micromatch": "3.1.5", + "micromatch": "^3.1.10", "p-each-series": "^2.1.0", "p-reduce": "^2.0.0", "read-pkg-up": "^7.0.0", From 1edae67326ecbb99d8b4be7e17a8ce4e14f439df Mon Sep 17 00:00:00 2001 From: Pierre Vanduynslager Date: Fri, 1 Nov 2019 16:30:33 -0400 Subject: [PATCH 078/107] fix: display erroring git commands properly --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 4116759c06..1546194bc1 100644 --- a/index.js +++ b/index.js @@ -84,7 +84,7 @@ async function run(context, plugins) { throw error; } } catch (error) { - logger.error(`The command "${error.cmd}" failed with the error message ${error.stderr}.`); + logger.error(`The command "${error.command}" failed with the error message ${error.stderr}.`); throw getError('EGITNOPERMISSION', context); } From 844e0b07e04754c8185d9d88523c8afc236de02a Mon Sep 17 00:00:00 2001 From: Pierre Vanduynslager Date: Fri, 1 Nov 2019 16:40:04 -0400 Subject: [PATCH 079/107] fix: remove hack to workaround GitHub Rebase & Merge --- lib/branches/get-tags.js | 2 +- lib/git.js | 17 ++--------------- test/branches/get-tags.test.js | 27 +-------------------------- test/git.test.js | 8 ++++---- test/helpers/git-utils.js | 13 ------------- 5 files changed, 8 insertions(+), 59 deletions(-) diff --git a/lib/branches/get-tags.js b/lib/branches/get-tags.js index 194f25de00..d732d1a920 100644 --- a/lib/branches/get-tags.js +++ b/lib/branches/get-tags.js @@ -25,7 +25,7 @@ module.exports = async ({cwd, env, options: {tagFormat}}, branches) => { const branchTags = await pReduce( tags, async (tags, {gitTag, ...rest}) => - (await isRefInHistory(gitTag, branch.name, true, {cwd, env})) + (await isRefInHistory(gitTag, branch.name, {cwd, env})) ? [...tags, {...rest, gitTag, gitHead: await getTagHead(gitTag, {cwd, env})}] : tags, [] diff --git a/lib/git.js b/lib/git.js index 099ae110c0..c776804c98 100644 --- a/lib/git.js +++ b/lib/git.js @@ -1,4 +1,3 @@ -const {matches, pick, memoize} = require('lodash'); const gitLogParser = require('git-log-parser'); const getStream = require('get-stream'); const execa = require('execa'); @@ -70,21 +69,16 @@ async function getBranches(repositoryUrl, execaOpts) { .filter(Boolean); } -const getBranchCommits = memoize((branch, execaOpts) => - getStream.array(gitLogParser.parse({_: branch}, {cwd: execaOpts.cwd, env: {...process.env, ...execaOpts.env}})) -); - /** * Verify if the `ref` is in the direct history of a given branch. * * @param {String} ref The reference to look for. * @param {String} branch The branch for which to check if the `ref` is in history. - * @param {Boolean} findRebasedTags Weither consider in history tags associated with a commit that was rebased to another branch (i.e. GitHub Rebase and Merge feature). * @param {Object} [execaOpts] Options to pass to `execa`. * * @return {Boolean} `true` if the reference is in the history of the current branch, falsy otherwise. */ -async function isRefInHistory(ref, branch, findRebasedTags, execaOpts) { +async function isRefInHistory(ref, branch, execaOpts) { if (!(await isRefExists(branch, execaOpts))) { return false; } @@ -94,13 +88,6 @@ async function isRefInHistory(ref, branch, findRebasedTags, execaOpts) { return true; } catch (error) { if (error.exitCode === 1) { - if (findRebasedTags) { - const [tagCommit] = await getStream.array( - gitLogParser.parse({_: ref, n: '1'}, {cwd: execaOpts.cwd, env: {...process.env, ...execaOpts.env}}) - ); - return (await getBranchCommits(branch, execaOpts)).some(matches(pick(tagCommit, ['message', 'author']))); - } - return false; } @@ -288,7 +275,7 @@ async function verifyBranchName(branch, execaOpts) { async function isBranchUpToDate(repositoryUrl, branch, execaOpts) { const {stdout: remoteHead} = await execa('git', ['ls-remote', '--heads', repositoryUrl, branch], execaOpts); try { - return await isRefInHistory(remoteHead.match(/^(\w+)?/)[1], branch, false, execaOpts); + return await isRefInHistory(remoteHead.match(/^(\w+)?/)[1], branch, execaOpts); } catch (error) { debug(error); } diff --git a/test/branches/get-tags.test.js b/test/branches/get-tags.test.js index 0ebe140dc9..78195dd733 100644 --- a/test/branches/get-tags.test.js +++ b/test/branches/get-tags.test.js @@ -1,6 +1,6 @@ import test from 'ava'; import getTags from '../../lib/branches/get-tags'; -import {gitRepo, gitCommits, gitTagVersion, gitCheckout, merge, changeAuthor} from '../helpers/git-utils'; +import {gitRepo, gitCommits, gitTagVersion, gitCheckout} from '../helpers/git-utils'; test('Get the valid tags', async t => { const {cwd} = await gitRepo(); @@ -175,28 +175,3 @@ test('Get the highest valid tag corresponding to the "tagFormat"', async t => { {name: 'master', tags: [{gitTag: '3.0.0-bar.2', version: '3.0.0', channel: undefined, gitHead: commits[0].hash}]}, ]); }); - -test('Get the tag on branch where commits have been rebased', async t => { - const {cwd} = await gitRepo(); - const commits = await gitCommits(['First'], {cwd}); - await gitCheckout('next', true, {cwd}); - commits.push(...(await gitCommits(['Second/n/n/commit body'], {cwd}))); - await gitTagVersion('v1.0.0@next', undefined, {cwd}); - await gitCheckout('master', false, {cwd}); - await merge('next', {cwd}); - // Simulate GitHub "Rebase and Merge" by changing the committer info, which will result in a new commit sha and losing the tag - await changeAuthor(commits[1].hash, {cwd}); - - const result = await getTags({cwd, options: {tagFormat: `v\${version}`}}, [{name: 'master'}, {name: 'next'}]); - - t.deepEqual(result, [ - { - name: 'master', - tags: [{gitTag: 'v1.0.0@next', version: '1.0.0', channel: 'next', gitHead: commits[1].hash}], - }, - { - name: 'next', - tags: [{gitTag: 'v1.0.0@next', version: '1.0.0', channel: 'next', gitHead: commits[1].hash}], - }, - ]); -}); diff --git a/test/git.test.js b/test/git.test.js index d804966d81..813844f3f6 100644 --- a/test/git.test.js +++ b/test/git.test.js @@ -105,10 +105,10 @@ test('Verify if the commit `sha` is in the direct history of the current branch' const otherCommits = await gitCommits(['Second'], {cwd}); await gitCheckout('master', false, {cwd}); - t.true(await isRefInHistory(commits[0].hash, 'master', false, {cwd})); - t.falsy(await isRefInHistory(otherCommits[0].hash, 'master', false, {cwd})); - t.falsy(await isRefInHistory(otherCommits[0].hash, 'missing-branch', false, {cwd})); - await t.throwsAsync(isRefInHistory('non-existant-sha', 'master', false, {cwd})); + t.true(await isRefInHistory(commits[0].hash, 'master', {cwd})); + t.falsy(await isRefInHistory(otherCommits[0].hash, 'master', {cwd})); + t.falsy(await isRefInHistory(otherCommits[0].hash, 'missing-branch', {cwd})); + await t.throwsAsync(isRefInHistory('non-existant-sha', 'master', {cwd})); }); test('Verify if a branch exists', async t => { diff --git a/test/helpers/git-utils.js b/test/helpers/git-utils.js index 375e003516..2019d561b8 100644 --- a/test/helpers/git-utils.js +++ b/test/helpers/git-utils.js @@ -256,16 +256,3 @@ export async function mergeFf(ref, execaOpts) { export async function rebase(ref, execaOpts) { await execa('git', ['rebase', ref], execaOpts); } - -export async function changeAuthor(sha, execaOpts) { - await execa( - 'git', - [ - 'filter-branch', - '-f', - '--env-filter', - `if [[ "$GIT_COMMIT" = "${sha}" ]]; then export GIT_COMMITTER_NAME="New Author" GIT_COMMITTER_EMAIL="author@test.com"; fi`, - ], - execaOpts - ); -} From cffe9a8d338f1d4be899fef4495504eda8a4031e Mon Sep 17 00:00:00 2001 From: Pierre Vanduynslager Date: Fri, 1 Nov 2019 16:44:29 -0400 Subject: [PATCH 080/107] perf: use `git tag --merge ` to filter tags present in a branch history BREAKING CHANGE: Git CLI version 2.7.1 or higher is now required The `--merge` option of the `git tag` command has been added in Git version 2.7.1 and is now used by semantic-release --- bin/semantic-release.js | 2 +- docs/support/FAQ.md | 4 ++++ lib/branches/get-tags.js | 25 +++++++++---------------- lib/git.js | 7 ++++--- test/branches/get-tags.test.js | 6 +++--- test/git.test.js | 4 ++-- 6 files changed, 23 insertions(+), 25 deletions(-) diff --git a/bin/semantic-release.js b/bin/semantic-release.js index 12dd2b56b6..37fcf85847 100755 --- a/bin/semantic-release.js +++ b/bin/semantic-release.js @@ -10,7 +10,7 @@ var execa = require('execa'); var findVersions = require('find-versions'); 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)) { console.error( diff --git a/docs/support/FAQ.md b/docs/support/FAQ.md index 4f7332143b..cb9d6278dd 100644 --- a/docs/support/FAQ.md +++ b/docs/support/FAQ.md @@ -238,6 +238,10 @@ In addition the [verify conditions step](../../README.md#release-steps) verifies 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? [`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. diff --git a/lib/branches/get-tags.js b/lib/branches/get-tags.js index d732d1a920..2f50a93845 100644 --- a/lib/branches/get-tags.js +++ b/lib/branches/get-tags.js @@ -2,7 +2,7 @@ const {template, escapeRegExp} = require('lodash'); const semver = require('semver'); const pReduce = require('p-reduce'); const debug = require('debug')('semantic-release:get-tags'); -const {getTags, isRefInHistory, getTagHead} = require('../../lib/git'); +const {getTags, getTagHead} = require('../../lib/git'); module.exports = async ({cwd, env, options: {tagFormat}}, branches) => { // Generate a regex to parse tags formatted with `tagFormat` @@ -10,25 +10,18 @@ module.exports = async ({cwd, env, options: {tagFormat}}, branches) => { // 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(' ', '(.[^@]+)@?(.+)?')}`; - const tags = (await getTags({cwd, env})) - .map(tag => { - const [, version, channel] = tag.match(tagRegexp) || []; - return {gitTag: tag, version, channel}; - }) - .filter(({version}) => version && semver.valid(semver.clean(version))); - - debug('found tags: %o', tags); return pReduce( branches, async (branches, branch) => { - const branchTags = await pReduce( - tags, - async (tags, {gitTag, ...rest}) => - (await isRefInHistory(gitTag, branch.name, {cwd, env})) - ? [...tags, {...rest, gitTag, gitHead: await getTagHead(gitTag, {cwd, env})}] - : tags, - [] + const branchTags = await Promise.all( + (await getTags(branch.name, {cwd, env})) + .map(tag => { + const [, version, channel] = tag.match(tagRegexp) || []; + return {gitTag: tag, version, channel}; + }) + .filter(({version}) => version && semver.valid(semver.clean(version))) + .map(async ({gitTag, ...rest}) => ({gitTag, gitHead: await getTagHead(gitTag, {cwd, env}), ...rest})) ); debug('found tags for branch %s: %o', branch.name, branchTags); diff --git a/lib/git.js b/lib/git.js index c776804c98..db8447e9c9 100644 --- a/lib/git.js +++ b/lib/git.js @@ -22,15 +22,16 @@ async function getTagHead(tagName, execaOpts) { } /** - * 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`. * * @return {Array} List of git tags. * @throws {Error} If the `git` command fails. */ -async function getTags(execaOpts) { - return (await execa('git', ['tag'], execaOpts)).stdout +async function getTags(branch, execaOpts) { + return (await execa('git', ['tag', '--merged', branch], execaOpts)).stdout .split('\n') .map(tag => tag.trim()) .filter(Boolean); diff --git a/test/branches/get-tags.test.js b/test/branches/get-tags.test.js index 78195dd733..0be5ae536d 100644 --- a/test/branches/get-tags.test.js +++ b/test/branches/get-tags.test.js @@ -109,15 +109,15 @@ test('Return branches with and empty tags array if no valid tag is found', async await gitCommits(['Third'], {cwd}); await gitTagVersion('v3.0', undefined, {cwd}); - const result = await getTags({cwd, options: {tagFormat: `prefix@v\${version}`}}, [{name: 'master'}, {name: 'next'}]); + const result = await getTags({cwd, options: {tagFormat: `prefix@v\${version}`}}, [{name: 'master'}]); - t.deepEqual(result, [{name: 'master', tags: []}, {name: 'next', tags: []}]); + 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('other-branch', true, {cwd}); + await gitCheckout('next', true, {cwd}); await gitCommits(['Second'], {cwd}); await gitTagVersion('v1.0.0', undefined, {cwd}); await gitTagVersion('v1.0.0@next', undefined, {cwd}); diff --git a/test/git.test.js b/test/git.test.js index 813844f3f6..34e5000d61 100644 --- a/test/git.test.js +++ b/test/git.test.js @@ -91,7 +91,7 @@ test('Fetch all tags on a detached head repository', async t => { await fetch(repositoryUrl, '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 => { @@ -243,7 +243,7 @@ test('Return falsy for invalid tag names', async t => { test('Throws error if obtaining the tags fails', async t => { 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 => { From 2ec856eb1d476f35ebc9d8b6dcd7c05bd3503fe6 Mon Sep 17 00:00:00 2001 From: Pierre Vanduynslager Date: Fri, 1 Nov 2019 16:44:51 -0400 Subject: [PATCH 081/107] docs: add requirements section to README --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index 651e7cc281..a82ac5f8ef 100644 --- a/README.md +++ b/README.md @@ -95,6 +95,14 @@ After running the tests, the command `semantic-release` will execute the followi | Publish | Publish the release. | | 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 - Usage From 56186419a791b02d806a5d40e7321959bad99134 Mon Sep 17 00:00:00 2001 From: Pierre Vanduynslager Date: Fri, 1 Nov 2019 22:07:55 -0400 Subject: [PATCH 082/107] fix(package): update micromatch to version 4.0.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 1ab79d3317..3d64734d25 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "lodash": "^4.17.15", "marked": "^0.7.0", "marked-terminal": "^3.2.0", - "micromatch": "^3.1.10", + "micromatch": "^4.0.2", "p-each-series": "^2.1.0", "p-reduce": "^2.0.0", "read-pkg-up": "^7.0.0", From de77a799a82cfe30aedc21dded61e39db2784a48 Mon Sep 17 00:00:00 2001 From: Pierre Vanduynslager Date: Thu, 7 Nov 2019 14:14:33 -0500 Subject: [PATCH 083/107] fix: call `getTagHead` only when necessary --- index.js | 7 +- lib/branches/get-tags.js | 4 +- lib/get-last-release.js | 9 ++- lib/get-releases-to-add.js | 6 +- test/branches/get-tags.test.js | 44 ++++++------ test/get-last-release.test.js | 30 ++++----- test/get-releases-to-add.test.js | 111 ++++++++++++++++--------------- test/index.test.js | 4 +- 8 files changed, 113 insertions(+), 102 deletions(-) diff --git a/index.js b/index.js index 1546194bc1..266429a89a 100644 --- a/index.js +++ b/index.js @@ -18,7 +18,7 @@ const {extractErrors, makeTag} = require('./lib/utils'); const getGitAuthUrl = require('./lib/get-git-auth-url'); const getBranches = require('./lib/branches'); const getLogger = require('./lib/get-logger'); -const {verifyAuth, isBranchUpToDate, getGitHead, tag, push} = require('./lib/git'); +const {verifyAuth, isBranchUpToDate, getGitHead, tag, push, getTagHead} = require('./lib/git'); const getError = require('./lib/get-error'); const {COMMIT_NAME, COMMIT_EMAIL} = require('./lib/definitions/constants'); @@ -97,6 +97,8 @@ async function run(context, plugins) { context.releases = []; await pEachSeries(releasesToAdd, async ({lastRelease, currentRelease, nextRelease}) => { + 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})); return; @@ -125,6 +127,9 @@ async function run(context, plugins) { } context.lastRelease = await getLastRelease(context); + if (context.lastRelease.gitHead) { + context.lastRelease.gitHead = await getTagHead(context.lastRelease.gitHead, {cwd, env}); + } if (context.lastRelease.gitTag) { logger.log( diff --git a/lib/branches/get-tags.js b/lib/branches/get-tags.js index 2f50a93845..2b9f4dd282 100644 --- a/lib/branches/get-tags.js +++ b/lib/branches/get-tags.js @@ -2,7 +2,7 @@ const {template, escapeRegExp} = require('lodash'); const semver = require('semver'); const pReduce = require('p-reduce'); const debug = require('debug')('semantic-release:get-tags'); -const {getTags, getTagHead} = require('../../lib/git'); +const {getTags} = require('../../lib/git'); module.exports = async ({cwd, env, options: {tagFormat}}, branches) => { // Generate a regex to parse tags formatted with `tagFormat` @@ -21,7 +21,7 @@ module.exports = async ({cwd, env, options: {tagFormat}}, branches) => { return {gitTag: tag, version, channel}; }) .filter(({version}) => version && semver.valid(semver.clean(version))) - .map(async ({gitTag, ...rest}) => ({gitTag, gitHead: await getTagHead(gitTag, {cwd, env}), ...rest})) + .map(async ({gitTag, ...rest}) => ({gitTag, ...rest})) ); debug('found tags for branch %s: %o', branch.name, branchTags); diff --git a/lib/get-last-release.js b/lib/get-last-release.js index 7ac63c3b89..58d2451ebb 100644 --- a/lib/get-last-release.js +++ b/lib/get-last-release.js @@ -7,7 +7,10 @@ const {makeTag} = require('./utils'); * * @typedef {Object} LastRelease * @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. */ /** @@ -24,13 +27,13 @@ const {makeTag} = require('./utils'); * @return {LastRelease} The last tagged release or empty object if none is found. */ module.exports = ({branch, options: {tagFormat}}, {before} = {}) => { - const [{version, gitTag, gitHead, channel} = {}] = branch.tags + const [{version, gitTag, channel} = {}] = branch.tags .filter(tag => (branch.type === 'prerelease' && branch.channel === tag.channel) || !semver.prerelease(tag.version)) .filter(tag => isUndefined(before) || semver.lt(tag.version, before)) .sort((a, b) => semver.rcompare(a.version, b.version)); if (gitTag) { - return {version, gitTag, gitHead, channel, name: makeTag(tagFormat, version)}; + return {version, gitTag, channel, gitHead: gitTag, name: makeTag(tagFormat, version)}; } return {}; diff --git a/lib/get-releases-to-add.js b/lib/get-releases-to-add.js index 5f27933215..0ccd11aeae 100644 --- a/lib/get-releases-to-add.js +++ b/lib/get-releases-to-add.js @@ -47,20 +47,20 @@ module.exports = context => { // Sort in ascending order to add the most recent release last .sort((a, b) => semver.compare(a.version, b.version)) // Construct the last and next release to add to the building branch channel - .map(({version, gitHead, gitTag}) => { + .map(({version, gitTag}) => { const lastRelease = getLastRelease(context, {before: version}); const type = lastRelease.version ? semverDiff(lastRelease.version, version) : 'major'; const name = makeTag(tagFormat, version); return { lastRelease, - currentRelease: {type, version, channel: higherBranch.channel, gitTag, name, gitHead}, + currentRelease: {type, version, channel: higherBranch.channel, gitTag, name, gitHead: gitTag}, nextRelease: { type, version, channel: branch.channel, gitTag: makeTag(tagFormat, version, branch.channel), name, - gitHead, + gitHead: gitTag, }, }; }), diff --git a/test/branches/get-tags.test.js b/test/branches/get-tags.test.js index 0be5ae536d..ab75163186 100644 --- a/test/branches/get-tags.test.js +++ b/test/branches/get-tags.test.js @@ -20,9 +20,9 @@ test('Get the valid tags', async t => { { name: 'master', tags: [ - {gitTag: 'v1.0.0', version: '1.0.0', channel: undefined, gitHead: commits[1].hash}, - {gitTag: 'v2.0.0', version: '2.0.0', channel: undefined, gitHead: commits[0].hash}, - {gitTag: 'v3.0.0-beta.1', version: '3.0.0-beta.1', channel: undefined, gitHead: commits[3].hash}, + {gitTag: 'v1.0.0', version: '1.0.0', channel: undefined}, + {gitTag: 'v2.0.0', version: '2.0.0', channel: undefined}, + {gitTag: 'v3.0.0-beta.1', version: '3.0.0-beta.1', channel: undefined}, ], }, ]); @@ -55,30 +55,30 @@ test('Get the valid tags from multiple branches', async t => { { name: '1.x', tags: [ - {gitTag: 'v1.0.0', version: '1.0.0', channel: undefined, gitHead: commits[0].hash}, - {gitTag: 'v1.0.0@1.x', version: '1.0.0', channel: '1.x', gitHead: commits[0].hash}, - {gitTag: 'v1.1.0', version: '1.1.0', channel: undefined, gitHead: commits[1].hash}, - {gitTag: 'v1.1.0@1.x', version: '1.1.0', channel: '1.x', gitHead: commits[1].hash}, + {gitTag: 'v1.0.0', version: '1.0.0', channel: undefined}, + {gitTag: 'v1.0.0@1.x', version: '1.0.0', channel: '1.x'}, + {gitTag: 'v1.1.0', version: '1.1.0', channel: undefined}, + {gitTag: 'v1.1.0@1.x', version: '1.1.0', channel: '1.x'}, ], }, { name: 'master', tags: [ ...result[0].tags, - {gitTag: 'v2.0.0', version: '2.0.0', channel: undefined, gitHead: commits[2].hash}, - {gitTag: 'v2.0.0@next', version: '2.0.0', channel: 'next', gitHead: commits[2].hash}, + {gitTag: 'v2.0.0', version: '2.0.0', channel: undefined}, + {gitTag: 'v2.0.0@next', version: '2.0.0', channel: 'next'}, ], }, { name: 'next', - tags: [...result[1].tags, {gitTag: 'v3.0.0@next', version: '3.0.0', channel: 'next', gitHead: commits[3].hash}], + tags: [...result[1].tags, {gitTag: 'v3.0.0@next', version: '3.0.0', channel: 'next'}], }, ]); }); test('Match the tag name from the begining of the string and the channel from the last "@"', async t => { const {cwd} = await gitRepo(); - const commits = await gitCommits(['First'], {cwd}); + await gitCommits(['First'], {cwd}); await gitTagVersion('prefix@v1.0.0', undefined, {cwd}); await gitTagVersion('prefix@v1.0.0@next', undefined, {cwd}); await gitTagVersion('prefix@v2.0.0', undefined, {cwd}); @@ -91,10 +91,10 @@ test('Match the tag name from the begining of the string and the channel from th { name: 'master', tags: [ - {gitTag: 'prefix@v1.0.0', version: '1.0.0', channel: undefined, gitHead: commits[0].hash}, - {gitTag: 'prefix@v1.0.0@next', version: '1.0.0', channel: 'next', gitHead: commits[0].hash}, - {gitTag: 'prefix@v2.0.0', version: '2.0.0', channel: undefined, gitHead: commits[0].hash}, - {gitTag: 'prefix@v2.0.0@next', version: '2.0.0', channel: 'next', gitHead: commits[0].hash}, + {gitTag: 'prefix@v1.0.0', version: '1.0.0', channel: undefined}, + {gitTag: 'prefix@v1.0.0@next', version: '1.0.0', channel: 'next'}, + {gitTag: 'prefix@v2.0.0', version: '2.0.0', channel: undefined}, + {gitTag: 'prefix@v2.0.0@next', version: '2.0.0', channel: 'next'}, ], }, ]); @@ -134,23 +134,23 @@ test('Return branches with and empty tags array if no valid tag is found in hist test('Get the highest valid tag corresponding to the "tagFormat"', async t => { const {cwd} = await gitRepo(); - const commits = await gitCommits(['First'], {cwd}); + 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', channel: undefined, gitHead: commits[0].hash}]}, + {name: 'master', tags: [{gitTag: '1.0.0', version: '1.0.0', channel: undefined}]}, ]); 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', channel: undefined, gitHead: commits[0].hash}]}, + {name: 'master', tags: [{gitTag: 'foo-1.0.0-bar', version: '1.0.0', channel: undefined}]}, ]); 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', channel: undefined, gitHead: commits[0].hash}], + tags: [{gitTag: 'foo-v1.0.0-bar', version: '1.0.0', channel: undefined}], }, ]); @@ -158,7 +158,7 @@ test('Get the highest valid tag corresponding to the "tagFormat"', async t => { 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', channel: undefined, gitHead: commits[0].hash}], + tags: [{gitTag: '(.+)/1.0.0/(a-z)', version: '1.0.0', channel: undefined}], }, ]); @@ -166,12 +166,12 @@ test('Get the highest valid tag corresponding to the "tagFormat"', async t => { 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', channel: undefined, gitHead: commits[0].hash}], + tags: [{gitTag: '2.0.0-1.0.0-bar.1', version: '1.0.0', channel: undefined}], }, ]); 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', channel: undefined, gitHead: commits[0].hash}]}, + {name: 'master', tags: [{gitTag: '3.0.0-bar.2', version: '3.0.0', channel: undefined}]}, ]); }); diff --git a/test/get-last-release.test.js b/test/get-last-release.test.js index 759739ab67..43a5ddf5b9 100644 --- a/test/get-last-release.test.js +++ b/test/get-last-release.test.js @@ -6,16 +6,16 @@ test('Get the highest non-prerelease valid tag', t => { branch: { name: 'master', tags: [ - {version: '2.0.0', gitTag: 'v2.0.0', gitHead: '222'}, - {version: '1.0.0', gitTag: 'v1.0.0', gitHead: '111'}, - {version: '3.0.0-beta.1', gitTag: 'v3.0.0-beta.1@beta', gitHead: '333'}, + {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@beta', gitHead: 'v3.0.0-beta.1@beta'}, ], type: 'release', }, options: {tagFormat: `v\${version}`}, }); - t.deepEqual(result, {version: '2.0.0', gitTag: 'v2.0.0', name: 'v2.0.0', gitHead: '222', channel: undefined}); + t.deepEqual(result, {version: '2.0.0', gitTag: 'v2.0.0', name: 'v2.0.0', gitHead: 'v2.0.0', channel: undefined}); }); test('Get the highest prerelease valid tag, ignoring other tags from other prerelease channels', t => { @@ -25,9 +25,9 @@ test('Get the highest prerelease valid tag, ignoring other tags from other prere prerelease: 'beta', channel: 'beta', tags: [ - {version: '1.0.0-beta.1', gitTag: 'v1.0.0-beta.1@beta', gitHead: '111', channel: 'beta'}, - {version: '1.0.0-beta.2', gitTag: 'v1.0.0-beta.2@beta', gitHead: '222', channel: 'beta'}, - {version: '1.0.0-alpha.1', gitTag: 'v1.0.0-alpha.1@alpha', gitHead: '333', channel: 'alpha'}, + {version: '1.0.0-beta.1', gitTag: 'v1.0.0-beta.1@beta', gitHead: 'v1.0.0-beta.1@beta', channel: 'beta'}, + {version: '1.0.0-beta.2', gitTag: 'v1.0.0-beta.2@beta', gitHead: 'v1.0.0-beta.2@beta', channel: 'beta'}, + {version: '1.0.0-alpha.1', gitTag: 'v1.0.0-alpha.1@alpha', gitHead: 'v1.0.0-alpha.1@alpha', channel: 'alpha'}, ], type: 'prerelease', }, @@ -38,7 +38,7 @@ test('Get the highest prerelease valid tag, ignoring other tags from other prere version: '1.0.0-beta.2', gitTag: 'v1.0.0-beta.2@beta', name: 'v1.0.0-beta.2', - gitHead: '222', + gitHead: 'v1.0.0-beta.2@beta', channel: 'beta', }); }); @@ -47,7 +47,7 @@ test('Return empty object if no valid tag is found', t => { const result = getLastRelease({ branch: { name: 'master', - tags: [{version: '3.0.0-beta.1', gitTag: 'v3.0.0-beta.1@beta', gitHead: '111'}], + tags: [{version: '3.0.0-beta.1', gitTag: 'v3.0.0-beta.1@beta', gitHead: 'v3.0.0-beta.1@beta'}], type: 'release', }, options: {tagFormat: `v\${version}`}, @@ -63,11 +63,11 @@ test('Get the highest non-prerelease valid tag before a certain version', t => { name: 'master', channel: undefined, tags: [ - {version: '2.0.0', gitTag: 'v2.0.0', gitHead: '333'}, - {version: '1.0.0', gitTag: 'v1.0.0', gitHead: '111'}, - {version: '2.0.0-beta.1', gitTag: 'v2.0.0-beta.1@beta', gitHead: '222'}, - {version: '2.1.0', gitTag: 'v2.1.0', gitHead: '444'}, - {version: '2.1.1', gitTag: 'v2.1.1', gitHead: '555'}, + {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: '2.0.0-beta.1', gitTag: 'v2.0.0-beta.1@beta', gitHead: 'v2.0.0-beta.1@beta'}, + {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', }, @@ -76,5 +76,5 @@ test('Get the highest non-prerelease valid tag before a certain version', t => { {before: '2.1.0'} ); - t.deepEqual(result, {version: '2.0.0', gitTag: 'v2.0.0', name: 'v2.0.0', gitHead: '333', channel: undefined}); + t.deepEqual(result, {version: '2.0.0', gitTag: 'v2.0.0', name: 'v2.0.0', gitHead: 'v2.0.0', channel: undefined}); }); diff --git a/test/get-releases-to-add.test.js b/test/get-releases-to-add.test.js index 3e3dc5fe72..7e6b03574a 100644 --- a/test/get-releases-to-add.test.js +++ b/test/get-releases-to-add.test.js @@ -9,12 +9,12 @@ test('Return versions merged from release to maintenance branch, excluding lower type: 'maintenance', mergeRange: '>=2.0.0 <3.0.0', tags: [ - {gitTag: 'v2.0.0@2.x', version: '2.0.0', channel: '2.x', gitHead: '111'}, - {gitTag: 'v2.0.0', version: '2.0.0', gitHead: '111'}, - {gitTag: 'v2.1.0', version: '2.1.0', gitHead: '222'}, - {gitTag: 'v2.1.1', version: '2.1.1', gitHead: '333'}, - {gitTag: 'v1.0.0', version: '1.0.0', gitHead: '444'}, - {gitTag: 'v1.1.0', version: '1.1.0', gitHead: '555'}, + {gitTag: 'v2.0.0@2.x', version: '2.0.0', channel: '2.x'}, + {gitTag: 'v2.0.0', version: '2.0.0'}, + {gitTag: 'v2.1.0', version: '2.1.0'}, + {gitTag: 'v2.1.1', version: '2.1.1'}, + {gitTag: 'v1.0.0', version: '1.0.0'}, + {gitTag: 'v1.1.0', version: '1.1.0'}, ], }, branches: [{name: '2.x', channel: '2.x'}, {name: 'master'}], @@ -23,14 +23,14 @@ test('Return versions merged from release to maintenance branch, excluding lower t.deepEqual(result, [ { - lastRelease: {version: '2.0.0', channel: '2.x', gitTag: 'v2.0.0@2.x', name: 'v2.0.0', gitHead: '111'}, + lastRelease: {version: '2.0.0', channel: '2.x', gitTag: 'v2.0.0@2.x', name: 'v2.0.0', gitHead: 'v2.0.0@2.x'}, currentRelease: { type: 'minor', version: '2.1.0', channel: undefined, gitTag: 'v2.1.0', name: 'v2.1.0', - gitHead: '222', + gitHead: 'v2.1.0', }, nextRelease: { type: 'minor', @@ -38,18 +38,18 @@ test('Return versions merged from release to maintenance branch, excluding lower channel: '2.x', gitTag: 'v2.1.0@2.x', name: 'v2.1.0', - gitHead: '222', + gitHead: 'v2.1.0', }, }, { - lastRelease: {version: '2.1.0', channel: undefined, gitTag: 'v2.1.0', name: 'v2.1.0', gitHead: '222'}, + lastRelease: {version: '2.1.0', channel: undefined, gitTag: 'v2.1.0', name: 'v2.1.0', gitHead: 'v2.1.0'}, currentRelease: { type: 'patch', version: '2.1.1', channel: undefined, gitTag: 'v2.1.1', name: 'v2.1.1', - gitHead: '333', + gitHead: 'v2.1.1', }, nextRelease: { type: 'patch', @@ -57,7 +57,7 @@ test('Return versions merged from release to maintenance branch, excluding lower channel: '2.x', gitTag: 'v2.1.1@2.x', name: 'v2.1.1', - gitHead: '333', + gitHead: 'v2.1.1', }, }, ]); @@ -68,10 +68,10 @@ test('Return versions merged between release branches', t => { branch: { name: 'master', tags: [ - {gitTag: 'v1.0.0', version: '1.0.0', gitHead: '111'}, - {gitTag: 'v1.0.0@next', version: '1.0.0', channel: 'next', gitHead: '111'}, - {gitTag: 'v1.1.0@next', version: '1.1.0', channel: 'next', gitHead: '222'}, - {gitTag: 'v2.0.0@next-major', version: '2.0.0', channel: 'next-major', gitHead: '333'}, + {gitTag: 'v1.0.0', version: '1.0.0'}, + {gitTag: 'v1.0.0@next', version: '1.0.0', channel: 'next'}, + {gitTag: 'v1.1.0@next', version: '1.1.0', channel: 'next'}, + {gitTag: 'v2.0.0@next-major', version: '2.0.0', channel: 'next-major'}, ], }, branches: [{name: 'master'}, {name: 'next', channel: 'next'}, {name: 'next-major', channel: 'next-major'}], @@ -80,14 +80,14 @@ test('Return versions merged between release branches', t => { t.deepEqual(result, [ { - lastRelease: {version: '1.0.0', channel: undefined, gitTag: 'v1.0.0', name: 'v1.0.0', gitHead: '111'}, + lastRelease: {version: '1.0.0', channel: undefined, gitTag: 'v1.0.0', name: 'v1.0.0', gitHead: 'v1.0.0'}, currentRelease: { type: 'minor', version: '1.1.0', channel: 'next', gitTag: 'v1.1.0@next', name: 'v1.1.0', - gitHead: '222', + gitHead: 'v1.1.0@next', }, nextRelease: { type: 'minor', @@ -95,18 +95,18 @@ test('Return versions merged between release branches', t => { channel: undefined, gitTag: 'v1.1.0', name: 'v1.1.0', - gitHead: '222', + gitHead: 'v1.1.0@next', }, }, { - lastRelease: {version: '1.1.0', gitTag: 'v1.1.0@next', name: 'v1.1.0', gitHead: '222', channel: 'next'}, + lastRelease: {version: '1.1.0', gitTag: 'v1.1.0@next', name: 'v1.1.0', gitHead: 'v1.1.0@next', channel: 'next'}, currentRelease: { type: 'major', version: '2.0.0', channel: 'next-major', gitTag: 'v2.0.0@next-major', name: 'v2.0.0', - gitHead: '333', + gitHead: 'v2.0.0@next-major', }, nextRelease: { type: 'major', @@ -114,7 +114,7 @@ test('Return versions merged between release branches', t => { channel: undefined, gitTag: 'v2.0.0', name: 'v2.0.0', - gitHead: '333', + gitHead: 'v2.0.0@next-major', }, }, ]); @@ -125,10 +125,10 @@ test('Return releases sorted by ascending order', t => { branch: { name: 'master', tags: [ - {gitTag: 'v2.0.0@next-major', version: '2.0.0', channel: 'next-major', gitHead: '333'}, - {gitTag: 'v1.1.0@next', version: '1.1.0', channel: 'next', gitHead: '222'}, - {gitTag: 'v1.0.0', version: '1.0.0', gitHead: '111'}, - {gitTag: 'v1.0.0@next', version: '1.0.0', channel: 'next', gitHead: '111'}, + {gitTag: 'v2.0.0@next-major', version: '2.0.0', channel: 'next-major'}, + {gitTag: 'v1.1.0@next', version: '1.1.0', channel: 'next'}, + {gitTag: 'v1.0.0', version: '1.0.0'}, + {gitTag: 'v1.0.0@next', version: '1.0.0', channel: 'next'}, ], }, branches: [{name: 'master'}, {name: 'next', channel: 'next'}, {name: 'next-major', channel: 'next-major'}], @@ -137,14 +137,14 @@ test('Return releases sorted by ascending order', t => { t.deepEqual(result, [ { - lastRelease: {version: '1.0.0', channel: undefined, gitTag: 'v1.0.0', name: 'v1.0.0', gitHead: '111'}, + lastRelease: {version: '1.0.0', channel: undefined, gitTag: 'v1.0.0', name: 'v1.0.0', gitHead: 'v1.0.0'}, currentRelease: { type: 'minor', version: '1.1.0', channel: 'next', gitTag: 'v1.1.0@next', name: 'v1.1.0', - gitHead: '222', + gitHead: 'v1.1.0@next', }, nextRelease: { type: 'minor', @@ -152,18 +152,18 @@ test('Return releases sorted by ascending order', t => { channel: undefined, gitTag: 'v1.1.0', name: 'v1.1.0', - gitHead: '222', + gitHead: 'v1.1.0@next', }, }, { - lastRelease: {version: '1.1.0', gitTag: 'v1.1.0@next', name: 'v1.1.0', gitHead: '222', channel: 'next'}, + lastRelease: {version: '1.1.0', gitTag: 'v1.1.0@next', name: 'v1.1.0', gitHead: 'v1.1.0@next', channel: 'next'}, currentRelease: { type: 'major', version: '2.0.0', channel: 'next-major', gitTag: 'v2.0.0@next-major', name: 'v2.0.0', - gitHead: '333', + gitHead: 'v2.0.0@next-major', }, nextRelease: { type: 'major', @@ -171,7 +171,7 @@ test('Return releases sorted by ascending order', t => { channel: undefined, gitTag: 'v2.0.0', name: 'v2.0.0', - gitHead: '333', + gitHead: 'v2.0.0@next-major', }, }, ]); @@ -179,7 +179,10 @@ test('Return releases sorted by ascending order', t => { test('No lastRelease', t => { const result = getReleasesToAdd({ - branch: {name: 'master', tags: [{gitTag: 'v1.0.0@next', version: '1.0.0', channel: 'next', gitHead: '111'}]}, + branch: { + name: 'master', + tags: [{gitTag: 'v1.0.0@next', version: '1.0.0', channel: 'next'}], + }, branches: [{name: 'master'}, {name: 'next', channel: 'next'}], options: {tagFormat: `v\${version}`}, }); @@ -193,7 +196,7 @@ test('No lastRelease', t => { channel: 'next', gitTag: 'v1.0.0@next', name: 'v1.0.0', - gitHead: '111', + gitHead: 'v1.0.0@next', }, nextRelease: { type: 'major', @@ -201,7 +204,7 @@ test('No lastRelease', t => { channel: undefined, gitTag: 'v1.0.0', name: 'v1.0.0', - gitHead: '111', + gitHead: 'v1.0.0@next', }, }, ]); @@ -212,10 +215,10 @@ test('Ignore pre-release versions', t => { branch: { name: 'master', tags: [ - {gitTag: 'v1.0.0', version: '1.0.0', gitHead: '111'}, - {gitTag: 'v1.0.0@next', version: '1.0.0', channel: 'next', gitHead: '111'}, - {gitTag: 'v1.1.0@next', version: '1.1.0', channel: 'next', gitHead: '222'}, - {gitTag: 'v2.0.0-alpha.1@alpha', version: '2.0.0', channel: 'alpha', gitHead: '333'}, + {gitTag: 'v1.0.0', version: '1.0.0'}, + {gitTag: 'v1.0.0@next', version: '1.0.0', channel: 'next'}, + {gitTag: 'v1.1.0@next', version: '1.1.0', channel: 'next'}, + {gitTag: 'v2.0.0-alpha.1@alpha', version: '2.0.0', channel: 'alpha'}, ], }, branches: [ @@ -228,14 +231,14 @@ test('Ignore pre-release versions', t => { t.deepEqual(result, [ { - lastRelease: {version: '1.0.0', channel: undefined, gitTag: 'v1.0.0', name: 'v1.0.0', gitHead: '111'}, + lastRelease: {version: '1.0.0', channel: undefined, gitTag: 'v1.0.0', name: 'v1.0.0', gitHead: 'v1.0.0'}, currentRelease: { type: 'minor', version: '1.1.0', channel: 'next', gitTag: 'v1.1.0@next', name: 'v1.1.0', - gitHead: '222', + gitHead: 'v1.1.0@next', }, nextRelease: { type: 'minor', @@ -243,7 +246,7 @@ test('Ignore pre-release versions', t => { channel: undefined, gitTag: 'v1.1.0', name: 'v1.1.0', - gitHead: '222', + gitHead: 'v1.1.0@next', }, }, ]); @@ -257,12 +260,12 @@ test('Exclude versions merged from release to maintenance branch if they have th type: 'maintenance', mergeRange: '>=2.0.0 <3.0.0', tags: [ - {gitTag: 'v2.0.0', version: '2.0.0', gitHead: '111'}, - {gitTag: 'v2.0.0', version: '2.0.0', gitHead: '111'}, - {gitTag: 'v2.1.0', version: '2.1.0', gitHead: '222'}, - {gitTag: 'v2.1.1', version: '2.1.1', gitHead: '333'}, - {gitTag: 'v1.0.0', version: '1.0.0', gitHead: '444'}, - {gitTag: 'v1.1.0', version: '1.1.0', gitHead: '555'}, + {gitTag: 'v2.0.0', version: '2.0.0'}, + {gitTag: 'v2.0.0', version: '2.0.0'}, + {gitTag: 'v2.1.0', version: '2.1.0'}, + {gitTag: 'v2.1.1', version: '2.1.1'}, + {gitTag: 'v1.0.0', version: '1.0.0'}, + {gitTag: 'v1.1.0', version: '1.1.0'}, ], }, branches: [{name: '2.x', channel: 'latest'}, {name: 'master', channel: 'latest'}], @@ -278,9 +281,9 @@ test('Exclude versions merged between release branches if they have the same "ch name: 'master', channel: 'latest', tags: [ - {gitTag: 'v1.0.0', channel: 'latest', version: '1.0.0', gitHead: '111'}, - {gitTag: 'v1.1.0', channel: 'latest', version: '1.1.0', gitHead: '222'}, - {gitTag: 'v2.0.0', channel: 'latest', version: '2.0.0', gitHead: '333'}, + {gitTag: 'v1.0.0', channel: 'latest', version: '1.0.0'}, + {gitTag: 'v1.1.0', channel: 'latest', version: '1.1.0'}, + {gitTag: 'v2.0.0', channel: 'latest', version: '2.0.0'}, ], }, branches: [ @@ -300,9 +303,9 @@ test('Exclude versions merged between release branches if they all have "channel name: 'master', channel: false, tags: [ - {gitTag: 'v1.0.0', version: '1.0.0', gitHead: '111'}, - {gitTag: 'v1.1.0', version: '1.1.0', gitHead: '222'}, - {gitTag: 'v2.0.0', version: '2.0.0', gitHead: '333'}, + {gitTag: 'v1.0.0', version: '1.0.0'}, + {gitTag: 'v1.1.0', version: '1.1.0'}, + {gitTag: 'v2.0.0', version: '2.0.0'}, ], }, branches: [{name: 'master', channel: false}, {name: 'next', channel: false}, {name: 'next-major', channel: false}], diff --git a/test/index.test.js b/test/index.test.js index e620058b95..7fd441fba7 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -96,7 +96,7 @@ test('Plugins are called with expected values', async t => { name: 'master', range: '>=1.0.0 <2.0.0', accept: ['patch', 'minor'], - tags: [{channel: 'next', gitTag: 'v1.0.0@next', version: '1.0.0', gitHead: commits[commits.length - 1].hash}], + tags: [{channel: 'next', gitTag: 'v1.0.0@next', version: '1.0.0'}], type: 'release', }, { @@ -104,7 +104,7 @@ test('Plugins are called with expected values', async t => { name: 'next', range: '>=2.0.0', accept: ['patch', 'minor', 'major'], - tags: [{channel: 'next', gitHead: commits[commits.length - 1].hash, gitTag: 'v1.0.0@next', version: '1.0.0'}], + tags: [{channel: 'next', gitTag: 'v1.0.0@next', version: '1.0.0'}], type: 'release', }, ]; From 131734873e904176044767ad929b5f53579556f6 Mon Sep 17 00:00:00 2001 From: Pierre Vanduynslager Date: Thu, 7 Nov 2019 14:16:23 -0500 Subject: [PATCH 084/107] fix: throws error if the commit associated with a tag cannot be found --- lib/git.js | 6 +----- test/git.test.js | 3 +-- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/lib/git.js b/lib/git.js index db8447e9c9..a2956ddeb2 100644 --- a/lib/git.js +++ b/lib/git.js @@ -14,11 +14,7 @@ Object.assign(gitLogParser.fields, {hash: 'H', message: 'B', gitTags: 'd', commi * @return {String} The commit sha of the tag in parameter or `null`. */ async function getTagHead(tagName, execaOpts) { - try { - return (await execa('git', ['rev-list', '-1', tagName], execaOpts)).stdout; - } catch (error) { - debug(error); - } + return (await execa('git', ['rev-list', '-1', tagName], execaOpts)).stdout; } /** diff --git a/test/git.test.js b/test/git.test.js index 34e5000d61..7383f15649 100644 --- a/test/git.test.js +++ b/test/git.test.js @@ -140,7 +140,7 @@ test('Get all branches', async t => { t.deepEqual((await getBranches(repositoryUrl, {cwd})).sort(), ['master', 'second-branch', 'third-branch'].sort()); }); -test('Get the commit sha for a given tag or falsy if the tag does not exists', async t => { +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 const {cwd} = await gitRepo(); // Add commits to the master branch @@ -149,7 +149,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}); 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 => { From 00420a83c0283e7b02a5385d78d0ec984120a852 Mon Sep 17 00:00:00 2001 From: Pierre Vanduynslager Date: Fri, 8 Nov 2019 11:30:43 -0500 Subject: [PATCH 085/107] fix: simplify `get-tags` algorithm --- lib/branches/get-tags.js | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/lib/branches/get-tags.js b/lib/branches/get-tags.js index 2b9f4dd282..adefcb317b 100644 --- a/lib/branches/get-tags.js +++ b/lib/branches/get-tags.js @@ -14,15 +14,10 @@ module.exports = async ({cwd, env, options: {tagFormat}}, branches) => { return pReduce( branches, async (branches, branch) => { - const branchTags = await Promise.all( - (await getTags(branch.name, {cwd, env})) - .map(tag => { - const [, version, channel] = tag.match(tagRegexp) || []; - return {gitTag: tag, version, channel}; - }) - .filter(({version}) => version && semver.valid(semver.clean(version))) - .map(async ({gitTag, ...rest}) => ({gitTag, ...rest})) - ); + const branchTags = (await getTags(branch.name, {cwd, env})).reduce((tags, tag) => { + const [, version, channel] = tag.match(tagRegexp) || []; + return version && semver.valid(semver.clean(version)) ? [...tags, {gitTag: tag, version, channel}] : tags; + }, []); debug('found tags for branch %s: %o', branch.name, branchTags); return [...branches, {...branch, tags: branchTags}]; From 751a5f1349c6bf415f6eaae4631118f163e45b77 Mon Sep 17 00:00:00 2001 From: Pierre Vanduynslager Date: Wed, 20 Nov 2019 14:00:22 -0500 Subject: [PATCH 086/107] fix: handle branch properties set to `false` --- lib/definitions/branches.js | 8 ++++---- test/definitions/branches.test.js | 14 +++++++------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/definitions/branches.js b/lib/definitions/branches.js index 1a2ddd7ea8..172082c4b9 100644 --- a/lib/definitions/branches.js +++ b/lib/definitions/branches.js @@ -1,15 +1,15 @@ -const {isUndefined, uniqBy} = require('lodash'); +const {isNil, uniqBy} = require('lodash'); const semver = require('semver'); const {isMaintenanceRange} = require('../utils'); const maintenance = { - filter: ({name, range}) => !isUndefined(range) || isMaintenanceRange(name), - branchValidator: ({range}) => (isUndefined(range) ? true : isMaintenanceRange(range)), + 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}) => !isUndefined(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, diff --git a/test/definitions/branches.test.js b/test/definitions/branches.test.js index 22d48416b1..222334d054 100644 --- a/test/definitions/branches.test.js +++ b/test/definitions/branches.test.js @@ -8,9 +8,10 @@ test('A "maintenance" branch is identified by having a "range" property or a "na 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: null})); - t.true(maintenance.filter({name: 'some-name', range: false})); + 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'})); @@ -24,9 +25,8 @@ test('A "maintenance" branches must have a "range" property formatted like "N.x" 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: ''})); - t.false(maintenance.branchValidator({name: 'some-name', range: null})); - t.false(maintenance.branchValidator({name: 'some-name', range: false})); }); test('The "maintenance" branches must have unique ranges', t => { @@ -36,13 +36,13 @@ test('The "maintenance" branches must have unique ranges', t => { t.false(maintenance.branchesValidator([{range: '1.x.x'}, {range: '1.x'}])); }); -test('A "prerelease" branch is identified by having a range "prerelease" property', t => { +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.true(prerelease.filter({name: 'some-name', prerelease: null})); - t.true(prerelease.filter({name: 'some-name', prerelease: false})); + 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'})); }); From e06eb82cfff6b6b90057a410cf2d3b3c6ca60637 Mon Sep 17 00:00:00 2001 From: Pierre Vanduynslager Date: Wed, 20 Nov 2019 14:00:39 -0500 Subject: [PATCH 087/107] chore: add Mockserver generated file to gitignore --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 058ab6905b..59d5cc4872 100644 --- a/.gitignore +++ b/.gitignore @@ -131,3 +131,6 @@ yarn.lock # Gitbook _book + +# Mockserver +CertificateAuthorityCertificate.pem From 20e7a38cdb5af95f5af98153765060b182d198e3 Mon Sep 17 00:00:00 2001 From: Pierre Vanduynslager Date: Wed, 20 Nov 2019 14:03:22 -0500 Subject: [PATCH 088/107] style: prettier formatting --- lib/git.js | 12 ++++---- test/branches/branches.test.js | 10 +++++-- test/branches/get-tags.test.js | 5 +++- test/branches/normalize.test.js | 47 +++++++++++++++++++++----------- test/get-releases-to-add.test.js | 11 ++++++-- test/helpers/git-utils.js | 8 ++++-- test/plugins/pipeline.test.js | 21 ++++++++++++-- 7 files changed, 82 insertions(+), 32 deletions(-) diff --git a/lib/git.js b/lib/git.js index a2956ddeb2..58304df6be 100644 --- a/lib/git.js +++ b/lib/git.js @@ -42,12 +42,14 @@ async function getTags(branch, execaOpts) { * @return {Promise>} The list of commits between `from` and `to`. */ async function getCommits(from, to, execaOpts) { - return (await getStream.array( - gitLogParser.parse( - {_: `${from ? from + '..' : ''}${to}`}, - {cwd: execaOpts.cwd, env: {...process.env, ...execaOpts.env}} + return ( + await getStream.array( + gitLogParser.parse( + {_: `${from ? from + '..' : ''}${to}`}, + {cwd: execaOpts.cwd, env: {...process.env, ...execaOpts.env}} + ) ) - )).map(({message, gitTags, ...commit}) => ({...commit, message: message.trim(), gitTags: gitTags.trim()})); + ).map(({message, gitTags, ...commit}) => ({...commit, message: message.trim(), gitTags: gitTags.trim()})); } /** diff --git a/test/branches/branches.test.js b/test/branches/branches.test.js index 339099ef91..76ed0dd10b 100644 --- a/test/branches/branches.test.js +++ b/test/branches/branches.test.js @@ -171,7 +171,10 @@ test('Throw SemanticReleaseError for invalid configurations', async t => { }); test('Throw a SemanticReleaseError if there is duplicate branches', async t => { - const branches = [{name: 'master', tags: []}, {name: 'master', tags: []}]; + const branches = [ + {name: 'master', tags: []}, + {name: 'master', tags: []}, + ]; const getBranches = proxyquire('../../lib/branches', {'./get-tags': () => branches, './expand': () => []}); const errors = [...(await t.throwsAsync(getBranches('repositoryUrl', {options: {branches}})))]; @@ -183,7 +186,10 @@ test('Throw a SemanticReleaseError if there is duplicate branches', async t => { }); test('Throw a SemanticReleaseError for each invalid branch name', async t => { - const branches = [{name: '~master', tags: []}, {name: '^master', tags: []}]; + const branches = [ + {name: '~master', tags: []}, + {name: '^master', tags: []}, + ]; const getBranches = proxyquire('../../lib/branches', {'./get-tags': () => branches, './expand': () => []}); const errors = [...(await t.throwsAsync(getBranches('repositoryUrl', {options: {branches}})))]; diff --git a/test/branches/get-tags.test.js b/test/branches/get-tags.test.js index ab75163186..699886c75c 100644 --- a/test/branches/get-tags.test.js +++ b/test/branches/get-tags.test.js @@ -129,7 +129,10 @@ test('Return branches with and empty tags array if no valid tag is found in hist const result = await getTags({cwd, options: {tagFormat: `prefix@v\${version}`}}, [{name: 'master'}, {name: 'next'}]); - t.deepEqual(result, [{name: 'master', tags: []}, {name: 'next', tags: []}]); + t.deepEqual(result, [ + {name: 'master', tags: []}, + {name: 'next', tags: []}, + ]); }); test('Get the highest valid tag corresponding to the "tagFormat"', async t => { diff --git a/test/branches/normalize.test.js b/test/branches/normalize.test.js index 0316206039..d137af41e5 100644 --- a/test/branches/normalize.test.js +++ b/test/branches/normalize.test.js @@ -4,7 +4,11 @@ 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 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}) => ({ @@ -303,24 +307,35 @@ test('Prerelease branches', t => { {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'}, - ]); + 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 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}, - ]); + 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}] + ); }); diff --git a/test/get-releases-to-add.test.js b/test/get-releases-to-add.test.js index 7e6b03574a..e7fdb32f47 100644 --- a/test/get-releases-to-add.test.js +++ b/test/get-releases-to-add.test.js @@ -268,7 +268,10 @@ test('Exclude versions merged from release to maintenance branch if they have th {gitTag: 'v1.1.0', version: '1.1.0'}, ], }, - branches: [{name: '2.x', channel: 'latest'}, {name: 'master', channel: 'latest'}], + branches: [ + {name: '2.x', channel: 'latest'}, + {name: 'master', channel: 'latest'}, + ], options: {tagFormat: `v\${version}`}, }); @@ -308,7 +311,11 @@ test('Exclude versions merged between release branches if they all have "channel {gitTag: 'v2.0.0', version: '2.0.0'}, ], }, - branches: [{name: 'master', channel: false}, {name: 'next', channel: false}, {name: 'next-major', channel: false}], + branches: [ + {name: 'master', channel: false}, + {name: 'next', channel: false}, + {name: 'next-major', channel: false}, + ], options: {tagFormat: `v\${version}`}, }); diff --git a/test/helpers/git-utils.js b/test/helpers/git-utils.js index 2019d561b8..0473bb3de2 100644 --- a/test/helpers/git-utils.js +++ b/test/helpers/git-utils.js @@ -86,9 +86,11 @@ export async function gitCommits(messages, execaOpts) { */ export async function gitGetCommits(from, execaOpts) { Object.assign(gitLogParser.fields, {hash: 'H', message: 'B', gitTags: 'd', committerDate: {key: 'ci', type: Date}}); - return (await getStream.array( - gitLogParser.parse({_: `${from ? from + '..' : ''}HEAD`}, {...execaOpts, env: {...process.env, ...execaOpts.env}}) - )).map(commit => { + return ( + await getStream.array( + gitLogParser.parse({_: `${from ? from + '..' : ''}HEAD`}, {...execaOpts, env: {...process.env, ...execaOpts.env}}) + ) + ).map(commit => { commit.message = commit.message.trim(); commit.gitTags = commit.gitTags.trim(); return commit; diff --git a/test/plugins/pipeline.test.js b/test/plugins/pipeline.test.js index 6c58129e30..d3f6e43431 100644 --- a/test/plugins/pipeline.test.js +++ b/test/plugins/pipeline.test.js @@ -47,7 +47,12 @@ test('Execute each function in series passing the "lastResult" and "result" to " const result = await pipeline([step1, step2, step3, step4], {settleAll: false, getNextInput})(5); t.deepEqual(result, [1, 2, 3, 4]); - t.deepEqual(getNextInput.args, [[5, 1], [5, 2], [5, 3], [5, 4]]); + t.deepEqual(getNextInput.args, [ + [5, 1], + [5, 2], + [5, 3], + [5, 4], + ]); }); test('Execute each function in series calling "transform" to modify the results', async t => { @@ -61,7 +66,12 @@ test('Execute each function in series calling "transform" to modify the results' const result = await pipeline([step1, step2, step3, step4], {getNextInput, transform})(5); t.deepEqual(result, [1 + 1, 2 + 1, 3 + 1, 4 + 1]); - t.deepEqual(getNextInput.args, [[5, 1 + 1], [5, 2 + 1], [5, 3 + 1], [5, 4 + 1]]); + t.deepEqual(getNextInput.args, [ + [5, 1 + 1], + [5, 2 + 1], + [5, 3 + 1], + [5, 4 + 1], + ]); }); test('Execute each function in series calling "transform" to modify the results with "settleAll"', async t => { @@ -75,7 +85,12 @@ test('Execute each function in series calling "transform" to modify the results const result = await pipeline([step1, step2, step3, step4], {settleAll: true, getNextInput, transform})(5); t.deepEqual(result, [1 + 1, 2 + 1, 3 + 1, 4 + 1]); - t.deepEqual(getNextInput.args, [[5, 1 + 1], [5, 2 + 1], [5, 3 + 1], [5, 4 + 1]]); + t.deepEqual(getNextInput.args, [ + [5, 1 + 1], + [5, 2 + 1], + [5, 3 + 1], + [5, 4 + 1], + ]); }); test('Stop execution and throw error if a step rejects', async t => { From 63f51ae6ddfa824fa217ca196c4dd44915b80f2b Mon Sep 17 00:00:00 2001 From: Pierre Vanduynslager Date: Wed, 20 Nov 2019 16:10:01 -0500 Subject: [PATCH 089/107] fix: allow multiple branches with same channel --- docs/usage/workflow-configuration.md | 8 +- lib/get-last-release.js | 7 +- lib/get-next-version.js | 3 +- lib/utils.js | 5 ++ test/index.test.js | 111 +++++++++++++++++++++++++++ test/utils.test.js | 10 +++ 6 files changed, 138 insertions(+), 6 deletions(-) diff --git a/docs/usage/workflow-configuration.md b/docs/usage/workflow-configuration.md index aee88c614f..c2d27265d9 100644 --- a/docs/usage/workflow-configuration.md +++ b/docs/usage/workflow-configuration.md @@ -48,8 +48,10 @@ For example the configuration `['+([0-9])?(.{+([0-9]),x}).x', 'master', 'next']` ### channel -The `channel` can be defined for any branch type. If it's not defined, releases will be done on the default distribution channel (for example the `@latest` [dist-tag](https://docs.npmjs.com/cli/dist-tag) for npm). -The value of `channel`, if defined, is generated with [Lodash template](https://lodash.com/docs#template) with the variable `name` available. +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 @@ -78,7 +80,7 @@ For example the configuration `['1.1.x', '1.2.x', 'master']` will be expanded as ### prerelease -A `prerelease` property applies only to pre-release branches, is required 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...). +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. diff --git a/lib/get-last-release.js b/lib/get-last-release.js index 58d2451ebb..6c4bf50c6e 100644 --- a/lib/get-last-release.js +++ b/lib/get-last-release.js @@ -1,6 +1,6 @@ const {isUndefined} = require('lodash'); const semver = require('semver'); -const {makeTag} = require('./utils'); +const {makeTag, isSameChannel} = require('./utils'); /** * Last release. @@ -28,7 +28,10 @@ const {makeTag} = require('./utils'); */ module.exports = ({branch, options: {tagFormat}}, {before} = {}) => { const [{version, gitTag, channel} = {}] = branch.tags - .filter(tag => (branch.type === 'prerelease' && branch.channel === tag.channel) || !semver.prerelease(tag.version)) + .filter( + tag => + (branch.type === 'prerelease' && isSameChannel(branch.channel, tag.channel)) || !semver.prerelease(tag.version) + ) .filter(tag => isUndefined(before) || semver.lt(tag.version, before)) .sort((a, b) => semver.rcompare(a.version, b.version)); diff --git a/lib/get-next-version.js b/lib/get-next-version.js index 19b9e2991c..825f77d63b 100644 --- a/lib/get-next-version.js +++ b/lib/get-next-version.js @@ -1,5 +1,6 @@ const semver = require('semver'); const {FIRST_RELEASE, FIRSTPRERELEASE} = require('./definitions/constants'); +const {isSameChannel} = require('./utils'); module.exports = ({branch, nextRelease: {type, channel}, lastRelease, logger}) => { let version; @@ -7,7 +8,7 @@ module.exports = ({branch, nextRelease: {type, channel}, lastRelease, logger}) = const {major, minor, patch} = semver.parse(lastRelease.version); version = branch.type === 'prerelease' - ? semver.prerelease(lastRelease.version) && lastRelease.channel === channel + ? semver.prerelease(lastRelease.version) && isSameChannel(lastRelease.channel, channel) ? semver.inc(lastRelease.version, 'prerelease') : `${semver.inc(`${major}.${minor}.${patch}`, type)}-${branch.prerelease}.${FIRSTPRERELEASE}` : semver.inc(lastRelease.version, type); diff --git a/lib/utils.js b/lib/utils.js index 9497026bdd..ef8463f712 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -71,6 +71,10 @@ function makeTag(tagFormat, version, channel) { return template(tagFormat)({version: `${version}${channel ? `@${channel}` : ''}`}); } +function isSameChannel(channel, otherChannel) { + return channel === otherChannel || (!channel && !otherChannel); +} + module.exports = { extractErrors, hideSensitiveValues, @@ -86,4 +90,5 @@ module.exports = { getFirstVersion, getRange, makeTag, + isSameChannel, }; diff --git a/test/index.test.js b/test/index.test.js index 7fd441fba7..d7f0b54ad7 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -581,6 +581,117 @@ test('Publish a pre-release version', async t => { t.is(releases[0].gitTag, 'v1.1.0-beta.2@beta'); }); +test('Publish releases from different branch on the same channel', async t => { + const {cwd, repositoryUrl} = await gitRepo(true); + await gitCommits(['feat: initial commit'], {cwd}); + await gitTagVersion('v1.0.0', undefined, {cwd}); + await gitPush(repositoryUrl, 'master', {cwd}); + await gitCheckout('next-major', true, {cwd}); + await gitPush(repositoryUrl, 'next-major', {cwd}); + await gitCheckout('next', true, {cwd}); + await gitCommits(['feat: a feature'], {cwd}); + await gitPush(repositoryUrl, 'next', {cwd}); + + const config = { + branches: ['master', {name: 'next', channel: false}, {name: 'next-major', channel: false}], + repositoryUrl, + }; + const addChannel = stub().resolves({}); + const options = { + ...config, + verifyConditions: stub().resolves(), + verifyRelease: stub().resolves(), + generateNotes: stub().resolves(''), + addChannel, + prepare: stub().resolves(), + publish: stub().resolves(), + success: stub().resolves(), + fail: stub().resolves(), + }; + + let semanticRelease = requireNoCache('..', { + './lib/get-logger': () => t.context.logger, + 'env-ci': () => ({isCi: true, branch: 'next', isPr: false}), + }); + let {releases} = await semanticRelease(options, {cwd, env: {}, stdout: {write: () => {}}, stderr: {write: () => {}}}); + + t.is(releases.length, 1); + t.is(releases[0].version, '1.1.0'); + t.is(releases[0].gitTag, 'v1.1.0'); + + await gitCommits(['fix: a fix'], {cwd}); + ({releases} = await semanticRelease(options, { + cwd, + env: {}, + stdout: {write: () => {}}, + stderr: {write: () => {}}, + })); + + t.is(releases.length, 1); + t.is(releases[0].version, '1.1.1'); + t.is(releases[0].gitTag, 'v1.1.1'); + + await gitCheckout('master', false, {cwd}); + await merge('next', {cwd}); + await gitPush('origin', 'master', {cwd}); + + semanticRelease = requireNoCache('..', { + './lib/get-logger': () => t.context.logger, + 'env-ci': () => ({isCi: true, branch: 'master', isPr: false}), + }); + + t.falsy(await semanticRelease(options, {cwd, env: {}, stdout: {write: () => {}}, stderr: {write: () => {}}})); + t.is(addChannel.callCount, 0); +}); + +test('Publish pre-releases the same channel as regular releases', async t => { + const {cwd, repositoryUrl} = await gitRepo(true); + await gitCommits(['feat: initial commit'], {cwd}); + await gitTagVersion('v1.0.0', undefined, {cwd}); + await gitPush(repositoryUrl, 'master', {cwd}); + await gitCheckout('beta', true, {cwd}); + await gitCommits(['feat: a feature'], {cwd}); + await gitPush(repositoryUrl, 'beta', {cwd}); + + const config = { + branches: ['master', {name: 'beta', channel: false, prerelease: true}], + repositoryUrl, + }; + const options = { + ...config, + verifyConditions: stub().resolves(), + verifyRelease: stub().resolves(), + generateNotes: stub().resolves(''), + addChannel: false, + prepare: stub().resolves(), + publish: stub().resolves(), + success: stub().resolves(), + fail: stub().resolves(), + }; + + const semanticRelease = requireNoCache('..', { + './lib/get-logger': () => t.context.logger, + 'env-ci': () => ({isCi: true, branch: 'beta', isPr: false}), + }); + let {releases} = await semanticRelease(options, {cwd, env: {}, stdout: {write: () => {}}, stderr: {write: () => {}}}); + + t.is(releases.length, 1); + t.is(releases[0].version, '1.1.0-beta.1'); + t.is(releases[0].gitTag, 'v1.1.0-beta.1'); + + await gitCommits(['fix: a fix'], {cwd}); + ({releases} = await semanticRelease(options, { + cwd, + env: {}, + stdout: {write: () => {}}, + stderr: {write: () => {}}, + })); + + t.is(releases.length, 1); + t.is(releases[0].version, '1.1.0-beta.2'); + t.is(releases[0].gitTag, 'v1.1.0-beta.2'); +}); + test('Do not add pre-releases to a different channel', async t => { const {cwd, repositoryUrl} = await gitRepo(true); const commits = await gitCommits(['feat: initial release'], {cwd}); diff --git a/test/utils.test.js b/test/utils.test.js index 08b4ebd97c..2130883893 100644 --- a/test/utils.test.js +++ b/test/utils.test.js @@ -14,6 +14,7 @@ import { getFirstVersion, getRange, makeTag, + isSameChannel, } from '../lib/utils'; test('extractErrors', t => { @@ -178,3 +179,12 @@ test('makeTag', t => { t.is(makeTag(`v\${version}`, '1.0.0', 'next'), 'v1.0.0@next'); t.is(makeTag(`v\${version}@test`, '1.0.0', 'next'), 'v1.0.0@next@test'); }); + +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)); +}); From 989058400785e0a1eefd70158f677de3be5a578d Mon Sep 17 00:00:00 2001 From: Eddie Date: Wed, 20 Nov 2019 20:29:59 -0700 Subject: [PATCH 090/107] fix: update plugins dependencies --- package.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 3d64734d25..b9e3f24d1c 100644 --- a/package.json +++ b/package.json @@ -22,10 +22,10 @@ "Pierre Vanduynslager (https://twitter.com/@pvdlg_)" ], "dependencies": { - "@semantic-release/commit-analyzer": "7.0.0-beta.4", + "@semantic-release/commit-analyzer": "^7.0.0-beta", "@semantic-release/error": "^2.2.0", - "@semantic-release/github": "5.6.0-beta.2", - "@semantic-release/npm": "6.0.0-beta.3", + "@semantic-release/github": "^5.6.0-beta", + "@semantic-release/npm": "^6.0.0-beta", "@semantic-release/release-notes-generator": "^7.1.2", "aggregate-error": "^3.0.0", "cosmiconfig": "^5.0.1", From 8d8910577f0702087684e360e3c92ee6cc5793a0 Mon Sep 17 00:00:00 2001 From: Eddie Leffler <757524+hershmire@users.noreply.github.com> Date: Wed, 20 Nov 2019 21:03:24 -0700 Subject: [PATCH 091/107] fix: update commit-analyzer dep version off errant publish --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b9e3f24d1c..b0c1899786 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ "Pierre Vanduynslager (https://twitter.com/@pvdlg_)" ], "dependencies": { - "@semantic-release/commit-analyzer": "^7.0.0-beta", + "@semantic-release/commit-analyzer": "7.0.0-beta.6", "@semantic-release/error": "^2.2.0", "@semantic-release/github": "^5.6.0-beta", "@semantic-release/npm": "^6.0.0-beta", From 1275b8c0059a877c7e4869d5f1fb7c3e27581b6f Mon Sep 17 00:00:00 2001 From: Pierre Vanduynslager Date: Sat, 23 Nov 2019 10:58:29 -0500 Subject: [PATCH 092/107] revert: fix: update commit-analyzer dep version off errant publish This reverts commit 8d8910577f0702087684e360e3c92ee6cc5793a0. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b0c1899786..b9e3f24d1c 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ "Pierre Vanduynslager (https://twitter.com/@pvdlg_)" ], "dependencies": { - "@semantic-release/commit-analyzer": "7.0.0-beta.6", + "@semantic-release/commit-analyzer": "^7.0.0-beta", "@semantic-release/error": "^2.2.0", "@semantic-release/github": "^5.6.0-beta", "@semantic-release/npm": "^6.0.0-beta", From 5744c5ecd2025d2bda7983f6e225ade1dff0f00c Mon Sep 17 00:00:00 2001 From: Pierre Vanduynslager Date: Wed, 27 Nov 2019 14:41:11 -0500 Subject: [PATCH 093/107] fix: add `channel` to publish success log --- index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 266429a89a..83dba95893 100644 --- a/index.js +++ b/index.js @@ -185,7 +185,9 @@ async function run(context, plugins) { 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) { logger.log(`Release note for version ${nextRelease.version}:`); From aec96c791f7413dace1bfdca08f7a5cd58cb0f5e Mon Sep 17 00:00:00 2001 From: Pierre Vanduynslager Date: Wed, 27 Nov 2019 15:08:40 -0500 Subject: [PATCH 094/107] fix: correctly determine release to add to a channel - Add only the most recent release to a channel (rather than adding all the one not added yet) - Avoid attempting to ad the version twice in case that version is already present in multiple upper branches --- index.js | 49 ++--- lib/branches/get-tags.js | 19 +- lib/get-last-release.js | 7 +- lib/get-next-version.js | 3 +- lib/get-release-to-add.js | 60 ++++++ lib/get-releases-to-add.js | 71 ------- test/branches/get-tags.test.js | 38 ++-- test/get-last-release.test.js | 17 +- test/get-next-version.test.js | 24 +-- test/get-release-to-add.test.js | 283 +++++++++++++++++++++++++++ test/get-releases-to-add.test.js | 323 ------------------------------- test/index.test.js | 47 ++--- test/integration.test.js | 2 +- 13 files changed, 440 insertions(+), 503 deletions(-) create mode 100644 lib/get-release-to-add.js delete mode 100644 lib/get-releases-to-add.js create mode 100644 test/get-release-to-add.test.js delete mode 100644 test/get-releases-to-add.test.js diff --git a/index.js b/index.js index 83dba95893..4e33d6c408 100644 --- a/index.js +++ b/index.js @@ -3,7 +3,6 @@ const marked = require('marked'); const TerminalRenderer = require('marked-terminal'); const envCi = require('env-ci'); const hookStd = require('hook-std'); -const pEachSeries = require('p-each-series'); const semver = require('semver'); const AggregateError = require('aggregate-error'); const pkg = require('./package.json'); @@ -13,7 +12,7 @@ const verify = require('./lib/verify'); const getNextVersion = require('./lib/get-next-version'); const getCommits = require('./lib/get-commits'); const getLastRelease = require('./lib/get-last-release'); -const getReleasesToAdd = require('./lib/get-releases-to-add'); +const getReleaseToAdd = require('./lib/get-release-to-add'); const {extractErrors, makeTag} = require('./lib/utils'); const getGitAuthUrl = require('./lib/get-git-auth-url'); const getBranches = require('./lib/branches'); @@ -24,7 +23,7 @@ const {COMMIT_NAME, COMMIT_EMAIL} = require('./lib/definitions/constants'); marked.setOptions({renderer: new TerminalRenderer()}); -/* eslint complexity: ["warn", 25] */ +/* eslint complexity: off */ async function run(context, plugins) { const {cwd, env, options, logger} = context; const {isCi, branch: ciBranch, isPr} = envCi({env, cwd}); @@ -92,35 +91,37 @@ async function run(context, plugins) { await plugins.verifyConditions(context); - const releasesToAdd = getReleasesToAdd(context); const errors = []; context.releases = []; + const releaseToAdd = getReleaseToAdd(context); + + if (releaseToAdd) { + const {lastRelease, currentRelease, nextRelease} = releaseToAdd; - await pEachSeries(releasesToAdd, async ({lastRelease, currentRelease, nextRelease}) => { 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})); - return; + } else { + const commits = await getCommits({...context, lastRelease, nextRelease}); + nextRelease.notes = await plugins.generateNotes({...context, commits, lastRelease, nextRelease}); + + await tag(nextRelease.gitTag, nextRelease.gitHead, {cwd, env}); + await push(options.repositoryUrl, {cwd, env}); + logger.success(`Created 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}); } - - const commits = await getCommits({...context, lastRelease, nextRelease}); - nextRelease.notes = await plugins.generateNotes({...context, commits, lastRelease, nextRelease}); - - logger.log('Create tag %s', nextRelease.gitTag); - await tag(nextRelease.gitTag, nextRelease.gitHead, {cwd, env}); - await push(options.repositoryUrl, {cwd, env}); - 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); diff --git a/lib/branches/get-tags.js b/lib/branches/get-tags.js index adefcb317b..bf26a331f6 100644 --- a/lib/branches/get-tags.js +++ b/lib/branches/get-tags.js @@ -1,4 +1,4 @@ -const {template, escapeRegExp} = require('lodash'); +const {template, escapeRegExp, flatMap} = require('lodash'); const semver = require('semver'); const pReduce = require('p-reduce'); const debug = require('debug')('semantic-release:get-tags'); @@ -14,10 +14,21 @@ module.exports = async ({cwd, env, options: {tagFormat}}, branches) => { return pReduce( branches, async (branches, branch) => { - const branchTags = (await getTags(branch.name, {cwd, env})).reduce((tags, tag) => { + const versions = (await getTags(branch.name, {cwd, env})).reduce((versions, tag) => { const [, version, channel] = tag.match(tagRegexp) || []; - return version && semver.valid(semver.clean(version)) ? [...tags, {gitTag: tag, version, channel}] : tags; - }, []); + if (version && semver.valid(semver.clean(version))) { + return { + ...versions, + [version]: versions[version] + ? {...versions[version], channels: [...versions[version].channels, channel]} + : {gitTag: tag, version, channels: [channel]}, + }; + } + + return versions; + }, {}); + + const branchTags = flatMap(versions); debug('found tags for branch %s: %o', branch.name, branchTags); return [...branches, {...branch, tags: branchTags}]; diff --git a/lib/get-last-release.js b/lib/get-last-release.js index 6c4bf50c6e..20b3519b29 100644 --- a/lib/get-last-release.js +++ b/lib/get-last-release.js @@ -27,16 +27,17 @@ const {makeTag, isSameChannel} = require('./utils'); * @return {LastRelease} The last tagged release or empty object if none is found. */ module.exports = ({branch, options: {tagFormat}}, {before} = {}) => { - const [{version, gitTag, channel} = {}] = branch.tags + const [{version, gitTag, channels} = {}] = branch.tags .filter( tag => - (branch.type === 'prerelease' && isSameChannel(branch.channel, tag.channel)) || !semver.prerelease(tag.version) + (branch.type === 'prerelease' && tag.channels.some(channel => isSameChannel(branch.channel, channel))) || + !semver.prerelease(tag.version) ) .filter(tag => isUndefined(before) || semver.lt(tag.version, before)) .sort((a, b) => semver.rcompare(a.version, b.version)); if (gitTag) { - return {version, gitTag, channel, gitHead: gitTag, name: makeTag(tagFormat, version)}; + return {version, gitTag, channels, gitHead: gitTag, name: makeTag(tagFormat, version)}; } return {}; diff --git a/lib/get-next-version.js b/lib/get-next-version.js index 825f77d63b..aed7ae34f8 100644 --- a/lib/get-next-version.js +++ b/lib/get-next-version.js @@ -8,7 +8,8 @@ module.exports = ({branch, nextRelease: {type, channel}, lastRelease, logger}) = const {major, minor, patch} = semver.parse(lastRelease.version); version = branch.type === 'prerelease' - ? semver.prerelease(lastRelease.version) && isSameChannel(lastRelease.channel, channel) + ? semver.prerelease(lastRelease.version) && + lastRelease.channels.some(lastReleaseChannel => isSameChannel(lastReleaseChannel, channel)) ? semver.inc(lastRelease.version, 'prerelease') : `${semver.inc(`${major}.${minor}.${patch}`, type)}-${branch.prerelease}.${FIRSTPRERELEASE}` : semver.inc(lastRelease.version, type); diff --git a/lib/get-release-to-add.js b/lib/get-release-to-add.js new file mode 100644 index 0000000000..09cefc8259 --- /dev/null +++ b/lib/get-release-to-add.js @@ -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} 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); + + const versiontoAdd = uniqBy( + branch.tags.filter( + ({channels, version}) => + !channels.includes(branch.channel) && + 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, + gitTag: makeTag(tagFormat, version, branch.channel), + name, + gitHead: gitTag, + }, + }; + } +}; diff --git a/lib/get-releases-to-add.js b/lib/get-releases-to-add.js deleted file mode 100644 index 0ccd11aeae..0000000000 --- a/lib/get-releases-to-add.js +++ /dev/null @@ -1,71 +0,0 @@ -const {uniq} = 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} Last release and next release to be added on the channel of the current branch. - */ -module.exports = context => { - const { - branch, - branches, - options: {tagFormat}, - } = context; - - return ( - branches - // Consider only releases of higher branches - .slice(branches.findIndex(({name}) => name === branch.name) + 1) - // Exclude prerelease branches - .filter(({type}) => type !== 'prerelease') - // Find higher branch releases merged to building branch but not released on associated channel - .reduce( - (releases, higherBranch) => [ - ...releases, - // For all unique release version of the higher branch merged on current branch, excluding lower than start range version for maintenance branches - ...uniq( - branch.tags.filter( - ({channel, version}) => - channel === higherBranch.channel && - channel !== branch.channel && - (branch.type !== 'maintenance' || semver.gte(version, getLowerBound(branch.mergeRange))) - ) - ) - // Find ones that are not released on the building branch channel - .filter(tag => - branch.tags.every( - ({version, channel}) => - version !== tag.version || channel === higherBranch.channel || channel !== branch.channel - ) - ) - // Sort in ascending order to add the most recent release last - .sort((a, b) => semver.compare(a.version, b.version)) - // Construct the last and next release to add to the building branch channel - .map(({version, gitTag}) => { - const lastRelease = getLastRelease(context, {before: version}); - const type = lastRelease.version ? semverDiff(lastRelease.version, version) : 'major'; - const name = makeTag(tagFormat, version); - return { - lastRelease, - currentRelease: {type, version, channel: higherBranch.channel, gitTag, name, gitHead: gitTag}, - nextRelease: { - type, - version, - channel: branch.channel, - gitTag: makeTag(tagFormat, version, branch.channel), - name, - gitHead: gitTag, - }, - }; - }), - ], - [] - ) - ); -}; diff --git a/test/branches/get-tags.test.js b/test/branches/get-tags.test.js index 699886c75c..c234ebe5ef 100644 --- a/test/branches/get-tags.test.js +++ b/test/branches/get-tags.test.js @@ -20,9 +20,9 @@ test('Get the valid tags', async t => { { name: 'master', tags: [ - {gitTag: 'v1.0.0', version: '1.0.0', channel: undefined}, - {gitTag: 'v2.0.0', version: '2.0.0', channel: undefined}, - {gitTag: 'v3.0.0-beta.1', version: '3.0.0-beta.1', channel: undefined}, + {gitTag: 'v1.0.0', version: '1.0.0', channels: [undefined]}, + {gitTag: 'v2.0.0', version: '2.0.0', channels: [undefined]}, + {gitTag: 'v3.0.0-beta.1', version: '3.0.0-beta.1', channels: [undefined]}, ], }, ]); @@ -55,23 +55,17 @@ test('Get the valid tags from multiple branches', async t => { { name: '1.x', tags: [ - {gitTag: 'v1.0.0', version: '1.0.0', channel: undefined}, - {gitTag: 'v1.0.0@1.x', version: '1.0.0', channel: '1.x'}, - {gitTag: 'v1.1.0', version: '1.1.0', channel: undefined}, - {gitTag: 'v1.1.0@1.x', version: '1.1.0', channel: '1.x'}, + {gitTag: 'v1.0.0', version: '1.0.0', channels: [undefined, '1.x']}, + {gitTag: 'v1.1.0', version: '1.1.0', channels: [undefined, '1.x']}, ], }, { name: 'master', - tags: [ - ...result[0].tags, - {gitTag: 'v2.0.0', version: '2.0.0', channel: undefined}, - {gitTag: 'v2.0.0@next', version: '2.0.0', channel: 'next'}, - ], + tags: [...result[0].tags, {gitTag: 'v2.0.0', version: '2.0.0', channels: [undefined, 'next']}], }, { name: 'next', - tags: [...result[1].tags, {gitTag: 'v3.0.0@next', version: '3.0.0', channel: 'next'}], + tags: [...result[1].tags, {gitTag: 'v3.0.0@next', version: '3.0.0', channels: ['next']}], }, ]); }); @@ -91,10 +85,8 @@ test('Match the tag name from the begining of the string and the channel from th { name: 'master', tags: [ - {gitTag: 'prefix@v1.0.0', version: '1.0.0', channel: undefined}, - {gitTag: 'prefix@v1.0.0@next', version: '1.0.0', channel: 'next'}, - {gitTag: 'prefix@v2.0.0', version: '2.0.0', channel: undefined}, - {gitTag: 'prefix@v2.0.0@next', version: '2.0.0', channel: 'next'}, + {gitTag: 'prefix@v1.0.0', version: '1.0.0', channels: [undefined, 'next']}, + {gitTag: 'prefix@v2.0.0', version: '2.0.0', channels: [undefined, 'next']}, ], }, ]); @@ -141,19 +133,19 @@ test('Get the highest valid tag corresponding to the "tagFormat"', async t => { 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', channel: undefined}]}, + {name: 'master', tags: [{gitTag: '1.0.0', version: '1.0.0', channels: [undefined]}]}, ]); 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', channel: undefined}]}, + {name: 'master', tags: [{gitTag: 'foo-1.0.0-bar', version: '1.0.0', channels: [undefined]}]}, ]); 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', channel: undefined}], + tags: [{gitTag: 'foo-v1.0.0-bar', version: '1.0.0', channels: [undefined]}], }, ]); @@ -161,7 +153,7 @@ test('Get the highest valid tag corresponding to the "tagFormat"', async t => { 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', channel: undefined}], + tags: [{gitTag: '(.+)/1.0.0/(a-z)', version: '1.0.0', channels: [undefined]}], }, ]); @@ -169,12 +161,12 @@ test('Get the highest valid tag corresponding to the "tagFormat"', async t => { 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', channel: undefined}], + tags: [{gitTag: '2.0.0-1.0.0-bar.1', version: '1.0.0', channels: [undefined]}], }, ]); 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', channel: undefined}]}, + {name: 'master', tags: [{gitTag: '3.0.0-bar.2', version: '3.0.0', channels: [undefined]}]}, ]); }); diff --git a/test/get-last-release.test.js b/test/get-last-release.test.js index 43a5ddf5b9..fa62e200a1 100644 --- a/test/get-last-release.test.js +++ b/test/get-last-release.test.js @@ -15,7 +15,7 @@ test('Get the highest non-prerelease valid tag', t => { options: {tagFormat: `v\${version}`}, }); - t.deepEqual(result, {version: '2.0.0', gitTag: 'v2.0.0', name: 'v2.0.0', gitHead: 'v2.0.0', channel: undefined}); + t.deepEqual(result, {version: '2.0.0', gitTag: 'v2.0.0', name: 'v2.0.0', gitHead: 'v2.0.0', channels: undefined}); }); test('Get the highest prerelease valid tag, ignoring other tags from other prerelease channels', t => { @@ -25,9 +25,14 @@ test('Get the highest prerelease valid tag, ignoring other tags from other prere prerelease: 'beta', channel: 'beta', tags: [ - {version: '1.0.0-beta.1', gitTag: 'v1.0.0-beta.1@beta', gitHead: 'v1.0.0-beta.1@beta', channel: 'beta'}, - {version: '1.0.0-beta.2', gitTag: 'v1.0.0-beta.2@beta', gitHead: 'v1.0.0-beta.2@beta', channel: 'beta'}, - {version: '1.0.0-alpha.1', gitTag: 'v1.0.0-alpha.1@alpha', gitHead: 'v1.0.0-alpha.1@alpha', channel: 'alpha'}, + {version: '1.0.0-beta.1', gitTag: 'v1.0.0-beta.1@beta', gitHead: 'v1.0.0-beta.1@beta', channels: ['beta']}, + {version: '1.0.0-beta.2', gitTag: 'v1.0.0-beta.2@beta', gitHead: 'v1.0.0-beta.2@beta', channels: ['beta']}, + { + version: '1.0.0-alpha.1', + gitTag: 'v1.0.0-alpha.1@alpha', + gitHead: 'v1.0.0-alpha.1@alpha', + channels: ['alpha'], + }, ], type: 'prerelease', }, @@ -39,7 +44,7 @@ test('Get the highest prerelease valid tag, ignoring other tags from other prere gitTag: 'v1.0.0-beta.2@beta', name: 'v1.0.0-beta.2', gitHead: 'v1.0.0-beta.2@beta', - channel: 'beta', + channels: ['beta'], }); }); @@ -76,5 +81,5 @@ test('Get the highest non-prerelease valid tag before a certain version', t => { {before: '2.1.0'} ); - t.deepEqual(result, {version: '2.0.0', gitTag: 'v2.0.0', name: 'v2.0.0', gitHead: 'v2.0.0', channel: undefined}); + t.deepEqual(result, {version: '2.0.0', gitTag: 'v2.0.0', name: 'v2.0.0', gitHead: 'v2.0.0', channels: undefined}); }); diff --git a/test/get-next-version.test.js b/test/get-next-version.test.js index a3212a5fb1..10908c206c 100644 --- a/test/get-next-version.test.js +++ b/test/get-next-version.test.js @@ -13,7 +13,7 @@ test('Increase version for patch release', t => { getNextVersion({ branch: {name: 'master', type: 'release'}, nextRelease: {type: 'patch'}, - lastRelease: {version: '1.0.0'}, + lastRelease: {version: '1.0.0', channels: [undefined]}, logger: t.context.logger, }), '1.0.1' @@ -25,7 +25,7 @@ test('Increase version for minor release', t => { getNextVersion({ branch: {name: 'master', type: 'release'}, nextRelease: {type: 'minor'}, - lastRelease: {version: '1.0.0'}, + lastRelease: {version: '1.0.0', channels: [undefined]}, logger: t.context.logger, }), '1.1.0' @@ -37,7 +37,7 @@ test('Increase version for major release', t => { getNextVersion({ branch: {name: 'master', type: 'release'}, nextRelease: {type: 'major'}, - lastRelease: {version: '1.0.0'}, + lastRelease: {version: '1.0.0', channels: [undefined]}, logger: t.context.logger, }), '2.0.0' @@ -61,7 +61,7 @@ test('Increase version for patch release on prerelease branch', t => { getNextVersion({ branch: {name: 'beta', type: 'prerelease', prerelease: 'beta'}, nextRelease: {type: 'patch'}, - lastRelease: {version: '1.0.0'}, + lastRelease: {version: '1.0.0', channels: [undefined]}, logger: t.context.logger, }), '1.0.1-beta.1' @@ -71,7 +71,7 @@ test('Increase version for patch release on prerelease branch', t => { getNextVersion({ branch: {name: 'beta', type: 'prerelease', prerelease: 'beta'}, nextRelease: {type: 'patch'}, - lastRelease: {version: '1.0.0-beta.1'}, + lastRelease: {version: '1.0.0-beta.1', channels: [undefined]}, logger: t.context.logger, }), '1.0.0-beta.2' @@ -81,7 +81,7 @@ test('Increase version for patch release on prerelease branch', t => { getNextVersion({ branch: {name: 'alpha', type: 'prerelease', prerelease: 'alpha'}, nextRelease: {type: 'patch', channel: 'alpha'}, - lastRelease: {version: '1.0.0-beta.1', channel: 'beta'}, + lastRelease: {version: '1.0.0-beta.1', channels: ['beta']}, logger: t.context.logger, }), '1.0.1-alpha.1' @@ -93,7 +93,7 @@ test('Increase version for minor release on prerelease branch', t => { getNextVersion({ branch: {name: 'beta', type: 'prerelease', prerelease: 'beta'}, nextRelease: {type: 'minor'}, - lastRelease: {version: '1.0.0'}, + lastRelease: {version: '1.0.0', channels: [undefined]}, logger: t.context.logger, }), '1.1.0-beta.1' @@ -103,7 +103,7 @@ test('Increase version for minor release on prerelease branch', t => { getNextVersion({ branch: {name: 'beta', type: 'prerelease', prerelease: 'beta'}, nextRelease: {type: 'minor'}, - lastRelease: {version: '1.0.0-beta.1'}, + lastRelease: {version: '1.0.0-beta.1', channels: [undefined]}, logger: t.context.logger, }), '1.0.0-beta.2' @@ -113,7 +113,7 @@ test('Increase version for minor release on prerelease branch', t => { getNextVersion({ branch: {name: 'alpha', type: 'prerelease', prerelease: 'alpha'}, nextRelease: {type: 'minor', channel: 'alpha'}, - lastRelease: {version: '1.0.0-beta.1', channel: 'beta'}, + lastRelease: {version: '1.0.0-beta.1', channels: ['beta']}, logger: t.context.logger, }), '1.1.0-alpha.1' @@ -125,7 +125,7 @@ test('Increase version for major release on prerelease branch', t => { getNextVersion({ branch: {name: 'beta', type: 'prerelease', prerelease: 'beta'}, nextRelease: {type: 'major'}, - lastRelease: {version: '1.0.0'}, + lastRelease: {version: '1.0.0', channels: [undefined]}, logger: t.context.logger, }), '2.0.0-beta.1' @@ -135,7 +135,7 @@ test('Increase version for major release on prerelease branch', t => { getNextVersion({ branch: {name: 'beta', type: 'prerelease', prerelease: 'beta'}, nextRelease: {type: 'major'}, - lastRelease: {version: '1.0.0-beta.1'}, + lastRelease: {version: '1.0.0-beta.1', channels: [undefined]}, logger: t.context.logger, }), '1.0.0-beta.2' @@ -145,7 +145,7 @@ test('Increase version for major release on prerelease branch', t => { getNextVersion({ branch: {name: 'alpha', type: 'prerelease', prerelease: 'alpha'}, nextRelease: {type: 'major', channel: 'alpha'}, - lastRelease: {version: '1.0.0-beta.1', channel: 'beta'}, + lastRelease: {version: '1.0.0-beta.1', channels: ['beta']}, logger: t.context.logger, }), '2.0.0-alpha.1' diff --git a/test/get-release-to-add.test.js b/test/get-release-to-add.test.js new file mode 100644 index 0000000000..2b13111311 --- /dev/null +++ b/test/get-release-to-add.test.js @@ -0,0 +1,283 @@ +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@2.x', version: '2.0.0', channels: ['2.x']}, + {gitTag: 'v2.0.0', version: '2.0.0', channels: [undefined]}, + {gitTag: 'v2.1.0', version: '2.1.0', channels: [undefined]}, + {gitTag: 'v2.1.1', version: '2.1.1', channels: [undefined]}, + {gitTag: 'v1.0.0', version: '1.0.0', channels: [undefined]}, + {gitTag: 'v1.1.0', version: '1.1.0', channels: [undefined]}, + ], + }, + branches: [{name: '2.x', channel: '2.x'}, {name: 'master'}], + options: {tagFormat: `v\${version}`}, + }); + + t.deepEqual(result, { + lastRelease: {version: '2.1.0', channels: [undefined], gitTag: 'v2.1.0', name: 'v2.1.0', gitHead: 'v2.1.0'}, + currentRelease: { + type: 'patch', + version: '2.1.1', + channels: [undefined], + 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@2.x', + 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: [undefined, 'next']}, + {gitTag: 'v1.1.0@next', version: '1.1.0', channels: ['next']}, + {gitTag: 'v2.0.0@next-major', 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@next', + name: 'v1.1.0', + gitHead: 'v1.1.0@next', + channels: ['next'], + }, + currentRelease: { + type: 'major', + version: '2.0.0', + channels: ['next-major'], + gitTag: 'v2.0.0@next-major', + name: 'v2.0.0', + gitHead: 'v2.0.0@next-major', + }, + nextRelease: { + type: 'major', + version: '2.0.0', + channel: undefined, + gitTag: 'v2.0.0', + name: 'v2.0.0', + gitHead: 'v2.0.0@next-major', + }, + }); +}); + +test('Return releases sorted by ascending order', t => { + const result = getReleaseToAdd({ + branch: { + name: 'master', + tags: [ + {gitTag: 'v2.0.0@next-major', version: '2.0.0', channels: ['next-major']}, + {gitTag: 'v1.1.0@next', version: '1.1.0', channels: ['next']}, + {gitTag: 'v1.0.0', version: '1.0.0', channels: [undefined, 'next']}, + // {gitTag: 'v1.0.0@next', version: '1.0.0', channel: '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@next', name: 'v1.1.0', gitHead: 'v1.1.0@next', channels: ['next']}, + currentRelease: { + type: 'major', + version: '2.0.0', + channels: ['next-major'], + gitTag: 'v2.0.0@next-major', + name: 'v2.0.0', + gitHead: 'v2.0.0@next-major', + }, + nextRelease: { + type: 'major', + version: '2.0.0', + channel: undefined, + gitTag: 'v2.0.0', + name: 'v2.0.0', + gitHead: 'v2.0.0@next-major', + }, + }); +}); + +test('No lastRelease', t => { + const result = getReleaseToAdd({ + branch: { + name: 'master', + tags: [{gitTag: 'v1.0.0@next', 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@next', + name: 'v1.0.0', + gitHead: 'v1.0.0@next', + }, + nextRelease: { + type: 'major', + version: '1.0.0', + channel: undefined, + gitTag: 'v1.0.0', + name: 'v1.0.0', + gitHead: 'v1.0.0@next', + }, + }); +}); + +test('Ignore pre-release versions', t => { + const result = getReleaseToAdd({ + branch: { + name: 'master', + tags: [ + {gitTag: 'v1.0.0', version: '1.0.0', channels: [undefined, 'next']}, + {gitTag: 'v1.1.0@next', version: '1.1.0', channels: ['next']}, + {gitTag: 'v2.0.0-alpha.1@alpha', 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: [undefined, '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@next', + name: 'v1.1.0', + gitHead: 'v1.1.0@next', + }, + nextRelease: { + type: 'minor', + version: '1.1.0', + channel: undefined, + gitTag: 'v1.1.0', + name: 'v1.1.0', + gitHead: 'v1.1.0@next', + }, + }); +}); + +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: [undefined]}, + {gitTag: 'v2.0.0', version: '2.0.0', channels: [undefined]}, + {gitTag: 'v2.1.0', version: '2.1.0', channels: [undefined]}, + {gitTag: 'v2.1.1', version: '2.1.1', channels: [undefined]}, + {gitTag: 'v1.0.0', version: '1.0.0', channels: [undefined]}, + {gitTag: 'v1.1.0', version: '1.1.0', channels: [undefined]}, + ], + }, + 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: [undefined]}, + {gitTag: 'v1.1.0', version: '1.1.0', channels: [undefined]}, + {gitTag: 'v2.0.0', version: '2.0.0', channels: [undefined]}, + ], + }, + 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@2.x', version: '2.0.0', channels: ['2.x']}, + {gitTag: 'v2.0.0', version: '2.0.0', channels: [undefined]}, + {gitTag: 'v2.1.0', version: '2.1.0', channels: [undefined]}, + {gitTag: 'v2.1.1', version: '2.1.1', channels: [undefined, '2.x']}, + {gitTag: 'v1.0.0', version: '1.0.0', channels: [undefined]}, + {gitTag: 'v1.1.0', version: '1.1.0', channels: [undefined]}, + ], + }, + branches: [{name: '2.x', channel: '2.x'}, {name: 'master'}], + options: {tagFormat: `v\${version}`}, + }); + + t.is(result, undefined); +}); diff --git a/test/get-releases-to-add.test.js b/test/get-releases-to-add.test.js deleted file mode 100644 index e7fdb32f47..0000000000 --- a/test/get-releases-to-add.test.js +++ /dev/null @@ -1,323 +0,0 @@ -import test from 'ava'; -import getReleasesToAdd from '../lib/get-releases-to-add'; - -test('Return versions merged from release to maintenance branch, excluding lower than branch start range', t => { - const result = getReleasesToAdd({ - branch: { - name: '2.x', - channel: '2.x', - type: 'maintenance', - mergeRange: '>=2.0.0 <3.0.0', - tags: [ - {gitTag: 'v2.0.0@2.x', version: '2.0.0', channel: '2.x'}, - {gitTag: 'v2.0.0', version: '2.0.0'}, - {gitTag: 'v2.1.0', version: '2.1.0'}, - {gitTag: 'v2.1.1', version: '2.1.1'}, - {gitTag: 'v1.0.0', version: '1.0.0'}, - {gitTag: 'v1.1.0', version: '1.1.0'}, - ], - }, - branches: [{name: '2.x', channel: '2.x'}, {name: 'master'}], - options: {tagFormat: `v\${version}`}, - }); - - t.deepEqual(result, [ - { - lastRelease: {version: '2.0.0', channel: '2.x', gitTag: 'v2.0.0@2.x', name: 'v2.0.0', gitHead: 'v2.0.0@2.x'}, - currentRelease: { - type: 'minor', - version: '2.1.0', - channel: undefined, - gitTag: 'v2.1.0', - name: 'v2.1.0', - gitHead: 'v2.1.0', - }, - nextRelease: { - type: 'minor', - version: '2.1.0', - channel: '2.x', - gitTag: 'v2.1.0@2.x', - name: 'v2.1.0', - gitHead: 'v2.1.0', - }, - }, - { - lastRelease: {version: '2.1.0', channel: undefined, gitTag: 'v2.1.0', name: 'v2.1.0', gitHead: 'v2.1.0'}, - currentRelease: { - type: 'patch', - version: '2.1.1', - channel: undefined, - 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@2.x', - name: 'v2.1.1', - gitHead: 'v2.1.1', - }, - }, - ]); -}); - -test('Return versions merged between release branches', t => { - const result = getReleasesToAdd({ - branch: { - name: 'master', - tags: [ - {gitTag: 'v1.0.0', version: '1.0.0'}, - {gitTag: 'v1.0.0@next', version: '1.0.0', channel: 'next'}, - {gitTag: 'v1.1.0@next', version: '1.1.0', channel: 'next'}, - {gitTag: 'v2.0.0@next-major', version: '2.0.0', channel: '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.0.0', channel: undefined, gitTag: 'v1.0.0', name: 'v1.0.0', gitHead: 'v1.0.0'}, - currentRelease: { - type: 'minor', - version: '1.1.0', - channel: 'next', - gitTag: 'v1.1.0@next', - name: 'v1.1.0', - gitHead: 'v1.1.0@next', - }, - nextRelease: { - type: 'minor', - version: '1.1.0', - channel: undefined, - gitTag: 'v1.1.0', - name: 'v1.1.0', - gitHead: 'v1.1.0@next', - }, - }, - { - lastRelease: {version: '1.1.0', gitTag: 'v1.1.0@next', name: 'v1.1.0', gitHead: 'v1.1.0@next', channel: 'next'}, - currentRelease: { - type: 'major', - version: '2.0.0', - channel: 'next-major', - gitTag: 'v2.0.0@next-major', - name: 'v2.0.0', - gitHead: 'v2.0.0@next-major', - }, - nextRelease: { - type: 'major', - version: '2.0.0', - channel: undefined, - gitTag: 'v2.0.0', - name: 'v2.0.0', - gitHead: 'v2.0.0@next-major', - }, - }, - ]); -}); - -test('Return releases sorted by ascending order', t => { - const result = getReleasesToAdd({ - branch: { - name: 'master', - tags: [ - {gitTag: 'v2.0.0@next-major', version: '2.0.0', channel: 'next-major'}, - {gitTag: 'v1.1.0@next', version: '1.1.0', channel: 'next'}, - {gitTag: 'v1.0.0', version: '1.0.0'}, - {gitTag: 'v1.0.0@next', version: '1.0.0', channel: 'next'}, - ], - }, - branches: [{name: 'master'}, {name: 'next', channel: 'next'}, {name: 'next-major', channel: 'next-major'}], - options: {tagFormat: `v\${version}`}, - }); - - t.deepEqual(result, [ - { - lastRelease: {version: '1.0.0', channel: undefined, gitTag: 'v1.0.0', name: 'v1.0.0', gitHead: 'v1.0.0'}, - currentRelease: { - type: 'minor', - version: '1.1.0', - channel: 'next', - gitTag: 'v1.1.0@next', - name: 'v1.1.0', - gitHead: 'v1.1.0@next', - }, - nextRelease: { - type: 'minor', - version: '1.1.0', - channel: undefined, - gitTag: 'v1.1.0', - name: 'v1.1.0', - gitHead: 'v1.1.0@next', - }, - }, - { - lastRelease: {version: '1.1.0', gitTag: 'v1.1.0@next', name: 'v1.1.0', gitHead: 'v1.1.0@next', channel: 'next'}, - currentRelease: { - type: 'major', - version: '2.0.0', - channel: 'next-major', - gitTag: 'v2.0.0@next-major', - name: 'v2.0.0', - gitHead: 'v2.0.0@next-major', - }, - nextRelease: { - type: 'major', - version: '2.0.0', - channel: undefined, - gitTag: 'v2.0.0', - name: 'v2.0.0', - gitHead: 'v2.0.0@next-major', - }, - }, - ]); -}); - -test('No lastRelease', t => { - const result = getReleasesToAdd({ - branch: { - name: 'master', - tags: [{gitTag: 'v1.0.0@next', version: '1.0.0', channel: 'next'}], - }, - branches: [{name: 'master'}, {name: 'next', channel: 'next'}], - options: {tagFormat: `v\${version}`}, - }); - - t.deepEqual(result, [ - { - lastRelease: {}, - currentRelease: { - type: 'major', - version: '1.0.0', - channel: 'next', - gitTag: 'v1.0.0@next', - name: 'v1.0.0', - gitHead: 'v1.0.0@next', - }, - nextRelease: { - type: 'major', - version: '1.0.0', - channel: undefined, - gitTag: 'v1.0.0', - name: 'v1.0.0', - gitHead: 'v1.0.0@next', - }, - }, - ]); -}); - -test('Ignore pre-release versions', t => { - const result = getReleasesToAdd({ - branch: { - name: 'master', - tags: [ - {gitTag: 'v1.0.0', version: '1.0.0'}, - {gitTag: 'v1.0.0@next', version: '1.0.0', channel: 'next'}, - {gitTag: 'v1.1.0@next', version: '1.1.0', channel: 'next'}, - {gitTag: 'v2.0.0-alpha.1@alpha', version: '2.0.0', channel: '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', channel: undefined, gitTag: 'v1.0.0', name: 'v1.0.0', gitHead: 'v1.0.0'}, - currentRelease: { - type: 'minor', - version: '1.1.0', - channel: 'next', - gitTag: 'v1.1.0@next', - name: 'v1.1.0', - gitHead: 'v1.1.0@next', - }, - nextRelease: { - type: 'minor', - version: '1.1.0', - channel: undefined, - gitTag: 'v1.1.0', - name: 'v1.1.0', - gitHead: 'v1.1.0@next', - }, - }, - ]); -}); - -test('Exclude versions merged from release to maintenance branch if they have the same "channel"', t => { - const result = getReleasesToAdd({ - branch: { - name: '2.x', - channel: 'latest', - type: 'maintenance', - mergeRange: '>=2.0.0 <3.0.0', - tags: [ - {gitTag: 'v2.0.0', version: '2.0.0'}, - {gitTag: 'v2.0.0', version: '2.0.0'}, - {gitTag: 'v2.1.0', version: '2.1.0'}, - {gitTag: 'v2.1.1', version: '2.1.1'}, - {gitTag: 'v1.0.0', version: '1.0.0'}, - {gitTag: 'v1.1.0', version: '1.1.0'}, - ], - }, - branches: [ - {name: '2.x', channel: 'latest'}, - {name: 'master', channel: 'latest'}, - ], - options: {tagFormat: `v\${version}`}, - }); - - t.deepEqual(result, []); -}); - -test('Exclude versions merged between release branches if they have the same "channel"', t => { - const result = getReleasesToAdd({ - branch: { - name: 'master', - channel: 'latest', - tags: [ - {gitTag: 'v1.0.0', channel: 'latest', version: '1.0.0'}, - {gitTag: 'v1.1.0', channel: 'latest', version: '1.1.0'}, - {gitTag: 'v2.0.0', channel: 'latest', version: '2.0.0'}, - ], - }, - branches: [ - {name: 'master', channel: 'latest'}, - {name: 'next', channel: 'latest'}, - {name: 'next-major', channel: 'latest'}, - ], - options: {tagFormat: `v\${version}`}, - }); - - t.deepEqual(result, []); -}); - -test('Exclude versions merged between release branches if they all have "channel" set to "false"', t => { - const result = getReleasesToAdd({ - branch: { - name: 'master', - channel: false, - tags: [ - {gitTag: 'v1.0.0', version: '1.0.0'}, - {gitTag: 'v1.1.0', version: '1.1.0'}, - {gitTag: 'v2.0.0', version: '2.0.0'}, - ], - }, - branches: [ - {name: 'master', channel: false}, - {name: 'next', channel: false}, - {name: 'next-major', channel: false}, - ], - options: {tagFormat: `v\${version}`}, - }); - - t.deepEqual(result, []); -}); diff --git a/test/index.test.js b/test/index.test.js index d7f0b54ad7..7c86579c30 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -1,5 +1,5 @@ import test from 'ava'; -import {escapeRegExp, isString, sortBy} from 'lodash'; +import {escapeRegExp, isString, sortBy, omit} from 'lodash'; import proxyquire from 'proxyquire'; import {spy, stub} from 'sinon'; import {WritableStreamBuffer} from 'stream-buffers'; @@ -57,7 +57,7 @@ test('Plugins are called with expected values', async t => { gitHead: commits[commits.length - 1].hash, gitTag: 'v1.0.0@next', name: 'v1.0.0', - channel: 'next', + channels: ['next'], }; const nextRelease = { name: 'v1.1.0', @@ -96,7 +96,7 @@ test('Plugins are called with expected values', async t => { name: 'master', range: '>=1.0.0 <2.0.0', accept: ['patch', 'minor'], - tags: [{channel: 'next', gitTag: 'v1.0.0@next', version: '1.0.0'}], + tags: [{channels: ['next'], gitTag: 'v1.0.0@next', version: '1.0.0'}], type: 'release', }, { @@ -104,7 +104,7 @@ test('Plugins are called with expected values', async t => { name: 'next', range: '>=2.0.0', accept: ['patch', 'minor', 'major'], - tags: [{channel: 'next', gitTag: 'v1.0.0@next', version: '1.0.0'}], + tags: [{channels: ['next'], gitTag: 'v1.0.0@next', version: '1.0.0'}], type: 'release', }, ]; @@ -124,7 +124,7 @@ test('Plugins are called with expected values', async t => { const releases = [ { - ...lastRelease, + ...omit(lastRelease, 'channels'), ...release1, type: 'major', version: '1.0.0', @@ -176,7 +176,7 @@ test('Plugins are called with expected values', async t => { t.deepEqual(generateNotes1.args[0][1].commits[0].hash, commits[1].hash); t.deepEqual(generateNotes1.args[0][1].commits[0].message, commits[1].message); t.deepEqual(generateNotes1.args[0][1].nextRelease, { - ...lastRelease, + ...omit(lastRelease, 'channels'), type: 'major', version: '1.0.0', channel: undefined, @@ -193,7 +193,7 @@ test('Plugins are called with expected values', async t => { t.deepEqual(generateNotes2.args[0][1].commits[0].hash, commits[1].hash); t.deepEqual(generateNotes2.args[0][1].commits[0].message, commits[1].message); t.deepEqual(generateNotes2.args[0][1].nextRelease, { - ...lastRelease, + ...omit(lastRelease, 'channels'), type: 'major', version: '1.0.0', channel: undefined, @@ -211,7 +211,7 @@ test('Plugins are called with expected values', async t => { t.deepEqual(generateNotes3.args[0][1].commits[0].hash, commits[1].hash); t.deepEqual(generateNotes3.args[0][1].commits[0].message, commits[1].message); t.deepEqual(generateNotes3.args[0][1].nextRelease, { - ...lastRelease, + ...omit(lastRelease, 'channels'), type: 'major', version: '1.0.0', channel: undefined, @@ -236,7 +236,7 @@ test('Plugins are called with expected values', async t => { t.deepEqual(addChannel.args[0][1].lastRelease, {}); t.deepEqual(addChannel.args[0][1].currentRelease, {...lastRelease, type: 'major'}); t.deepEqual(addChannel.args[0][1].nextRelease, { - ...lastRelease, + ...omit(lastRelease, 'channels'), type: 'major', version: '1.0.0', channel: undefined, @@ -330,7 +330,7 @@ test('Plugins are called with expected values', async t => { t.deepEqual(success.args[0][1].commits[0].hash, commits[1].hash); t.deepEqual(success.args[0][1].commits[0].message, commits[1].message); t.deepEqual(success.args[0][1].nextRelease, { - ...lastRelease, + ...omit(lastRelease, 'channels'), type: 'major', version: '1.0.0', channel: undefined, @@ -782,14 +782,6 @@ async function addChannelMacro(t, mergeFunction) { publish, success, }; - const nextRelease1 = { - name: 'v2.0.0', - type: 'major', - version: '2.0.0', - channel: undefined, - gitTag: 'v2.0.0', - gitHead: commits[1].hash, - }; const nextRelease2 = { name: 'v2.0.1', type: 'patch', @@ -806,15 +798,11 @@ async function addChannelMacro(t, mergeFunction) { const result = await semanticRelease(options, {cwd, env: {}, stdout: {write: () => {}}, stderr: {write: () => {}}}); t.deepEqual(result.releases, [ - {...nextRelease1, ...release1, notes, pluginName: '[Function: functionStub]'}, - {...nextRelease1, notes, pluginName: '[Function: functionStub]'}, {...nextRelease2, ...release1, notes, pluginName: '[Function: functionStub]'}, {...nextRelease2, notes, pluginName: '[Function: functionStub]'}, ]); // Verify the tag has been created on the local and remote repo and reference - t.is(await gitTagHead(nextRelease1.gitTag, {cwd}), nextRelease1.gitHead); - t.is(await gitRemoteTagHead(repositoryUrl, nextRelease1.gitTag, {cwd}), nextRelease1.gitHead); t.is(await gitTagHead(nextRelease2.gitTag, {cwd}), nextRelease2.gitHead); t.is(await gitRemoteTagHead(repositoryUrl, nextRelease2.gitTag, {cwd}), nextRelease2.gitHead); } @@ -1490,15 +1478,6 @@ test('Throws "EINVALIDMAINTENANCEMERGE" if merge an out of range release in a ma fail, }; - const nextRelease = { - type: 'patch', - version: '1.1.1', - channel: '1.1.x', - gitTag: 'v1.1.1@1.1.x', - name: 'v1.1.1', - gitHead: commits[2].hash, - }; - const semanticRelease = proxyquire('..', { './lib/logger': t.context.logger, 'env-ci': () => ({isCi: true, branch: '1.1.x', isPr: false}), @@ -1509,13 +1488,11 @@ test('Throws "EINVALIDMAINTENANCEMERGE" if merge an out of range release in a ma )), ]; - t.is(addChannel.callCount, 1); - t.deepEqual(addChannel.args[0][1].nextRelease, {...nextRelease, notes}); + t.is(addChannel.callCount, 0); t.is(publish.callCount, 0); - t.is(success.callCount, 1); - t.deepEqual(success.args[0][1].releases, [{...nextRelease, notes, pluginName: '[Function: functionStub]'}]); + t.is(success.callCount, 0); t.is(fail.callCount, 1); t.deepEqual(fail.args[0][1].errors, errors); diff --git a/test/integration.test.js b/test/integration.test.js index 3b0d4d66bd..576f2cd1aa 100644 --- a/test/integration.test.js +++ b/test/integration.test.js @@ -269,7 +269,7 @@ test('Release patch, minor and major versions', async t => { const updateReleaseMock = await mockServer.mock( `/repos/${owner}/${packageName}/releases/${releaseId}`, { - body: {tag_name: `v${version}`, name: `v${version}`, prerelease: false}, + body: {name: `v${version}`, prerelease: false}, headers: [{name: 'Authorization', values: [`token ${env.GH_TOKEN}`]}], }, {body: {html_url: `release-url/${version}`}, method: 'PATCH'} From 97748c5e257b158b61e7eab1ae737180d0238301 Mon Sep 17 00:00:00 2001 From: Pierre Vanduynslager Date: Wed, 27 Nov 2019 15:09:09 -0500 Subject: [PATCH 095/107] fix: do not create tags in dry-run mode for released to add to a channel --- index.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 4e33d6c408..b79a4dba68 100644 --- a/index.js +++ b/index.js @@ -106,9 +106,13 @@ async function run(context, plugins) { const commits = await getCommits({...context, lastRelease, nextRelease}); nextRelease.notes = await plugins.generateNotes({...context, commits, lastRelease, nextRelease}); - await tag(nextRelease.gitTag, nextRelease.gitHead, {cwd, env}); - await push(options.repositoryUrl, {cwd, env}); - logger.success(`Created tag ${nextRelease.gitTag}`); + if (options.dryRun) { + logger.warn(`Skip ${nextRelease.gitTag} tag creation in dry-run mode`); + } else { + await tag(nextRelease.gitTag, nextRelease.gitHead, {cwd, env}); + await push(options.repositoryUrl, {cwd, env}); + logger.success(`Created tag ${nextRelease.gitTag}`); + } context.branch.tags.push({ version: nextRelease.version, From e722354f4f34d58227fe134f2fa3e931f8aaaf3b Mon Sep 17 00:00:00 2001 From: Pierre Vanduynslager Date: Wed, 27 Nov 2019 15:09:45 -0500 Subject: [PATCH 096/107] style: merge both `filter` functions in `get-last-release` --- lib/get-last-release.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/get-last-release.js b/lib/get-last-release.js index 20b3519b29..f8cc5ede91 100644 --- a/lib/get-last-release.js +++ b/lib/get-last-release.js @@ -30,10 +30,10 @@ module.exports = ({branch, options: {tagFormat}}, {before} = {}) => { const [{version, gitTag, channels} = {}] = branch.tags .filter( tag => - (branch.type === 'prerelease' && tag.channels.some(channel => isSameChannel(branch.channel, channel))) || - !semver.prerelease(tag.version) + ((branch.type === 'prerelease' && tag.channels.some(channel => isSameChannel(branch.channel, channel))) || + !semver.prerelease(tag.version)) && + (isUndefined(before) || semver.lt(tag.version, before)) ) - .filter(tag => isUndefined(before) || semver.lt(tag.version, before)) .sort((a, b) => semver.rcompare(a.version, b.version)); if (gitTag) { From 2caafbaa2be54330b5b3e6dd71dda0270b566663 Mon Sep 17 00:00:00 2001 From: Pierre Vanduynslager Date: Thu, 28 Nov 2019 13:51:32 -0500 Subject: [PATCH 097/107] fix: add a flag indicate which branch is the main one --- lib/branches/normalize.js | 1 + test/branches/normalize.test.js | 117 ++++++++++++++++++++++++++------ test/index.test.js | 2 + 3 files changed, 99 insertions(+), 21 deletions(-) diff --git a/lib/branches/normalize.js b/lib/branches/normalize.js index 4e3e9b01f0..103519c10b 100644 --- a/lib/branches/normalize.js +++ b/lib/branches/normalize.js @@ -91,6 +91,7 @@ function release({release}) { name, range: getRange(min, bound), accept: bound ? RELEASE_TYPE.slice(0, RELEASE_TYPE.indexOf(diff)) : RELEASE_TYPE, + main: idx === 0, }; }); } diff --git a/test/branches/normalize.test.js b/test/branches/normalize.test.js index d137af41e5..b7e01a1a13 100644 --- a/test/branches/normalize.test.js +++ b/test/branches/normalize.test.js @@ -155,16 +155,26 @@ test('Release branches - initial state', t => { ]; t.deepEqual( - normalize.release({release}).map(({type, name, range, accept, channel}) => ({type, name, range, accept, channel})), + normalize + .release({release}) + .map(({type, name, range, accept, channel, main}) => ({type, name, range, accept, channel, main})), [ - {type: 'release', name: 'master', range: '>=1.0.0 <1.1.0', accept: ['patch'], channel: undefined}, - {type: 'release', name: 'next', range: '>=1.1.0 <2.0.0', accept: ['patch', 'minor'], channel: 'next'}, + {type: 'release', name: 'master', range: '>=1.0.0 <1.1.0', accept: ['patch'], channel: undefined, main: true}, + { + type: 'release', + name: 'next', + range: '>=1.1.0 <2.0.0', + accept: ['patch', 'minor'], + channel: 'next', + main: false, + }, { type: 'release', name: 'next-major', range: '>=2.0.0', accept: ['patch', 'minor', 'major'], channel: 'next-major', + main: false, }, ] ); @@ -178,16 +188,26 @@ test('Release branches - 3 release branches', t => { ]; t.deepEqual( - normalize.release({release}).map(({type, name, range, accept, channel}) => ({type, name, range, accept, channel})), + 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}, - {type: 'release', name: 'next', range: '>=1.2.0 <2.0.0', accept: ['patch', 'minor'], channel: 'next'}, + {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, }, ] ); @@ -200,10 +220,26 @@ test('Release branches - 2 release branches', t => { ]; t.deepEqual( - normalize.release({release}).map(({type, name, range, accept, channel}) => ({type, name, range, accept, channel})), + 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}, - {type: 'release', name: 'next', range: '>=2.1.0', accept: ['patch', 'minor', 'major'], channel: 'next'}, + { + 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, + }, ] ); }); @@ -225,16 +261,19 @@ test('Release branches - cap ranges to first release only present on following b ]; t.deepEqual( - normalize.release({release}).map(({type, name, range, accept, channel}) => ({type, name, range, accept, channel})), + 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}, - {type: 'release', name: 'next', range: '>=2.1.0 <2.2.0', accept: ['patch'], channel: 'next'}, + {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, }, ] ); @@ -247,10 +286,26 @@ test('Release branches - Handle missing previous tags in branch history', t => { ]; t.deepEqual( - normalize.release({release}).map(({type, name, range, accept, channel}) => ({type, name, range, accept, channel})), + normalize + .release({release}) + .map(({type, name, range, accept, channel, main}) => ({type, name, range, accept, channel, main})), [ - {type: 'release', name: 'master', range: '>=2.0.0 <3.0.0', accept: ['patch', 'minor'], channel: undefined}, - {type: 'release', name: 'next', range: '>=3.0.0', accept: ['patch', 'minor', 'major'], channel: 'next'}, + { + type: 'release', + name: 'master', + range: '>=2.0.0 <3.0.0', + accept: ['patch', 'minor'], + channel: undefined, + main: true, + }, + { + type: 'release', + name: 'next', + range: '>=3.0.0', + accept: ['patch', 'minor', 'major'], + channel: 'next', + main: false, + }, ] ); }); @@ -263,16 +318,26 @@ test('Release branches - enforce release gaps after downstream merge', t => { ]; t.deepEqual( - normalize.release({release}).map(({type, name, range, accept, channel}) => ({type, name, range, accept, channel})), + 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}, - {type: 'release', name: 'next', range: '>=2.1.0 <3.0.0', accept: ['patch', 'minor'], channel: 'next'}, + {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 <3.0.0', + accept: ['patch', 'minor'], + channel: 'next', + main: false, + }, { type: 'release', name: 'next-major', range: '>=3.0.0', accept: ['patch', 'minor', 'major'], channel: 'next-major', + main: false, }, ] ); @@ -286,16 +351,26 @@ test('Release branches - limit releases on 2nd and 3rd branche based on 1st bran ]; t.deepEqual( - normalize.release({release}).map(({type, name, range, accept, channel}) => ({type, name, range, accept, channel})), + normalize + .release({release}) + .map(({type, name, range, accept, channel, main}) => ({type, name, range, accept, channel, main})), [ - {type: 'release', name: 'master', range: '>=3.0.0 <3.1.0', accept: ['patch'], channel: undefined}, - {type: 'release', name: 'next', range: '>=3.1.0 <4.0.0', accept: ['patch', 'minor'], channel: 'next'}, + {type: 'release', name: 'master', range: '>=3.0.0 <3.1.0', accept: ['patch'], channel: undefined, main: true}, + { + type: 'release', + name: 'next', + range: '>=3.1.0 <4.0.0', + accept: ['patch', 'minor'], + channel: 'next', + main: false, + }, { type: 'release', name: 'next-major', range: '>=4.0.0', accept: ['patch', 'minor', 'major'], channel: 'next-major', + main: false, }, ] ); diff --git a/test/index.test.js b/test/index.test.js index 7c86579c30..11f35ca283 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -98,6 +98,7 @@ test('Plugins are called with expected values', async t => { accept: ['patch', 'minor'], tags: [{channels: ['next'], gitTag: 'v1.0.0@next', version: '1.0.0'}], type: 'release', + main: true, }, { channel: 'next', @@ -106,6 +107,7 @@ test('Plugins are called with expected values', async t => { accept: ['patch', 'minor', 'major'], tags: [{channels: ['next'], gitTag: 'v1.0.0@next', version: '1.0.0'}], type: 'release', + main: false, }, ]; const branch = branches[0]; From b2c1b2c670f8f2dd4da71721ffb329c26e8d2cd7 Mon Sep 17 00:00:00 2001 From: Pierre Vanduynslager Date: Thu, 28 Nov 2019 01:15:00 -0500 Subject: [PATCH 098/107] feat: use Git notes to store the channels on which a version has been released BREAKING CHANGE: this feature change the way semantic-release keep track of the channels on which a version has been released. It now use a JSON object stored in a [Git note](https://git-scm.com/docs/git-notes) instead of Git tags formatted as v{version}@{channel}. The tags formatted as v{version}@{channel} will now be ignored. If you have made releases with v16.0.0 on branches other than the default one you will have to update your repository. The changes to make consist in: - Finding all the versions that have been released on a branch other than the default one by searching for all tags formatted v{version}@{channel} - For each of those version: - Create a tag without the {@channel} if none doesn't already exists - Add a Git note to the tag without the {@channel} containing the channels on which the version was released formatted as `{"channels":["channel1","channel2"]}` and using `null` for the default channel (for example.`{"channels":[null,"channel1","channel2"]}`) - Push the tags and notes - Update the GitHub releases that refer to a tag formatted as v{version}@{channel} to use the tag without it - Delete the tags formatted as v{version}@{channel} --- index.js | 15 ++-- lib/branches/get-tags.js | 31 ++++----- lib/branches/index.js | 4 +- lib/definitions/constants.js | 3 + lib/get-release-to-add.js | 8 +-- lib/git.js | 70 +++++++++++++++++++ lib/utils.js | 4 +- test/branches/get-tags.test.js | 75 ++++++++------------ test/get-last-release.test.js | 21 +++--- test/get-release-to-add.test.js | 109 +++++++++++++++-------------- test/git.test.js | 93 +++++++++++++++++++++++++ test/helpers/git-utils.js | 22 ++++++ test/index.test.js | 119 ++++++++++++++++++-------------- test/integration.test.js | 18 ++--- test/utils.test.js | 4 -- 15 files changed, 386 insertions(+), 210 deletions(-) diff --git a/index.js b/index.js index b79a4dba68..29a79f7d6d 100644 --- a/index.js +++ b/index.js @@ -17,7 +17,7 @@ const {extractErrors, makeTag} = require('./lib/utils'); const getGitAuthUrl = require('./lib/get-git-auth-url'); const getBranches = require('./lib/branches'); const getLogger = require('./lib/get-logger'); -const {verifyAuth, isBranchUpToDate, getGitHead, tag, push, getTagHead} = require('./lib/git'); +const {verifyAuth, isBranchUpToDate, getGitHead, tag, push, pushNotes, getTagHead, addNote} = require('./lib/git'); const getError = require('./lib/get-error'); const {COMMIT_NAME, COMMIT_EMAIL} = require('./lib/definitions/constants'); @@ -109,9 +109,10 @@ async function run(context, plugins) { if (options.dryRun) { logger.warn(`Skip ${nextRelease.gitTag} tag creation in dry-run mode`); } else { - await tag(nextRelease.gitTag, nextRelease.gitHead, {cwd, env}); + await addNote({channels: [...currentRelease.channels, nextRelease.channel]}, nextRelease.gitHead, {cwd, env}); await push(options.repositoryUrl, {cwd, env}); - logger.success(`Created tag ${nextRelease.gitTag}`); + await pushNotes(options.repositoryUrl, {cwd, env}); + logger.success(`Add channel ${nextRelease.channel} to tag ${nextRelease.gitTag}`); } context.branch.tags.push({ @@ -148,7 +149,7 @@ async function run(context, plugins) { const nextRelease = { type: await plugins.analyzeCommits(context), - channel: context.branch.channel, + channel: context.branch.channel || null, gitHead: await getGitHead({cwd, env}), }; if (!nextRelease.type) { @@ -158,8 +159,8 @@ async function run(context, plugins) { context.nextRelease = nextRelease; nextRelease.version = getNextVersion(context); - nextRelease.gitTag = makeTag(options.tagFormat, nextRelease.version, nextRelease.channel); - nextRelease.name = makeTag(options.tagFormat, 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', { @@ -181,7 +182,9 @@ async function run(context, plugins) { } else { // Create the tag before calling the publish plugins as some require the tag to exists await tag(nextRelease.gitTag, nextRelease.gitHead, {cwd, env}); + await addNote({channels: [nextRelease.channel]}, nextRelease.gitHead, {cwd, env}); await push(options.repositoryUrl, {cwd, env}); + await pushNotes(options.repositoryUrl, {cwd, env}); logger.success(`Created tag ${nextRelease.gitTag}`); } diff --git a/lib/branches/get-tags.js b/lib/branches/get-tags.js index bf26a331f6..8cffbeb405 100644 --- a/lib/branches/get-tags.js +++ b/lib/branches/get-tags.js @@ -1,34 +1,29 @@ -const {template, escapeRegExp, flatMap} = require('lodash'); +const {template, escapeRegExp} = require('lodash'); const semver = require('semver'); const pReduce = require('p-reduce'); const debug = require('debug')('semantic-release:get-tags'); -const {getTags} = require('../../lib/git'); +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(' ', '(.[^@]+)@?(.+)?')}`; + const tagRegexp = `^${escapeRegExp(template(tagFormat)({version: ' '})).replace(' ', '(.+)')}`; return pReduce( branches, async (branches, branch) => { - const versions = (await getTags(branch.name, {cwd, env})).reduce((versions, tag) => { - const [, version, channel] = tag.match(tagRegexp) || []; - if (version && semver.valid(semver.clean(version))) { - return { - ...versions, - [version]: versions[version] - ? {...versions[version], channels: [...versions[version].channels, channel]} - : {gitTag: tag, version, channels: [channel]}, - }; - } - - return versions; - }, {}); - - const branchTags = flatMap(versions); + 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}]; diff --git a/lib/branches/index.js b/lib/branches/index.js index 044289e821..b3781f0905 100644 --- a/lib/branches/index.js +++ b/lib/branches/index.js @@ -3,7 +3,7 @@ const AggregateError = require('aggregate-error'); const pEachSeries = require('p-each-series'); const DEFINITIONS = require('../definitions/branches'); const getError = require('../get-error'); -const {fetch, verifyBranchName} = require('../git'); +const {fetch, fetchNotes, verifyBranchName} = require('../git'); const expand = require('./expand'); const getTags = require('./get-tags'); const normalize = require('./normalize'); @@ -21,6 +21,8 @@ module.exports = async (repositoryUrl, context) => { await fetch(repositoryUrl, name, {cwd, env}); }); + await fetchNotes(repositoryUrl, {cwd, env}); + const branches = await getTags(context, remoteBranches); const errors = []; diff --git a/lib/definitions/constants.js b/lib/definitions/constants.js index 491a1a71a3..999999c9ac 100644 --- a/lib/definitions/constants.js +++ b/lib/definitions/constants.js @@ -14,6 +14,8 @@ const SECRET_REPLACEMENT = '[secure]'; const SECRET_MIN_SIZE = 5; +const GIT_NOTE_REF = 'semantic-release'; + module.exports = { RELEASE_TYPE, FIRST_RELEASE, @@ -23,4 +25,5 @@ module.exports = { RELEASE_NOTES_SEPARATOR, SECRET_REPLACEMENT, SECRET_MIN_SIZE, + GIT_NOTE_REF, }; diff --git a/lib/get-release-to-add.js b/lib/get-release-to-add.js index 09cefc8259..a5ac7d884d 100644 --- a/lib/get-release-to-add.js +++ b/lib/get-release-to-add.js @@ -23,12 +23,12 @@ module.exports = context => { .slice(branches.findIndex(({name}) => name === branch.name) + 1) // Exclude prerelease branches .filter(({type}) => type !== 'prerelease') - .map(({channel}) => channel); + .map(({channel}) => channel || null); const versiontoAdd = uniqBy( branch.tags.filter( ({channels, version}) => - !channels.includes(branch.channel) && + !channels.includes(branch.channel || null) && intersection(channels, higherChannels).length > 0 && (branch.type !== 'maintenance' || semver.gte(version, getLowerBound(branch.mergeRange))) ), @@ -50,8 +50,8 @@ module.exports = context => { nextRelease: { type, version, - channel: branch.channel, - gitTag: makeTag(tagFormat, version, branch.channel), + channel: branch.channel || null, + gitTag: makeTag(tagFormat, version), name, gitHead: gitTag, }, diff --git a/lib/git.js b/lib/git.js index 58304df6be..0c2d7836a6 100644 --- a/lib/git.js +++ b/lib/git.js @@ -2,6 +2,7 @@ const gitLogParser = require('git-log-parser'); const getStream = require('get-stream'); const execa = require('execa'); 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}}); @@ -146,6 +147,27 @@ async function fetch(repositoryUrl, 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, + }); + } +} + /** * Get the HEAD sha. * @@ -230,6 +252,18 @@ async function push(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. * @@ -280,6 +314,38 @@ async function isBranchUpToDate(repositoryUrl, branch, execaOpts) { } } +/** + * 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 = { getTagHead, getTags, @@ -288,13 +354,17 @@ module.exports = { isRefInHistory, isRefExists, fetch, + fetchNotes, getGitHead, repoUrl, isGitRepo, verifyAuth, tag, push, + pushNotes, verifyTagName, isBranchUpToDate, verifyBranchName, + getNote, + addNote, }; diff --git a/lib/utils.js b/lib/utils.js index ef8463f712..e40c5d196d 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -67,8 +67,8 @@ function getRange(min, max) { return `>=${min}${max ? ` <${max}` : ''}`; } -function makeTag(tagFormat, version, channel) { - return template(tagFormat)({version: `${version}${channel ? `@${channel}` : ''}`}); +function makeTag(tagFormat, version) { + return template(tagFormat)({version}); } function isSameChannel(channel, otherChannel) { diff --git a/test/branches/get-tags.test.js b/test/branches/get-tags.test.js index c234ebe5ef..7321f92323 100644 --- a/test/branches/get-tags.test.js +++ b/test/branches/get-tags.test.js @@ -1,6 +1,6 @@ import test from 'ava'; import getTags from '../../lib/branches/get-tags'; -import {gitRepo, gitCommits, gitTagVersion, gitCheckout} from '../helpers/git-utils'; +import {gitRepo, gitCommits, gitTagVersion, gitCheckout, gitAddNote} from '../helpers/git-utils'; test('Get the valid tags', async t => { const {cwd} = await gitRepo(); @@ -20,9 +20,9 @@ test('Get the valid tags', async t => { { name: 'master', tags: [ - {gitTag: 'v1.0.0', version: '1.0.0', channels: [undefined]}, - {gitTag: 'v2.0.0', version: '2.0.0', channels: [undefined]}, - {gitTag: 'v3.0.0-beta.1', version: '3.0.0-beta.1', channels: [undefined]}, + {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]}, ], }, ]); @@ -30,20 +30,21 @@ test('Get the valid tags', async t => { test('Get the valid tags from multiple branches', async t => { const {cwd} = await gitRepo(); - const commits = await gitCommits(['First'], {cwd}); + await gitCommits(['First'], {cwd}); await gitTagVersion('v1.0.0', undefined, {cwd}); - await gitTagVersion('v1.0.0@1.x', undefined, {cwd}); - commits.push(...(await gitCommits(['Second'], {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 gitTagVersion('v1.1.0@1.x', 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}); - commits.push(...(await gitCommits(['Third'], {cwd}))); + await gitCommits(['Third'], {cwd}); await gitTagVersion('v2.0.0', undefined, {cwd}); - await gitTagVersion('v2.0.0@next', undefined, {cwd}); + await gitAddNote(JSON.stringify({channels: [null, 'next']}), 'v2.0.0', {cwd}); await gitCheckout('next', true, {cwd}); - commits.push(...(await gitCommits(['Fourth'], {cwd}))); - await gitTagVersion('v3.0.0@next', undefined, {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'}, @@ -55,39 +56,17 @@ test('Get the valid tags from multiple branches', async t => { { name: '1.x', tags: [ - {gitTag: 'v1.0.0', version: '1.0.0', channels: [undefined, '1.x']}, - {gitTag: 'v1.1.0', version: '1.1.0', channels: [undefined, '1.x']}, + {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: [undefined, 'next']}], + 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@next', version: '3.0.0', channels: ['next']}], - }, - ]); -}); - -test('Match the tag name from the begining of the string and the channel from the last "@"', async t => { - const {cwd} = await gitRepo(); - await gitCommits(['First'], {cwd}); - await gitTagVersion('prefix@v1.0.0', undefined, {cwd}); - await gitTagVersion('prefix@v1.0.0@next', undefined, {cwd}); - await gitTagVersion('prefix@v2.0.0', undefined, {cwd}); - await gitTagVersion('prefix@v2.0.0@next', undefined, {cwd}); - await gitTagVersion('other-prefix@v3.0.0', undefined, {cwd}); - - const result = await getTags({cwd, options: {tagFormat: `prefix@v\${version}`}}, [{name: 'master'}]); - - t.deepEqual(result, [ - { - name: 'master', - tags: [ - {gitTag: 'prefix@v1.0.0', version: '1.0.0', channels: [undefined, 'next']}, - {gitTag: 'prefix@v2.0.0', version: '2.0.0', channels: [undefined, 'next']}, - ], + tags: [...result[1].tags, {gitTag: 'v3.0.0', version: '3.0.0', channels: ['next']}], }, ]); }); @@ -112,11 +91,13 @@ test('Return branches with and empty tags array if no valid tag is found in hist await gitCheckout('next', true, {cwd}); await gitCommits(['Second'], {cwd}); await gitTagVersion('v1.0.0', undefined, {cwd}); - await gitTagVersion('v1.0.0@next', 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 gitTagVersion('v2.0.0@next', 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 gitTagVersion('v3.0.0@next', 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'}]); @@ -133,19 +114,19 @@ test('Get the highest valid tag corresponding to the "tagFormat"', async t => { 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: [undefined]}]}, + {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: [undefined]}]}, + {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: [undefined]}], + tags: [{gitTag: 'foo-v1.0.0-bar', version: '1.0.0', channels: [null]}], }, ]); @@ -153,7 +134,7 @@ test('Get the highest valid tag corresponding to the "tagFormat"', async t => { 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: [undefined]}], + tags: [{gitTag: '(.+)/1.0.0/(a-z)', version: '1.0.0', channels: [null]}], }, ]); @@ -161,12 +142,12 @@ test('Get the highest valid tag corresponding to the "tagFormat"', async t => { 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: [undefined]}], + 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: [undefined]}]}, + {name: 'master', tags: [{gitTag: '3.0.0-bar.2', version: '3.0.0', channels: [null]}]}, ]); }); diff --git a/test/get-last-release.test.js b/test/get-last-release.test.js index fa62e200a1..bb3a2ee26e 100644 --- a/test/get-last-release.test.js +++ b/test/get-last-release.test.js @@ -8,7 +8,7 @@ test('Get the highest non-prerelease valid tag', t => { 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@beta', gitHead: 'v3.0.0-beta.1@beta'}, + {version: '3.0.0-beta.1', gitTag: 'v3.0.0-beta.1', gitHead: 'v3.0.0-beta.1'}, ], type: 'release', }, @@ -25,14 +25,9 @@ test('Get the highest prerelease valid tag, ignoring other tags from other prere prerelease: 'beta', channel: 'beta', tags: [ - {version: '1.0.0-beta.1', gitTag: 'v1.0.0-beta.1@beta', gitHead: 'v1.0.0-beta.1@beta', channels: ['beta']}, - {version: '1.0.0-beta.2', gitTag: 'v1.0.0-beta.2@beta', gitHead: 'v1.0.0-beta.2@beta', channels: ['beta']}, - { - version: '1.0.0-alpha.1', - gitTag: 'v1.0.0-alpha.1@alpha', - gitHead: 'v1.0.0-alpha.1@alpha', - channels: ['alpha'], - }, + {version: '1.0.0-beta.1', gitTag: 'v1.0.0-beta.1', gitHead: 'v1.0.0-beta.1', channels: ['beta']}, + {version: '1.0.0-beta.2', gitTag: 'v1.0.0-beta.2', gitHead: 'v1.0.0-beta.2', channels: ['beta']}, + {version: '1.0.0-alpha.1', gitTag: 'v1.0.0-alpha.1', gitHead: 'v1.0.0-alpha.1', channels: ['alpha']}, ], type: 'prerelease', }, @@ -41,9 +36,9 @@ test('Get the highest prerelease valid tag, ignoring other tags from other prere t.deepEqual(result, { version: '1.0.0-beta.2', - gitTag: 'v1.0.0-beta.2@beta', + gitTag: 'v1.0.0-beta.2', name: 'v1.0.0-beta.2', - gitHead: 'v1.0.0-beta.2@beta', + gitHead: 'v1.0.0-beta.2', channels: ['beta'], }); }); @@ -52,7 +47,7 @@ test('Return empty object if no valid tag is found', t => { const result = getLastRelease({ branch: { name: 'master', - tags: [{version: '3.0.0-beta.1', gitTag: 'v3.0.0-beta.1@beta', gitHead: 'v3.0.0-beta.1@beta'}], + tags: [{version: '3.0.0-beta.1', gitTag: 'v3.0.0-beta.1', gitHead: 'v3.0.0-beta.1'}], type: 'release', }, options: {tagFormat: `v\${version}`}, @@ -70,7 +65,7 @@ test('Get the highest non-prerelease valid tag before a certain version', t => { 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: '2.0.0-beta.1', gitTag: 'v2.0.0-beta.1@beta', gitHead: 'v2.0.0-beta.1@beta'}, + {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'}, ], diff --git a/test/get-release-to-add.test.js b/test/get-release-to-add.test.js index 2b13111311..823e281792 100644 --- a/test/get-release-to-add.test.js +++ b/test/get-release-to-add.test.js @@ -9,12 +9,12 @@ test('Return versions merged from release to maintenance branch, excluding lower type: 'maintenance', mergeRange: '>=2.0.0 <3.0.0', tags: [ - {gitTag: 'v2.0.0@2.x', version: '2.0.0', channels: ['2.x']}, - {gitTag: 'v2.0.0', version: '2.0.0', channels: [undefined]}, - {gitTag: 'v2.1.0', version: '2.1.0', channels: [undefined]}, - {gitTag: 'v2.1.1', version: '2.1.1', channels: [undefined]}, - {gitTag: 'v1.0.0', version: '1.0.0', channels: [undefined]}, - {gitTag: 'v1.1.0', version: '1.1.0', channels: [undefined]}, + {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'}], @@ -22,11 +22,11 @@ test('Return versions merged from release to maintenance branch, excluding lower }); t.deepEqual(result, { - lastRelease: {version: '2.1.0', channels: [undefined], gitTag: 'v2.1.0', name: 'v2.1.0', gitHead: 'v2.1.0'}, + 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: [undefined], + channels: [null], gitTag: 'v2.1.1', name: 'v2.1.1', gitHead: 'v2.1.1', @@ -35,7 +35,7 @@ test('Return versions merged from release to maintenance branch, excluding lower type: 'patch', version: '2.1.1', channel: '2.x', - gitTag: 'v2.1.1@2.x', + gitTag: 'v2.1.1', name: 'v2.1.1', gitHead: 'v2.1.1', }, @@ -47,9 +47,9 @@ test('Return versions merged between release branches', t => { branch: { name: 'master', tags: [ - {gitTag: 'v1.0.0', version: '1.0.0', channels: [undefined, 'next']}, - {gitTag: 'v1.1.0@next', version: '1.1.0', channels: ['next']}, - {gitTag: 'v2.0.0@next-major', version: '2.0.0', channels: ['next-major']}, + {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'}], @@ -59,26 +59,26 @@ test('Return versions merged between release branches', t => { t.deepEqual(result, { lastRelease: { version: '1.1.0', - gitTag: 'v1.1.0@next', + gitTag: 'v1.1.0', name: 'v1.1.0', - gitHead: 'v1.1.0@next', + gitHead: 'v1.1.0', channels: ['next'], }, currentRelease: { type: 'major', version: '2.0.0', channels: ['next-major'], - gitTag: 'v2.0.0@next-major', + gitTag: 'v2.0.0', name: 'v2.0.0', - gitHead: 'v2.0.0@next-major', + gitHead: 'v2.0.0', }, nextRelease: { type: 'major', version: '2.0.0', - channel: undefined, + channel: null, gitTag: 'v2.0.0', name: 'v2.0.0', - gitHead: 'v2.0.0@next-major', + gitHead: 'v2.0.0', }, }); }); @@ -88,10 +88,9 @@ test('Return releases sorted by ascending order', t => { branch: { name: 'master', tags: [ - {gitTag: 'v2.0.0@next-major', version: '2.0.0', channels: ['next-major']}, - {gitTag: 'v1.1.0@next', version: '1.1.0', channels: ['next']}, - {gitTag: 'v1.0.0', version: '1.0.0', channels: [undefined, 'next']}, - // {gitTag: 'v1.0.0@next', version: '1.0.0', channel: 'next'}, + {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'}], @@ -99,22 +98,22 @@ test('Return releases sorted by ascending order', t => { }); t.deepEqual(result, { - lastRelease: {version: '1.1.0', gitTag: 'v1.1.0@next', name: 'v1.1.0', gitHead: 'v1.1.0@next', channels: ['next']}, + 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@next-major', + gitTag: 'v2.0.0', name: 'v2.0.0', - gitHead: 'v2.0.0@next-major', + gitHead: 'v2.0.0', }, nextRelease: { type: 'major', version: '2.0.0', - channel: undefined, + channel: null, gitTag: 'v2.0.0', name: 'v2.0.0', - gitHead: 'v2.0.0@next-major', + gitHead: 'v2.0.0', }, }); }); @@ -123,7 +122,7 @@ test('No lastRelease', t => { const result = getReleaseToAdd({ branch: { name: 'master', - tags: [{gitTag: 'v1.0.0@next', version: '1.0.0', channels: ['next']}], + tags: [{gitTag: 'v1.0.0', version: '1.0.0', channels: ['next']}], }, branches: [{name: 'master'}, {name: 'next', channel: 'next'}], options: {tagFormat: `v\${version}`}, @@ -135,17 +134,17 @@ test('No lastRelease', t => { type: 'major', version: '1.0.0', channels: ['next'], - gitTag: 'v1.0.0@next', + gitTag: 'v1.0.0', name: 'v1.0.0', - gitHead: 'v1.0.0@next', + gitHead: 'v1.0.0', }, nextRelease: { type: 'major', version: '1.0.0', - channel: undefined, + channel: null, gitTag: 'v1.0.0', name: 'v1.0.0', - gitHead: 'v1.0.0@next', + gitHead: 'v1.0.0', }, }); }); @@ -155,9 +154,9 @@ test('Ignore pre-release versions', t => { branch: { name: 'master', tags: [ - {gitTag: 'v1.0.0', version: '1.0.0', channels: [undefined, 'next']}, - {gitTag: 'v1.1.0@next', version: '1.1.0', channels: ['next']}, - {gitTag: 'v2.0.0-alpha.1@alpha', version: '2.0.0-alpha.1', channels: ['alpha']}, + {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: [ @@ -169,22 +168,22 @@ test('Ignore pre-release versions', t => { }); t.deepEqual(result, { - lastRelease: {version: '1.0.0', channels: [undefined, 'next'], gitTag: 'v1.0.0', name: 'v1.0.0', gitHead: 'v1.0.0'}, + 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@next', + gitTag: 'v1.1.0', name: 'v1.1.0', - gitHead: 'v1.1.0@next', + gitHead: 'v1.1.0', }, nextRelease: { type: 'minor', version: '1.1.0', - channel: undefined, + channel: null, gitTag: 'v1.1.0', name: 'v1.1.0', - gitHead: 'v1.1.0@next', + gitHead: 'v1.1.0', }, }); }); @@ -197,12 +196,12 @@ test('Exclude versions merged from release to maintenance branch if they have th type: 'maintenance', mergeRange: '>=2.0.0 <3.0.0', tags: [ - {gitTag: 'v2.0.0', version: '2.0.0', channels: [undefined]}, - {gitTag: 'v2.0.0', version: '2.0.0', channels: [undefined]}, - {gitTag: 'v2.1.0', version: '2.1.0', channels: [undefined]}, - {gitTag: 'v2.1.1', version: '2.1.1', channels: [undefined]}, - {gitTag: 'v1.0.0', version: '1.0.0', channels: [undefined]}, - {gitTag: 'v1.1.0', version: '1.1.0', channels: [undefined]}, + {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: [ @@ -243,9 +242,9 @@ test('Exclude versions merged between release branches if they all have "channel name: 'master', channel: false, tags: [ - {gitTag: 'v1.0.0', version: '1.0.0', channels: [undefined]}, - {gitTag: 'v1.1.0', version: '1.1.0', channels: [undefined]}, - {gitTag: 'v2.0.0', version: '2.0.0', channels: [undefined]}, + {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: [ @@ -267,12 +266,12 @@ test('Exclude versions number less than the latest version already released on t type: 'maintenance', mergeRange: '>=2.0.0 <3.0.0', tags: [ - {gitTag: 'v2.0.0@2.x', version: '2.0.0', channels: ['2.x']}, - {gitTag: 'v2.0.0', version: '2.0.0', channels: [undefined]}, - {gitTag: 'v2.1.0', version: '2.1.0', channels: [undefined]}, - {gitTag: 'v2.1.1', version: '2.1.1', channels: [undefined, '2.x']}, - {gitTag: 'v1.0.0', version: '1.0.0', channels: [undefined]}, - {gitTag: 'v1.1.0', version: '1.1.0', channels: [undefined]}, + {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'}], diff --git a/test/git.test.js b/test/git.test.js index 7383f15649..9df6d03cfe 100644 --- a/test/git.test.js +++ b/test/git.test.js @@ -14,6 +14,9 @@ import { isGitRepo, verifyTagName, isBranchUpToDate, + getNote, + addNote, + fetchNotes, } from '../lib/git'; import { gitRepo, @@ -27,6 +30,8 @@ import { gitRemoteTagHead, gitPush, gitDetachedHead, + gitAddNote, + gitGetNote, } from './helpers/git-utils'; test('Get the last commit sha', async t => { @@ -276,3 +281,91 @@ test('Return "true" if local repository is ahead', async t => { t.true(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', {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', {cwd}); + await fetchNotes(repositoryUrl, {cwd}); + + t.is(await gitGetNote(commit.hash, {cwd}), '{"note":"note"}'); +}); diff --git a/test/helpers/git-utils.js b/test/helpers/git-utils.js index 0473bb3de2..b5ea65b34e 100644 --- a/test/helpers/git-utils.js +++ b/test/helpers/git-utils.js @@ -4,6 +4,7 @@ import fileUrl from 'file-url'; import pEachSeries from 'p-each-series'; import gitLogParser from 'git-log-parser'; import getStream from 'get-stream'; +import {GIT_NOTE_REF} from '../../lib/definitions/constants'; /** * Commit message informations. @@ -258,3 +259,24 @@ export async function mergeFf(ref, execaOpts) { 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; +} diff --git a/test/index.test.js b/test/index.test.js index 11f35ca283..0c3d867de3 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -19,6 +19,8 @@ import { merge, mergeFf, rebase, + gitAddNote, + gitGetNote, } from './helpers/git-utils'; const requireNoCache = proxyquire.noPreserveCache(); @@ -45,7 +47,8 @@ test('Plugins are called with expected values', async t => { // Add commits to the master branch let commits = await gitCommits(['First'], {cwd}); // Create the tag corresponding to version 1.0.0 - await gitTagVersion('v1.0.0@next', undefined, {cwd}); + await gitTagVersion('v1.0.0', undefined, {cwd}); + await gitAddNote(JSON.stringify({channels: ['next']}), 'v1.0.0', {cwd}); commits = (await gitCommits(['Second'], {cwd})).concat(commits); await gitCheckout('next', true, {cwd}); await gitPush(repositoryUrl, 'next', {cwd}); @@ -55,7 +58,7 @@ test('Plugins are called with expected values', async t => { const lastRelease = { version: '1.0.0', gitHead: commits[commits.length - 1].hash, - gitTag: 'v1.0.0@next', + gitTag: 'v1.0.0', name: 'v1.0.0', channels: ['next'], }; @@ -65,7 +68,7 @@ test('Plugins are called with expected values', async t => { version: '1.1.0', gitHead: await getGitHead({cwd}), gitTag: 'v1.1.0', - channel: undefined, + channel: null, }; const notes1 = 'Release notes 1'; const notes2 = 'Release notes 2'; @@ -96,7 +99,7 @@ test('Plugins are called with expected values', async t => { name: 'master', range: '>=1.0.0 <2.0.0', accept: ['patch', 'minor'], - tags: [{channels: ['next'], gitTag: 'v1.0.0@next', version: '1.0.0'}], + tags: [{channels: ['next'], gitTag: 'v1.0.0', version: '1.0.0'}], type: 'release', main: true, }, @@ -105,7 +108,7 @@ test('Plugins are called with expected values', async t => { name: 'next', range: '>=2.0.0', accept: ['patch', 'minor', 'major'], - tags: [{channels: ['next'], gitTag: 'v1.0.0@next', version: '1.0.0'}], + tags: [{channels: ['next'], gitTag: 'v1.0.0', version: '1.0.0'}], type: 'release', main: false, }, @@ -130,7 +133,7 @@ test('Plugins are called with expected values', async t => { ...release1, type: 'major', version: '1.0.0', - channel: undefined, + channel: null, gitTag: 'v1.0.0', notes: `${notes1}\n\n${notes2}\n\n${notes3}`, pluginName: '[Function: functionStub]', @@ -181,7 +184,7 @@ test('Plugins are called with expected values', async t => { ...omit(lastRelease, 'channels'), type: 'major', version: '1.0.0', - channel: undefined, + channel: null, gitTag: 'v1.0.0', name: 'v1.0.0', }); @@ -198,7 +201,7 @@ test('Plugins are called with expected values', async t => { ...omit(lastRelease, 'channels'), type: 'major', version: '1.0.0', - channel: undefined, + channel: null, gitTag: 'v1.0.0', name: 'v1.0.0', notes: notes1, @@ -216,7 +219,7 @@ test('Plugins are called with expected values', async t => { ...omit(lastRelease, 'channels'), type: 'major', version: '1.0.0', - channel: undefined, + channel: null, gitTag: 'v1.0.0', name: 'v1.0.0', notes: `${notes1}\n\n${notes2}`, @@ -224,7 +227,7 @@ test('Plugins are called with expected values', async t => { branch.tags.push({ version: '1.0.0', - channel: undefined, + channel: null, gitTag: 'v1.0.0', gitHead: commits[commits.length - 1].hash, }); @@ -241,7 +244,7 @@ test('Plugins are called with expected values', async t => { ...omit(lastRelease, 'channels'), type: 'major', version: '1.0.0', - channel: undefined, + channel: null, gitTag: 'v1.0.0', name: 'v1.0.0', notes: `${notes1}\n\n${notes2}\n\n${notes3}`, @@ -335,7 +338,7 @@ test('Plugins are called with expected values', async t => { ...omit(lastRelease, 'channels'), type: 'major', version: '1.0.0', - channel: undefined, + channel: null, gitTag: 'v1.0.0', name: 'v1.0.0', notes: `${notes1}\n\n${notes2}\n\n${notes3}`, @@ -435,7 +438,7 @@ test('Use new gitHead, and recreate release notes if a prepare plugin create a c version: '2.0.0', gitHead: await getGitHead({cwd}), gitTag: 'v2.0.0', - channel: undefined, + channel: null, }; const notes = 'Release notes'; @@ -494,15 +497,16 @@ test('Use new gitHead, and recreate release notes if a prepare plugin create a c test('Make a new release when a commit is forward-ported to an upper branch', async t => { const {cwd, repositoryUrl} = await gitRepo(true); - const commits = await gitCommits(['feat: initial release'], {cwd}); + await gitCommits(['feat: initial release'], {cwd}); await gitTagVersion('v1.0.0', undefined, {cwd}); - await gitTagVersion('v1.0.0@1.0.x', undefined, {cwd}); + await gitAddNote(JSON.stringify({channels: [null, '1.0.x']}), 'v1.0.0', {cwd}); await gitCheckout('1.0.x', true, {cwd}); - commits.push(...(await gitCommits(['fix: fix on maintenance version 1.0.x'], {cwd}))); - await gitTagVersion('v1.0.1@1.0.x', undefined, {cwd}); + await gitCommits(['fix: fix on maintenance version 1.0.x'], {cwd}); + await gitTagVersion('v1.0.1', undefined, {cwd}); + await gitAddNote(JSON.stringify({channels: ['1.0.x']}), 'v1.0.1', {cwd}); await gitPush('origin', '1.0.x', {cwd}); await gitCheckout('master', false, {cwd}); - commits.push(...(await gitCommits(['feat: new feature on master'], {cwd}))); + await gitCommits(['feat: new feature on master'], {cwd}); await gitTagVersion('v1.1.0', undefined, {cwd}); await merge('1.0.x', {cwd}); await gitPush('origin', 'master', {cwd}); @@ -568,7 +572,8 @@ test('Publish a pre-release version', async t => { t.is(releases.length, 1); t.is(releases[0].version, '1.1.0-beta.1'); - t.is(releases[0].gitTag, 'v1.1.0-beta.1@beta'); + t.is(releases[0].gitTag, 'v1.1.0-beta.1'); + t.is(await gitGetNote('v1.1.0-beta.1', {cwd}), '{"channels":["beta"]}'); await gitCommits(['fix: a fix'], {cwd}); ({releases} = await semanticRelease(options, { @@ -580,7 +585,8 @@ test('Publish a pre-release version', async t => { t.is(releases.length, 1); t.is(releases[0].version, '1.1.0-beta.2'); - t.is(releases[0].gitTag, 'v1.1.0-beta.2@beta'); + t.is(releases[0].gitTag, 'v1.1.0-beta.2'); + t.is(await gitGetNote('v1.1.0-beta.2', {cwd}), '{"channels":["beta"]}'); }); test('Publish releases from different branch on the same channel', async t => { @@ -696,14 +702,16 @@ test('Publish pre-releases the same channel as regular releases', async t => { test('Do not add pre-releases to a different channel', async t => { const {cwd, repositoryUrl} = await gitRepo(true); - const commits = await gitCommits(['feat: initial release'], {cwd}); + await gitCommits(['feat: initial release'], {cwd}); await gitTagVersion('v1.0.0', undefined, {cwd}); - await gitTagVersion('v1.0.0@beta', undefined, {cwd}); + await gitAddNote(JSON.stringify({channels: [null, 'beta']}), 'v1.0.0', {cwd}); await gitCheckout('beta', true, {cwd}); - commits.push(...(await gitCommits(['feat: breaking change/n/nBREAKING CHANGE: break something'], {cwd}))); - await gitTagVersion('v2.0.0-beta.1@beta', undefined, {cwd}); - commits.push(...(await gitCommits(['fix: a fix'], {cwd}))); - await gitTagVersion('v2.0.0-beta.2@beta', undefined, {cwd}); + await gitCommits(['feat: breaking change/n/nBREAKING CHANGE: break something'], {cwd}); + await gitTagVersion('v2.0.0-beta.1', undefined, {cwd}); + await gitAddNote(JSON.stringify({channels: ['beta']}), 'v2.0.0-beta.1', {cwd}); + await gitCommits(['fix: a fix'], {cwd}); + await gitTagVersion('v2.0.0-beta.2', undefined, {cwd}); + await gitAddNote(JSON.stringify({channels: ['beta']}), 'v2.0.0-beta.2', {cwd}); await gitPush('origin', 'beta', {cwd}); await gitCheckout('master', false, {cwd}); await merge('beta', {cwd}); @@ -748,14 +756,18 @@ async function addChannelMacro(t, mergeFunction) { const {cwd, repositoryUrl} = await gitRepo(true); const commits = await gitCommits(['feat: initial release'], {cwd}); await gitTagVersion('v1.0.0', undefined, {cwd}); - await gitTagVersion('v1.0.0@next', undefined, {cwd}); + await gitAddNote(JSON.stringify({channels: [null, 'next']}), 'v1.0.0', {cwd}); await gitCheckout('next', true, {cwd}); commits.push(...(await gitCommits(['feat: breaking change/n/nBREAKING CHANGE: break something'], {cwd}))); - await gitTagVersion('v2.0.0@next', undefined, {cwd}); + await gitTagVersion('v2.0.0', undefined, {cwd}); + await gitAddNote(JSON.stringify({channels: ['next']}), 'v2.0.0', {cwd}); + commits.push(...(await gitCommits(['fix: a fix'], {cwd}))); - await gitTagVersion('v2.0.1@next', undefined, {cwd}); + await gitTagVersion('v2.0.1', undefined, {cwd}); + await gitAddNote(JSON.stringify({channels: ['next']}), 'v2.0.1', {cwd}); commits.push(...(await gitCommits(['feat: a feature'], {cwd}))); - await gitTagVersion('v2.1.0@next', undefined, {cwd}); + await gitTagVersion('v2.1.0', undefined, {cwd}); + await gitAddNote(JSON.stringify({channels: ['next']}), 'v2.1.0', {cwd}); await gitPush('origin', 'next', {cwd}); await gitCheckout('master', false, {cwd}); // Merge all commits but last one from next to master @@ -788,7 +800,7 @@ async function addChannelMacro(t, mergeFunction) { name: 'v2.0.1', type: 'patch', version: '2.0.1', - channel: undefined, + channel: null, gitTag: 'v2.0.1', gitHead: commits[2].hash, }; @@ -832,7 +844,7 @@ test('Call all "success" plugins even if one errors out', async t => { version: '2.0.0', gitHead: await getGitHead({cwd}), gitTag: 'v2.0.0', - channel: undefined, + channel: null, }; const notes = 'Release notes'; const verifyConditions1 = stub().resolves(); @@ -967,9 +979,11 @@ test('Dry-run skips addChannel, prepare, publish and success', async t => { const {cwd, repositoryUrl} = await gitRepo(true); await gitCommits(['First'], {cwd}); await gitTagVersion('v1.0.0', undefined, {cwd}); - await gitTagVersion('v1.0.0@next', undefined, {cwd}); - await gitTagVersion('v1.1.0@next', undefined, {cwd}); + await gitAddNote(JSON.stringify({channels: [null, 'next']}), 'v1.0.0', {cwd}); await gitCommits(['Second'], {cwd}); + await gitTagVersion('v1.1.0', undefined, {cwd}); + await gitAddNote(JSON.stringify({channels: ['next']}), 'v1.1.0', {cwd}); + await gitPush(repositoryUrl, 'master', {cwd}); await gitCheckout('next', true, {cwd}); await gitPush('origin', 'next', {cwd}); @@ -1249,8 +1263,10 @@ test('Accept "undefined" value returned by "generateNotes" and "false" by "publi const {cwd, repositoryUrl} = await gitRepo(true); await gitCommits(['First'], {cwd}); await gitTagVersion('v1.0.0', undefined, {cwd}); - await gitTagVersion('v1.0.0@next', undefined, {cwd}); - await gitTagVersion('v1.1.0@next', undefined, {cwd}); + await gitAddNote(JSON.stringify({channels: [null, 'next']}), 'v1.0.0', {cwd}); + await gitCommits(['Second'], {cwd}); + await gitTagVersion('v1.1.0', undefined, {cwd}); + await gitAddNote(JSON.stringify({channels: ['next']}), 'v1.1.0', {cwd}); await gitPush(repositoryUrl, 'master', {cwd}); await gitCheckout('next', true, {cwd}); await gitPush('origin', 'next', {cwd}); @@ -1262,7 +1278,7 @@ test('Accept "undefined" value returned by "generateNotes" and "false" by "publi version: '1.2.0', gitHead: await getGitHead({cwd}), gitTag: 'v1.2.0', - channel: undefined, + channel: null, }; const analyzeCommits = stub().resolves(nextRelease.type); const verifyRelease = stub().resolves(); @@ -1335,16 +1351,16 @@ test('Returns false if triggered by a PR', async t => { test('Throws "EINVALIDNEXTVERSION" if next release is out of range of the current maintenance branch', async t => { const {cwd, repositoryUrl} = await gitRepo(true); - const commits = await gitCommits(['feat: initial commit'], {cwd}); + await gitCommits(['feat: initial commit'], {cwd}); await gitTagVersion('v1.0.0', undefined, {cwd}); - await gitTagVersion('v1.0.0@1.x', undefined, {cwd}); + await gitAddNote(JSON.stringify({channels: [null, '1.x']}), 'v1.0.0', {cwd}); await gitCheckout('1.x', true, {cwd}); await gitPush('origin', '1.x', {cwd}); await gitCheckout('master', false, {cwd}); - commits.push(...(await gitCommits(['feat: new feature on master'], {cwd}))); + await gitCommits(['feat: new feature on master'], {cwd}); await gitTagVersion('v1.1.0', undefined, {cwd}); await gitCheckout('1.x', false, {cwd}); - commits.push(...(await gitCommits(['feat: feature on maintenance version 1.x'], {cwd}))); + await gitCommits(['feat: feature on maintenance version 1.x'], {cwd}); await gitPush('origin', 'master', {cwd}); const verifyConditions = stub().resolves(); @@ -1386,16 +1402,17 @@ test('Throws "EINVALIDNEXTVERSION" if next release is out of range of the curren test('Throws "EINVALIDNEXTVERSION" if next release is out of range of the current release branch', async t => { const {cwd, repositoryUrl} = await gitRepo(true); - const commits = await gitCommits(['feat: initial commit'], {cwd}); + await gitCommits(['feat: initial commit'], {cwd}); await gitTagVersion('v1.0.0', undefined, {cwd}); await gitCheckout('next', true, {cwd}); - commits.push(...(await gitCommits(['feat: new feature on next'], {cwd}))); - await gitTagVersion('v1.1.0@next', undefined, {cwd}); + await gitCommits(['feat: new feature on next'], {cwd}); + await gitTagVersion('v1.1.0', undefined, {cwd}); + await gitAddNote(JSON.stringify({channels: ['next']}), 'v1.1.0', {cwd}); await gitPush('origin', 'next', {cwd}); await gitCheckout('next-major', true, {cwd}); await gitPush('origin', 'next-major', {cwd}); await gitCheckout('master', false, {cwd}); - commits.push(...(await gitCommits(['feat: new feature on master', 'fix: new fix on master'], {cwd}))); + await gitCommits(['feat: new feature on master', 'fix: new fix on master'], {cwd}); await gitPush('origin', 'master', {cwd}); const verifyConditions = stub().resolves(); @@ -1437,18 +1454,18 @@ test('Throws "EINVALIDNEXTVERSION" if next release is out of range of the curren test('Throws "EINVALIDMAINTENANCEMERGE" if merge an out of range release in a maintenance branch', async t => { const {cwd, repositoryUrl} = await gitRepo(true); - const commits = await gitCommits(['First'], {cwd}); + await gitCommits(['First'], {cwd}); await gitTagVersion('v1.0.0', undefined, {cwd}); - await gitTagVersion('v1.0.0@1.1.x', undefined, {cwd}); - commits.push(...(await gitCommits(['Second'], {cwd}))); + await gitAddNote(JSON.stringify({channels: [null, '1.1.x']}), 'v1.0.0', {cwd}); + await gitCommits(['Second'], {cwd}); await gitTagVersion('v1.1.0', undefined, {cwd}); - await gitTagVersion('v1.1.0@1.1.x', undefined, {cwd}); + await gitAddNote(JSON.stringify({channels: [null, '1.1.x']}), 'v1.1.0', {cwd}); await gitCheckout('1.1.x', 'master', {cwd}); await gitPush('origin', '1.1.x', {cwd}); await gitCheckout('master', false, {cwd}); - commits.push(...(await gitCommits(['Third'], {cwd}))); + await gitCommits(['Third'], {cwd}); await gitTagVersion('v1.1.1', undefined, {cwd}); - commits.push(...(await gitCommits(['Fourth'], {cwd}))); + await gitCommits(['Fourth'], {cwd}); await gitTagVersion('v1.2.0', undefined, {cwd}); await gitPush('origin', 'master', {cwd}); await gitCheckout('1.1.x', false, {cwd}); diff --git a/test/integration.test.js b/test/integration.test.js index 576f2cd1aa..8840a1888e 100644 --- a/test/integration.test.js +++ b/test/integration.test.js @@ -16,6 +16,7 @@ import { gitPush, gitCheckout, merge, + gitGetNote, } from './helpers/git-utils'; import {npmView} from './helpers/npm-utils'; import gitbox from './helpers/gitbox'; @@ -220,7 +221,7 @@ test('Release patch, minor and major versions', async t => { createReleaseMock = await mockServer.mock( `/repos/${owner}/${packageName}/releases`, { - body: {tag_name: `v${version}@next`, name: `v${version}`}, + body: {tag_name: `v${version}`, name: `v${version}`}, headers: [{name: 'Authorization', values: [`token ${env.GH_TOKEN}`]}], }, {body: {html_url: `release-url/${version}`}} @@ -246,8 +247,9 @@ test('Release patch, minor and major versions', async t => { } = await npmView(packageName, testEnv)); head = await gitHead({cwd}); t.is(releasedVersion, version); - t.is(await gitTagHead(`v${version}@next`, {cwd}), head); - t.is(await gitRemoteTagHead(authUrl, `v${version}@next`, {cwd}), head); + t.is(await gitGetNote(`v${version}`, {cwd}), '{"channels":["next"]}'); + t.is(await gitTagHead(`v${version}`, {cwd}), head); + t.is(await gitRemoteTagHead(authUrl, `v${version}`, {cwd}), head); t.log(`+ released ${releasedVersion} on @next`); await mockServer.verify(verifyMock); @@ -262,7 +264,7 @@ test('Release patch, minor and major versions', async t => { {body: {permissions: {push: true}}, method: 'GET'} ); const getReleaseMock = await mockServer.mock( - `/repos/${owner}/${packageName}/releases/tags/v2.0.0@next`, + `/repos/${owner}/${packageName}/releases/tags/v2.0.0`, {headers: [{name: 'Authorization', values: [`token ${env.GH_TOKEN}`]}]}, {body: {id: releaseId}, method: 'GET'} ); @@ -292,11 +294,9 @@ test('Release patch, minor and major versions', async t => { 'dist-tags': {latest: releasedVersion}, } = await npmView(packageName, testEnv)); t.is(releasedVersion, version); - t.is(await gitTagHead(`v${version}`, {cwd}), await gitTagHead(`v${version}@next`, {cwd})); - t.is( - await gitRemoteTagHead(authUrl, `v${version}`, {cwd}), - await gitRemoteTagHead(authUrl, `v${version}@next`, {cwd}) - ); + 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); diff --git a/test/utils.test.js b/test/utils.test.js index 2130883893..dd05a04907 100644 --- a/test/utils.test.js +++ b/test/utils.test.js @@ -174,10 +174,6 @@ test('getRange', t => { test('makeTag', t => { t.is(makeTag(`v\${version}`, '1.0.0'), 'v1.0.0'); - t.is(makeTag(`v\${version}`, '1.0.0', false), 'v1.0.0'); - t.is(makeTag(`v\${version}`, '1.0.0', null), 'v1.0.0'); - t.is(makeTag(`v\${version}`, '1.0.0', 'next'), 'v1.0.0@next'); - t.is(makeTag(`v\${version}@test`, '1.0.0', 'next'), 'v1.0.0@next@test'); }); test('isSameChannel', t => { From cbef9d18da0f5dcaf22e6c7d8737442f954a9481 Mon Sep 17 00:00:00 2001 From: Pierre Vanduynslager Date: Tue, 3 Dec 2019 17:38:10 -0500 Subject: [PATCH 099/107] fix: modify fetch function to handle CircleCI specifics --- index.js | 2 +- lib/branches/index.js | 4 +- lib/git.js | 10 +++-- test/branches/branches.test.js | 81 ++++++++++++++++++++++++++-------- test/git.test.js | 34 ++++++++++++-- test/helpers/git-utils.js | 11 +++++ 6 files changed, 114 insertions(+), 28 deletions(-) diff --git a/index.js b/index.js index 29a79f7d6d..8696d8b254 100644 --- a/index.js +++ b/index.js @@ -53,7 +53,7 @@ async function run(context, plugins) { await verify(context); options.repositoryUrl = await getGitAuthUrl(context); - context.branches = await getBranches(options.repositoryUrl, context); + context.branches = await getBranches(options.repositoryUrl, ciBranch, context); context.branch = context.branches.find(({name}) => name === ciBranch); if (!context.branch) { diff --git a/lib/branches/index.js b/lib/branches/index.js index b3781f0905..b94e76f23b 100644 --- a/lib/branches/index.js +++ b/lib/branches/index.js @@ -8,7 +8,7 @@ const expand = require('./expand'); const getTags = require('./get-tags'); const normalize = require('./normalize'); -module.exports = async (repositoryUrl, context) => { +module.exports = async (repositoryUrl, ciBranch, context) => { const {cwd, env} = context; const remoteBranches = await expand( @@ -18,7 +18,7 @@ module.exports = async (repositoryUrl, context) => { ); await pEachSeries(remoteBranches, async ({name}) => { - await fetch(repositoryUrl, name, {cwd, env}); + await fetch(repositoryUrl, name, ciBranch, {cwd, env}); }); await fetchNotes(repositoryUrl, {cwd, env}); diff --git a/lib/git.js b/lib/git.js index 0c2d7836a6..efaecadba2 100644 --- a/lib/git.js +++ b/lib/git.js @@ -119,7 +119,7 @@ async function isRefExists(ref, execaOpts) { * @param {String} branch The repository branch to fetch. * @param {Object} [execaOpts] Options to pass to `execa`. */ -async function fetch(repositoryUrl, branch, execaOpts) { +async function fetch(repositoryUrl, branch, ciBranch, execaOpts) { const isLocalExists = (await execa('git', ['rev-parse', '--verify', branch], {...execaOpts, reject: false})).exitCode === 0; @@ -130,7 +130,9 @@ async function fetch(repositoryUrl, branch, execaOpts) { 'fetch', '--unshallow', '--tags', - ...(isLocalExists ? [repositoryUrl] : [repositoryUrl, `+refs/heads/${branch}:refs/heads/${branch}`]), + ...(branch === ciBranch && isLocalExists + ? [repositoryUrl] + : ['--update-head-ok', repositoryUrl, `+refs/heads/${branch}:refs/heads/${branch}`]), ], execaOpts ); @@ -140,7 +142,9 @@ async function fetch(repositoryUrl, branch, execaOpts) { [ 'fetch', '--tags', - ...(isLocalExists ? [repositoryUrl] : [repositoryUrl, `+refs/heads/${branch}:refs/heads/${branch}`]), + ...(branch === ciBranch && isLocalExists + ? [repositoryUrl] + : ['--update-head-ok', repositoryUrl, `+refs/heads/${branch}:refs/heads/${branch}`]), ], execaOpts ); diff --git a/test/branches/branches.test.js b/test/branches/branches.test.js index 76ed0dd10b..a658aa2bd0 100644 --- a/test/branches/branches.test.js +++ b/test/branches/branches.test.js @@ -24,7 +24,10 @@ test('Enforce ranges with branching release workflow', async t => { ]; const getBranches = proxyquire('../../lib/branches', {'./get-tags': () => branches, './expand': () => []}); - let result = (await getBranches('repositoryUrl', {options: {branches}})).map(({name, range}) => ({name, range})); + 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 <1.1.0', 'Can release only patch on master'); @@ -32,43 +35,64 @@ test('Enforce ranges with branching release workflow', async t => { t.is(getBranch(result, 'next-major').range, '>=2.0.0', 'Can release only major on next-major'); release(branches, 'master', '1.0.0'); - result = (await getBranches('repositoryUrl', {options: {branches}})).map(({name, range}) => ({name, range})); + 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 <1.1.0', 'Can release only patch on master'); release(branches, 'master', '1.0.1'); - result = (await getBranches('repositoryUrl', {options: {branches}})).map(({name, range}) => ({name, range})); + 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'); merge(branches, 'master', 'next'); merge(branches, 'master', 'next-major'); - result = (await getBranches('repositoryUrl', {options: {branches}})).map(({name, range}) => ({name, range})); + 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.0 <2.0.0', 'Can release only minor on next'); t.is(getBranch(result, 'next-major').range, '>=2.0.0', 'Can release only major on next-major'); release(branches, 'next', '1.1.0'); release(branches, 'next', '1.1.1'); - result = (await getBranches('repositoryUrl', {options: {branches}})).map(({name, range}) => ({name, range})); + result = (await getBranches('repositoryUrl', 'master', {options: {branches}})).map(({name, range}) => ({ + name, + range, + })); t.is(getBranch(result, 'next').range, '>=1.1.1 <2.0.0', 'Can release only patch or minor, > than 1.1.0 on next'); release(branches, 'next-major', '2.0.0'); release(branches, 'next-major', '2.0.1'); - result = (await getBranches('repositoryUrl', {options: {branches}})).map(({name, range}) => ({name, range})); + 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, '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', {options: {branches}})).map(({name, range}) => ({name, range})); + 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'); release(branches, 'master', '1.0.1'); - result = (await getBranches('repositoryUrl', {options: {branches}})).map(({name, range}) => ({name, range})); + 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, @@ -80,7 +104,10 @@ test('Enforce ranges with branching release workflow', async t => { release(branches, 'master', '1.0.2'); release(branches, 'master', '1.0.3'); release(branches, 'master', '1.0.4'); - result = (await getBranches('repositoryUrl', {options: {branches}})).map(({name, range}) => ({name, range})); + 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, @@ -90,7 +117,10 @@ test('Enforce ranges with branching release workflow', async t => { 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', {options: {branches}})).map(({name, range}) => ({name, range})); + result = (await getBranches('repositoryUrl', 'master', {options: {branches}})).map(({name, range}) => ({ + name, + range, + })); t.is(getBranch(result, 'master').range, '>=1.1.1 <1.2.0', 'Can release only patch, > than 1.1.1 on master'); t.is(getBranch(result, 'next').range, '>=1.2.0 <2.0.0', 'Can release only patch or minor, > than 1.2.0 on next'); t.is(getBranch(result, 'next-major').range, '>=2.0.1', 'Can release any version, > than 2.0.1 on next-major'); @@ -102,34 +132,49 @@ test('Enforce ranges with branching release workflow', async t => { 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', {options: {branches}})).map(({name, range}) => ({name, range})); + result = (await getBranches('repositoryUrl', 'master', {options: {branches}})).map(({name, range}) => ({ + name, + range, + })); t.is(getBranch(result, 'master').range, '>=1.1.1 <1.2.0', 'Can release only patch, > 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', {options: {branches}})).map(({name, range}) => ({name, range})); + result = (await getBranches('repositoryUrl', 'master', {options: {branches}})).map(({name, range}) => ({ + name, + range, + })); t.is(getBranch(result, 'master').range, '>=1.1.1 <1.2.0', 'Can release only patch, > 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', {options: {branches}})).map(({name, range}) => ({name, range})); + result = (await getBranches('repositoryUrl', 'master', {options: {branches}})).map(({name, range}) => ({ + name, + range, + })); t.is(getBranch(result, 'master').range, '>=2.0.1 <2.1.0', 'Can release only patch, > than 2.0.1 on master'); t.is(getBranch(result, 'next').range, '>=2.1.0 <3.0.0', 'Can release only minor on next'); t.is(getBranch(result, 'next-major').range, '>=3.0.0', 'Can release only major 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'); - result = (await getBranches('repositoryUrl', {options: {branches}})).map(({name, range}) => ({name, range})); + result = (await getBranches('repositoryUrl', 'master', {options: {branches}})).map(({name, range}) => ({ + name, + range, + })); t.is(getBranch(result, 'master').range, '>=2.0.1 <2.1.0', 'Can release only patch, > than 2.0.1 on master'); t.is(getBranch(result, 'next').range, '>=2.1.0 <3.0.0', 'Can release only minor on next'); t.is(getBranch(result, 'next-major').range, '>=3.0.0', 'Can release only major on next-major'); branches.push({name: '1.1.x', tags: []}); merge(branches, '1.x', '1.1.x'); - result = (await getBranches('repositoryUrl', {options: {branches}})).map(({name, range}) => ({name, range})); + 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'); @@ -146,7 +191,7 @@ test('Throw SemanticReleaseError for invalid configurations', async t => { {name: 'preview', prerelease: 'alpha', tags: []}, ]; const getBranches = proxyquire('../../lib/branches', {'./get-tags': () => branches, './expand': () => []}); - const errors = [...(await t.throwsAsync(getBranches('repositoryUrl', {options: {branches}})))]; + const errors = [...(await t.throwsAsync(getBranches('repositoryUrl', 'master', {options: {branches}})))]; t.is(errors[0].name, 'SemanticReleaseError'); t.is(errors[0].code, 'EMAINTENANCEBRANCH'); @@ -177,7 +222,7 @@ test('Throw a SemanticReleaseError if there is duplicate branches', async t => { ]; const getBranches = proxyquire('../../lib/branches', {'./get-tags': () => branches, './expand': () => []}); - const errors = [...(await t.throwsAsync(getBranches('repositoryUrl', {options: {branches}})))]; + const errors = [...(await t.throwsAsync(getBranches('repositoryUrl', 'master', {options: {branches}})))]; t.is(errors[0].name, 'SemanticReleaseError'); t.is(errors[0].code, 'EDUPLICATEBRANCHES'); @@ -192,7 +237,7 @@ test('Throw a SemanticReleaseError for each invalid branch name', async t => { ]; const getBranches = proxyquire('../../lib/branches', {'./get-tags': () => branches, './expand': () => []}); - const errors = [...(await t.throwsAsync(getBranches('repositoryUrl', {options: {branches}})))]; + const errors = [...(await t.throwsAsync(getBranches('repositoryUrl', 'master', {options: {branches}})))]; t.is(errors[0].name, 'SemanticReleaseError'); t.is(errors[0].code, 'EINVALIDBRANCHNAME'); diff --git a/test/git.test.js b/test/git.test.js index 9df6d03cfe..eb320d1a38 100644 --- a/test/git.test.js +++ b/test/git.test.js @@ -30,6 +30,7 @@ import { gitRemoteTagHead, gitPush, gitDetachedHead, + gitDetachedHeadFromBranch, gitAddNote, gitGetNote, } from './helpers/git-utils'; @@ -63,7 +64,7 @@ test('Unshallow and fetch repository', async t => { // Verify the shallow clone contains only one commit t.is((await gitGetCommits(undefined, {cwd})).length, 1); - await fetch(repositoryUrl, 'master', {cwd}); + await fetch(repositoryUrl, 'master', 'master', {cwd}); // Verify the shallow clone contains all the commits t.is((await gitGetCommits(undefined, {cwd})).length, 2); @@ -78,8 +79,8 @@ test('Do not throw error when unshallow a complete repository', async t => { await gitCommits(['Second'], {cwd}); await gitPush(repositoryUrl, 'second-branch', {cwd}); - await t.notThrowsAsync(fetch(repositoryUrl, 'master', {cwd})); - await t.notThrowsAsync(fetch(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 => { @@ -94,11 +95,36 @@ test('Fetch all tags on a detached head repository', async t => { await gitPush(repositoryUrl, 'master', {cwd}); cwd = await gitDetachedHead(repositoryUrl, commit.hash); - await fetch(repositoryUrl, 'master', {cwd}); + await fetch(repositoryUrl, 'master', 'master', {cwd}); t.deepEqual((await getTags('master', {cwd})).sort(), ['v1.0.0', 'v1.0.1', 'v1.1.0'].sort()); }); +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 the commit `sha` is in the direct history of the current branch', async t => { // Create a git repository, set the current working directory at the root of the repo const {cwd} = await gitRepo(); diff --git a/test/helpers/git-utils.js b/test/helpers/git-utils.js index b5ea65b34e..2dfa4ba289 100644 --- a/test/helpers/git-utils.js +++ b/test/helpers/git-utils.js @@ -166,6 +166,17 @@ export async function gitDetachedHead(repositoryUrl, head) { 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. * From ec54c0be8a2481621ca4a813e697759a0845c863 Mon Sep 17 00:00:00 2001 From: Pierre Vanduynslager Date: Tue, 3 Dec 2019 20:07:42 -0500 Subject: [PATCH 100/107] test: fix calls to `fetch` in tests --- test/git.test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/git.test.js b/test/git.test.js index eb320d1a38..09c2180262 100644 --- a/test/git.test.js +++ b/test/git.test.js @@ -374,7 +374,7 @@ test('Unshallow and fetch repository with notes', async t => { // Verify the shallow clone doesn't contains the note await t.throwsAsync(gitGetNote(commits[0].hash, {cwd})); - await fetch(repositoryUrl, 'master', {cwd}); + await fetch(repositoryUrl, 'master', 'master', {cwd}); await fetchNotes(repositoryUrl, {cwd}); // Verify the shallow clone contains the note @@ -390,7 +390,7 @@ test('Fetch all notes on a detached head repository', async t => { await gitAddNote(JSON.stringify({note: 'note'}), commit.hash, {cwd}); cwd = await gitDetachedHead(repositoryUrl, commit.hash); - await fetch(repositoryUrl, 'master', {cwd}); + await fetch(repositoryUrl, 'master', 'master', {cwd}); await fetchNotes(repositoryUrl, {cwd}); t.is(await gitGetNote(commit.hash, {cwd}), '{"note":"note"}'); From 916c2685c57f3490fb1e50afbf72ea8dce11e188 Mon Sep 17 00:00:00 2001 From: Pierre Vanduynslager Date: Wed, 4 Dec 2019 17:53:27 -0500 Subject: [PATCH 101/107] feat: allow to release any version on a branch if up to date with next branch --- docs/usage/workflow-configuration.md | 21 ++++----- lib/branches/normalize.js | 33 ++++++-------- test/branches/branches.test.js | 49 ++++++++++++--------- test/branches/normalize.test.js | 65 ++++++++++------------------ test/index.test.js | 6 +-- 5 files changed, 77 insertions(+), 97 deletions(-) diff --git a/docs/usage/workflow-configuration.md b/docs/usage/workflow-configuration.md index c2d27265d9..8c08990c80 100644 --- a/docs/usage/workflow-configuration.md +++ b/docs/usage/workflow-configuration.md @@ -100,7 +100,7 @@ For example the configuration `['master', {name: 'pre/rc', prerelease: '${name.r ### 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. +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). @@ -112,20 +112,17 @@ See [publishing on distribution channels recipe](../recipes/distribution-channel #### Pushing to a release branch -With the configuration `"branches": ["master", "next"]`, if the last release published from `master` is `1.0.0` then: +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` -- Only versions in range `>=2.0.0` release can be published from `next`, so a `BREAKING CHANGE` commit must be pushed first on `next` and can be followed by any type of commits +- 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 -With the configuration `"branches": ["master", "next", "next-major"]`, if the last release published from `master` is `1.0.0` then: -- Only versions in range `1.0.x` can be published from `master`, so only `fix` commits can be pushed to `master` -- Only versions in range `>=1.1.0` can be published from `next`, so a `feat` commit must be pushed first on `next` and can be followed by `fix` and `feat` commits -- Only versions in range `>=2.0.0` release can be published from `next`, so a `BREAKING CHANGE` commit must be pushed first on `next-major` and can be followed by any type of commits - -Those verifications prevent situations such as: -1. Create a `feat` commit on `next` which triggers the release of version `1.0.0` on channel `next` +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. Push a `fix` commit to `master` which triggers the release of version `1.0.1` on the default channel -4. Push a `fix` commit to `next` which would attempt to release the version `1.0.1` on channel `next` and fails as this version already exists +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 diff --git a/lib/branches/normalize.js b/lib/branches/normalize.js index 103519c10b..369bd9d717 100644 --- a/lib/branches/normalize.js +++ b/lib/branches/normalize.js @@ -1,5 +1,4 @@ const {sortBy, isNil} = require('lodash'); -const semver = require('semver'); const semverDiff = require('semver-diff'); const {FIRST_RELEASE, RELEASE_TYPE} = require('../definitions/constants'); const { @@ -61,35 +60,29 @@ function release({release}) { return release; } - const breakpoints = release.length > 2 ? ['minor', 'major'] : ['major']; - - // The intial bound is the last release from the base branch of `FIRST_RELEASE` (1.0.0) - let bound = getLatestVersion(tagsToVersions(release[0].tags)) || FIRST_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 lower bound is the highest version between the current branch last release and the previous branch upper bound (`bound`) - const min = highest(getLatestVersion(versions), bound); - if (release.length - 1 === idx) { - // If the current branch is the last one of the release branch, there is no upper bound - bound = undefined; - } else { - // The default upper bound is the lower bound increment with the release type of the current branch position - const upperBound = semver.inc(min, breakpoints[idx]); - // Find the lowest version that is present on the current branch but none of the previous ones - const nextFirstVersion = getFirstVersion(tagsToVersions(release[idx + 1].tags), release.slice(0, idx + 1)); - // The upper bound is the lowest version between `nextFirstVersion` and the default upper bound - bound = lowest(nextFirstVersion, upperBound); - } + // 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(min, bound) : null; + const diff = bound ? semverDiff(lastVersion, bound) : null; return { ...rest, channel: idx === 0 ? channel : isNil(channel) ? name : channel, tags, type: 'release', name, - range: getRange(min, bound), + range: getRange(lastVersion, bound), accept: bound ? RELEASE_TYPE.slice(0, RELEASE_TYPE.indexOf(diff)) : RELEASE_TYPE, main: idx === 0, }; diff --git a/test/branches/branches.test.js b/test/branches/branches.test.js index a658aa2bd0..a87bbba790 100644 --- a/test/branches/branches.test.js +++ b/test/branches/branches.test.js @@ -30,9 +30,9 @@ test('Enforce ranges with branching release workflow', async t => { })); 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 <1.1.0', 'Can release only patch on master'); - t.is(getBranch(result, 'next').range, '>=1.1.0 <2.0.0', 'Can release only minor on next'); - t.is(getBranch(result, 'next-major').range, '>=2.0.0', 'Can release only major on next-major'); + 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}) => ({ @@ -41,14 +41,18 @@ test('Enforce ranges with branching release workflow', async t => { })); 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 <1.1.0', 'Can release only patch 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 <1.1.0', 'Can release only patch, > than 1.0.1 on master'); + 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'); @@ -56,9 +60,9 @@ test('Enforce ranges with branching release workflow', async t => { 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.0 <2.0.0', 'Can release only minor on next'); - t.is(getBranch(result, 'next-major').range, '>=2.0.0', 'Can release only major on next-major'); + 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'); @@ -66,7 +70,9 @@ test('Enforce ranges with branching release workflow', async t => { name, range, })); - 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, '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'); @@ -74,6 +80,8 @@ test('Enforce ranges with branching release workflow', async t => { 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'); @@ -88,7 +96,6 @@ test('Enforce ranges with branching release workflow', async t => { merge(branches, 'master', '1.0.x'); merge(branches, 'master', '1.x'); - release(branches, 'master', '1.0.1'); result = (await getBranches('repositoryUrl', 'master', {options: {branches}})).map(({name, range}) => ({ name, range, @@ -121,8 +128,9 @@ test('Enforce ranges with branching release workflow', async t => { name, range, })); - t.is(getBranch(result, 'master').range, '>=1.1.1 <1.2.0', 'Can release only patch, > than 1.1.1 on master'); - t.is(getBranch(result, 'next').range, '>=1.2.0 <2.0.0', 'Can release only patch or minor, > than 1.2.0 on next'); + + 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, @@ -136,7 +144,7 @@ test('Enforce ranges with branching release workflow', async t => { name, range, })); - t.is(getBranch(result, 'master').range, '>=1.1.1 <1.2.0', 'Can release only patch, > than 1.1.1 on master'); + 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'); @@ -145,7 +153,7 @@ test('Enforce ranges with branching release workflow', async t => { name, range, })); - t.is(getBranch(result, 'master').range, '>=1.1.1 <1.2.0', 'Can release only patch, > than 1.1.1 on master'); + 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'); @@ -155,19 +163,20 @@ test('Enforce ranges with branching release workflow', async t => { name, range, })); - t.is(getBranch(result, 'master').range, '>=2.0.1 <2.1.0', 'Can release only patch, > than 2.0.1 on master'); - t.is(getBranch(result, 'next').range, '>=2.1.0 <3.0.0', 'Can release only minor on next'); - t.is(getBranch(result, 'next-major').range, '>=3.0.0', 'Can release only major on next-major'); + 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, '>=2.0.1 <2.1.0', 'Can release only patch, > than 2.0.1 on master'); - t.is(getBranch(result, 'next').range, '>=2.1.0 <3.0.0', 'Can release only minor on next'); - t.is(getBranch(result, 'next-major').range, '>=3.0.0', 'Can release only major on next-major'); + 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'); diff --git a/test/branches/normalize.test.js b/test/branches/normalize.test.js index b7e01a1a13..765ec866ae 100644 --- a/test/branches/normalize.test.js +++ b/test/branches/normalize.test.js @@ -159,19 +159,26 @@ test('Release branches - initial state', t => { .release({release}) .map(({type, name, range, accept, channel, main}) => ({type, name, range, accept, channel, main})), [ - {type: 'release', name: 'master', range: '>=1.0.0 <1.1.0', accept: ['patch'], channel: undefined, main: true}, + { + type: 'release', + name: 'master', + range: '>=1.0.0', + accept: ['patch', 'minor', 'major'], + channel: undefined, + main: true, + }, { type: 'release', name: 'next', - range: '>=1.1.0 <2.0.0', - accept: ['patch', 'minor'], + range: '>=1.0.0', + accept: ['patch', 'minor', 'major'], channel: 'next', main: false, }, { type: 'release', name: 'next-major', - range: '>=2.0.0', + range: '>=1.0.0', accept: ['patch', 'minor', 'major'], channel: 'next-major', main: false, @@ -293,15 +300,15 @@ test('Release branches - Handle missing previous tags in branch history', t => { { type: 'release', name: 'master', - range: '>=2.0.0 <3.0.0', - accept: ['patch', 'minor'], + range: '>=2.0.0', + accept: ['patch', 'minor', 'major'], channel: undefined, main: true, }, { type: 'release', name: 'next', - range: '>=3.0.0', + range: '>=2.0.0', accept: ['patch', 'minor', 'major'], channel: 'next', main: false, @@ -310,10 +317,10 @@ test('Release branches - Handle missing previous tags in branch history', t => { ); }); -test('Release branches - enforce release gaps after downstream merge', t => { +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'])}, - {name: 'next', tags: toTags(['1.0.0', '1.1.0', '2.0.0'])}, + {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'])}, ]; @@ -322,52 +329,26 @@ test('Release branches - enforce release gaps after downstream merge', t => { .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 <3.0.0', - accept: ['patch', 'minor'], - channel: 'next', - main: false, - }, { type: 'release', - name: 'next-major', + name: 'master', range: '>=3.0.0', accept: ['patch', 'minor', 'major'], - channel: 'next-major', - main: false, + channel: undefined, + main: true, }, - ] - ); -}); - -test('Release branches - limit releases on 2nd and 3rd branche 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 <3.1.0', accept: ['patch'], channel: undefined, main: true}, { type: 'release', name: 'next', - range: '>=3.1.0 <4.0.0', - accept: ['patch', 'minor'], + range: '>=3.0.0', + accept: ['patch', 'minor', 'major'], channel: 'next', main: false, }, { type: 'release', name: 'next-major', - range: '>=4.0.0', + range: '>=3.0.0', accept: ['patch', 'minor', 'major'], channel: 'next-major', main: false, diff --git a/test/index.test.js b/test/index.test.js index 0c3d867de3..586b0799eb 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -97,8 +97,8 @@ test('Plugins are called with expected values', async t => { { channel: undefined, name: 'master', - range: '>=1.0.0 <2.0.0', - accept: ['patch', 'minor'], + range: '>=1.0.0', + accept: ['patch', 'minor', 'major'], tags: [{channels: ['next'], gitTag: 'v1.0.0', version: '1.0.0'}], type: 'release', main: true, @@ -106,7 +106,7 @@ test('Plugins are called with expected values', async t => { { channel: 'next', name: 'next', - range: '>=2.0.0', + range: '>=1.0.0', accept: ['patch', 'minor', 'major'], tags: [{channels: ['next'], gitTag: 'v1.0.0', version: '1.0.0'}], type: 'release', From 0716a45b7ddd280b57156aa7e16979a2797ac0a1 Mon Sep 17 00:00:00 2001 From: Pierre Vanduynslager Date: Thu, 5 Dec 2019 01:09:09 -0500 Subject: [PATCH 102/107] feat: require Node.js >=10.13 BREAKING CHANGE: Require Node.js >= 10.13 --- .travis.yml | 3 +-- bin/semantic-release.js | 2 +- docs/recipes/github-actions.md | 2 +- docs/recipes/gitlab-ci.md | 2 +- docs/support/FAQ.md | 10 +++++----- docs/support/node-version.md | 6 +++--- lib/branches/index.js | 2 +- lib/get-git-auth-url.js | 3 ++- lib/git.js | 4 ++-- lib/utils.js | 6 ++++-- package.json | 2 +- test/helpers/git-utils.js | 2 +- 12 files changed, 23 insertions(+), 21 deletions(-) diff --git a/.travis.yml b/.travis.yml index f6aa5c3dee..f0e66956c8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,8 +5,7 @@ services: node_js: - 12 - - 10 - - 8.16 + - 10.13 # Trigger a push build on release and greenkeeper branches + PRs build on every branches # Avoid double build on PRs (See https://github.com/travis-ci/travis-ci/issues/1147) diff --git a/bin/semantic-release.js b/bin/semantic-release.js index 37fcf85847..8cfbaadaa0 100755 --- a/bin/semantic-release.js +++ b/bin/semantic-release.js @@ -35,7 +35,7 @@ execa('git', ['--version']) process.exit(1); }); -// Node 8+ from this point on +// Node 10+ from this point on require('../cli')() .then(exitCode => { process.exitCode = exitCode; diff --git a/docs/recipes/github-actions.md b/docs/recipes/github-actions.md index c448a6d94d..ed84f7745f 100644 --- a/docs/recipes/github-actions.md +++ b/docs/recipes/github-actions.md @@ -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. -**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 diff --git a/docs/recipes/gitlab-ci.md b/docs/recipes/gitlab-ci.md index 5df4b1b453..dd57673076 100644 --- a/docs/recipes/gitlab-ci.md +++ b/docs/recipes/gitlab-ci.md @@ -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. -**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 diff --git a/docs/support/FAQ.md b/docs/support/FAQ.md index cb9d6278dd..40ef307269 100644 --- a/docs/support/FAQ.md +++ b/docs/support/FAQ.md @@ -38,7 +38,7 @@ Yes with the [dry-run options](../usage/configuration.md#dryrun) which prints to ## 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: @@ -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`. -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: @@ -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: - 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) -- 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. @@ -232,9 +232,9 @@ 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). -## 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. diff --git a/docs/support/node-version.md b/docs/support/node-version.md index 633a8c7271..8a6266a5ad 100644 --- a/docs/support/node-version.md +++ b/docs/support/node-version.md @@ -1,6 +1,6 @@ # 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. @@ -8,9 +8,9 @@ See our [Node Support Policy](node-support-policy.md) for our long-term promise ## 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. diff --git a/lib/branches/index.js b/lib/branches/index.js index b94e76f23b..8bedfe6978 100644 --- a/lib/branches/index.js +++ b/lib/branches/index.js @@ -50,7 +50,7 @@ module.exports = async (repositoryUrl, ciBranch, context) => { const duplicates = [...branches] .map(branch => branch.name) .sort() - .filter((val, idx, arr) => arr[idx] === arr[idx + 1] && arr[idx] !== arr[idx - 1]); + .filter((_, idx, arr) => arr[idx] === arr[idx + 1] && arr[idx] !== arr[idx - 1]); if (duplicates.length > 0) { errors.push(getError('EDUPLICATEBRANCHES', {duplicates})); diff --git a/lib/get-git-auth-url.js b/lib/get-git-auth-url.js index d02b0cc680..88d63a726c 100644 --- a/lib/get-git-auth-url.js +++ b/lib/get-git-auth-url.js @@ -47,7 +47,8 @@ module.exports = async ({cwd, env, branch, options: {repositoryUrl}}) => { if (gitCredentials) { // 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] = + /^(?!.+:\/\/)(?:(?.*)@)?(?.*?):(?.*)$/.exec(repositoryUrl) || []; const {port, hostname, ...parsed} = parse( match ? `ssh://${auth ? `${auth}@` : ''}${host}/${path}` : repositoryUrl ); diff --git a/lib/git.js b/lib/git.js index efaecadba2..563b477424 100644 --- a/lib/git.js +++ b/lib/git.js @@ -65,7 +65,7 @@ async function getCommits(from, to, execaOpts) { async function getBranches(repositoryUrl, execaOpts) { return (await execa('git', ['ls-remote', '--heads', repositoryUrl], execaOpts)).stdout .split('\n') - .map(branch => branch.match(/^.+refs\/heads\/(.+)$/)[1]) + .map(branch => branch.match(/^.+refs\/heads\/(?.+)$/)[1]) .filter(Boolean); } @@ -312,7 +312,7 @@ async function verifyBranchName(branch, execaOpts) { async function isBranchUpToDate(repositoryUrl, branch, execaOpts) { const {stdout: remoteHead} = await execa('git', ['ls-remote', '--heads', repositoryUrl, branch], execaOpts); try { - return await isRefInHistory(remoteHead.match(/^(\w+)?/)[1], branch, execaOpts); + return await isRefInHistory(remoteHead.match(/^(?\w+)?/)[1], branch, execaOpts); } catch (error) { debug(error); } diff --git a/lib/utils.js b/lib/utils.js index e40c5d196d..14d9d028b1 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -31,11 +31,13 @@ function isMaintenanceRange(range) { } function getUpperBound(range) { - return semver.valid(range) ? range : ((semver.validRange(range) || '').match(/<(\d+\.\d+\.\d+)$/) || [])[1]; + return semver.valid(range) + ? range + : ((semver.validRange(range) || '').match(/<(?\d+\.\d+\.\d+)$/) || [])[1]; } function getLowerBound(range) { - return ((semver.validRange(range) || '').match(/(\d+\.\d+\.\d+)/) || [])[1]; + return ((semver.validRange(range) || '').match(/(?\d+\.\d+\.\d+)/) || [])[1]; } function highest(version1, version2) { diff --git a/package.json b/package.json index d2538fcba0..01bf4aa4c9 100644 --- a/package.json +++ b/package.json @@ -72,7 +72,7 @@ "xo": "^0.25.0" }, "engines": { - "node": ">=8.16" + "node": ">=10.13" }, "files": [ "bin", diff --git a/test/helpers/git-utils.js b/test/helpers/git-utils.js index 2dfa4ba289..c474801b55 100644 --- a/test/helpers/git-utils.js +++ b/test/helpers/git-utils.js @@ -213,7 +213,7 @@ export async function gitRemoteTagHead(repositoryUrl, tagName, execaOpts) { return (await execa('git', ['ls-remote', '--tags', repositoryUrl, tagName], execaOpts)).stdout .split('\n') .filter(tag => Boolean(tag)) - .map(tag => tag.match(/^(\S+)/)[1])[0]; + .map(tag => tag.match(/^(?\S+)/)[1])[0]; } /** From 9ecc7a369cc75e7745f8748593df856b85bdb0ea Mon Sep 17 00:00:00 2001 From: Pierre Vanduynslager Date: Mon, 9 Dec 2019 17:45:57 -0500 Subject: [PATCH 103/107] fix: increase next version on prerelease branch based on highest commit type --- lib/get-next-version.js | 26 ++++-- test/get-next-version.test.js | 171 ++++++++++++++++++++++++++-------- 2 files changed, 151 insertions(+), 46 deletions(-) diff --git a/lib/get-next-version.js b/lib/get-next-version.js index aed7ae34f8..e78b724ad8 100644 --- a/lib/get-next-version.js +++ b/lib/get-next-version.js @@ -1,18 +1,28 @@ const semver = require('semver'); const {FIRST_RELEASE, FIRSTPRERELEASE} = require('./definitions/constants'); -const {isSameChannel} = require('./utils'); +const {isSameChannel, getLatestVersion, tagsToVersions, highest} = require('./utils'); module.exports = ({branch, nextRelease: {type, channel}, lastRelease, logger}) => { let version; if (lastRelease.version) { const {major, minor, patch} = semver.parse(lastRelease.version); - version = - branch.type === 'prerelease' - ? semver.prerelease(lastRelease.version) && - lastRelease.channels.some(lastReleaseChannel => isSameChannel(lastReleaseChannel, channel)) - ? semver.inc(lastRelease.version, 'prerelease') - : `${semver.inc(`${major}.${minor}.${patch}`, type)}-${branch.prerelease}.${FIRSTPRERELEASE}` - : semver.inc(lastRelease.version, type); + + 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)), type)}-${branch.prerelease}.${FIRSTPRERELEASE}` + ); + } else { + 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; diff --git a/test/get-next-version.test.js b/test/get-next-version.test.js index 10908c206c..8005d76c38 100644 --- a/test/get-next-version.test.js +++ b/test/get-next-version.test.js @@ -11,9 +11,9 @@ test.beforeEach(t => { test('Increase version for patch release', t => { t.is( getNextVersion({ - branch: {name: 'master', type: 'release'}, + branch: {name: 'master', type: 'release', tags: [{gitTag: 'v1.0.0', version: '1.0.0', channels: [null]}]}, nextRelease: {type: 'patch'}, - lastRelease: {version: '1.0.0', channels: [undefined]}, + lastRelease: {version: '1.0.0', channels: [null]}, logger: t.context.logger, }), '1.0.1' @@ -23,9 +23,9 @@ test('Increase version for patch release', t => { test('Increase version for minor release', t => { t.is( getNextVersion({ - branch: {name: 'master', type: 'release'}, + branch: {name: 'master', type: 'release', tags: [{gitTag: 'v1.0.0', version: '1.0.0', channels: [null]}]}, nextRelease: {type: 'minor'}, - lastRelease: {version: '1.0.0', channels: [undefined]}, + lastRelease: {version: '1.0.0', channels: [null]}, logger: t.context.logger, }), '1.1.0' @@ -35,9 +35,9 @@ test('Increase version for minor release', t => { test('Increase version for major release', t => { t.is( getNextVersion({ - branch: {name: 'master', type: 'release'}, + branch: {name: 'master', type: 'release', tags: [{gitTag: 'v1.0.0', version: '1.0.0', channels: [null]}]}, nextRelease: {type: 'major'}, - lastRelease: {version: '1.0.0', channels: [undefined]}, + lastRelease: {version: '1.0.0', channels: [null]}, logger: t.context.logger, }), '2.0.0' @@ -47,7 +47,7 @@ test('Increase version for major release', t => { test('Return 1.0.0 if there is no previous release', t => { t.is( getNextVersion({ - branch: {name: 'master', type: 'release'}, + branch: {name: 'master', type: 'release', tags: []}, nextRelease: {type: 'minor'}, lastRelease: {}, logger: t.context.logger, @@ -59,9 +59,14 @@ test('Return 1.0.0 if there is no previous release', t => { test('Increase version for patch release on prerelease branch', t => { t.is( getNextVersion({ - branch: {name: 'beta', type: 'prerelease', prerelease: 'beta'}, - nextRelease: {type: 'patch'}, - lastRelease: {version: '1.0.0', channels: [undefined]}, + 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' @@ -69,31 +74,49 @@ test('Increase version for patch release on prerelease branch', t => { t.is( getNextVersion({ - branch: {name: 'beta', type: 'prerelease', prerelease: 'beta'}, - nextRelease: {type: 'patch'}, - lastRelease: {version: '1.0.0-beta.1', channels: [undefined]}, + 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.0-beta.2' + '1.0.1-beta.2' ); t.is( getNextVersion({ - branch: {name: 'alpha', type: 'prerelease', prerelease: 'alpha'}, + 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.0-beta.1', channels: ['beta']}, + lastRelease: {version: '1.0.1-beta.1', channels: ['beta']}, logger: t.context.logger, }), - '1.0.1-alpha.1' + '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'}, - nextRelease: {type: 'minor'}, - lastRelease: {version: '1.0.0', channels: [undefined]}, + 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' @@ -101,31 +124,49 @@ test('Increase version for minor release on prerelease branch', t => { t.is( getNextVersion({ - branch: {name: 'beta', type: 'prerelease', prerelease: 'beta'}, - nextRelease: {type: 'minor'}, - lastRelease: {version: '1.0.0-beta.1', channels: [undefined]}, + 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.0.0-beta.2' + '1.1.0-beta.2' ); t.is( getNextVersion({ - branch: {name: 'alpha', type: 'prerelease', prerelease: 'alpha'}, + 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.0.0-beta.1', channels: ['beta']}, + lastRelease: {version: '1.1.0-beta.1', channels: ['beta']}, logger: t.context.logger, }), - '1.1.0-alpha.1' + '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'}, - nextRelease: {type: 'major'}, - lastRelease: {version: '1.0.0', channels: [undefined]}, + 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' @@ -133,29 +174,42 @@ test('Increase version for major release on prerelease branch', t => { t.is( getNextVersion({ - branch: {name: 'beta', type: 'prerelease', prerelease: 'beta'}, - nextRelease: {type: 'major'}, - lastRelease: {version: '1.0.0-beta.1', channels: [undefined]}, + 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, }), - '1.0.0-beta.2' + '2.0.0-beta.2' ); t.is( getNextVersion({ - branch: {name: 'alpha', type: 'prerelease', prerelease: 'alpha'}, + 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: '1.0.0-beta.1', channels: ['beta']}, + lastRelease: {version: '2.0.0-beta.1', channels: ['beta']}, logger: t.context.logger, }), - '2.0.0-alpha.1' + '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'}, + branch: {name: 'beta', type: 'prerelease', prerelease: 'beta', tags: []}, nextRelease: {type: 'minor'}, lastRelease: {}, logger: t.context.logger, @@ -163,3 +217,44 @@ test('Return 1.0.0 if there is no previous release on prerelease branch', t => { '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' + ); +}); From 9a1af4de44c4548137bf438df8f4ca10a07af63e Mon Sep 17 00:00:00 2001 From: Pierre Vanduynslager Date: Tue, 10 Dec 2019 00:05:30 -0500 Subject: [PATCH 104/107] fix: remove unnecessary `await` --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 8696d8b254..457a907533 100644 --- a/index.js +++ b/index.js @@ -132,7 +132,7 @@ async function run(context, plugins) { throw new AggregateError(errors); } - context.lastRelease = await getLastRelease(context); + context.lastRelease = getLastRelease(context); if (context.lastRelease.gitHead) { context.lastRelease.gitHead = await getTagHead(context.lastRelease.gitHead, {cwd, env}); } From a8747c4f86a1947250aa86ab1869fb4bde10bb71 Mon Sep 17 00:00:00 2001 From: Pierre Vanduynslager Date: Tue, 10 Dec 2019 00:06:26 -0500 Subject: [PATCH 105/107] fix: verify is branch is up to date by comparing remote and local HEAD --- lib/git.js | 38 ++++---------------------------------- test/git.test.js | 31 ++++++++----------------------- 2 files changed, 12 insertions(+), 57 deletions(-) diff --git a/lib/git.js b/lib/git.js index 563b477424..dc75018ac3 100644 --- a/lib/git.js +++ b/lib/git.js @@ -69,33 +69,6 @@ async function getBranches(repositoryUrl, execaOpts) { .filter(Boolean); } -/** - * Verify if the `ref` is in the direct history of a given branch. - * - * @param {String} ref The reference to look for. - * @param {String} branch The branch for which to check if the `ref` is in history. - * @param {Object} [execaOpts] Options to pass to `execa`. - * - * @return {Boolean} `true` if the reference is in the history of the current branch, falsy otherwise. - */ -async function isRefInHistory(ref, branch, execaOpts) { - if (!(await isRefExists(branch, execaOpts))) { - return false; - } - - try { - await execa('git', ['merge-base', '--is-ancestor', ref, branch], execaOpts); - return true; - } catch (error) { - if (error.exitCode === 1) { - return false; - } - - debug(error); - throw error; - } -} - /** * Verify if the `ref` exits * @@ -310,12 +283,10 @@ async function verifyBranchName(branch, execaOpts) { * @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) { - const {stdout: remoteHead} = await execa('git', ['ls-remote', '--heads', repositoryUrl, branch], execaOpts); - try { - return await isRefInHistory(remoteHead.match(/^(?\w+)?/)[1], branch, execaOpts); - } catch (error) { - debug(error); - } + return ( + (await getGitHead(execaOpts)) === + (await execa('git', ['ls-remote', '--heads', repositoryUrl, branch], execaOpts)).stdout.match(/^(?\w+)?/)[1] + ); } /** @@ -355,7 +326,6 @@ module.exports = { getTags, getCommits, getBranches, - isRefInHistory, isRefExists, fetch, fetchNotes, diff --git a/test/git.test.js b/test/git.test.js index 09c2180262..781994f65b 100644 --- a/test/git.test.js +++ b/test/git.test.js @@ -2,7 +2,6 @@ import test from 'ava'; import tempy from 'tempy'; import { getTagHead, - isRefInHistory, isRefExists, fetch, getGitHead, @@ -125,23 +124,6 @@ test('Fetch all tags on a repository with a detached head from branch', async t t.deepEqual((await getTags('master', {cwd})).sort(), ['v1.0.0', 'v1.0.1', 'v1.1.0', 'v2.0.0'].sort()); }); -test('Verify if the commit `sha` is in the direct history of the current branch', 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}); - // Create the new branch 'other-branch' from master - await gitCheckout('other-branch', true, {cwd}); - // Add commits to the 'other-branch' branch - const otherCommits = await gitCommits(['Second'], {cwd}); - await gitCheckout('master', false, {cwd}); - - t.true(await isRefInHistory(commits[0].hash, 'master', {cwd})); - t.falsy(await isRefInHistory(otherCommits[0].hash, 'master', {cwd})); - t.falsy(await isRefInHistory(otherCommits[0].hash, 'missing-branch', {cwd})); - await t.throwsAsync(isRefInHistory('non-existant-sha', 'master', {cwd})); -}); - test('Verify if a branch exists', async t => { // Create a git repository, set the current working directory at the root of the repo const {cwd} = await gitRepo(); @@ -299,13 +281,16 @@ test('Return falsy if repository is not up to date', async t => { t.falsy(await isBranchUpToDate(repositoryUrl, 'master', {cwd})); }); -test('Return "true" if local repository is ahead', async t => { - const {cwd, repositoryUrl} = await gitRepo(true); - await gitCommits(['First'], {cwd}); - await gitPush(repositoryUrl, 'master', {cwd}); +test('Return falsy if detached head repository is not up to date', async t => { + let {cwd, repositoryUrl} = await gitRepo(); + + 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.true(await isBranchUpToDate(repositoryUrl, 'master', {cwd})); + t.falsy(await isBranchUpToDate(repositoryUrl, 'master', {cwd})); }); test('Get a commit note', async t => { From 61665be9ec7487c303509f19097f588d993ec155 Mon Sep 17 00:00:00 2001 From: Pierre Vanduynslager Date: Tue, 10 Dec 2019 00:13:45 -0500 Subject: [PATCH 106/107] fix: correct log when adding channel to tag --- index.js | 6 +++++- test/index.test.js | 21 ++++++++++++++------- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/index.js b/index.js index 457a907533..2f732a8ae6 100644 --- a/index.js +++ b/index.js @@ -112,7 +112,11 @@ async function run(context, plugins) { 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 channel ${nextRelease.channel} to tag ${nextRelease.gitTag}`); + logger.success( + `Add ${nextRelease.channel ? `channel ${nextRelease.channel}` : 'default channel'} to tag ${ + nextRelease.gitTag + }` + ); } context.branch.tags.push({ diff --git a/test/index.test.js b/test/index.test.js index 586b0799eb..67961e6d35 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -785,7 +785,14 @@ async function addChannelMacro(t, mergeFunction) { const publish = stub().resolves(); const success = stub().resolves(); - const config = {branches: [{name: 'master'}, {name: 'next'}], repositoryUrl, tagFormat: `v\${version}`}; + const config = { + branches: [ + {name: 'master', channel: 'latest'}, + {name: 'next', channel: 'next'}, + ], + repositoryUrl, + tagFormat: `v\${version}`, + }; const options = { ...config, verifyConditions, @@ -796,11 +803,11 @@ async function addChannelMacro(t, mergeFunction) { publish, success, }; - const nextRelease2 = { + const nextRelease = { name: 'v2.0.1', type: 'patch', version: '2.0.1', - channel: null, + channel: 'latest', gitTag: 'v2.0.1', gitHead: commits[2].hash, }; @@ -812,13 +819,13 @@ async function addChannelMacro(t, mergeFunction) { const result = await semanticRelease(options, {cwd, env: {}, stdout: {write: () => {}}, stderr: {write: () => {}}}); t.deepEqual(result.releases, [ - {...nextRelease2, ...release1, notes, pluginName: '[Function: functionStub]'}, - {...nextRelease2, notes, pluginName: '[Function: functionStub]'}, + {...nextRelease, ...release1, notes, pluginName: '[Function: functionStub]'}, + {...nextRelease, notes, pluginName: '[Function: functionStub]'}, ]); // Verify the tag has been created on the local and remote repo and reference - t.is(await gitTagHead(nextRelease2.gitTag, {cwd}), nextRelease2.gitHead); - t.is(await gitRemoteTagHead(repositoryUrl, nextRelease2.gitTag, {cwd}), nextRelease2.gitHead); + t.is(await gitTagHead(nextRelease.gitTag, {cwd}), nextRelease.gitHead); + t.is(await gitRemoteTagHead(repositoryUrl, nextRelease.gitTag, {cwd}), nextRelease.gitHead); } addChannelMacro.title = providedTitle => `Add version to a channel after a merge (${providedTitle})`; From 9772563a22c4fd313eb8bbcdde948503ad1d3703 Mon Sep 17 00:00:00 2001 From: Pierre Vanduynslager Date: Fri, 13 Dec 2019 16:01:02 -0500 Subject: [PATCH 107/107] fix: look also for previous prerelease versions to determine the next one --- lib/get-next-version.js | 4 +++- test/get-next-version.test.js | 17 +++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/get-next-version.js b/lib/get-next-version.js index e78b724ad8..05f91a11f4 100644 --- a/lib/get-next-version.js +++ b/lib/get-next-version.js @@ -14,7 +14,9 @@ module.exports = ({branch, nextRelease: {type, channel}, lastRelease, logger}) = ) { version = highest( semver.inc(lastRelease.version, 'prerelease'), - `${semver.inc(getLatestVersion(tagsToVersions(branch.tags)), type)}-${branch.prerelease}.${FIRSTPRERELEASE}` + `${semver.inc(getLatestVersion(tagsToVersions(branch.tags), {withPrerelease: true}), type)}-${ + branch.prerelease + }.${FIRSTPRERELEASE}` ); } else { version = `${semver.inc(`${major}.${minor}.${patch}`, type)}-${branch.prerelease}.${FIRSTPRERELEASE}`; diff --git a/test/get-next-version.test.js b/test/get-next-version.test.js index 8005d76c38..2bd808d1ee 100644 --- a/test/get-next-version.test.js +++ b/test/get-next-version.test.js @@ -258,3 +258,20 @@ test('Increase version for release on prerelease branch based on highest commit '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' + ); +});