Compare commits
167
Commits
+2
-1
@@ -4,8 +4,9 @@ services:
|
||||
- docker
|
||||
|
||||
node_js:
|
||||
- 12
|
||||
- 10
|
||||
- 8
|
||||
- 8.16
|
||||
|
||||
# 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)
|
||||
|
||||
+1
-1
@@ -224,7 +224,7 @@ All the [semantic-release](https://github.com/semantic-release) repositories use
|
||||
Before pushing your code changes make sure there are no linting errors with `npm run lint`.
|
||||
|
||||
**Tips**:
|
||||
- Most linting errors can be automatically fixed with `npm run lint --fix`.
|
||||
- Most linting errors can be automatically fixed with `npm run lint -- --fix`.
|
||||
- Install the [XO plugin](https://github.com/sindresorhus/xo#editor-plugins) for your editor to see linting errors directly in your editor and automatically fix them on save.
|
||||
|
||||
### Tests
|
||||
|
||||
@@ -17,11 +17,6 @@
|
||||
<img alt="semantic-release" src="https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg">
|
||||
</a>
|
||||
</p>
|
||||
<p align="center">
|
||||
<a href="https://waffle.io/semantic-release/semantic-release">
|
||||
<img alt="Waffle.io" src="https://badge.waffle.io/semantic-release/semantic-release.svg?columns=all">
|
||||
</a>
|
||||
</p>
|
||||
<p align="center">
|
||||
<a href="https://www.npmjs.com/package/semantic-release">
|
||||
<img alt="npm latest version" src="https://img.shields.io/npm/v/semantic-release/latest.svg">
|
||||
@@ -61,7 +56,7 @@ This removes the immediate connection between human emotions and version numbers
|
||||
|
||||
By default **semantic-release** uses [Angular Commit Message Conventions](https://github.com/angular/angular.js/blob/master/DEVELOPERS.md#-git-commit-guidelines). The commit message format can be changed with the [`preset` or `config` options](docs/usage/configuration.md#options) of the [@semantic-release/commit-analyzer](https://github.com/semantic-release/commit-analyzer#options) and [@semantic-release/release-notes-generator](https://github.com/semantic-release/release-notes-generator#options) plugins.
|
||||
|
||||
Tools such as [commitizen](https://github.com/commitizen/cz-cli), [commitlint](https://github.com/marionebl/commitlint) or [semantic-git-commit-cli](https://github.com/JPeer264/node-semantic-git-commit-cli) can be used to help contributors and enforce valid commit messages.
|
||||
Tools such as [commitizen](https://github.com/commitizen/cz-cli) or [commitlint](https://github.com/conventional-changelog/commitlint) can be used to help contributors and enforce valid commit messages.
|
||||
|
||||
Here is an example of the release type that will be done based on a commit messages:
|
||||
|
||||
@@ -77,11 +72,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
|
||||
|
||||
@@ -99,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
|
||||
@@ -107,17 +111,20 @@ 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)
|
||||
- [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)
|
||||
- [Plugins](docs/developer-guide/plugin.md)
|
||||
- [Shareable configuration](docs/developer-guide/shareable-configuration.md)
|
||||
- [Plugins development](docs/developer-guide/plugin.md)
|
||||
- [Shareable configuration development](docs/developer-guide/shareable-configuration.md)
|
||||
- Support
|
||||
- [Resources](docs/support/resources.md)
|
||||
- [Frequently Asked Questions](docs/support/FAQ.md)
|
||||
|
||||
+8
-7
@@ -1,10 +1,12 @@
|
||||
# Summary
|
||||
|
||||
## Usage
|
||||
- [Getting started](docs/usage/getting-started.md#getting-started)
|
||||
- [Installation](docs/usage/installation.md#installation)
|
||||
- [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
|
||||
@@ -12,19 +14,18 @@
|
||||
- [Shareable configuration](docs/extending/shareable-configurations-list.md)
|
||||
|
||||
## Recipes
|
||||
- [CI configurations](docs/recipes/README.md)
|
||||
- [CircleCI 2.0 workflows](docs/recipes/circleci-workflows.md)
|
||||
- [CI configurations](docs/recipes/README.md#ci-configurations)
|
||||
- [CircleCI 2.0](docs/recipes/circleci-workflows.md)
|
||||
- [Travis CI](docs/recipes/travis.md)
|
||||
- [Travis CI with build stages](docs/recipes/travis-build-stages.md)
|
||||
- [GitLab CI](docs/recipes/gitlab-ci.md)
|
||||
- [Git hosted services](docs/recipes/README.md)
|
||||
- [Git hosted services](docs/recipes/README.md#git-hosted-services)
|
||||
- [Git authentication with SSH keys](docs/recipes/git-auth-ssh-keys.md)
|
||||
- [Package managers and languages](docs/recipes/README.md)
|
||||
- [Package managers and languages](docs/recipes/README.md#package-managers-and-languages)
|
||||
|
||||
## Developer guide
|
||||
- [JavaScript API](docs/developer-guide/js-api.md)
|
||||
- [Plugin](docs/developer-guide/plugin.md)
|
||||
- [Shareable configuration](docs/developer-guide/shareable-configuration.md)
|
||||
- [Plugin development](docs/developer-guide/plugin.md)
|
||||
- [Shareable configuration development](docs/developer-guide/shareable-configuration.md)
|
||||
|
||||
## Support
|
||||
- [Resources](docs/support/resources.md)
|
||||
|
||||
@@ -3,14 +3,14 @@
|
||||
// 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');
|
||||
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(
|
||||
@@ -21,9 +21,8 @@ See https://github.com/semantic-release/semantic-release/blob/master/docs/suppor
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
execa
|
||||
.stdout('git', ['--version'])
|
||||
.then(stdout => {
|
||||
execa('git', ['--version'])
|
||||
.then(({stdout}) => {
|
||||
var gitVersion = findVersions(stdout)[0];
|
||||
if (semver.lt(gitVersion, MIN_GIT_VERSION)) {
|
||||
console.error(`[semantic-release]: Git version ${MIN_GIT_VERSION} is required. Found ${gitVersion}.`);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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',
|
||||
@@ -46,7 +46,7 @@ try {
|
||||
}
|
||||
|
||||
for (const release of releases) {
|
||||
console.log(`The release was published with plugin "${pluginName}".`);
|
||||
console.log(`The release was published with plugin "${release.pluginName}".`);
|
||||
}
|
||||
} else {
|
||||
console.log('No release published.');
|
||||
|
||||
@@ -1 +1,106 @@
|
||||
# Plugin developer guide
|
||||
# Plugin Developer Guide
|
||||
|
||||
To create a plugin for `semantic-release`, you need to decide which parts of the release lifecycle are important to that plugin. For example, it is best to always have a `verify` step because you may be receiving inputs from a user and want to make sure they exist. A plugin can abide by any of the following lifecycles:
|
||||
|
||||
- `verify`
|
||||
- `prepare`
|
||||
- `publish`
|
||||
- `success`
|
||||
- `fail`
|
||||
|
||||
`semantic-release` will require the plugin via `node` and look through the required object for methods named like the lifecyles stated above. For example, if your plugin only had a `verify` and `success` step, the `main` file for your object would need to `export` an object with `verify` and `success` functions.
|
||||
|
||||
In addition to the lifecycle methods, each lifecyle is passed two objects:
|
||||
|
||||
1. `pluginConfig` - an object containing the options that a user may pass in via their `release.config.js` file (or similar)
|
||||
2. `context` - provided by `semantic-release` for access to things like `env` variables set on the running process.
|
||||
|
||||
For each lifecycle you create, you will want to ensure it can accept `pluginConfig` and `context` as parameters.
|
||||
|
||||
## Creating a Plugin Project
|
||||
|
||||
It is recommended that you generate a new project with `yarn init`. This will provide you with a basic node project to get started with. From there, create an `index.js` file, and make sure it is specified as the `main` in the `package.json`. We will use this file to orchestrate the lifecycle methods later on.
|
||||
|
||||
Next, create a `src` or `lib` folder in the root of the project. This is where we will store our logic and code for how our lifecycle methods work. Finally, create a `test` folder so you can write tests related to your logic.
|
||||
|
||||
We recommend you setup a linting system to ensure good javascript practices are enforced. ESLint is usually the system of choice, and the configuration can be whatever you or your team fancies.
|
||||
|
||||
## Exposing Lifecycle Methods
|
||||
|
||||
In your `index.js` file, you can start by writing the following code
|
||||
|
||||
```javascript
|
||||
const verifyConditions = require('./src/verify');
|
||||
|
||||
let verified;
|
||||
|
||||
/**
|
||||
* Called by semantic-release during the verification step
|
||||
* @param {*} pluginConfig The semantic-release plugin config
|
||||
* @param {*} context The context provided by semantic-release
|
||||
*/
|
||||
async function verify(pluginConfig, context) {
|
||||
await verifyConditions(pluginConfig, context);
|
||||
verified = true;
|
||||
}
|
||||
|
||||
module.exports = { verify };
|
||||
```
|
||||
|
||||
Then, in your `src` folder, create a file called `verify.js` and add the following
|
||||
|
||||
```javascript
|
||||
const AggregateError = require('aggregate-error');
|
||||
|
||||
/**
|
||||
* A method to verify that the user has given us a slack webhook url to post to
|
||||
*/
|
||||
module.exports = async (pluginConfig, context) => {
|
||||
const { logger } = context;
|
||||
const errors = [];
|
||||
|
||||
// Throw any errors we accumulated during the validation
|
||||
if (errors.length > 0) {
|
||||
throw new AggregateError(errors);
|
||||
}
|
||||
};
|
||||
```
|
||||
|
||||
As of right now, this code won't do anything. However, if you were to run this plugin via `semantic-release`, it would run when the `verify` step occurred.
|
||||
|
||||
Following this structure, you can create different steps and checks to run through out the release process.
|
||||
|
||||
## Supporting Options
|
||||
|
||||
Let's say we want to verify that an `option` is passed. An `option` is a configuration object that is specific to your plugin. For example, the user may set an `option` in their release config like:
|
||||
|
||||
```js
|
||||
{
|
||||
prepare: {
|
||||
path: "@semantic-release/my-special-plugin"
|
||||
message: "My cool release message"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
This `message` option will be passed to the `pluginConfig` object mentioned earlier. We can use the validation method we created to verify this option exists so we can perform logic based on that knowledge. In our `verify` file, we can add the following:
|
||||
|
||||
```js
|
||||
const { message } = pluginConfig;
|
||||
|
||||
if (message.length) {
|
||||
//...
|
||||
}
|
||||
```
|
||||
|
||||
## Supporting Environment Variables
|
||||
|
||||
Similar to `options`, environment variables exist to allow users to pass tokens and set special URLs. These are set on the `context` object instead of the `pluginConfig` object. Let's say we wanted to check for `GITHUB_TOKEN` in the environment because we want to post to GitHub on the user's behalf. To do this, we can add the following to our `verify` command:
|
||||
|
||||
```js
|
||||
const { env } = context;
|
||||
|
||||
if (env.GITHUB_TOKEN) {
|
||||
//...
|
||||
}
|
||||
```
|
||||
@@ -2,15 +2,19 @@
|
||||
|
||||
## Official plugins
|
||||
- [@semantic-release/commit-analyzer](https://github.com/semantic-release/commit-analyzer)
|
||||
- **Note**: this is already part of semantic-release and does not have to be installed separately
|
||||
- `analyzeCommits`: Determine the type of release by analyzing commits with [conventional-changelog](https://github.com/conventional-changelog/conventional-changelog)
|
||||
- [@semantic-release/release-notes-generator](https://github.com/semantic-release/release-notes-generator)
|
||||
- **Note**: this is already part of semantic-release and does not have to be installed separately
|
||||
- `generateNotes`: Generate release notes for the commits added since the last release with [conventional-changelog](https://github.com/conventional-changelog/conventional-changelog)
|
||||
- [@semantic-release/github](https://github.com/semantic-release/github)
|
||||
- **Note**: this is already part of semantic-release and does not have to be installed separately
|
||||
- `verifyConditions`: Verify the presence and the validity of the GitHub authentication and release configuration
|
||||
- `publish`: Publish a [GitHub release](https://help.github.com/articles/about-releases)
|
||||
- `success`: Add a comment to GitHub issues and pull requests resolved in the release
|
||||
- `fail`: Open a GitHub issue when a release fails
|
||||
- [@semantic-release/npm](https://github.com/semantic-release/npm)
|
||||
- **Note**: this is already part of semantic-release and does not have to be installed separately
|
||||
- `verifyConditions`: Verify the presence and the validity of the npm authentication and release configuration
|
||||
- `prepare`: Update the package.json version and create the npm package tarball
|
||||
- `publish`: Publish the package on the npm registry
|
||||
@@ -41,6 +45,10 @@
|
||||
|
||||
[Open a Pull Request](https://github.com/semantic-release/semantic-release/blob/master/CONTRIBUTING.md#submitting-a-pull-request) to add your plugin to the list.
|
||||
|
||||
- [semantic-release-slack-bot](https://github.com/juliuscc/semantic-release-slack-bot)
|
||||
- `verifyConditions`: Verify that the environment variable `SLACK_WEBHOOK` has been defined.
|
||||
- `success`: Publish a message about the success to a slack channel.
|
||||
- `fail`: Optionally publish a message about failure to a slack channel.
|
||||
- [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
|
||||
@@ -71,3 +79,15 @@
|
||||
- `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
|
||||
- [gradle-semantic-release](https://github.com/KengoTODA/gradle-semantic-release-plugin)
|
||||
- `verifyConditions`: Verify that project has a Gradle wrapper script, and `build.gradle` contains a task to publish artifacts.
|
||||
- `prepare`: Changes the version number in the `gradle.properties`
|
||||
- `publish`: Triggers Gradle to publish artifacts.
|
||||
- [semantic-release-circleci-orb](https://github.com/matt-oakes/semantic-release-circleci-orb)
|
||||
- `verifyConditions`: Verify the presence of the `CIRCLECI_API_TOKEN` environment variable, `orbName` option, and the `circleci` CLI.
|
||||
- `publish`: Publish the CircleCI orb.
|
||||
- [semantic-release-github-pages](https://github.com/qiwi/semantic-release-gh-pages-plugin)
|
||||
- `verifyConditions`: Verify the presence of the auth token set via environment variables.
|
||||
- `publish`: Pushes commit to the documentation branch.
|
||||
|
||||
@@ -5,3 +5,9 @@
|
||||
- [@semantic-release/gitlab-config](https://github.com/semantic-release/gitlab-config) - semantic-release shareable configuration for GitLab
|
||||
|
||||
## Community configurations
|
||||
- [@jedmao/semantic-release-npm-github-config](https://github.com/jedmao/semantic-release-npm-github-config)
|
||||
- Provides an informative [git](https://github.com/semantic-release/git) commit message for the release commit that does not trigger continuous integration and conforms to the [conventional commits specification](https://www.conventionalcommits.org/) (e.g., "chore(release): 1.2.3 [skip ci]\n\nnotes").
|
||||
- Creates a tarball that gets uploaded with each [GitHub release](https://github.com/semantic-release/github).
|
||||
- Publishes the same tarball to [npm](https://github.com/semantic-release/npm).
|
||||
- Commits the version change in `package.json`.
|
||||
- Creates or updates a [changelog](https://github.com/semantic-release/changelog) file.
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
- [CircleCI 2.0 workflows](circleci-workflows.md)
|
||||
- [Travis CI](travis.md)
|
||||
- [GitLab CI](gitlab-ci.md)
|
||||
- [GitHub Actions](github-actions.md)
|
||||
|
||||
## Git hosted services
|
||||
- [Git authentication with SSH keys](git-auth-ssh-keys.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
|
||||
|
||||
@@ -137,7 +137,7 @@ jobs:
|
||||
# Make sure only the current user can read the private key
|
||||
- chmod 600 /tmp/git_deploy_key
|
||||
# Create a script to return the passphrase environment variable to ssh-add
|
||||
- echo 'echo ${SSH_PASSPHRASE}' > /tmp/askpass && chmod +x /tmp/askpass
|
||||
- echo 'echo ${SSL_PASSPHRASE}' > /tmp/askpass && chmod +x /tmp/askpass
|
||||
# Start the authentication agent
|
||||
- eval "$(ssh-agent -s)"
|
||||
# Add the key to the authentication agent
|
||||
@@ -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
|
||||
```
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
# Using semantic-release with [GitHub Actions](https://help.github.com/en/categories/automating-your-workflow-with-github-actions)
|
||||
|
||||
## Environment variables
|
||||
|
||||
The [Authentication](../usage/ci-configuration.md#authentication) environment variables can be configured with [Secret Variables](https://help.github.com/en/articles/virtual-environments-for-github-actions#creating-and-using-secrets-encrypted-variables).
|
||||
|
||||
In this example an [`NPM_TOKEN`](https://docs.npmjs.com/creating-and-viewing-authentication-tokens) is required to publish a package to the npm registry. GitHub Actions [automatically populate](https://help.github.com/en/articles/virtual-environments-for-github-actions#github_token-secret) a [`GITHUB_TOKEN`](https://help.github.com/en/articles/creating-a-personal-access-token-for-the-command-line) environment variable which can be used in Workflows.
|
||||
|
||||
## Node project configuration
|
||||
|
||||
[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).
|
||||
|
||||
### `.github/workflows/release.yml` configuration for Node projects
|
||||
|
||||
The following is a minimal configuration for [`semantic-release`](https://github.com/semantic-release/semantic-release) with a build running on Node 12 when a new commit is pushed to a `master` branch. See [Configuring a Workflow](https://help.github.com/en/articles/configuring-a-workflow) for additional configuration options.
|
||||
|
||||
```yaml
|
||||
name: Release
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
jobs:
|
||||
release:
|
||||
name: Release
|
||||
runs-on: ubuntu-18.04
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v1
|
||||
- name: Setup Node.js
|
||||
uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: 12
|
||||
- name: Install dependencies
|
||||
run: npm ci
|
||||
- name: Release
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||
run: npx semantic-release
|
||||
```
|
||||
|
||||
## Pushing `package.json` changes to a `master` branch
|
||||
|
||||
To keep `package.json` updated in the `master` branch, [`@semantic-release/git`](https://github.com/semantic-release/git) plugin can be used.
|
||||
|
||||
**Note**: Automatically populated `GITHUB_TOKEN` cannot be used if branch protection is enabled for the target branch. It is **not** advised to mitigate this limitation by overriding an automatically populated `GITHUB_TOKEN` variable with a [Personal Access Tokens](https://help.github.com/en/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line), as it poses a security risk. Since Secret Variables are available for Workflows triggered by any branch, it becomes a potential vector of attack, where a Workflow triggered from a non-protected branch can expose and use a token with elevated permissions, yielding branch protection insignificant. One can use Personal Access Tokens in trusted environments, where all developers should have the ability to perform administrative actions in the given repository and branch protection is enabled solely for convenience purposes, to remind about required reviews or CI checks.
|
||||
|
||||
## Trigger semantic-release on demand
|
||||
|
||||
There is a way to trigger semantic-relase on demand. Use [`repository_dispatch`](https://help.github.com/en/articles/events-that-trigger-workflows#external-events-repository_dispatch) event to have control on when to generate a release by making an HTTP request, e.g.:
|
||||
|
||||
```yaml
|
||||
name: Release
|
||||
on:
|
||||
repository_dispatch:
|
||||
types: [semantic-release]
|
||||
jobs:
|
||||
# ...
|
||||
```
|
||||
|
||||
To trigger a release, call (with a [Personal Access Tokens](https://help.github.com/en/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line) stored in `GITHUB_TOKEN` environment variable):
|
||||
|
||||
```
|
||||
$ curl -v -H "Accept: application/vnd.github.everest-preview+json" -H "Authorization: token ${GITHUB_TOKEN}" https://api.github.com/repos/[org-name-or-username]/[repository]/dispatches -d '{ "event_type": "semantic-release" }'
|
||||
```
|
||||
@@ -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.16 version](../support/FAQ.md#why-does-semantic-release-require-node-version--816).
|
||||
|
||||
### `.gitlab-ci.yml` configuration for Node projects
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
+15
-11
@@ -4,7 +4,7 @@
|
||||
|
||||
**semantic-release** takes care of updating the `package.json`’s version before publishing to [npm](https://www.npmjs.com).
|
||||
|
||||
By default, only the published package will contains the version, which is the only place where it is *really* required, but the updated `package.json` will not be pushed to the Git repository
|
||||
By default, only the published package will contain the version, which is the only place where it is *really* required, but the updated `package.json` will not be pushed to the Git repository
|
||||
|
||||
However, the [`@semantic-release/git`](https://github.com/semantic-release/git) plugin can be used to push the updated `package.json` as well as other files to the Git repository.
|
||||
|
||||
@@ -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.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.
|
||||
|
||||
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.16.
|
||||
|
||||
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](#why-does-semantic-release-require-node-version--83) to execute the `semantic-release` command
|
||||
- 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
|
||||
|
||||
See the [CI configuration recipes](../recipes/README.md#ci-configurations) for more details on specific CI environments.
|
||||
|
||||
@@ -141,11 +141,11 @@ See the [`@semantic-release/npm`](https://github.com/semantic-release/npm#semant
|
||||
|
||||
If you have introduced a breaking bug in a release you have 2 options:
|
||||
- If you have a fix immediately ready, commit and push it (or merge it via a pull request) to the release branch
|
||||
- Otherwise [revert the commit](https://git-scm.com/docs/git-revert) that introduced the bug and push the revert commit (or merge it via a pull request) to the release branch
|
||||
- Otherwise, [revert the commit](https://git-scm.com/docs/git-revert) that introduced the bug and push the revert commit (or merge it via a pull request) to the release branch
|
||||
|
||||
In both cases **semantic-release** will publish a new release, so your package users' will get the fixed/reverted version.
|
||||
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 release. 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.
|
||||
|
||||
@@ -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`.
|
||||
|
||||
@@ -232,11 +232,15 @@ 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.16?
|
||||
|
||||
**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.16 or higher**.
|
||||
|
||||
See [Node version requirement](../support/node-version.md#node-version-requirement) for more details and solutions.
|
||||
See [Node version requirement](./node-version.md#node-version-requirement) for more details and solutions.
|
||||
|
||||
## Why does semantic-release require Git version >= 2.7.1?
|
||||
|
||||
**semantic-release** uses Git CLI commands to read information about the repository such as branches, commit history and tags. Certain commands and options (such as [the `--merged` option of the `git tag` command](https://git-scm.com/docs/git-tag/2.7.0#git-tag---no-mergedltcommitgt) or bug fixes related to `git ls-files`) used by **semantic-release** are only available in Git version 2.7.1 and higher.
|
||||
|
||||
## What is npx?
|
||||
|
||||
|
||||
@@ -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.16 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.16
|
||||
|
||||
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.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.
|
||||
|
||||
See [CI configuration](../usage/ci-configuration.md) and [CI configuration recipes](../recipes/README.md#ci-configurations) for more details.
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ npm ERR! You do not have permission to publish "<package-name>". 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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -2,12 +2,23 @@
|
||||
|
||||
## 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) or [GoCD Pipelines](https://docs.gocd.org/current/introduction/concepts_in_go.html#pipeline).
|
||||
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.
|
||||
Here is a few example of the CI services that can be used to achieve this:
|
||||
- [Travis Build Stages](https://docs.travis-ci.com/user/build-stages)
|
||||
- [CircleCI Workflows](https://circleci.com/docs/2.0/workflows)
|
||||
- [GitHub Actions](https://github.com/features/actions)
|
||||
- [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).
|
||||
|
||||
See [CI configuration recipes](../recipes/README.md#ci-configurations) for more details.
|
||||
|
||||
## Authentication
|
||||
|
||||
### Push access to the remote repository
|
||||
|
||||
**semantic-release** requires push access to the project Git repository in order to create [Git tags](https://git-scm.com/book/en/v2/Git-Basics-Tagging). The Git authentication can be set with one of the following environment variables:
|
||||
|
||||
| Variable | Description |
|
||||
@@ -19,6 +30,8 @@ See [CI configuration recipes](../recipes/README.md#ci-configurations) for more
|
||||
|
||||
Alternatively the Git authentication can be set up via [SSH keys](../recipes/git-auth-ssh-keys.md).
|
||||
|
||||
### Authentication for plugins
|
||||
|
||||
Most **semantic-release** [plugins](plugins.md) require setting up authentication in order to publish to a package manager registry. The default [@semantic-release/npm](https://github.com/semantic-release/npm#environment-variables) and [@semantic-release/github](https://github.com/semantic-release/github#environment-variables) plugins require the following environment variables:
|
||||
|
||||
| Variable | Description |
|
||||
@@ -26,8 +39,10 @@ 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).<br/>**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.<br/>**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.
|
||||
|
||||
See [CI configuration recipes](../recipes/README.md#ci-configurations) for more details on how to configure environment variables in your CI service.
|
||||
|
||||
**Note**: The environment variables `GH_TOKEN`, `GITHUB_TOKEN`, `GL_TOKEN` and `GITLAB_TOKEN` can be used for both the Git authentication and the API authentication required by [@semantic-release/github](https://github.com/semantic-release/github) and [@semantic-release/gitlab](https://github.com/semantic-release/gitlab).
|
||||
|
||||
+14
-20
@@ -1,17 +1,17 @@
|
||||
# Configuration
|
||||
|
||||
**semantic-release** configuration consists of:
|
||||
- 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))
|
||||
- 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))
|
||||
|
||||
All of these options can be configured directly or by extending a [shareable configuration](shareable-configurations.md).
|
||||
All of these options can be configured through config file, CLI arguments or by extending a [shareable configuration](shareable-configurations.md).
|
||||
|
||||
Additionally, metadata of Git tags generated by **semantic-release** can be customized via standard [Git environment variables](#git-environment-variables).
|
||||
|
||||
## Configuration file
|
||||
|
||||
**semantic-release**’s [options](#options), mode and [plugins](plugins.md) can be set via:
|
||||
**semantic-release**’s [options](#options), mode and [plugins](plugins.md) can be set via either:
|
||||
- A `.releaserc` file, written in YAML or JSON, with optional extensions: .`yaml`/`.yml`/`.json`/`.js`
|
||||
- A `release.config.js` file that exports an object
|
||||
- A `release` key in the project's `package.json` file
|
||||
@@ -20,8 +20,7 @@ Alternatively, some options can be set via CLI arguments.
|
||||
|
||||
The following three examples are the same.
|
||||
|
||||
Via `release` key in the project's `package.json` file:
|
||||
|
||||
- Via `release` key in the project's `package.json` file:
|
||||
```json
|
||||
{
|
||||
"release": {
|
||||
@@ -29,23 +28,15 @@ Via `release` key in the project's `package.json` file:
|
||||
}
|
||||
}
|
||||
```
|
||||
```bash
|
||||
$ semantic-release
|
||||
```
|
||||
|
||||
Via `.releaserc` file:
|
||||
|
||||
- Via `.releaserc` file:
|
||||
```json
|
||||
{
|
||||
"branches": ["master", "next"]
|
||||
}
|
||||
```
|
||||
```bash
|
||||
$ semantic-release
|
||||
```
|
||||
|
||||
Via CLI argument:
|
||||
|
||||
- Via CLI argument:
|
||||
```bash
|
||||
$ semantic-release --branch next
|
||||
```
|
||||
@@ -70,7 +61,7 @@ List of modules or file paths containing a [shareable configuration](shareable-c
|
||||
### branches
|
||||
|
||||
Type: `Array`, `String`, `Object`<br>
|
||||
Default: `['+([1-9])?(.{+([1-9]),x}).x', 'master', 'next', 'next-major', {name: 'beta', prerelease: true}, {name: 'alpha', prerelease: true}]`<br>
|
||||
Default: `['+([0-9])?(.{+([0-9]),x}).x', 'master', 'next', 'next-major', {name: 'beta', prerelease: true}, {name: 'alpha', prerelease: true}]`<br>
|
||||
CLI arguments: `--branches`
|
||||
|
||||
The branches on which releases should happen. By default **semantic-release** will release:
|
||||
@@ -81,9 +72,11 @@ 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.
|
||||
See [Workflow configuration](workflow-configuration.md#workflow-configuration) for more details.
|
||||
|
||||
### repositoryUrl
|
||||
|
||||
@@ -156,7 +149,8 @@ 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 branches](#branches) 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.
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
# Getting started
|
||||
|
||||
In order to use **semantic-release** you must follows this steps:
|
||||
- [Install](./installation.md#installation) **semantic-release** in your project
|
||||
- Configure your Continuous Integration service to [run **semantic-release**](./ci-configuration.md#run-semantic-release-only-after-all-tests-succeeded)
|
||||
- Configure your Git repository and package manager repository [authentication](ci-configuration.md#authentication) in your Continuous Integration service
|
||||
- Configure **semantic-release** [options and plugins](./configuration.md#configuration)
|
||||
In order to use **semantic-release** you must follow these steps:
|
||||
1. [Install](./installation.md#installation) **semantic-release** in your project
|
||||
2. Configure your Continuous Integration service to [run **semantic-release**](./ci-configuration.md#run-semantic-release-only-after-all-tests-succeeded)
|
||||
3. Configure your Git repository and package manager repository [authentication](ci-configuration.md#authentication) in your Continuous Integration service
|
||||
4. Configure **semantic-release** [options and plugins](./configuration.md#configuration)
|
||||
|
||||
Alternatively those steps can be easily done with the [**semantic-release** interactive CLI](https://github.com/semantic-release/cli):
|
||||
|
||||
@@ -19,4 +19,4 @@ semantic-release-cli setup
|
||||
|
||||
See the [semantic-release-cli](https://github.com/semantic-release/cli#what-it-does) documentation for more details.
|
||||
|
||||
**Note**: only a limited number of options, CI services and plugins is currently supported by `semantic-release-cli`.
|
||||
**Note**: only a limited number of options, CI services and plugins are currently supported by `semantic-release-cli`.
|
||||
|
||||
@@ -24,6 +24,6 @@ For other type of projects we recommend installing **semantic-release** directly
|
||||
$ npx semantic-release
|
||||
```
|
||||
|
||||
**Note:** For a global installation, it's recommended to specify the major **semantic-release** version to install (for example with with `npx semantic-release@15`, or `npm install -g semantic-release@15`). This way your build will not automatically use the next major **semantic-release** release that could possibly break your build. You will have to upgrade manually when a new major version is released.
|
||||
**Note**: For a global installation, it's recommended to specify the major **semantic-release** version to install (for example with with `npx semantic-release@15`). This way your build will not automatically use the next major **semantic-release** release that could possibly break your build. You will have to upgrade manually when a new major version is released.
|
||||
|
||||
**Note:** `npx` is a tool bundled with `npm@>=5.2.0`. It is used to conveniently install the semantic-release binary and to execute it. See [What is npx](../support/FAQ.md#what-is-npx) for more details.
|
||||
**Note**: `npx` is a tool bundled with `npm@>=5.2.0`. It is used to conveniently install the semantic-release binary and to execute it. See [What is npx](../support/FAQ.md#what-is-npx) for more details.
|
||||
|
||||
+23
-9
@@ -17,25 +17,39 @@ A plugin is a npm module that can implement one or more of the following steps:
|
||||
|
||||
**Note:** If no plugin with a `analyzeCommits` step is defined `@semantic-release/commit-analyzer` will be used.
|
||||
|
||||
See [available plugins](../extending/plugins-list.md).
|
||||
## Plugins installation
|
||||
|
||||
## Plugins configuration
|
||||
### Default plugins
|
||||
|
||||
Each plugin must be installed and configured with the [`plugins` options](./configuration.md#plugins) by specifying the list of plugins by npm module name.
|
||||
These four plugins are already part of **semantic-release** and don't have to be installed separately:
|
||||
```
|
||||
"@semantic-release/commit-analyzer"
|
||||
"@semantic-release/github"
|
||||
"@semantic-release/npm"
|
||||
"@semantic-release/release-notes-generator"
|
||||
```
|
||||
|
||||
### Additional plugins
|
||||
|
||||
[Additional plugins](../extending/plugins-list.md) have to be installed via npm:
|
||||
|
||||
```bash
|
||||
$ npm install @semantic-release/commit-analyzer @semantic-release/release-notes-generator @semantic-release/npm -D
|
||||
$ npm install @semantic-release/git @semantic-release/changelog -D
|
||||
```
|
||||
|
||||
## Plugins declaration and execution order
|
||||
|
||||
Each plugin must be configured with the [`plugins` options](./configuration.md#plugins) by specifying the list of plugins by npm module name.
|
||||
|
||||
```json
|
||||
{
|
||||
"plugins": ["@semantic-release/commit-analyzer", "@semantic-release/release-notes-generator", "@semantic-release/npm"]
|
||||
}
|
||||
```
|
||||
|
||||
## Plugin ordering
|
||||
**Note:** If the `plugins` option is defined, it overrides the default plugin list, rather than merging with it.
|
||||
|
||||
For each [release step](../../README.md#release-steps) the plugins that implement that step will be executed in the order in which the are defined.
|
||||
For each [release step](../../README.md#release-steps) the plugins that implement that step will be executed in the order in which they are defined.
|
||||
|
||||
```json
|
||||
{
|
||||
@@ -55,11 +69,11 @@ With this configuration **semantic-release** will:
|
||||
- execute the `generateNotes` implementation of `@semantic-release/release-notes-generator`
|
||||
- execute the `publish` implementation of `@semantic-release/npm`
|
||||
|
||||
## Plugin options
|
||||
## Plugin options configuration
|
||||
|
||||
A plugin options can specified by wrapping the name and an options object in an array. Options configured this way will be passed only to that specific plugin.
|
||||
A plugin configuration can be specified by wrapping the name and an options object in an array. Options configured this way will be passed only to that specific plugin.
|
||||
|
||||
Global plugin options can defined at the root of the **semantic-release** configuration object. Options configured this way will be passed to all plugins.
|
||||
Global plugin configuration can be defined at the root of the **semantic-release** configuration object. Options configured this way will be passed to all plugins.
|
||||
|
||||
```json
|
||||
{
|
||||
|
||||
@@ -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.
|
||||
|
||||
|
||||
@@ -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: [
|
||||
|
||||
@@ -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');
|
||||
|
||||
@@ -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) {
|
||||
@@ -64,28 +65,26 @@ async function run(context, plugins) {
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
logger[options.dryRun ? 'warn' : 'success'](
|
||||
`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
|
||||
} 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;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -98,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;
|
||||
@@ -126,12 +127,13 @@ 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(
|
||||
`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}`);
|
||||
|
||||
@@ -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) => [
|
||||
|
||||
@@ -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} = require('../../lib/git');
|
||||
|
||||
module.exports = async ({cwd, env, options: {tagFormat}}, branches) => {
|
||||
// Generate a regex to parse tags formatted with `tagFormat`
|
||||
@@ -10,26 +10,14 @@ 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, true, {cwd, env}))
|
||||
? [...tags, {...rest, gitTag, gitHead: await getTagHead(gitTag, {cwd, env})}]
|
||||
: tags,
|
||||
[]
|
||||
);
|
||||
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}];
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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,
|
||||
|
||||
+13
-11
@@ -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 =>
|
||||
@@ -30,14 +29,15 @@ Please make sure to add the \`repositoryUrl\` to the [semantic-release configura
|
||||
)}).`,
|
||||
}),
|
||||
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 \`${name}\` on remote Git repository with URL \`${repositoryUrl}\`.
|
||||
message: 'Cannot push to the Git repository.',
|
||||
details: `**semantic-release** cannot push the version tag to the branch \`${name}\` on the remote Git repository with URL \`${repositoryUrl}\`.
|
||||
|
||||
Please refer to the [authentication configuration documentation](${linkify(
|
||||
'docs/usage/ci-configuration.md#authentication'
|
||||
)}) to configure the Git credentials on your CI environment and make sure the [repositoryUrl](${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).`,
|
||||
This can be caused by:
|
||||
- a misconfiguration of the [repositoryUrl](${linkify('docs/usage/configuration.md#repositoryurl')}) option
|
||||
- the repository being unavailable
|
||||
- or missing push permission for the user configured via the [Git credentials on your CI environment](${linkify(
|
||||
'docs/usage/ci-configuration.md#authentication'
|
||||
)})`,
|
||||
}),
|
||||
EINVALIDTAGFORMAT: ({options: {tagFormat}}) => ({
|
||||
message: 'Invalid `tagFormat` option.',
|
||||
@@ -185,6 +185,8 @@ Your configuration for the problematic branches is \`${stringify(branches)}\`.`,
|
||||
'docs/usage/configuration.md#branches'
|
||||
)}).
|
||||
|
||||
This may occur if your repository does not have a release branch, such as \`master\`.
|
||||
|
||||
Your configuration for the problematic branches is \`${stringify(branches)}\`.`,
|
||||
}),
|
||||
EPRERELEASEBRANCH: ({branch}) => ({
|
||||
@@ -211,8 +213,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}\``))}.
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
/* eslint require-atomic-updates: off */
|
||||
|
||||
const {isString, isPlainObject} = require('lodash');
|
||||
const {getGitHead} = require('../git');
|
||||
const hideSensitive = require('../hide-sensitive');
|
||||
@@ -59,6 +61,7 @@ module.exports = {
|
||||
// Regenerate the release notes
|
||||
context.nextRelease.notes = await generateNotes(context);
|
||||
}
|
||||
|
||||
// Call the next prepare plugin with the updated `nextRelease`
|
||||
return context;
|
||||
},
|
||||
|
||||
+4
-3
@@ -30,6 +30,7 @@ module.exports = async (context, opts) => {
|
||||
if (options.ci === false) {
|
||||
options.noCi = true;
|
||||
}
|
||||
|
||||
const pluginsPath = {};
|
||||
let extendPaths;
|
||||
({extends: extendPaths, ...options} = options);
|
||||
@@ -66,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',
|
||||
@@ -92,6 +93,6 @@ module.exports = async (context, opts) => {
|
||||
};
|
||||
|
||||
async function pkgRepoUrl(opts) {
|
||||
const {pkg} = await readPkgUp(opts);
|
||||
return pkg && (isPlainObject(pkg.repository) ? pkg.repository.url : pkg.repository);
|
||||
const {packageJson} = (await readPkgUp(opts)) || {};
|
||||
return packageJson && (isPlainObject(packageJson.repository) ? packageJson.repository.url : packageJson.repository);
|
||||
}
|
||||
|
||||
+21
-14
@@ -1,18 +1,8 @@
|
||||
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');
|
||||
|
||||
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);
|
||||
|
||||
@@ -39,16 +41,21 @@ module.exports = async ({cwd, env, branch, options: {repositoryUrl}}) => {
|
||||
// Test if push is allowed without transforming the URL (e.g. is ssh keys are set up)
|
||||
try {
|
||||
await verifyAuth(repositoryUrl, branch.name, {cwd, env});
|
||||
} catch (error) {
|
||||
} catch (_) {
|
||||
const envVar = Object.keys(GIT_TOKENS).find(envVar => !isNil(env[envVar]));
|
||||
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) || [];
|
||||
const {port, hostname, ...parsed} = parse(
|
||||
match ? `ssh://${auth ? `${auth}@` : ''}${host}/${path}` : repositoryUrl
|
||||
);
|
||||
|
||||
return format({
|
||||
...parse(match ? `ssh://${auth ? `${auth}@` : ''}${host}/${path}` : repositoryUrl),
|
||||
...parsed,
|
||||
auth: gitCredentials,
|
||||
host: `${hostname}${protocol === 'ssh:' ? '' : port ? `:${port}` : ''}`,
|
||||
protocol: protocol && /http[^s]/.test(protocol) ? 'http' : 'https',
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -23,14 +26,14 @@ 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, 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 {};
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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,
|
||||
},
|
||||
};
|
||||
}),
|
||||
|
||||
+31
-39
@@ -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');
|
||||
@@ -15,23 +14,20 @@ 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.stdout('git', ['rev-list', '-1', tagName], execaOpts);
|
||||
} catch (error) {
|
||||
debug(error);
|
||||
}
|
||||
return (await execa('git', ['rev-list', '-1', tagName], execaOpts)).stdout;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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<String>} List of git tags.
|
||||
* @throws {Error} If the `git` command fails.
|
||||
*/
|
||||
async function getTags(execaOpts) {
|
||||
return (await execa.stdout('git', ['tag'], execaOpts))
|
||||
async function getTags(branch, execaOpts) {
|
||||
return (await execa('git', ['tag', '--merged', branch], execaOpts)).stdout
|
||||
.split('\n')
|
||||
.map(tag => tag.trim())
|
||||
.filter(Boolean);
|
||||
@@ -57,33 +53,29 @@ 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<String>} 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('git', ['ls-remote', '--heads', repositoryUrl], execaOpts)).stdout
|
||||
.split('\n')
|
||||
.map(branch => branch.match(/^.+refs\/heads\/(.+)$/)[1])
|
||||
.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;
|
||||
}
|
||||
@@ -92,13 +84,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 (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'])));
|
||||
}
|
||||
if (error.exitCode === 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -117,7 +103,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);
|
||||
}
|
||||
@@ -126,12 +112,13 @@ 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;
|
||||
(await execa('git', ['rev-parse', '--verify', branch], {...execaOpts, reject: false})).exitCode === 0;
|
||||
|
||||
try {
|
||||
await execa(
|
||||
@@ -140,14 +127,18 @@ async function fetch(branch, execaOpts) {
|
||||
'fetch',
|
||||
'--unshallow',
|
||||
'--tags',
|
||||
...(isLocalExists ? [] : ['origin', `+refs/heads/${branch}:refs/heads/${branch}`]),
|
||||
...(isLocalExists ? [repositoryUrl] : [repositoryUrl, `+refs/heads/${branch}:refs/heads/${branch}`]),
|
||||
],
|
||||
execaOpts
|
||||
);
|
||||
} catch (error) {
|
||||
} catch (_) {
|
||||
await execa(
|
||||
'git',
|
||||
['fetch', '--tags', ...(isLocalExists ? [] : ['origin', `+refs/heads/${branch}:refs/heads/${branch}`])],
|
||||
[
|
||||
'fetch',
|
||||
'--tags',
|
||||
...(isLocalExists ? [repositoryUrl] : [repositoryUrl, `+refs/heads/${branch}:refs/heads/${branch}`]),
|
||||
],
|
||||
execaOpts
|
||||
);
|
||||
}
|
||||
@@ -160,8 +151,8 @@ async function fetch(branch, execaOpts) {
|
||||
*
|
||||
* @return {String} the sha of the HEAD commit.
|
||||
*/
|
||||
function getGitHead(execaOpts) {
|
||||
return execa.stdout('git', ['rev-parse', 'HEAD'], execaOpts);
|
||||
async function getGitHead(execaOpts) {
|
||||
return (await execa('git', ['rev-parse', 'HEAD'], execaOpts)).stdout;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -173,7 +164,7 @@ function getGitHead(execaOpts) {
|
||||
*/
|
||||
async function repoUrl(execaOpts) {
|
||||
try {
|
||||
return await execa.stdout('git', ['config', '--get', 'remote.origin.url'], execaOpts);
|
||||
return (await execa('git', ['config', '--get', 'remote.origin.url'], execaOpts)).stdout;
|
||||
} catch (error) {
|
||||
debug(error);
|
||||
}
|
||||
@@ -188,7 +179,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);
|
||||
}
|
||||
@@ -247,7 +238,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);
|
||||
}
|
||||
@@ -263,7 +254,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);
|
||||
}
|
||||
@@ -272,15 +263,16 @@ 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 {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);
|
||||
}
|
||||
|
||||
@@ -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];
|
||||
}
|
||||
|
||||
|
||||
@@ -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}"`);
|
||||
|
||||
@@ -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.
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
@@ -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 || {}];
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 142 KiB After Width: | Height: | Size: 117 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 117 KiB After Width: | Height: | Size: 65 KiB |
+41
-41
@@ -3,75 +3,76 @@
|
||||
"description": "Automated semver compliant package publishing",
|
||||
"version": "0.0.0-development",
|
||||
"author": "Stephan Bönnemann <stephan@boennemann.me> (http://boennemann.me)",
|
||||
"ava": {
|
||||
"files": [
|
||||
"test/**/*.test.js"
|
||||
],
|
||||
"helpers": [
|
||||
"test/helpers/**/*"
|
||||
]
|
||||
},
|
||||
"bin": {
|
||||
"semantic-release": "bin/semantic-release.js"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/semantic-release/semantic-release/issues"
|
||||
},
|
||||
"config": {
|
||||
"commitizen": {
|
||||
"path": "cz-conventional-changelog"
|
||||
}
|
||||
},
|
||||
"contributors": [
|
||||
"Gregor Martynus (https://twitter.com/gr2m)",
|
||||
"Pierre Vanduynslager (https://twitter.com/@pvdlg_)"
|
||||
],
|
||||
"dependencies": {
|
||||
"@semantic-release/commit-analyzer": "^7.0.0-beta.1",
|
||||
"@semantic-release/commit-analyzer": "7.0.0-beta.4",
|
||||
"@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.6.0-beta.2",
|
||||
"@semantic-release/npm": "6.0.0-beta.3",
|
||||
"@semantic-release/release-notes-generator": "^7.1.2",
|
||||
"aggregate-error": "^2.0.0",
|
||||
"aggregate-error": "^3.0.0",
|
||||
"cosmiconfig": "^5.0.1",
|
||||
"debug": "^4.0.0",
|
||||
"env-ci": "^3.0.0",
|
||||
"execa": "^1.0.0",
|
||||
"figures": "^2.0.0",
|
||||
"env-ci": "^4.0.0",
|
||||
"execa": "^3.2.0",
|
||||
"figures": "^3.0.0",
|
||||
"find-versions": "^3.0.0",
|
||||
"get-stream": "^4.0.0",
|
||||
"get-stream": "^5.0.0",
|
||||
"git-log-parser": "^1.2.0",
|
||||
"hook-std": "^1.1.0",
|
||||
"hosted-git-info": "^2.7.1",
|
||||
"lodash": "^4.17.4",
|
||||
"marked": "^0.5.0",
|
||||
"marked-terminal": "^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",
|
||||
"hook-std": "^2.0.0",
|
||||
"hosted-git-info": "^3.0.0",
|
||||
"lodash": "^4.17.15",
|
||||
"marked": "^0.7.0",
|
||||
"marked-terminal": "^3.2.0",
|
||||
"micromatch": "^4.0.2",
|
||||
"p-each-series": "^2.1.0",
|
||||
"p-reduce": "^2.0.0",
|
||||
"read-pkg-up": "^7.0.0",
|
||||
"resolve-from": "^5.0.0",
|
||||
"semver": "^6.0.0",
|
||||
"semver-diff": "^3.1.1",
|
||||
"signale": "^1.2.1",
|
||||
"yargs": "^12.0.0"
|
||||
"yargs": "^14.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"ava": "^1.0.1",
|
||||
"clear-module": "^3.0.0",
|
||||
"ava": "^2.0.0",
|
||||
"clear-module": "^4.0.0",
|
||||
"codecov": "^3.0.0",
|
||||
"commitizen": "^3.0.0",
|
||||
"cz-conventional-changelog": "^2.0.0",
|
||||
"delay": "^4.0.0",
|
||||
"dockerode": "^2.5.2",
|
||||
"file-url": "^2.0.2",
|
||||
"fs-extra": "^7.0.0",
|
||||
"dockerode": "^3.0.0",
|
||||
"file-url": "^3.0.0",
|
||||
"fs-extra": "^8.0.0",
|
||||
"got": "^9.0.0",
|
||||
"js-yaml": "^3.10.0",
|
||||
"mockserver-client": "^5.1.1",
|
||||
"nock": "^10.0.0",
|
||||
"nyc": "^13.1.0",
|
||||
"p-retry": "^3.0.0",
|
||||
"nock": "^11.1.0",
|
||||
"nyc": "^14.0.0",
|
||||
"p-retry": "^4.0.0",
|
||||
"proxyquire": "^2.0.0",
|
||||
"sinon": "^7.1.1",
|
||||
"sinon": "^7.2.7",
|
||||
"stream-buffers": "^3.0.2",
|
||||
"tempy": "^0.2.1",
|
||||
"xo": "^0.23.0"
|
||||
"tempy": "^0.3.0",
|
||||
"xo": "^0.25.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=8.3"
|
||||
"node": ">=8.16"
|
||||
},
|
||||
"files": [
|
||||
"bin",
|
||||
@@ -119,7 +120,6 @@
|
||||
"url": "git+https://github.com/semantic-release/semantic-release.git"
|
||||
},
|
||||
"scripts": {
|
||||
"cm": "git-cz",
|
||||
"codecov": "codecov -f coverage/coverage-final.json",
|
||||
"lint": "xo",
|
||||
"pretest": "npm run lint",
|
||||
|
||||
@@ -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');
|
||||
|
||||
@@ -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},
|
||||
@@ -41,8 +41,8 @@ test('Expand branches defined with globs', async t => {
|
||||
{name: 'beta', channel: `channel-\${name}`, prerelease: true},
|
||||
];
|
||||
|
||||
t.deepEqual(await expand({cwd}, branches), [
|
||||
{name: '1.1.x'},
|
||||
t.deepEqual(await expand(repositoryUrl, {cwd}, branches), [
|
||||
{name: '1.0.x'},
|
||||
{name: '1.x.x'},
|
||||
{name: '2.x'},
|
||||
{name: 'master', channel: 'latest'},
|
||||
|
||||
@@ -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();
|
||||
@@ -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'},
|
||||
],
|
||||
},
|
||||
]);
|
||||
@@ -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});
|
||||
@@ -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,37 +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}]},
|
||||
]);
|
||||
});
|
||||
|
||||
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}],
|
||||
},
|
||||
{name: 'master', tags: [{gitTag: '3.0.0-bar.2', version: '3.0.0', channel: undefined}]},
|
||||
]);
|
||||
});
|
||||
|
||||
+3
-3
@@ -175,7 +175,7 @@ test.serial('Display help', async t => {
|
||||
t.is(exitCode, 0);
|
||||
});
|
||||
|
||||
test.serial('Return error code and prints help if called with a command', async t => {
|
||||
test.serial('Return error exitCode and prints help if called with a command', async t => {
|
||||
const run = stub().resolves(true);
|
||||
const argv = ['', '', 'pre'];
|
||||
const cli = requireNoCache('../cli', {'.': run, process: {...process, argv}});
|
||||
@@ -187,7 +187,7 @@ test.serial('Return error code and prints help if called with a command', async
|
||||
t.is(exitCode, 1);
|
||||
});
|
||||
|
||||
test.serial('Return error code if multiple plugin are set for single plugin', async t => {
|
||||
test.serial('Return error exitCode if multiple plugin are set for single plugin', async t => {
|
||||
const run = stub().resolves(true);
|
||||
const argv = ['', '', '--analyze-commits', 'analyze1', 'analyze2'];
|
||||
const cli = requireNoCache('../cli', {'.': run, process: {...process, argv}});
|
||||
@@ -199,7 +199,7 @@ test.serial('Return error code if multiple plugin are set for single plugin', as
|
||||
t.is(exitCode, 1);
|
||||
});
|
||||
|
||||
test.serial('Return error code if semantic-release throw error', async t => {
|
||||
test.serial('Return error exitCode if semantic-release throw error', async t => {
|
||||
const run = stub().rejects(new Error('semantic-release error'));
|
||||
const argv = ['', ''];
|
||||
const cli = requireNoCache('../cli', {'.': run, process: {...process, argv}});
|
||||
|
||||
@@ -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',
|
||||
@@ -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');
|
||||
});
|
||||
|
||||
@@ -86,9 +86,9 @@ test('Convert shorthand URL', async t => {
|
||||
cwd,
|
||||
env,
|
||||
branch: {name: 'master'},
|
||||
options: {repositoryUrl: 'semanitc-release/semanitc-release'},
|
||||
options: {repositoryUrl: 'semantic-release/semantic-release'},
|
||||
}),
|
||||
'https://github.com/semanitc-release/semanitc-release.git'
|
||||
'https://github.com/semantic-release/semantic-release.git'
|
||||
);
|
||||
});
|
||||
|
||||
@@ -100,9 +100,9 @@ test('Convert GitLab shorthand URL', async t => {
|
||||
cwd,
|
||||
env,
|
||||
branch: {name: 'master'},
|
||||
options: {repositoryUrl: 'gitlab:semanitc-release/semanitc-release'},
|
||||
options: {repositoryUrl: 'gitlab:semantic-release/semantic-release'},
|
||||
}),
|
||||
'https://gitlab.com/semanitc-release/semanitc-release.git'
|
||||
'https://gitlab.com/semantic-release/semantic-release.git'
|
||||
);
|
||||
});
|
||||
|
||||
@@ -161,6 +161,19 @@ test('Return the "http" formatted URL if "gitCredentials" is defined and reposit
|
||||
);
|
||||
});
|
||||
|
||||
test('Return the "http" formatted URL if "gitCredentials" is defined and repositoryUrl is a "http" URL with custom port', async t => {
|
||||
const {cwd} = await gitRepo();
|
||||
|
||||
t.is(
|
||||
await getAuthUrl({
|
||||
cwd,
|
||||
env: {...env, GIT_CREDENTIALS: 'user:pass'},
|
||||
options: {branch: 'master', repositoryUrl: 'http://host.null:8080/owner/repo.git'},
|
||||
}),
|
||||
'http://user:pass@host.null:8080/owner/repo.git'
|
||||
);
|
||||
});
|
||||
|
||||
test('Return the "https" formatted URL if "gitCredentials" is defined and repositoryUrl is a "git+https" URL', async t => {
|
||||
const {cwd} = await gitRepo();
|
||||
|
||||
@@ -189,6 +202,19 @@ test('Return the "http" formatted URL if "gitCredentials" is defined and reposit
|
||||
);
|
||||
});
|
||||
|
||||
test('Return the "http" formatted URL if "gitCredentials" is defined and repositoryUrl is a "ssh" URL', async t => {
|
||||
const {cwd} = await gitRepo();
|
||||
|
||||
t.is(
|
||||
await getAuthUrl({
|
||||
cwd,
|
||||
env: {...env, GIT_CREDENTIALS: 'user:pass'},
|
||||
options: {branch: 'master', repositoryUrl: 'ssh://git@host.null:2222/owner/repo.git'},
|
||||
}),
|
||||
'https://user:pass@host.null/owner/repo.git'
|
||||
);
|
||||
});
|
||||
|
||||
test('Return the "https" formatted URL if "gitCredentials" is defined with "GH_TOKEN"', async t => {
|
||||
const {cwd} = await gitRepo();
|
||||
|
||||
@@ -273,6 +299,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();
|
||||
|
||||
|
||||
@@ -6,23 +6,48 @@ 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 => {
|
||||
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: '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',
|
||||
},
|
||||
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: 'v1.0.0-beta.2@beta',
|
||||
channel: 'beta',
|
||||
});
|
||||
});
|
||||
|
||||
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}`},
|
||||
@@ -38,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',
|
||||
},
|
||||
@@ -51,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});
|
||||
});
|
||||
|
||||
@@ -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 => {
|
||||
|
||||
@@ -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}],
|
||||
|
||||
+16
-17
@@ -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,9 +89,9 @@ 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());
|
||||
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 => {
|
||||
@@ -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 => {
|
||||
@@ -137,10 +137,10 @@ 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 => {
|
||||
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 => {
|
||||
@@ -243,7 +242,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 => {
|
||||
@@ -251,7 +250,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 +259,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 +274,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}));
|
||||
});
|
||||
|
||||
+13
-25
@@ -69,8 +69,9 @@ export async function initBareRepo(repositoryUrl, branch = 'master') {
|
||||
* @returns {Array<Commit>} The created commits, in reverse order (to match `git log` order).
|
||||
*/
|
||||
export async function gitCommits(messages, execaOpts) {
|
||||
await pEachSeries(messages, message =>
|
||||
execa.stdout('git', ['commit', '-m', message, '--allow-empty', '--no-gpg-sign'], execaOpts)
|
||||
await pEachSeries(
|
||||
messages,
|
||||
async message => (await execa('git', ['commit', '-m', message, '--allow-empty', '--no-gpg-sign'], execaOpts)).stdout
|
||||
);
|
||||
return (await gitGetCommits(undefined, execaOpts)).slice(0, messages.length);
|
||||
}
|
||||
@@ -98,10 +99,10 @@ export async function gitGetCommits(from, execaOpts) {
|
||||
* Checkout a branch on the current git repository.
|
||||
*
|
||||
* @param {String} branch Branch name.
|
||||
* @param {Boolean} create `true` to create the branch, `false` to checkout an existing branch.
|
||||
* @param {Boolean} create to create the branch, `false` to checkout an existing branch.
|
||||
* @param {Object} [execaOpts] Options to pass to `execa`.
|
||||
*/
|
||||
export async function gitCheckout(branch, create = true, execaOpts) {
|
||||
export async function gitCheckout(branch, create, execaOpts) {
|
||||
await execa('git', create ? ['checkout', '-b', branch] : ['checkout', branch], execaOpts);
|
||||
}
|
||||
|
||||
@@ -112,8 +113,8 @@ export async function gitCheckout(branch, create = true, execaOpts) {
|
||||
*
|
||||
* @return {String} The sha of the head commit in the current git repository.
|
||||
*/
|
||||
export function gitHead(execaOpts) {
|
||||
return execa.stdout('git', ['rev-parse', 'HEAD'], execaOpts);
|
||||
export async function gitHead(execaOpts) {
|
||||
return (await execa('git', ['rev-parse', 'HEAD'], execaOpts)).stdout;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -181,8 +182,8 @@ export async function gitAddConfig(name, value, execaOpts) {
|
||||
*
|
||||
* @return {String} The sha of the commit associated with `tagName` on the local repository.
|
||||
*/
|
||||
export function gitTagHead(tagName, execaOpts) {
|
||||
return execa.stdout('git', ['rev-list', '-1', tagName], execaOpts);
|
||||
export async function gitTagHead(tagName, execaOpts) {
|
||||
return (await execa('git', ['rev-list', '-1', tagName], execaOpts)).stdout;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -195,7 +196,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('git', ['ls-remote', '--tags', repositoryUrl, tagName], execaOpts)).stdout
|
||||
.split('\n')
|
||||
.filter(tag => Boolean(tag))
|
||||
.map(tag => tag.match(/^(\S+)/)[1])[0];
|
||||
@@ -209,8 +210,8 @@ export async function gitRemoteTagHead(repositoryUrl, tagName, execaOpts) {
|
||||
*
|
||||
* @return {String} The tag associatedwith the sha in parameter or `null`.
|
||||
*/
|
||||
export function gitCommitTag(gitHead, execaOpts) {
|
||||
return execa.stdout('git', ['describe', '--tags', '--exact-match', gitHead], execaOpts);
|
||||
export async function gitCommitTag(gitHead, execaOpts) {
|
||||
return (await execa('git', ['describe', '--tags', '--exact-match', gitHead], execaOpts)).stdout;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -222,7 +223,7 @@ export function gitCommitTag(gitHead, execaOpts) {
|
||||
*
|
||||
* @throws {Error} if the push failed.
|
||||
*/
|
||||
export async function gitPush(repositoryUrl = 'origin', branch = 'master', execaOpts) {
|
||||
export async function gitPush(repositoryUrl, branch, execaOpts) {
|
||||
await execa('git', ['push', '--tags', repositoryUrl, `HEAD:${branch}`], execaOpts);
|
||||
}
|
||||
|
||||
@@ -255,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
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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';
|
||||
|
||||
@@ -30,7 +30,7 @@ async function start() {
|
||||
minTimeout: 1000,
|
||||
factor: 2,
|
||||
});
|
||||
} catch (error) {
|
||||
} catch (_) {
|
||||
throw new Error(`Couldn't start mock-server after 2 min`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ async function start() {
|
||||
minTimeout: 1000,
|
||||
factor: 2,
|
||||
});
|
||||
} catch (error) {
|
||||
} catch (_) {
|
||||
throw new Error(`Couldn't start npm-registry-docker after 2 min`);
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
+21
-16
@@ -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,
|
||||
@@ -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',
|
||||
},
|
||||
];
|
||||
@@ -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},
|
||||
];
|
||||
|
||||
@@ -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,
|
||||
});
|
||||
@@ -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: () => {}},
|
||||
}));
|
||||
@@ -694,10 +695,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 +770,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 +1207,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 +1404,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);
|
||||
|
||||
+30
-30
@@ -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 => {
|
||||
|
||||
@@ -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');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user