Compare commits
102
Commits
+2
-2
@@ -7,11 +7,11 @@ node_js:
|
||||
- 10
|
||||
- 8
|
||||
|
||||
# Trigger a push build on caribou and greenkeeper branches + PRs build on every branches
|
||||
# Trigger a push build on master and greenkeeper branches + PRs build on every branches
|
||||
# Avoid double build on PRs (See https://github.com/travis-ci/travis-ci/issues/1147)
|
||||
branches:
|
||||
only:
|
||||
- caribou
|
||||
- master
|
||||
- /^greenkeeper.*$/
|
||||
|
||||
# Retry install on fail to avoid failing a build on network/disk/external errors
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
<h1 align="center" style="border-bottom: none;">📦🚀 semantic-release</h1>
|
||||
<h3 align="center">Fully automated version management and package publishing</h3>
|
||||
<p align="center">
|
||||
<a href="https://gitter.im/semantic-release/semantic-release">
|
||||
<img alt="Gitter" src="https://badges.gitter.im/semantic-release/semantic-release.svg">
|
||||
<a href="https://spectrum.chat/semantic-release">
|
||||
<img alt="Join the community on Spectrum" src="https://withspectrum.github.io/badge/badge.svg">
|
||||
</a>
|
||||
<a href="https://travis-ci.org/semantic-release/semantic-release">
|
||||
<img alt="Travis" src="https://img.shields.io/travis/semantic-release/semantic-release/caribou.svg">
|
||||
<img alt="Travis" src="https://img.shields.io/travis/semantic-release/semantic-release/master.svg">
|
||||
</a>
|
||||
<a href="https://codecov.io/gh/semantic-release/semantic-release">
|
||||
<img alt="Codecov" src="https://img.shields.io/codecov/c/github/semantic-release/semantic-release/caribou.svg">
|
||||
<img alt="Codecov" src="https://img.shields.io/codecov/c/github/semantic-release/semantic-release/master.svg">
|
||||
</a>
|
||||
<a href="https://greenkeeper.io">
|
||||
<img alt="Greenkeeper" src="https://badges.greenkeeper.io/semantic-release/semantic-release.svg">
|
||||
@@ -52,7 +52,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), [commitlint](https://github.com/conventional-changelog/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.
|
||||
|
||||
Here is an example of the release type that will be done based on a commit messages:
|
||||
|
||||
@@ -76,23 +76,24 @@ If you need more control over the timing of releases you have a couple of option
|
||||
|
||||
### Release steps
|
||||
|
||||
After running the tests the command `semantic-release` will execute the following steps:
|
||||
After running the tests, the command `semantic-release` will execute the following steps:
|
||||
|
||||
| Step | Description |
|
||||
|-------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||
| Verify Conditions | Verify all the conditions to proceed with the release with the [verify conditions plugins](docs/usage/plugins.md#verifyconditions-plugin). |
|
||||
| Get last release | Obtain the commit corresponding to the last release by analyzing [Git tags](https://git-scm.com/book/en/v2/Git-Basics-Tagging). |
|
||||
| Analyze commits | Determine the type of release with the [analyze commits plugin](docs/usage/plugins.md#analyzecommits-plugin) based on the commits added since the last release. |
|
||||
| Verify release | Verify the release conformity with the [verify release plugins](docs/usage/plugins.md#verifyrelease-plugin). |
|
||||
| Generate notes | Generate release notes with the [generate notes plugin](docs/usage/plugins.md#generatenotes-plugin) for the commits added since the last release. |
|
||||
| Create Git tag | Create a Git tag corresponding to the new release version |
|
||||
| Prepare | Prepare the release with the [prepare plugins](docs/usage/plugins.md#prepare-plugin). |
|
||||
| Publish | Publish the release with the [publish plugins](docs/usage/plugins.md#publish-plugin). |
|
||||
| Notify | Notify of new releases or errors with the [success](docs/usage/plugins.md#success-plugin) and [fail](docs/usage/plugins.md#fail-plugin) plugins. |
|
||||
| Step | Description |
|
||||
|-------------------|---------------------------------------------------------------------------------------------------------------------------------|
|
||||
| Verify Conditions | Verify all the conditions to proceed with the release. |
|
||||
| Get last release | Obtain the commit corresponding to the last release by analyzing [Git tags](https://git-scm.com/book/en/v2/Git-Basics-Tagging). |
|
||||
| Analyze commits | Determine the type of release based on the commits added since the last release. |
|
||||
| Verify release | Verify the release conformity. |
|
||||
| Generate notes | Generate release notes for the commits added since the last release. |
|
||||
| Create Git tag | Create a Git tag corresponding to the new release version. |
|
||||
| Prepare | Prepare the release. |
|
||||
| Publish | Publish the release. |
|
||||
| Notify | Notify of new releases or errors. |
|
||||
|
||||
## Documentation
|
||||
|
||||
- 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)
|
||||
@@ -118,7 +119,7 @@ After running the tests the command `semantic-release` will execute the followin
|
||||
## Get help
|
||||
|
||||
- [Stack Overflow](https://stackoverflow.com/questions/tagged/semantic-release)
|
||||
- [Gitter chat](https://gitter.im/semantic-release/semantic-release)
|
||||
- [Spectrum community](https://spectrum.chat/semantic-release)
|
||||
- [Twitter](https://twitter.com/SemanticRelease)
|
||||
|
||||
## Badge
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// Bad news: We have to write plain ES5 in this file
|
||||
// Good news: It's the only file of the entire project
|
||||
|
||||
/* eslint-disable no-var, promise/prefer-await-to-then, prefer-destructuring */
|
||||
/* eslint-disable no-var */
|
||||
|
||||
var semver = require('semver');
|
||||
var execa = require('execa');
|
||||
@@ -16,7 +16,7 @@ if (!semver.satisfies(process.version, pkg.engines.node)) {
|
||||
console.error(
|
||||
`[semantic-release]: node version ${pkg.engines.node} is required. Found ${process.version}.
|
||||
|
||||
See https://github.com/semantic-release/semantic-release/blob/caribou/docs/support/node-version.md for more details and solutions.`
|
||||
See https://github.com/semantic-release/semantic-release/blob/master/docs/support/node-version.md for more details and solutions.`
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
@@ -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');
|
||||
|
||||
@@ -22,6 +22,7 @@ Usage:
|
||||
.option('b', {alias: 'branch', describe: 'Git branch to release from', type: 'string', group: 'Options'})
|
||||
.option('r', {alias: 'repository-url', describe: 'Git repository URL', type: 'string', group: 'Options'})
|
||||
.option('t', {alias: 'tag-format', describe: 'Git tag format', type: 'string', group: 'Options'})
|
||||
.option('p', {alias: 'plugins', describe: 'Plugins', ...stringList, group: 'Options'})
|
||||
.option('e', {alias: 'extends', describe: 'Shareable configurations', ...stringList, group: 'Options'})
|
||||
.option('ci', {describe: 'Toggle CI verifications', type: 'boolean', group: 'Options'})
|
||||
.option('verify-conditions', {...stringList, group: 'Plugins'})
|
||||
@@ -46,21 +47,18 @@ Usage:
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Set the `noCi` options as yargs sets the `ci` options instead (because arg starts with `--no`)
|
||||
if (opts.ci === false) {
|
||||
opts.noCi = true;
|
||||
}
|
||||
|
||||
if (opts.debug) {
|
||||
// Debug must be enabled before other requires in order to work
|
||||
require('debug').enable('semantic-release:*');
|
||||
}
|
||||
|
||||
await require('.')(opts);
|
||||
return 0;
|
||||
} catch (error) {
|
||||
if (error.name !== 'YError') {
|
||||
stderr.write(hideSensitive(env)(util.inspect(error, {colors: true})));
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
codecov:
|
||||
branch: caribou
|
||||
@@ -39,7 +39,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,59 +1,93 @@
|
||||
# Plugins list
|
||||
|
||||
## Default plugins
|
||||
|
||||
- [@semantic-release/github](https://github.com/semantic-release/github)
|
||||
- [verifyConditions](https://github.com/semantic-release/github#verifyconditions): Verify the presence and the validity of the GitHub authentication and release configuration
|
||||
- [publish](https://github.com/semantic-release/github#publish): Publish a [GitHub release](https://help.github.com/articles/about-releases)
|
||||
- [success](https://github.com/semantic-release/github#success): Add a comment to GitHub issues and pull requests resolved in the release
|
||||
- [fail](https://github.com/semantic-release/github#fail): Open a GitHub issue when a release fails
|
||||
- [@semantic-release/npm](https://github.com/semantic-release/npm)
|
||||
- [verifyConditions](https://github.com/semantic-release/npm#verifyconditions): Verify the presence and the validity of the npm authentication and release configuration
|
||||
- [prepare](https://github.com/semantic-release/npm#prepare): Update the package.json version and create the npm package tarball
|
||||
- [publish](https://github.com/semantic-release/npm#publish): Publish the package on the npm registry
|
||||
|
||||
## 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
|
||||
- [@semantic-release/gitlab](https://github.com/semantic-release/gitlab)
|
||||
- [verifyConditions](https://github.com/semantic-release/gitlab#verifyconditions): Verify the presence and the validity of the GitLab authentication and release configuration
|
||||
- [publish](https://github.com/semantic-release/gitlab#publish): Publish a [GitLab release](https://docs.gitlab.com/ce/workflow/releases.html)
|
||||
- `verifyConditions`: Verify the presence and the validity of the GitLab authentication and release configuration
|
||||
- `publish`: Publish a [GitLab release](https://docs.gitlab.com/ce/workflow/releases.html)
|
||||
- [@semantic-release/git](https://github.com/semantic-release/git)
|
||||
- [verifyConditions](https://github.com/semantic-release/git#verifyconditions): Verify the presence and the validity of the Git authentication and release configuration
|
||||
- [prepare](https://github.com/semantic-release/git#prepare): Push a release commit and tag, including configurable files
|
||||
- `verifyConditions`: Verify the presence and the validity of the Git authentication and release configuration
|
||||
- `prepare`: Push a release commit and tag, including configurable files
|
||||
- [@semantic-release/changelog](https://github.com/semantic-release/changelog)
|
||||
- [verifyConditions](https://github.com/semantic-release/changelog#verifyconditions): Verify the presence and the validity of the configuration
|
||||
- [prepare](https://github.com/semantic-release/changelog#prepare): Create or update the changelog file in the local project repository
|
||||
- `verifyConditions`: Verify the presence and the validity of the configuration
|
||||
- `prepare`: Create or update the changelog file in the local project repository
|
||||
- [@semantic-release/exec](https://github.com/semantic-release/exec)
|
||||
- [verifyConditions](https://github.com/semantic-release/exec#verifyconditions): Execute a shell command to verify if the release should happen
|
||||
- [analyzeCommits](https://github.com/semantic-release/exec#analyzecommits): Execute a shell command to determine the type of release
|
||||
- [verifyRelease](https://github.com/semantic-release/exec#verifyrelease): Execute a shell command to verifying a release that was determined before and is about to be published.
|
||||
- [generateNotes](https://github.com/semantic-release/exec#analyzecommits): Execute a shell command to generate the release note
|
||||
- [prepare](https://github.com/semantic-release/exec#prepare): Execute a shell command to prepare the release
|
||||
- [publish](https://github.com/semantic-release/exec#publish): Execute a shell command to publish the release
|
||||
- [success](https://github.com/semantic-release/exec#success): Execute a shell command to notify of a new release
|
||||
- [fail](https://github.com/semantic-release/exec#fail): Execute a shell command to notify of a failed release
|
||||
- `verifyConditions`: Execute a shell command to verify if the release should happen
|
||||
- `analyzeCommits`: Execute a shell command to determine the type of release
|
||||
- `verifyRelease`: Execute a shell command to verifying a release that was determined before and is about to be published
|
||||
- `generateNotes`: Execute a shell command to generate the release note
|
||||
- `prepare`: Execute a shell command to prepare the release
|
||||
- `publish`: Execute a shell command to publish the release
|
||||
- `success`: Execute a shell command to notify of a new release
|
||||
- `fail`: Execute a shell command to notify of a failed release
|
||||
- [@semantic-release/apm](https://github.com/semantic-release/apm)
|
||||
- `verifyConditions`: Verify the presence of the `ATOM_ACCESS_TOKEN` environment variable and the [`apm`](https://github.com/atom/apm) CLI
|
||||
- `prepare`: Update the `package.json` version with [`npm version`](https://docs.npmjs.com/cli/version)
|
||||
- `publish`: Publish the [Atom package](https://flight-manual.atom.io/hacking-atom/sections/publishing)
|
||||
|
||||
## Community plugins
|
||||
|
||||
[Open a Pull Request](https://github.com/semantic-release/semantic-release/blob/caribou/CONTRIBUTING.md#submitting-a-pull-request) to add your plugin to the list.
|
||||
[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-docker](https://github.com/felixfbecker/semantic-release-docker) Set of semantic-release plugins for publishing a docker image to Docker Hub
|
||||
- [verifyConditions](https://github.com/felixfbecker/semantic-release-docker#verifyconditions) Verify that all needed configuration is present and login to the Docker registry.
|
||||
- [publish](https://github.com/felixfbecker/semantic-release-docker#publish) Tag the image specified by `name` with the new version, push it to Docker Hub and update the latest tag.
|
||||
- [semantic-release-gcr](https://github.com/carlos-cubas/semantic-release-gcr) Set of semantic-release plugins for publishing a docker image to Google Container Registry
|
||||
- [verifyConditions](https://github.com/carlos-cubas/semantic-release-gcr#verifyconditions) Verify that all needed configuration is present and login to the Docker registry.
|
||||
- [publish](https://github.com/carlos-cubas/semantic-release-gcr#publish) Tag the image specified by `name` with the new version, push it to Docker Hub and update the latest tag.
|
||||
- [semantic-release-vsce](https://github.com/raix/semantic-release-vsce) Set of semantic-release plugins for publishing Visual Studio Code extensions to the marketplace
|
||||
- **verifyConditions** Verify the presence and the validity of the vsce authentication and release configuration
|
||||
- **prepare** Create a `.vsix` for distribution
|
||||
- **publish** Publish the package to the Visual Studio Code marketplace
|
||||
- [semantic-release-verify-deps](https://github.com/piercus/semantic-release-verify-deps)
|
||||
- [verifyConditions](https://github.com/piercus/semantic-release-verify-deps) Check the dependencies format against a regexp before a release
|
||||
- [semantic-release-chrome](https://github.com/GabrielDuarteM/semantic-release-chrome) Set of semantic-release plugins for publishing a Chrome extension release.
|
||||
- [verifyConditions](https://github.com/GabrielDuarteM/semantic-release-chrome#verifyconditions) Verify the presence of the authentication (set via environment variables).
|
||||
- [prepare](https://github.com/GabrielDuarteM/semantic-release-chrome#prepare) Write the correct version to the manifest.json and creates a zip file of the whole dist folder.
|
||||
- [publish](https://github.com/GabrielDuarteM/semantic-release-chrome#publish) Uploads the generated zip file to the webstore, and publish the item.
|
||||
- [semantic-release-firefox](https://github.com/felixfbecker/semantic-release-firefox) Set of semantic-release plugins for publishing a Firefox extension release.
|
||||
- [verifyConditions](https://github.com/felixfbecker/semantic-release-firefox#verifyconditions) Verify the presence of the authentication (set via environment variables).
|
||||
- [prepare](https://github.com/felixfbecker/semantic-release-firefox#prepare) Write the correct version to the manifest.json, creates a xpi file of the dist folder and a zip of the sources.
|
||||
- [publish](https://github.com/felixfbecker/semantic-release-firefox#publish) Submit the generated archives to the webstore for review, and publish the item including release notes.
|
||||
- [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
|
||||
- [semantic-release-gcr](https://github.com/carlos-cubas/semantic-release-gcr)
|
||||
- `verifyConditions`: Verify that all needed configuration is present and login to the Docker registry
|
||||
- `publish`: Tag the image specified by `name` with the new version, push it to Docker Hub and update the latest tag
|
||||
- [semantic-release-vsce](https://github.com/raix/semantic-release-vsce)
|
||||
- `verifyConditions`: Verify the presence and the validity of the vsce authentication and release configuration
|
||||
- `prepare`: Create a `.vsix` for distribution
|
||||
- `publish`: Publish the package to the Visual Studio Code marketplace
|
||||
- [semantic-release-verify-deps](https://github.com/piercus/semantic-release-verify-deps)
|
||||
- `verifyConditions`: Check the dependencies format against a regexp before a release
|
||||
- [semantic-release-chrome](https://github.com/GabrielDuarteM/semantic-release-chrome)
|
||||
- `verifyConditions`: Verify the presence of the authentication (set via environment variables)
|
||||
- `prepare`: Write the correct version to the `manifest.json` and creates a zip file of the whole dist folder
|
||||
- `publish`: Uploads the generated zip file to the webstore, and publish the item
|
||||
- [semantic-release-firefox](https://github.com/felixfbecker/semantic-release-firefox)
|
||||
- `verifyConditions`: Verify the presence of the authentication (set via environment variables)
|
||||
- `prepare`: Write the correct version to the `manifest.json`, creates a `xpi` file of the dist folder and a zip of the sources
|
||||
- `publish`: Submit the generated archives to the webstore for review, and publish the item including release notes
|
||||
- [semantic-release-gerrit](https://github.com/pascalMN/semantic-release-gerrit)
|
||||
- `generateNotes`: Generate release notes with Gerrit reviews URL
|
||||
- [semantic-release-expo](https://github.com/bycedric/semantic-release-expo)
|
||||
- `verifyConditions`: Verify Expo manifest(s) are readable and valid.
|
||||
- `prepare`: Update version, ios build number and android version code in the Expo manifest(s).
|
||||
- [maven-semantic-release](https://github.com/conveyal/maven-semantic-release)
|
||||
- `verifyConditions`: Verifies that the `pom.xml` file and other files exist and are setup to allow releases
|
||||
- `verifyRelease`: Checks and warns (does not error by default) if the version numbers found on maven central and within the Git project differ by quite a bit
|
||||
- `prepare`: Changes the version number in the `pom.xml` (or all `pom.xml` files in maven projects with multiple `pom.xml` files) 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.
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
## CI configurations
|
||||
- [CircleCI 2.0 workflows](circleci-workflows.md)
|
||||
- [Travis CI](travis.md)
|
||||
- [Travis CI with build stages](travis-build-stages.md)
|
||||
- [GitLab CI](gitlab-ci.md)
|
||||
|
||||
## Git hosted services
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
The [Authentication](../usage/ci-configuration.md#authentication) environment variables can be configured in [CircleCi Project Settings](https://circleci.com/docs/2.0/env-vars/#adding-environment-variables-in-the-app)..
|
||||
|
||||
Alternatively, the default `NPM_TOKEN` and `GH_TOKEN` can be easily [setup with semantic-release-cli](../usage/ci-configuration.md#automatic-setup-with-semantic-release-cli).
|
||||
Alternatively, the default `NPM_TOKEN` and `GH_TOKEN` can be easily [setup with semantic-release-cli](../usage/getting-started.md#getting-started).
|
||||
|
||||
## Multiple Node jobs configuration
|
||||
|
||||
|
||||
@@ -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
|
||||
```
|
||||
|
||||
@@ -1,95 +0,0 @@
|
||||
# Using semantic-release with [Travis CI build stages](https://docs.travis-ci.com/user/build-stages)
|
||||
|
||||
## Environment variables
|
||||
|
||||
The [Authentication](../usage/ci-configuration.md#authentication) environment variables can be configured in [Travis Repository Settings](https://docs.travis-ci.com/user/environment-variables/#defining-variables-in-repository-Settings) or with the [travis env set CLI](https://github.com/travis-ci/travis.rb#env).
|
||||
|
||||
Alternatively, the default `NPM_TOKEN` and `GH_TOKEN` can be easily [setup with semantic-release-cli](../usage/ci-configuration.md#automatic-setup-with-semantic-release-cli).
|
||||
|
||||
## Multiple Node jobs configuration
|
||||
|
||||
### `.travis.yml` configuration for multiple Node jobs
|
||||
|
||||
This example is a minimal configuration for **semantic-release** with a build running Node 6 and 8. See [Travis - Customizing the Build](https://docs.travis-ci.com/user/customizing-the-build) for additional configuration options.
|
||||
|
||||
This example creates a `release` [build stage](https://docs.travis-ci.com/user/build-stages) that [runs `semantic-release` only after all test jobs are successful](../usage/ci-configuration.md#run-semantic-release-only-after-all-tests-succeeded).
|
||||
|
||||
It's recommended to run the `semantic-release` command in the [Travis `deploy` step](https://docs.travis-ci.com/user/customizing-the-build/#The-Build-Lifecycle) so if an error occurs the build will fail and Travis will send a notification.
|
||||
|
||||
**Note**: It's not recommended to run the `semantic-release` command in the Travis `script` step as each script in this step will be executed regardless of the outcome of the previous one. See [travis-ci/travis-ci#1066](https://github.com/travis-ci/travis-ci/issues/1066).
|
||||
|
||||
**Advanced configuration**: Running the tests in the `script` step of the `release` stage is not necessary as the previous stage(s) already ran them. To increase speed, the `script` step of the `release` stage can be overwritten to skip the tests. Note that other commands such as build or compilation might still be required.
|
||||
|
||||
```yaml
|
||||
language: node_js
|
||||
|
||||
node_js:
|
||||
- 8
|
||||
- 6
|
||||
|
||||
jobs:
|
||||
include:
|
||||
# Define the release stage that runs semantic-release
|
||||
- stage: release
|
||||
node_js: lts/*
|
||||
# Advanced: optionally overwrite your default `script` step to skip the tests
|
||||
# script: skip
|
||||
deploy:
|
||||
provider: script
|
||||
skip_cleanup: true
|
||||
script:
|
||||
- npx semantic-release
|
||||
```
|
||||
|
||||
### `package.json` configuration for multiple Node jobs
|
||||
|
||||
A `package.json` is required only for [local](../usage/installation.md#local-installation) **semantic-release** installation.
|
||||
|
||||
```json
|
||||
{
|
||||
"devDependencies": {
|
||||
"semantic-release": "^15.0.0"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Non-JavaScript projects configuration
|
||||
|
||||
For projects that require to be tested with one or multiple version of a Non-JavaScript [language](https://docs.travis-ci.com/user/languages), optionally on multiple [Operating Systems](https://docs.travis-ci.com/user/multi-os).
|
||||
|
||||
This recipe cover the Travis specifics only. See [Non JavaScript projects recipe](../support/FAQ.md#can-i-use-semantic-release-to-publish-non-javascript-packages) for more information on the **semantic-release** configuration.
|
||||
|
||||
### `.travis.yml` configuration for non-JavaScript projects
|
||||
|
||||
This example is a minimal configuration for **semantic-release** with a build running [Go 1.6 and 1.7](https://docs.travis-ci.com/user/languages/go). See [Travis - Customizing the Build](https://docs.travis-ci.com/user/customizing-the-build) for additional configuration options.
|
||||
|
||||
This example creates a `release` [build stage](https://docs.travis-ci.com/user/build-stages) that [runs `semantic-release` only after all test jobs are successful](../usage/ci-configuration.md#run-semantic-release-only-after-all-tests-succeeded).
|
||||
|
||||
It's recommended to run the `semantic-release` command in the [Travis `deploy` step](https://docs.travis-ci.com/user/customizing-the-build/#The-Build-Lifecycle) so if an error occurs the build will fail and Travis will send a notification.
|
||||
|
||||
**Note**: It's not recommended to run the `semantic-release` command in the Travis `script` step as each script in this step will be executed regardless of the outcome of the previous one. See [travis-ci/travis-ci#1066](https://github.com/travis-ci/travis-ci/issues/1066).
|
||||
|
||||
**Advanced configuration**: Running the tests in the `script` step of the `release` stage is not necessary as the previous stage(s) already ran them. To increase speed, the `script` step of the `release` stage can be overwritten to skip the tests. Note that other commands such as build or compilation might still be required.
|
||||
|
||||
```yaml
|
||||
language: go
|
||||
|
||||
go:
|
||||
- 1.6
|
||||
- 1.7
|
||||
|
||||
jobs:
|
||||
include:
|
||||
# Define the release stage that runs semantic-release
|
||||
- stage: release
|
||||
# Advanced: optionally overwrite your default `script` step to skip the tests
|
||||
# script:
|
||||
# - make
|
||||
deploy:
|
||||
provider: script
|
||||
skip_cleanup: true
|
||||
script:
|
||||
# Use nvm to install and use the Node LTS version (nvm is installed on all Travis images)
|
||||
- nvm install lts/*
|
||||
- npx semantic-release
|
||||
```
|
||||
+38
-72
@@ -4,62 +4,22 @@
|
||||
|
||||
The [Authentication](../usage/ci-configuration.md#authentication) environment variables can be configured in [Travis Repository Settings](https://docs.travis-ci.com/user/environment-variables/#defining-variables-in-repository-Settings) or with the [travis env set CLI](https://github.com/travis-ci/travis.rb#env).
|
||||
|
||||
Alternatively, the default `NPM_TOKEN` and `GH_TOKEN` can be easily [setup with semantic-release-cli](../usage/ci-configuration.md#automatic-setup-with-semantic-release-cli).
|
||||
Alternatively, the default `NPM_TOKEN` and `GH_TOKEN` can be easily [setup with semantic-release-cli](../usage/getting-started.md#getting-started).
|
||||
|
||||
## Single Node job configuration
|
||||
## Node.js projects configuration
|
||||
|
||||
For projects that require to be tested only with a single [Node version](https://docs.travis-ci.com/user/getting-started/#Selecting-a-different-programming-language) on [one Operating System](https://docs.travis-ci.com/user/getting-started/#Selecting-infrastructure-(optional)).
|
||||
|
||||
**Note**: [Node 8 is the minimal version required](../support/FAQ.md#why-does-semantic-release-require-node-version--83).
|
||||
|
||||
### `.travis.yml` configuration for single Node job
|
||||
|
||||
This example is a minimal configuration for semantic-release with a build running Node 8 on Linux. See [Travis - Customizing the Build](https://docs.travis-ci.com/user/customizing-the-build) for additional configuration options.
|
||||
|
||||
It's recommended to run the `semantic-release` command in the [Travis `deploy` step](https://docs.travis-ci.com/user/customizing-the-build/#The-Build-Lifecycle) so if an error occurs the build will fail and Travis will send a notification.
|
||||
|
||||
**Note**: It's not recommended to run the `semantic-release` command in the Travis `script` step as each script in this step will be executed regardless of the outcome of the previous one. See [travis-ci/travis-ci#1066](https://github.com/travis-ci/travis-ci/issues/1066).
|
||||
|
||||
```yaml
|
||||
language: node_js
|
||||
|
||||
node_js: 8
|
||||
|
||||
deploy:
|
||||
provider: script
|
||||
skip_cleanup: true
|
||||
script:
|
||||
- npx semantic-release
|
||||
```
|
||||
|
||||
### `package.json` configuration for single Node job
|
||||
|
||||
A `package.json` is required only for [local](../usage/installation.md#local-installation) **semantic-release** installation.
|
||||
|
||||
```json
|
||||
{
|
||||
"devDependencies": {
|
||||
"semantic-release": "^11.0.0"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Multiple Node jobs configuration
|
||||
|
||||
For projects that require to be tested with multiple [Node versions](https://docs.travis-ci.com/user/languages/javascript-with-nodejs/#Specifying-Node.js-versions) and/or on multiple [Operating Systems](https://docs.travis-ci.com/user/multi-os).
|
||||
|
||||
**Note**: At least one job must run a [Node >= 8 version](../support/FAQ.md#why-does-semantic-release-require-node-version--83).
|
||||
|
||||
### `.travis.yml` configuration for multiple Node jobs
|
||||
### `.travis.yml` configuration for multiple Node.js jobs
|
||||
|
||||
This example is a minimal configuration for **semantic-release** with a build running Node 6 and 8. See [Travis - Customizing the Build](https://docs.travis-ci.com/user/customizing-the-build) for additional configuration options.
|
||||
|
||||
This example uses [`travis-deploy-once`](https://github.com/semantic-release/travis-deploy-once) in order to [Run `semantic-release` only after all tests succeeded](../usage/ci-configuration.md#run-semantic-release-only-after-all-tests-succeeded). Alternatively you can use [Travis CI Build Stages recipe](travis-build-stages.md).
|
||||
This example creates a `release` [build stage](https://docs.travis-ci.com/user/build-stages) that [runs `semantic-release` only after all test jobs are successful](../usage/ci-configuration.md#run-semantic-release-only-after-all-tests-succeeded).
|
||||
|
||||
It's recommended to run the `semantic-release` command in the [Travis `deploy` step](https://docs.travis-ci.com/user/customizing-the-build/#The-Build-Lifecycle) so if an error occurs the build will fail and Travis will send a notification.
|
||||
|
||||
**Note**: It's not recommended to run the `semantic-release` command in the Travis `script` step as each script in this step will be executed regardless of the outcome of the previous one. See [travis-ci/travis-ci#1066](https://github.com/travis-ci/travis-ci/issues/1066).
|
||||
|
||||
**Advanced configuration**: Running the tests in the `script` step of the `release` stage is not necessary as the previous stage(s) already ran them. To increase speed, the `script` step of the `release` stage can be overwritten to skip the tests. Note that other commands such as build or compilation might still be required.
|
||||
|
||||
```yaml
|
||||
language: node_js
|
||||
|
||||
@@ -67,15 +27,20 @@ node_js:
|
||||
- 8
|
||||
- 6
|
||||
|
||||
deploy:
|
||||
provider: script
|
||||
skip_cleanup: true
|
||||
script:
|
||||
- npx travis-deploy-once "npx semantic-release"
|
||||
jobs:
|
||||
include:
|
||||
# Define the release stage that runs semantic-release
|
||||
- stage: release
|
||||
node_js: lts/*
|
||||
# Advanced: optionally overwrite your default `script` step to skip the tests
|
||||
# script: skip
|
||||
deploy:
|
||||
provider: script
|
||||
skip_cleanup: true
|
||||
script:
|
||||
- npx semantic-release
|
||||
```
|
||||
|
||||
**Note**: See the `travis-deploy-once` [`pro`](https://github.com/semantic-release/travis-deploy-once#-p---pro) and [`travis-url`](https://github.com/semantic-release/travis-deploy-once#-u---travis-url) options for using with [Travis Pro](https://docs.travis-ci.com/user/travis-pro) and [Travis Enterprise](https://enterprise.travis-ci.com).
|
||||
|
||||
### `package.json` configuration for multiple Node jobs
|
||||
|
||||
A `package.json` is required only for [local](../usage/installation.md#local-installation) **semantic-release** installation.
|
||||
@@ -83,13 +48,12 @@ A `package.json` is required only for [local](../usage/installation.md#local-ins
|
||||
```json
|
||||
{
|
||||
"devDependencies": {
|
||||
"semantic-release": "^15.0.0",
|
||||
"travis-deploy-once": "^5.0.0"
|
||||
"semantic-release": "^15.0.0"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Non-JavaScript projects configuration
|
||||
## Non-Node.js projects configuration
|
||||
|
||||
For projects that require to be tested with one or multiple version of a Non-JavaScript [language](https://docs.travis-ci.com/user/languages), optionally on multiple [Operating Systems](https://docs.travis-ci.com/user/multi-os).
|
||||
|
||||
@@ -97,14 +61,16 @@ This recipe cover the Travis specifics only. See [Non JavaScript projects recipe
|
||||
|
||||
### `.travis.yml` configuration for non-JavaScript projects
|
||||
|
||||
This example is a minimal configuration for **semantic-release** with a build running [Go 1.6 and 1.7](https://docs.travis-ci.com/user/languages/go) on Linux and OSX. See [Travis - Customizing the Build](https://docs.travis-ci.com/user/customizing-the-build) for additional configuration options.
|
||||
This example is a minimal configuration for **semantic-release** with a build running [Go 1.6 and 1.7](https://docs.travis-ci.com/user/languages/go). See [Travis - Customizing the Build](https://docs.travis-ci.com/user/customizing-the-build) for additional configuration options.
|
||||
|
||||
This example uses [`travis-deploy-once`](https://github.com/semantic-release/travis-deploy-once) in order to [run `semantic-release` only after all tests succeeded](../usage/ci-configuration.md#run-semantic-release-only-after-all-tests-succeeded). Alternatively you can use [Travis CI Build Stages recipe](travis-build-stages.md).
|
||||
This example creates a `release` [build stage](https://docs.travis-ci.com/user/build-stages) that [runs `semantic-release` only after all test jobs are successful](../usage/ci-configuration.md#run-semantic-release-only-after-all-tests-succeeded).
|
||||
|
||||
It's recommended to run the `semantic-release` command in the [Travis `deploy` step](https://docs.travis-ci.com/user/customizing-the-build/#The-Build-Lifecycle) so if an error occurs the build will fail and Travis will send a notification.
|
||||
|
||||
**Note**: It's not recommended to run the `semantic-release` command in the Travis `script` step as each script in this step will be executed regardless of the outcome of the previous one. See [travis-ci/travis-ci#1066](https://github.com/travis-ci/travis-ci/issues/1066).
|
||||
|
||||
**Advanced configuration**: Running the tests in the `script` step of the `release` stage is not necessary as the previous stage(s) already ran them. To increase speed, the `script` step of the `release` stage can be overwritten to skip the tests. Note that other commands such as build or compilation might still be required.
|
||||
|
||||
```yaml
|
||||
language: go
|
||||
|
||||
@@ -112,18 +78,18 @@ go:
|
||||
- 1.6
|
||||
- 1.7
|
||||
|
||||
os:
|
||||
- linux
|
||||
- osx
|
||||
|
||||
deploy:
|
||||
provider: script
|
||||
skip_cleanup: true
|
||||
script:
|
||||
# Use nvm to install and use the Node LTS version (nvm is installed on all Travis images)
|
||||
- nvm install lts/*
|
||||
# Run semantic-release only on one job, after all other are successful
|
||||
- npx travis-deploy-once "npx semantic-release"
|
||||
jobs:
|
||||
include:
|
||||
# Define the release stage that runs semantic-release
|
||||
- stage: release
|
||||
# Advanced: optionally overwrite your default `script` step to skip the tests
|
||||
# script:
|
||||
# - make
|
||||
deploy:
|
||||
provider: script
|
||||
skip_cleanup: true
|
||||
script:
|
||||
# Use nvm to install and use the Node LTS version (nvm is installed on all Travis images)
|
||||
- nvm install lts/*
|
||||
- npx semantic-release
|
||||
```
|
||||
|
||||
**Note**: See the `travis-deploy-once` [`pro`](https://github.com/semantic-release/travis-deploy-once#-p---pro) and [`travis-url`](https://github.com/semantic-release/travis-deploy-once#-u---travis-url) options for using with [Travis Pro](https://docs.travis-ci.com/user/travis-pro) and [Travis Enterprise](https://enterprise.travis-ci.com).
|
||||
|
||||
+33
-20
@@ -12,7 +12,25 @@ However, the [`@semantic-release/git`](https://github.com/semantic-release/git)
|
||||
|
||||
The `package.json`’s version will be updated by the `semantic-release` command just before publishing to [npm](https://www.npmjs.com), therefore it won't be available for scripts ran before the `semantic-release` command.
|
||||
|
||||
As semantic-release uses the [npm CLI](https://docs.npmjs.com/cli/npm) to publish, all [npm hook scripts](https://docs.npmjs.com/misc/scripts#hook-scripts) will be executed. Therefore you can run your build script in the [`prepublishOnly`](https://docs.npmjs.com/misc/scripts#prepublish-and-prepare) hook. It will be executed after the `semantic-release` command update the `package.json`’s version and before publishing.
|
||||
As the [`@semantic-release/npm`](https://github.com/semantic-release/npm) plugin uses the [npm CLI](https://docs.npmjs.com/cli/npm) to update the `package.json` version and publish the package, all [npm hook scripts](https://docs.npmjs.com/misc/scripts#description) will be executed.
|
||||
|
||||
You can run your build script in:
|
||||
- the `prepublishOnly` or `prepack` hook so it will be executed during the `publish` step of `@semantic-release/npm`
|
||||
- the `postversion` hook so it will be executed during the `prepare` step of `@semantic-release/npm`, which allow for example to update files before committing them with the [`@semantic-release/git`](https://github.com/semantic-release/git) plugin
|
||||
|
||||
If using npm hook scripts is not possible, and alternative solution is to [`@semantic-release/exec`](https://github.com/semantic-release/exec) plugin to run your script in the `prepare` step:
|
||||
```json
|
||||
{
|
||||
"plugins": [
|
||||
"@semantic-release/commit-analyzer",
|
||||
"@semantic-release/release-notes-generator",
|
||||
"@semantic-release/npm",
|
||||
["@semantic-release/exec", {
|
||||
"prepareCmd": "./my-build-script.sh ${nextRelease.version}",
|
||||
}],
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
## Is there a way to preview which version would currently get published?
|
||||
|
||||
@@ -59,28 +77,23 @@ To publish a non-Node package (without a `package.json`) you would need to:
|
||||
|
||||
See the [CI configuration recipes](../recipes/README.md#ci-configurations) for more details on specific CI environments.
|
||||
|
||||
In addition you will need to configure the **semantic-release** [plugins](../usage/plugins.md#plugins) to:
|
||||
- Disable the [`@semantic-release/npm`](https://github.com/semantic-release/npm) plugin
|
||||
- Define plugins for the [verifyConditions](../usage/plugins.md#verifyconditions-plugin), [prepare](../usage/plugins.md#prepare-plugin) and [publish](../usage/plugins.md#publish-plugin) steps to release on your package registry. The [`@semantic-release/exec`](https://github.com/semantic-release/exec) plugin is recommended for situation where a release can be done with a shell command.
|
||||
In addition you will need to configure the **semantic-release** [plugins](../usage/plugins.md#plugins) to disable the [`@semantic-release/npm`](https://github.com/semantic-release/npm) plugin which is used by default and use a plugin for your project type.
|
||||
|
||||
Here is a basic example to create [GitHub releases](https://help.github.com/articles/about-releases) and use shell command to publish:
|
||||
If there is no specific plugin for your project type you can use the [`@semantic-release/exec`](https://github.com/semantic-release/exec) plugin to publish the release with a shell command.
|
||||
|
||||
Here is a basic example to create [GitHub releases](https://help.github.com/articles/about-releases) and use a shell command to publish:
|
||||
|
||||
```json
|
||||
{
|
||||
"verifyConditions": ["@semantic-release/github"],
|
||||
"prepare": [
|
||||
{
|
||||
"path": "@semantic-release/exec",
|
||||
"cmd": "set-version ${nextRelease.version}"
|
||||
}
|
||||
],
|
||||
"publish": [
|
||||
"plugins": [
|
||||
"@semantic-release/commit-analyzer",
|
||||
"@semantic-release/release-notes-generator",
|
||||
"@semantic-release/github",
|
||||
{
|
||||
"path": "@semantic-release/exec",
|
||||
"cmd": "publish-package"
|
||||
}
|
||||
],
|
||||
["@semantic-release/exec", {
|
||||
"prepareCmd" : "set-version ${nextRelease.version}",
|
||||
"publishCmd" : "publish-package"
|
||||
}]
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
@@ -114,7 +127,7 @@ See the [GitLab CI recipes](../recipes/gitlab-ci.md#using-semantic-release-with-
|
||||
|
||||
## Can I use semantic-release with any Git hosted environment?
|
||||
|
||||
By default **semantic-release** uses the [`@semantic-release/github`](https://github.com/semantic-release/github) plugin to publish a [GitHub release](https://help.github.com/articles/about-releases). For other Git hosted environment the [`@semantic-release/git`](https://github.com/semantic-release/git) and [`@semantic-release/changelog`](https://github.com/semantic-release/changelog) plugins can be used via [plugins configuration](../usage/plugins.md#configuration).
|
||||
By default **semantic-release** uses the [`@semantic-release/github`](https://github.com/semantic-release/github) plugin to publish a [GitHub release](https://help.github.com/articles/about-releases). For other Git hosted environment the [`@semantic-release/git`](https://github.com/semantic-release/git) and [`@semantic-release/changelog`](https://github.com/semantic-release/changelog) plugins can be used via [plugins configuration](../usage/plugins.md).
|
||||
|
||||
See the [`@semantic-release/git`](https://github.com/semantic-release/git#semantic-releasegit) [`@semantic-release/changelog`](https://github.com/semantic-release/changelog#semantic-releasechangelog) plugins documentation for more details.
|
||||
|
||||
@@ -132,7 +145,7 @@ If you have introduced a breaking bug in a release you have 2 options:
|
||||
|
||||
In both cases **semantic-release** will publish a new release, so your package users' will get the fixed/reverted version.
|
||||
|
||||
Depending on the package manager you are using, you might be able to un-publish or deprecate a release, in order to prevent users to download it by accident. For example npm allows you to [un-publish](https://docs.npmjs.com/cli/unpublish) in [next 72 hours](https://www.npmjs.com/policies/unpublish) after releasing or to [deprecate](https://docs.npmjs.com/cli/deprecate) a release.
|
||||
Depending on the package manager you are using, you might be able to un-publish or deprecate a release, in order to prevent users from downloading it by accident. For example npm allows you to [un-publish](https://docs.npmjs.com/cli/unpublish) [within 72 hours](https://www.npmjs.com/policies/unpublish) after releasing. You may also [deprecate](https://docs.npmjs.com/cli/deprecate) a release if you would rather avoid un-publishing.
|
||||
|
||||
In any case **do not remove the Git tag associated with the buggy version**, otherwise **semantic-release** will later try to republish that version. Publishing a version after un-publishing is not supported by most package managers.
|
||||
|
||||
|
||||
@@ -4,17 +4,17 @@
|
||||
|
||||
- ["Introducing Reliable Dependency and Release Management for npm Packages" - Gregor Martynus](https://www.youtube.com/watch?v=R2RJWLcfzwc)
|
||||
- ["Kill all humans" - Jan Lehnardt](https://www.youtube.com/watch?v=ZXyx_1kN1L8&t=2s)
|
||||
- [Publishing JavaScript Packages" - JavaScript Air](https://javascriptair.com/episodes/2016-07-20)
|
||||
- ["Publishing JavaScript Packages" - JavaScript Air](https://javascriptair.com/episodes/2016-07-20)
|
||||
- ["Managing Dependencies like a boss 😎" - JavaScript Air](https://javascriptair.com/episodes/2016-08-17)
|
||||
- ["Dependency Hell Just Froze Over" - Stephan Bönnemann](https://www.youtube.com/watch?v=PA139CERNbc)
|
||||
- [“semantic-release Q&A with Kent C. Dodds”](https://www.youtube.com/watch?v=g6y3DnhkjrI)
|
||||
- [“We fail to follow SemVer – and why it needn’t matter” - Stephan Bönnemann](https://www.youtube.com/watch?v=tc2UgG5L7WM)
|
||||
- ["semantic-release Q&A with Kent C. Dodds"](https://www.youtube.com/watch?v=g6y3DnhkjrI)
|
||||
- ["We fail to follow SemVer – and why it needn’t matter" - Stephan Bönnemann](https://www.youtube.com/watch?v=tc2UgG5L7WM)
|
||||
|
||||
## Articles
|
||||
|
||||
- [“Introduction to SemVer” - Irina Gebauer](https://blog.greenkeeper.io/introduction-to-semver-d272990c44f2)
|
||||
- ["Introduction to SemVer" - Irina Gebauer](https://blog.greenkeeper.io/introduction-to-semver-d272990c44f2)
|
||||
- ["Introduction to Semantic Release" - liv](https://blog.greenkeeper.io/introduction-to-semantic-release-33f73b117c8)
|
||||
|
||||
## Tutorials
|
||||
|
||||
- [“How to Write a JavaScript Library - Automating Releases with semantic-release” – egghead.io](https://egghead.io/lessons/javascript-automating-releases-with-semantic-release)
|
||||
- ["How to Write a JavaScript Library - Automating Releases with semantic-release" – egghead.io](https://egghead.io/lessons/javascript-automating-releases-with-semantic-release)
|
||||
|
||||
@@ -1,49 +1,26 @@
|
||||
# Troubleshooting
|
||||
|
||||
## ENOTINHISTORY Commit not in history
|
||||
|
||||
This error happens when the commit associated with the last release cannot be found in the branch history.
|
||||
|
||||
Multiple situation can cause this issue:
|
||||
- The package name configured in your `package.json` already exists and **semantic-release** obtains the last release of that package, which is unrelated to yours
|
||||
- The commit history has been rewritten since the last release (with `git rebase` and `git push -f`)
|
||||
|
||||
If the package name configured in your `package.json` already exits, you should change it, and commit the `package.json`. Then **semantic-release** will proceed normally and make the initial release.
|
||||
|
||||
If you can identify the commit in your branch history that should be associated with the release version mentioned in the error message you can recover by tagging this commit:
|
||||
|
||||
```bash
|
||||
$ git tag -f v<version of the last release> <commit sha1 corresponding to last release>
|
||||
$ git push -f --tags origin <your release branch>
|
||||
```
|
||||
|
||||
## ENOGITHEAD There is no commit associated with last release
|
||||
|
||||
This error happens when there is no commit associated with the last release that can be found in the package metadata on the npm registry.
|
||||
|
||||
This usually happen when the last release has been made without access to the git repository informations.
|
||||
|
||||
You can recover from that issue by identifying the commit in your branch history that should have been associated with the release version mentioned in the error message and tagging this commit:
|
||||
|
||||
```bash
|
||||
$ git tag -f v<version of the last release> <commit sha1 corresponding to last release>
|
||||
$ git push -f --tags origin <your release branch>
|
||||
```
|
||||
|
||||
## You do not have permission to publish 'package-name'
|
||||
|
||||
When running semantic-release you may encounter the following error:
|
||||
When running semantic-release you might encounter the following error:
|
||||
|
||||
```
|
||||
An error occurred while running semantic-release: { Error: Command failed: npm publish ./. --registry https://registry.npmjs.org/
|
||||
```bash
|
||||
npm ERR! publish Failed PUT 403
|
||||
npm ERR! code E403
|
||||
npm ERR! You do not have permission to publish "<package-name>". Are you logged in as the correct user? : <package-name>
|
||||
```
|
||||
|
||||
This message is a little unclear, and might not have anything to with your `NPM_TOKEN` or authentication method. It might instead be related to the package name itself. If there is already a package with the same name as yours or, there is a very close match, it could trigger this error.
|
||||
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.
|
||||
|
||||
Best way to be sure, is to search [npmjs.org](https://www.npmjs.com/)) using your package name. If there is a name conflict, rename your package in your `package.json`
|
||||
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
|
||||
$ npm install --global npm-name-cli
|
||||
$ npm-name <package-name>
|
||||
```
|
||||
|
||||
If the package name is not available, change it in your `package.json` or consider using an [npm scope](https://docs.npmjs.com/misc/scope).
|
||||
|
||||
## Squashed commits are ignored by **semantic-release**
|
||||
|
||||
@@ -54,3 +31,26 @@ When [squashing commits](https://git-scm.com/book/en/v2/Git-Tools-Rewriting-Hist
|
||||
When squashing commits make sure to rewrite the resulting commit message to be compliant with the project's commit message convention.
|
||||
|
||||
**Note**: if the resulting squashed commit would encompasses multiple changes (for example multiple unrelated features or fixes) then it's probably not a good idea to squash those commits together. A commit should contain exactly one self-contained functional change and a functional change should be contained in exactly one commit. See [atomic commits](https://en.wikipedia.org/wiki/Atomic_commit).
|
||||
|
||||
## `reference already exists` error when pushing tag
|
||||
|
||||
**semantic-release** read [Git tags](https://git-scm.com/book/en/v2/Git-Basics-Tagging) that are present in the history of your release branch in order to determine the last release published. Then it determines the next version to release based on the commits pushed since then and create the corresponding tag.
|
||||
If a tag with the name already in your repository, Git will throw and error as tags must be unique across the repository.
|
||||
This situation happens when you have a version tag identical to the new one **semantic-release** is trying to create that is not in the history of the current branch.
|
||||
|
||||
If an actual release with that version number was published you need to merge all the commits up to that release into your release branch.
|
||||
|
||||
If there is no published release with that version number, the tag must be deleted.
|
||||
|
||||
```bash
|
||||
# Verify if the commit exists in the repository
|
||||
$ git rev-list -1 <tag name>
|
||||
# If a commit sha is returned, then the tag exists
|
||||
|
||||
# Verify the branches having the tagged commit in their history
|
||||
$ git branch --contains <tag name>
|
||||
|
||||
# Delete the tag
|
||||
$ git tag -d <tag name>
|
||||
$ git push origin :refs/tags/<tag name>
|
||||
```
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
# Usage
|
||||
|
||||
- [Getting started](getting-started.md#getting-started)
|
||||
- [Installation](installation.md#installation)
|
||||
- [CI Configuration](ci-configuration.md#ci-configuration)
|
||||
- [Configuration](configuration.md#configuration)
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
## Run `semantic-release` only after all tests succeeded
|
||||
|
||||
The `semantic-release` command must be executed only after all the tests in the CI build pass. If the build runs multiple jobs (for example to test on multiple Operating Systems or Node versions) the CI has to be configured to guarantee that the `semantic-release` command is executed only after all jobs are successful. This can be achieved with [Travis Build Stages](https://docs.travis-ci.com/user/build-stages), [CircleCI Workflows](https://circleci.com/docs/2.0/workflows), [Codeship Deployment Pipelines](https://documentation.codeship.com/basic/builds-and-configuration/deployment-pipelines), [GitLab Pipelines](https://docs.gitlab.com/ee/ci/pipelines.html#introduction-to-pipelines-and-jobs), [Wercker Workflows](http://devcenter.wercker.com/docs/workflows), [GoCD Pipelines](https://docs.gocd.org/current/introduction/concepts_in_go.html#pipeline) or specific tools like [`travis-deploy-once`](https://github.com/semantic-release/travis-deploy-once).
|
||||
The `semantic-release` command must be executed only after all the tests in the CI build pass. If the build runs multiple jobs (for example to test on multiple Operating Systems or Node versions) the CI has to be configured to guarantee that the `semantic-release` command is executed only after all jobs are successful. This can be achieved with [Travis Build Stages](https://docs.travis-ci.com/user/build-stages), [CircleCI Workflows](https://circleci.com/docs/2.0/workflows), [Codeship Deployment Pipelines](https://documentation.codeship.com/basic/builds-and-configuration/deployment-pipelines), [GitLab Pipelines](https://docs.gitlab.com/ee/ci/pipelines.html#introduction-to-pipelines-and-jobs), [Codefresh Pipelines](https://codefresh.io/docs/docs/configure-ci-cd-pipeline/introduction-to-codefresh-pipelines), [Wercker Workflows](http://devcenter.wercker.com/docs/workflows) or [GoCD Pipelines](https://docs.gocd.org/current/introduction/concepts_in_go.html#pipeline).
|
||||
|
||||
See [CI configuration recipes](../recipes/README.md#ci-configurations) for more details.
|
||||
|
||||
@@ -26,23 +26,8 @@ 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.
|
||||
|
||||
## Automatic setup with `semantic-release-cli`
|
||||
|
||||
[`semantic-release-cli`](https://github.com/semantic-release/cli) allows for easy [installation](installation.md) of **semantic-release** in your Node project as well as setting up the CI configuration:
|
||||
|
||||
```bash
|
||||
npm install -g semantic-release-cli
|
||||
|
||||
cd your-module
|
||||
semantic-release-cli setup
|
||||
```
|
||||
|
||||

|
||||
|
||||
See the [semantic-release-cli](https://github.com/semantic-release/cli#what-it-does) documentation for more details.
|
||||
|
||||
+59
-88
@@ -1,19 +1,25 @@
|
||||
# Configuration
|
||||
|
||||
In order to customize **semantic-release**’s behavior, [options](#options) and [plugins](plugins.md) can be set via:
|
||||
**semantic-release** configuration consists of:
|
||||
- Git repository options ([URL](#repositoryurl), [release branch](#branch) and [tag format](#tagformat))
|
||||
- [plugins](#plugins) definition
|
||||
- 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).
|
||||
|
||||
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:
|
||||
- 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
|
||||
- CLI arguments
|
||||
|
||||
Alternatively, some options can be set via CLI arguments.
|
||||
|
||||
The following three examples are the same.
|
||||
|
||||
Via CLI argument:
|
||||
|
||||
```bash
|
||||
$ semantic-release --branch next
|
||||
```
|
||||
|
||||
Via `release` key in the project's `package.json` file:
|
||||
|
||||
```json
|
||||
@@ -38,21 +44,18 @@ Via `.releaserc` file:
|
||||
$ semantic-release
|
||||
```
|
||||
|
||||
Via CLI argument:
|
||||
|
||||
```bash
|
||||
$ semantic-release --branch next
|
||||
```
|
||||
|
||||
**Note**: CLI arguments take precedence over options configured in the configuration file.
|
||||
|
||||
**Note**: Plugin options cannot be defined via CLI arguments and must be defined in the configuration file.
|
||||
|
||||
**Note**: When configuring via `package.json`, the configuration must be under the `release` property. However, when using a `.releaserc` or a `release.config.js` file, the configuration must be set without a `release` property.
|
||||
|
||||
## Environment variables
|
||||
|
||||
| Variable | Description | Default |
|
||||
|-----------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------|
|
||||
| `GIT_AUTHOR_NAME` | The author name associated with the [Git release tag](https://git-scm.com/book/en/v2/Git-Basics-Tagging). See [Git environment variables](https://git-scm.com/book/en/v2/Git-Internals-Environment-Variables#_committing). | @semantic-release-bot. |
|
||||
| `GIT_AUTHOR_EMAIL` | The author email associated with the [Git release tag](https://git-scm.com/book/en/v2/Git-Basics-Tagging). See [Git environment variables](https://git-scm.com/book/en/v2/Git-Internals-Environment-Variables#_committing). | @semantic-release-bot email address. |
|
||||
| `GIT_COMMITTER_NAME` | The committer name associated with the [Git release tag](https://git-scm.com/book/en/v2/Git-Basics-Tagging). See [Git environment variables](https://git-scm.com/book/en/v2/Git-Internals-Environment-Variables#_committing). | @semantic-release-bot. |
|
||||
| `GIT_COMMITTER_EMAIL` | The committer email associated with the [Git release tag](https://git-scm.com/book/en/v2/Git-Basics-Tagging). See [Git environment variables](https://git-scm.com/book/en/v2/Git-Internals-Environment-Variables#_committing). | @semantic-release-bot email address. |
|
||||
|
||||
## Options
|
||||
|
||||
### extends
|
||||
@@ -92,6 +95,18 @@ The [Git tag](https://git-scm.com/book/en/v2/Git-Basics-Tagging) format used by
|
||||
|
||||
**Note**: The `tagFormat` must contain the `version` variable exactly once and compile to a [valid Git reference](https://git-scm.com/docs/git-check-ref-format#_description).
|
||||
|
||||
### plugins
|
||||
|
||||
Type: `Array`<br>
|
||||
Default: `['@semantic-release/commit-analyzer', '@semantic-release/release-notes-generator', '@semantic-release/npm', '@semantic-release/github']`<br>
|
||||
CLI arguments: `-p`, `--plugins`
|
||||
|
||||
Define the list of plugins to use. Plugins will run in series, in the order defined, for each [steps](../../README.md#release-steps) if they implement it.
|
||||
|
||||
Plugins configuration can defined by wrapping the name and an options object in an array.
|
||||
|
||||
See [Plugins configuration](plugins.md#plugins) for more details.
|
||||
|
||||
### dryRun
|
||||
|
||||
Type: `Boolean`<br>
|
||||
@@ -106,7 +121,7 @@ Type: `Boolean`<br>
|
||||
Default: `true`<br>
|
||||
CLI arguments: `--ci` / `--no-ci`
|
||||
|
||||
Set to `fasle` to skip Continuous Integration environment verifications. This allows for making releases from a local machine.
|
||||
Set to `false` to skip Continuous Integration environment verifications. This allows for making releases from a local machine.
|
||||
|
||||
**Note**: The CLI arguments `--no-ci` is equivalent to `--ci false`.
|
||||
|
||||
@@ -116,84 +131,40 @@ Type: `Boolean`<br>
|
||||
Default: `false`<br>
|
||||
CLI argument: `--debug`
|
||||
|
||||
Output debugging information. It can also be enabled by setting the `DEBUG` environment variable to `semantic-release:*`.
|
||||
Output debugging information. This can also be enabled by setting the `DEBUG` environment variable to `semantic-release:*`.
|
||||
|
||||
### verifyConditions
|
||||
**Note**: The `debug` is used only supported via CLI argument. To enable debug mode from the [JS API](../developer-guide/js-api.md#javascript-api) use `require('debug').enable('semantic-release:*')`.
|
||||
|
||||
Type: `Array`, `String`, `Object`<br>
|
||||
Default: `['@semantic-release/npm', '@semantic-release/github']`<br>
|
||||
CLI argument: `--verify-conditions`
|
||||
## Git environment variables
|
||||
|
||||
Define the list of [verify conditions plugins](plugins.md#verifyconditions-plugin). Plugins will run in series, in the order defined in the `Array`.
|
||||
| Variable | Description | Default |
|
||||
|-----------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------|
|
||||
| `GIT_AUTHOR_NAME` | The author name associated with the [Git release tag](https://git-scm.com/book/en/v2/Git-Basics-Tagging). See [Git environment variables](https://git-scm.com/book/en/v2/Git-Internals-Environment-Variables#_committing). | @semantic-release-bot. |
|
||||
| `GIT_AUTHOR_EMAIL` | The author email associated with the [Git release tag](https://git-scm.com/book/en/v2/Git-Basics-Tagging). See [Git environment variables](https://git-scm.com/book/en/v2/Git-Internals-Environment-Variables#_committing). | @semantic-release-bot email address. |
|
||||
| `GIT_COMMITTER_NAME` | The committer name associated with the [Git release tag](https://git-scm.com/book/en/v2/Git-Basics-Tagging). See [Git environment variables](https://git-scm.com/book/en/v2/Git-Internals-Environment-Variables#_committing). | @semantic-release-bot. |
|
||||
| `GIT_COMMITTER_EMAIL` | The committer email associated with the [Git release tag](https://git-scm.com/book/en/v2/Git-Basics-Tagging). See [Git environment variables](https://git-scm.com/book/en/v2/Git-Internals-Environment-Variables#_committing). | @semantic-release-bot email address. |
|
||||
|
||||
See [Plugins configuration](plugins.md#configuration) for more details.
|
||||
## Existing version tags
|
||||
|
||||
### analyzeCommits
|
||||
**semantic-release** uses [Git tags](https://git-scm.com/book/en/v2/Git-Basics-Tagging) to determine the commits added since the last release. If a release has been published before setting up **semantic-release** you must make sure the most recent commit included in the last published release is in the [release branch](#branch) history and is tagged with the version released, formatted according to the [tag format](#tagformat) configured (defaults to `vx.y.z`).
|
||||
|
||||
Type: `String`, `Object`<br>
|
||||
Default: `'@semantic-release/commit-analyzer'`<br>
|
||||
CLI argument: `--analyze-commits`
|
||||
If the previous releases were published with [`npm publish`](https://docs.npmjs.com/cli/publish) this should already be the case.
|
||||
|
||||
Define the [analyze commits plugin](plugins.md#analyzecommits-plugin).
|
||||
For example, if your release branch is `master`, the last release published on your project is `1.1.0` and the last commit included has the sha `1234567`, you must make sure this commit is in `master` history and is tagged with `v1.1.0`.
|
||||
|
||||
See [Plugins configuration](plugins.md#configuration) for more details.
|
||||
```bash
|
||||
# Make sure the commit 1234567 is in the release branch history
|
||||
$ git branch --contains 1234567
|
||||
|
||||
### verifyRelease
|
||||
# If the commit is not in the branch history it means that either:
|
||||
# - you use a different branch than the one your release from before
|
||||
# - or the commit sha has been rewritten (with git rebase)
|
||||
# In both cases you need to configure your repository to have the last release commit in the history of the release branch
|
||||
|
||||
Type: `Array`, `String`, `Object`<br>
|
||||
Default: `[]`<br>
|
||||
CLI argument: `--verify-release`
|
||||
# List the tags for the commit 1234567
|
||||
$ git tag --contains 1234567
|
||||
|
||||
Define the list of [verify release plugins](plugins.md#verifyrelease-plugin). Plugins will run in series, in the order defined in the `Array`.
|
||||
|
||||
See [Plugins configuration](plugins.md#configuration) for more details.
|
||||
|
||||
### generateNotes
|
||||
|
||||
Type: `Array`, `String`, `Object`<br>
|
||||
Default: `['@semantic-release/release-notes-generator']`<br>
|
||||
CLI argument: `--generate-notes`
|
||||
|
||||
Define the [generate notes plugins](plugins.md#generatenotes-plugin).
|
||||
|
||||
See [Plugins configuration](plugins.md#configuration) for more details.
|
||||
|
||||
### prepare
|
||||
|
||||
Type: `Array`, `String`, `Object`<br>
|
||||
Default: `['@semantic-release/npm']`<br>
|
||||
CLI argument: `--prepare`
|
||||
|
||||
Define the list of [prepare plugins](plugins.md#prepare-plugin). Plugins will run in series, in the order defined in the `Array`.
|
||||
|
||||
See [Plugins configuration](plugins.md#configuration) for more details.
|
||||
|
||||
### publish
|
||||
|
||||
Type: `Array`, `String`, `Object`<br>
|
||||
Default: `['@semantic-release/npm', '@semantic-release/github']`<br>
|
||||
CLI argument: `--publish`
|
||||
|
||||
Define the list of [publish plugins](plugins.md#publish-plugin). Plugins will run in series, in the order defined in the `Array`.
|
||||
|
||||
See [Plugins configuration](plugins.md#configuration) for more details.
|
||||
|
||||
### success
|
||||
|
||||
Type: `Array`, `String`, `Object`<br>
|
||||
Default: `['@semantic-release/github']`<br>
|
||||
CLI argument: `--success`
|
||||
|
||||
Define the list of [success plugins](plugins.md#success-plugin). Plugins will run in series, in the order defined in the `Array`.
|
||||
|
||||
See [Plugins configuration](plugins.md#configuration) for more details.
|
||||
|
||||
### fail
|
||||
|
||||
Type: `Array`, `String`, `Object`<br>
|
||||
Default: `['@semantic-release/github']`<br>
|
||||
CLI argument: `--fail`
|
||||
|
||||
Define the list of [fail plugins](plugins.md#fail-plugin). Plugins will run in series, in the order defined in the `Array`.
|
||||
|
||||
See [Plugins configuration](plugins.md#configuration) for more details.
|
||||
# If v1.1.0 is not in the list you add it with
|
||||
$ git tag v1.1.0 1234567
|
||||
$ git push origin v1.1.0
|
||||
```
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
# Getting started
|
||||
|
||||
In order to use **semantic-release** you must follow these 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)
|
||||
|
||||
Alternatively those steps can be easily done with the [**semantic-release** interactive CLI](https://github.com/semantic-release/cli):
|
||||
|
||||
```bash
|
||||
npm install -g semantic-release-cli
|
||||
|
||||
cd your-module
|
||||
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 are currently supported by `semantic-release-cli`.
|
||||
+73
-96
@@ -1,114 +1,91 @@
|
||||
# Plugins
|
||||
|
||||
Each [release step](../../README.md#release-steps) is implemented within a plugin or a list of plugins that can be configured. This allows for support of different [commit message formats](../../README.md#commit-message-format), release note generators and publishing platforms.
|
||||
Each [release step](../../README.md#release-steps) is implemented by configurable plugins. This allows for support of different [commit message formats](../../README.md#commit-message-format), release note generators and publishing platforms.
|
||||
|
||||
See [plugins list](../extending/plugins-list.md).
|
||||
A plugin is a npm module that can implement one or more of the following steps:
|
||||
|
||||
## Plugin types
|
||||
| Step | Required | Description |
|
||||
|--------------------|----------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||
| `verifyConditions` | No | Responsible for verifying conditions necessary to proceed with the release: configuration is correct, authentication token are valid, etc... |
|
||||
| `analyzeCommits` | Yes | Responsible for determining the type of the next release (`major`, `minor` or `patch`). If multiple plugins with a `analyzeCommits` step are defined, the release type will be the highest one among plugins output. |
|
||||
| `verifyRelease` | No | Responsible for verifying the parameters (version, type, dist-tag etc...) of the release that is about to be published. |
|
||||
| `generateNotes` | No | Responsible for generating the content of the release note. If multiple plugins with a `generateNotes` step are defined, the release notes will be the result of the concatenation of each plugin output. |
|
||||
| `prepare` | No | Responsible for preparing the release, for example creating or updating files such as `package.json`, `CHANGELOG.md`, documentation or compiled assets and pushing a commit. |
|
||||
| `publish` | No | Responsible for publishing the release. |
|
||||
| `success` | No | Responsible for notifying of a new release. |
|
||||
| `fail` | No | Responsible for notifying of a failed release. |
|
||||
|
||||
### verifyConditions plugin
|
||||
**Note:** If no plugin with a `analyzeCommits` step is defined `@semantic-release/commit-analyzer` will be used.
|
||||
|
||||
Responsible for verifying conditions necessary to proceed with the release: configuration is correct, authentication token are valid, etc...
|
||||
## Plugins installation
|
||||
|
||||
Default implementation: [@semantic-release/npm](https://github.com/semantic-release/npm#verifyconditions) and [@semantic-release/github](https://github.com/semantic-release/github#verifyconditions).<br>
|
||||
Optional.<br>
|
||||
Accept multiple plugins.
|
||||
These five plugins are already part of **semantic-release** and don't have to be installed separately:
|
||||
```
|
||||
"@semantic-release/commit-analyzer"
|
||||
"@semantic-release/error"
|
||||
"@semantic-release/github"
|
||||
"@semantic-release/npm"
|
||||
"@semantic-release/release-notes-generator"
|
||||
```
|
||||
|
||||
### analyzeCommits plugin
|
||||
[Additional plugins](../extending/plugins-list.md) have to be installed via npm:
|
||||
|
||||
Responsible for determining the type of the next release (`major`, `minor` or `patch`).
|
||||
```bash
|
||||
$ npm install @semantic-release/git @semantic-release/changelog -D
|
||||
```
|
||||
|
||||
Default implementation: [@semantic-release/commit-analyzer](https://github.com/semantic-release/commit-analyzer).<br>
|
||||
Required.<br>
|
||||
Accept only one plugin.
|
||||
## Plugins configuration
|
||||
|
||||
### verifyRelease plugin
|
||||
Each plugin must be configured with the [`plugins` options](./configuration.md#plugins) by specifying the list of plugins by npm module name.
|
||||
|
||||
Responsible for verifying the parameters (version, type, dist-tag etc...) of the release that is about to be published. For example the [cracks plugin](https://github.com/semantic-release/cracks) is able to verify that if a release contains breaking changes, its type must be `major`.
|
||||
|
||||
Default implementation: none.<br>
|
||||
Optional.<br>
|
||||
Accept multiple plugins.
|
||||
|
||||
### generateNotes plugin
|
||||
|
||||
Responsible for generating release notes. If multiple `generateNotes` plugins are defined, the release notes will be the result of the concatenation of plugin output.
|
||||
|
||||
Default implementation: [@semantic-release/release-notes-generator](https://github.com/semantic-release/release-notes-generator).<br>
|
||||
Optional.<br>
|
||||
Accept multiple plugins.
|
||||
|
||||
### prepare plugin
|
||||
|
||||
Responsible for preparing the release, including:
|
||||
- Creating or updating files such as `package.json`, `CHANGELOG.md`, documentation or compiled assets.
|
||||
- Create and push commits
|
||||
|
||||
Default implementation: [@semantic-release/npm](https://github.com/semantic-release/npm#prepare).<br>
|
||||
Optional.<br>
|
||||
Accept multiple plugins.
|
||||
|
||||
### publish plugin
|
||||
|
||||
Responsible for publishing the release.
|
||||
|
||||
Default implementation: [@semantic-release/npm](https://github.com/semantic-release/npm#publish) and [@semantic-release/github](https://github.com/semantic-release/github#publish).<br>
|
||||
Optional.<br>
|
||||
Accept multiple plugins.
|
||||
|
||||
### success plugin
|
||||
|
||||
Responsible for notifying of a new release.
|
||||
|
||||
Default implementation: [@semantic-release/github](https://github.com/semantic-release/github#success).<br>
|
||||
Optional.<br>
|
||||
Accept multiple plugins.
|
||||
|
||||
### fail plugin
|
||||
|
||||
Responsible for notifying of a failed release.
|
||||
|
||||
Default implementation: [@semantic-release/github](https://github.com/semantic-release/github#fail).<br>
|
||||
Optional.<br>
|
||||
Accept multiple plugins.
|
||||
|
||||
## Configuration
|
||||
|
||||
Plugin can be configured by specifying the plugin's module name or file path directly as a `String` or within the `path` key of an `Object`.
|
||||
|
||||
Plugins specific options can be set similarly to the other **semantic-release** [options](configuration.md#options) or within the plugin `Object`. Plugins options defined along with the other **semantic-release** [options](configuration.md#options) will apply to all plugins. Options defined within the plugin `Object` will apply to that specific plugin.
|
||||
|
||||
For example:
|
||||
```json
|
||||
{
|
||||
"release": {
|
||||
"verifyConditions": [
|
||||
{
|
||||
"path": "@semantic-release/exec",
|
||||
"cmd": "verify-conditions.sh"
|
||||
},
|
||||
"@semantic-release/npm",
|
||||
"@semantic-release/github"
|
||||
],
|
||||
"analyzeCommits": "custom-plugin",
|
||||
"verifyRelease": [
|
||||
{
|
||||
"path": "@semantic-release/exec",
|
||||
"cmd": "verify-release.sh"
|
||||
},
|
||||
],
|
||||
"generateNotes": "./build/my-plugin.js",
|
||||
"githubUrl": "https://my-ghe.com",
|
||||
"githubApiPathPrefix": "/api-prefix"
|
||||
}
|
||||
"plugins": ["@semantic-release/commit-analyzer", "@semantic-release/release-notes-generator", "@semantic-release/npm"]
|
||||
}
|
||||
```
|
||||
|
||||
## Plugin ordering
|
||||
|
||||
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.
|
||||
|
||||
```json
|
||||
{
|
||||
"plugins": [
|
||||
"@semantic-release/commit-analyzer",
|
||||
"@semantic-release/release-notes-generator",
|
||||
"@semantic-release/npm",
|
||||
"@semantic-release/git"
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
With this configuration **semantic-release** will:
|
||||
- execute the `verifyConditions` implementation of `@semantic-release/npm` then `@semantic-release/git`
|
||||
- execute the `analyzeCommits` implementation of `@semantic-release/commit-analyzer`
|
||||
- execute the `prepare` implementation of `@semantic-release/npm` then `@semantic-release/git`
|
||||
- execute the `generateNotes` implementation of `@semantic-release/release-notes-generator`
|
||||
- execute the `publish` implementation of `@semantic-release/npm`
|
||||
|
||||
## Plugin options
|
||||
|
||||
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.
|
||||
|
||||
Global plugin options can defined at the root of the **semantic-release** configuration object. Options configured this way will be passed to all plugins.
|
||||
|
||||
```json
|
||||
{
|
||||
"plugins": [
|
||||
"@semantic-release/commit-analyzer",
|
||||
"@semantic-release/release-notes-generator",
|
||||
["@semantic-release/github", {
|
||||
"assets": ["dist/**"]
|
||||
}],
|
||||
"@semantic-release/git"
|
||||
],
|
||||
"preset": "angular"
|
||||
}
|
||||
```
|
||||
|
||||
With this configuration:
|
||||
- the `custom-plugin` npm module will be used to [analyze commits](#analyzecommits-plugin)
|
||||
- the `./build/my-plugin.js` script will be used to [generate release notes](#generatenotes-plugin)
|
||||
- the [`@semantic-release/exec`](https://github.com/semantic-release/exec), [`@semantic-release/npm`](https://github.com/semantic-release/npm) and [`@semantic-release/github`](https://github.com/semantic-release/github) plugins will be used to [verify conditions](#verifyconditions-plugin)
|
||||
- the [`@semantic-release/exec`](https://github.com/semantic-release/exec) plugin will be used to [verify the release](#verifyrelease-plugin)
|
||||
- the `cmd` option will be set to `verify-conditions.sh` only for the [`@semantic-release/exec`](https://github.com/semantic-release/exec) plugin used to [verify conditions](#verifyconditions-plugin)
|
||||
- the `cmd` option will be set to `verify-release.sh` only for the [`@semantic-release/exec`](https://github.com/semantic-release/exec) plugin used to [verify the release](#verifyrelease-plugin)
|
||||
- the `githubUrl` and `githubApiPathPrefix` options will be set to respectively `https://my-ghe.com` and `/api-prefix` for all plugins
|
||||
- All plugins will receive the `preset` option, which will be used by both `@semantic-release/commit-analyzer` and `@semantic-release/release-notes-generator` (and ignored by `@semantic-release/github` and `@semantic-release/git`)
|
||||
- The `@semantic-release/github` plugin will receive the `assets` options (`@semantic-release/git` will not receive it and therefore will use it's default value for that option)
|
||||
|
||||
@@ -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.
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ const getLastRelease = require('./lib/get-last-release');
|
||||
const {extractErrors} = require('./lib/utils');
|
||||
const getGitAuthUrl = require('./lib/get-git-auth-url');
|
||||
const getLogger = require('./lib/get-logger');
|
||||
const {fetch, verifyAuth, isBranchUpToDate, gitHead: getGitHead, tag, push} = require('./lib/git');
|
||||
const {fetch, verifyAuth, isBranchUpToDate, getGitHead, tag, push} = require('./lib/git');
|
||||
const getError = require('./lib/get-error');
|
||||
const {COMMIT_NAME, COMMIT_EMAIL} = require('./lib/definitions/constants');
|
||||
|
||||
@@ -24,7 +24,7 @@ async function run(context, plugins) {
|
||||
const {isCi, branch: ciBranch, isPr} = envCi({env, cwd});
|
||||
|
||||
if (!isCi && !options.dryRun && !options.noCi) {
|
||||
logger.log('This run was not triggered in a known CI environment, running in dry-run mode.');
|
||||
logger.warn('This run was not triggered in a known CI environment, running in dry-run mode.');
|
||||
options.dryRun = true;
|
||||
} else {
|
||||
// When running on CI, set the commits author and commiter info and prevent the `git` CLI to prompt for username/password. See #703.
|
||||
@@ -52,21 +52,29 @@ async function run(context, plugins) {
|
||||
);
|
||||
return false;
|
||||
}
|
||||
logger.success(`Run automated release from branch ${ciBranch}`);
|
||||
|
||||
logger[options.dryRun ? 'warn' : 'success'](
|
||||
`Run automated release from branch ${ciBranch}${options.dryRun ? ' in dry-run mode' : ''}`
|
||||
);
|
||||
|
||||
await verify(context);
|
||||
|
||||
options.repositoryUrl = await getGitAuthUrl(context);
|
||||
|
||||
try {
|
||||
await verifyAuth(options.repositoryUrl, options.branch, {cwd, env});
|
||||
} catch (error) {
|
||||
if (!(await isBranchUpToDate(options.branch, {cwd, env}))) {
|
||||
logger.log(
|
||||
`The local branch ${options.branch} is behind the remote one, therefore a new version won't be published.`
|
||||
);
|
||||
return false;
|
||||
try {
|
||||
await verifyAuth(options.repositoryUrl, options.branch, {cwd, env});
|
||||
} catch (error) {
|
||||
if (!(await isBranchUpToDate(options.branch, {cwd, env}))) {
|
||||
logger.log(
|
||||
`The local branch ${options.branch} 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}.`);
|
||||
throw getError('EGITNOPERMISSION', {options});
|
||||
}
|
||||
@@ -86,32 +94,37 @@ async function run(context, plugins) {
|
||||
logger.log('There are no relevant changes, so no new version is released.');
|
||||
return false;
|
||||
}
|
||||
|
||||
context.nextRelease = nextRelease;
|
||||
nextRelease.version = getNextVersion(context);
|
||||
nextRelease.gitTag = template(options.tagFormat)({version: nextRelease.version});
|
||||
|
||||
await plugins.verifyRelease(context);
|
||||
|
||||
if (options.dryRun) {
|
||||
const notes = await plugins.generateNotes(context);
|
||||
logger.log(`Release note for version ${nextRelease.version}:`);
|
||||
if (notes) {
|
||||
context.stdout.write(marked(notes));
|
||||
}
|
||||
} else {
|
||||
nextRelease.notes = await plugins.generateNotes(context);
|
||||
await plugins.prepare(context);
|
||||
nextRelease.notes = await plugins.generateNotes(context);
|
||||
|
||||
await plugins.prepare(context);
|
||||
|
||||
if (options.dryRun) {
|
||||
logger.warn(`Skip ${nextRelease.gitTag} tag creation in dry-run mode`);
|
||||
} else {
|
||||
// Create the tag before calling the publish plugins as some require the tag to exists
|
||||
await tag(nextRelease.gitTag, {cwd, env});
|
||||
await push(options.repositoryUrl, options.branch, {cwd, env});
|
||||
await push(options.repositoryUrl, {cwd, env});
|
||||
logger.success(`Created tag ${nextRelease.gitTag}`);
|
||||
}
|
||||
|
||||
context.releases = await plugins.publish(context);
|
||||
context.releases = await plugins.publish(context);
|
||||
|
||||
await plugins.success(context);
|
||||
await plugins.success(context);
|
||||
|
||||
logger.success(`Published release ${nextRelease.version}`);
|
||||
logger.success(`Published release ${nextRelease.version}`);
|
||||
|
||||
if (options.dryRun) {
|
||||
logger.log(`Release note for version ${nextRelease.version}:`);
|
||||
if (nextRelease.notes) {
|
||||
context.stdout.write(marked(nextRelease.notes));
|
||||
}
|
||||
}
|
||||
|
||||
return pick(context, ['lastRelease', 'commits', 'nextRelease', 'releases']);
|
||||
@@ -158,9 +171,7 @@ module.exports = async (opts = {}, {cwd = process.cwd(), env = process.env, stdo
|
||||
unhook();
|
||||
return result;
|
||||
} catch (error) {
|
||||
if (!options.dryRun) {
|
||||
await callFail(context, plugins, error);
|
||||
}
|
||||
await callFail(context, plugins, error);
|
||||
throw error;
|
||||
}
|
||||
} catch (error) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
const RELEASE_TYPE = ['major', 'premajor', 'minor', 'preminor', 'patch', 'prepatch', 'prerelease'];
|
||||
const RELEASE_TYPE = ['prerelease', 'prepatch', 'patch', 'preminor', 'minor', 'premajor', 'major'];
|
||||
|
||||
const FIRST_RELEASE = '1.0.0';
|
||||
|
||||
|
||||
+15
-10
@@ -1,19 +1,18 @@
|
||||
const url = require('url');
|
||||
const {inspect} = require('util');
|
||||
const {toLower, isString} = 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/caribou/${file}`;
|
||||
const linkify = file => `${homepage}/blob/master/${file}`;
|
||||
|
||||
module.exports = {
|
||||
ENOGITREPO: () => ({
|
||||
ENOGITREPO: ({cwd}) => ({
|
||||
message: 'Not running from a git repository.',
|
||||
details: `The \`semantic-release\` command must be executed from a Git repository.
|
||||
|
||||
The current working directory is \`${process.cwd()}\`.
|
||||
The current working directory is \`${cwd}\`.
|
||||
|
||||
Please verify your CI configuration to make sure the \`semantic-release\` command is executed from the root of the cloned repository.`,
|
||||
}),
|
||||
@@ -55,15 +54,21 @@ Your configuration for the \`tagFormat\` option is \`${stringify(tagFormat)}\`.`
|
||||
|
||||
Your configuration for the \`tagFormat\` option is \`${stringify(tagFormat)}\`.`,
|
||||
}),
|
||||
EPLUGINCONF: ({type, multiple, required, pluginConf}) => ({
|
||||
EPLUGINCONF: ({type, required, pluginConf}) => ({
|
||||
message: `The \`${type}\` plugin configuration is invalid.`,
|
||||
details: `The [${type} plugin configuration](${linkify(`docs/usage/plugins.md#${toLower(type)}-plugin`)}) ${
|
||||
required ? 'is required and ' : ''
|
||||
}must be ${
|
||||
multiple ? 'a single or an array of plugins' : 'a single plugin'
|
||||
} definition. A plugin definition is either a string or an object with a \`path\` property.
|
||||
} must be a single or an array of plugins definition. A plugin definition is an npm module name, optionnaly wrapped in an array with an object.
|
||||
|
||||
Your configuration for the \`${type}\` plugin is \`${stringify(pluginConf)}\`.`,
|
||||
Your configuration for the \`${type}\` plugin is \`${stringify(pluginConf)}\`.`,
|
||||
}),
|
||||
EPLUGINSCONF: ({plugin}) => ({
|
||||
message: 'The `plugins` configuration is invalid.',
|
||||
details: `The [plugins](${linkify(
|
||||
'docs/usage/configuration.md#plugins'
|
||||
)}) option must be an array of plugin definions. A plugin definition is an npm module name, optionnaly wrapped in an array with an object.
|
||||
|
||||
The invalid configuration is \`${stringify(plugin)}\`.`,
|
||||
}),
|
||||
EPLUGIN: ({pluginName, type}) => ({
|
||||
message: `A plugin configured in the step ${type} is not a valid semantic-release plugin.`,
|
||||
|
||||
+22
-23
@@ -1,37 +1,40 @@
|
||||
const {isString, isPlainObject} = require('lodash');
|
||||
const {gitHead} = require('../git');
|
||||
const {getGitHead} = require('../git');
|
||||
const hideSensitive = require('../hide-sensitive');
|
||||
const {hideSensitiveValues} = require('../utils');
|
||||
const {RELEASE_TYPE, RELEASE_NOTES_SEPARATOR} = require('./constants');
|
||||
|
||||
module.exports = {
|
||||
verifyConditions: {
|
||||
default: ['@semantic-release/npm', '@semantic-release/github'],
|
||||
multiple: true,
|
||||
required: false,
|
||||
dryRun: true,
|
||||
pipelineConfig: () => ({settleAll: true}),
|
||||
},
|
||||
analyzeCommits: {
|
||||
default: '@semantic-release/commit-analyzer',
|
||||
multiple: false,
|
||||
default: ['@semantic-release/commit-analyzer'],
|
||||
required: true,
|
||||
dryRun: true,
|
||||
outputValidator: output => !output || RELEASE_TYPE.includes(output),
|
||||
preprocess: ({commits, ...inputs}) => ({
|
||||
...inputs,
|
||||
commits: commits.filter(commit => !/\[skip\s+release\]|\[release\s+skip\]/i.test(commit.message)),
|
||||
}),
|
||||
postprocess: ([result]) => result,
|
||||
postprocess: results =>
|
||||
RELEASE_TYPE[
|
||||
results.reduce((highest, result) => {
|
||||
const typeIndex = RELEASE_TYPE.indexOf(result);
|
||||
return typeIndex > highest ? typeIndex : highest;
|
||||
}, -1)
|
||||
],
|
||||
},
|
||||
verifyRelease: {
|
||||
default: false,
|
||||
multiple: true,
|
||||
required: false,
|
||||
dryRun: true,
|
||||
pipelineConfig: () => ({settleAll: true}),
|
||||
},
|
||||
generateNotes: {
|
||||
default: ['@semantic-release/release-notes-generator'],
|
||||
multiple: true,
|
||||
required: false,
|
||||
dryRun: true,
|
||||
outputValidator: output => !output || isString(output),
|
||||
pipelineConfig: () => ({
|
||||
getNextInput: ({nextRelease, ...context}, notes) => ({
|
||||
@@ -45,49 +48,45 @@ module.exports = {
|
||||
postprocess: (results, {env}) => hideSensitive(env)(results.filter(Boolean).join(RELEASE_NOTES_SEPARATOR)),
|
||||
},
|
||||
prepare: {
|
||||
default: ['@semantic-release/npm'],
|
||||
multiple: true,
|
||||
required: false,
|
||||
pipelineConfig: ({generateNotes}, logger) => ({
|
||||
dryRun: false,
|
||||
pipelineConfig: ({generateNotes}) => ({
|
||||
getNextInput: async context => {
|
||||
const newGitHead = await gitHead({cwd: context.cwd});
|
||||
const newGitHead = await getGitHead({cwd: context.cwd});
|
||||
// If previous prepare plugin has created a commit (gitHead changed)
|
||||
if (context.nextRelease.gitHead !== newGitHead) {
|
||||
context.nextRelease.gitHead = newGitHead;
|
||||
// Regenerate the release notes
|
||||
logger.log('Call plugin %s', 'generateNotes');
|
||||
context.nextRelease.notes = await generateNotes(context);
|
||||
}
|
||||
|
||||
// Call the next prepare plugin with the updated `nextRelease`
|
||||
return context;
|
||||
},
|
||||
}),
|
||||
},
|
||||
publish: {
|
||||
default: ['@semantic-release/npm', '@semantic-release/github'],
|
||||
multiple: true,
|
||||
required: false,
|
||||
dryRun: false,
|
||||
outputValidator: output => !output || isPlainObject(output),
|
||||
pipelineConfig: () => ({
|
||||
// Add `nextRelease` and plugin properties to published release
|
||||
transform: (release, step, {nextRelease}) => ({
|
||||
...(isPlainObject(release) ? release : {}),
|
||||
...nextRelease,
|
||||
...(release === false ? {} : nextRelease),
|
||||
...release,
|
||||
...step,
|
||||
}),
|
||||
}),
|
||||
},
|
||||
success: {
|
||||
default: ['@semantic-release/github'],
|
||||
multiple: true,
|
||||
required: false,
|
||||
dryRun: false,
|
||||
pipelineConfig: () => ({settleAll: true}),
|
||||
preprocess: ({releases, env, ...inputs}) => ({...inputs, env, releases: hideSensitiveValues(env, releases)}),
|
||||
},
|
||||
fail: {
|
||||
default: ['@semantic-release/github'],
|
||||
multiple: true,
|
||||
required: false,
|
||||
dryRun: false,
|
||||
pipelineConfig: () => ({settleAll: true}),
|
||||
preprocess: ({errors, env, ...inputs}) => ({...inputs, env, errors: hideSensitiveValues(env, errors)}),
|
||||
},
|
||||
|
||||
+33
-15
@@ -1,4 +1,4 @@
|
||||
const {castArray, pickBy, isUndefined, isNull, isString, isPlainObject} = require('lodash');
|
||||
const {castArray, pickBy, isNil, isString, isPlainObject} = require('lodash');
|
||||
const readPkgUp = require('read-pkg-up');
|
||||
const cosmiconfig = require('cosmiconfig');
|
||||
const resolveFrom = require('resolve-from');
|
||||
@@ -6,6 +6,7 @@ const debug = require('debug')('semantic-release:config');
|
||||
const {repoUrl} = require('./git');
|
||||
const PLUGINS_DEFINITIONS = require('./definitions/plugins');
|
||||
const plugins = require('./plugins');
|
||||
const {validatePlugin, parseConfig} = require('./plugins/utils');
|
||||
|
||||
const CONFIG_NAME = 'release';
|
||||
const CONFIG_FILES = [
|
||||
@@ -20,9 +21,16 @@ const CONFIG_FILES = [
|
||||
|
||||
module.exports = async (context, opts) => {
|
||||
const {cwd, env} = context;
|
||||
const {config} = (await cosmiconfig(CONFIG_NAME, {searchPlaces: CONFIG_FILES}).search(cwd)) || {};
|
||||
const {config, filepath} = (await cosmiconfig(CONFIG_NAME, {searchPlaces: CONFIG_FILES}).search(cwd)) || {};
|
||||
|
||||
debug('load config from: %s', filepath);
|
||||
|
||||
// Merge config file options and CLI/API options
|
||||
let options = {...config, ...opts};
|
||||
if (options.ci === false) {
|
||||
options.noCi = true;
|
||||
}
|
||||
|
||||
const pluginsPath = {};
|
||||
let extendPaths;
|
||||
({extends: extendPaths, ...options} = options);
|
||||
@@ -34,17 +42,21 @@ module.exports = async (context, opts) => {
|
||||
|
||||
// For each plugin defined in a shareable config, save in `pluginsPath` the extendable config path,
|
||||
// so those plugin will be loaded relatively to the config file
|
||||
Object.entries(extendsOpts).reduce((pluginsPath, [option, value]) => {
|
||||
if (PLUGINS_DEFINITIONS[option]) {
|
||||
castArray(value)
|
||||
.filter(plugin => isString(plugin) || (isPlainObject(plugin) && isString(plugin.path)))
|
||||
.map(plugin => (isString(plugin) ? plugin : plugin.path))
|
||||
.forEach(plugin => {
|
||||
pluginsPath[plugin] = extendPath;
|
||||
});
|
||||
}
|
||||
return pluginsPath;
|
||||
}, pluginsPath);
|
||||
Object.entries(extendsOpts)
|
||||
.filter(([, value]) => Boolean(value))
|
||||
.reduce((pluginsPath, [option, value]) => {
|
||||
castArray(value).forEach(plugin => {
|
||||
if (option === 'plugins' && validatePlugin(plugin)) {
|
||||
pluginsPath[parseConfig(plugin)[0]] = extendPath;
|
||||
} else if (
|
||||
PLUGINS_DEFINITIONS[option] &&
|
||||
(isString(plugin) || (isPlainObject(plugin) && isString(plugin.path)))
|
||||
) {
|
||||
pluginsPath[isString(plugin) ? plugin : plugin.path] = extendPath;
|
||||
}
|
||||
});
|
||||
return pluginsPath;
|
||||
}, pluginsPath);
|
||||
|
||||
return {...result, ...extendsOpts};
|
||||
}, {}),
|
||||
@@ -57,8 +69,14 @@ module.exports = async (context, opts) => {
|
||||
branch: 'master',
|
||||
repositoryUrl: (await pkgRepoUrl({normalize: false, cwd})) || (await repoUrl({cwd, env})),
|
||||
tagFormat: `v\${version}`,
|
||||
plugins: [
|
||||
'@semantic-release/commit-analyzer',
|
||||
'@semantic-release/release-notes-generator',
|
||||
'@semantic-release/npm',
|
||||
'@semantic-release/github',
|
||||
],
|
||||
// Remove `null` and `undefined` options so they can be replaced with default ones
|
||||
...pickBy(options, option => !isUndefined(option) && !isNull(option)),
|
||||
...pickBy(options, option => !isNil(option)),
|
||||
};
|
||||
|
||||
debug('options values: %O', options);
|
||||
@@ -67,6 +85,6 @@ module.exports = async (context, opts) => {
|
||||
};
|
||||
|
||||
async function pkgRepoUrl(opts) {
|
||||
const {pkg} = await readPkgUp(opts);
|
||||
const {package: pkg} = (await readPkgUp(opts)) || {};
|
||||
return pkg && (isPlainObject(pkg.repository) ? pkg.repository.url : pkg.repository);
|
||||
}
|
||||
|
||||
+34
-24
@@ -1,19 +1,8 @@
|
||||
const {parse, format} = require('url');
|
||||
const {isUndefined} = require('lodash');
|
||||
const gitUrlParse = require('git-url-parse');
|
||||
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
|
||||
@@ -26,31 +15,52 @@ const GIT_TOKENS = {
|
||||
* @return {String} The formatted Git repository URL.
|
||||
*/
|
||||
module.exports = async ({cwd, env, options: {repositoryUrl, branch}}) => {
|
||||
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);
|
||||
|
||||
if (info && info.getDefaultRepresentation() === 'shortcut') {
|
||||
// Expand shorthand URLs (such as `owner/repo` or `gitlab:owner/repo`)
|
||||
repositoryUrl = info.https();
|
||||
} else {
|
||||
const {protocols} = gitUrlParse(repositoryUrl);
|
||||
|
||||
} else if (protocol && protocol.includes('http')) {
|
||||
// Replace `git+https` and `git+http` with `https` or `http`
|
||||
if (protocols.includes('http') || protocols.includes('https')) {
|
||||
repositoryUrl = format({...parse(repositoryUrl), protocol: protocols.includes('https') ? 'https' : 'http'});
|
||||
}
|
||||
repositoryUrl = format({...parsed, protocol: protocol.includes('https') ? 'https' : 'http', href: null});
|
||||
}
|
||||
|
||||
// Test if push is allowed without transforming the URL (e.g. is ssh keys are set up)
|
||||
try {
|
||||
await verifyAuth(repositoryUrl, branch, {cwd, env});
|
||||
} catch (error) {
|
||||
const envVar = Object.keys(GIT_TOKENS).find(envVar => !isUndefined(env[envVar]));
|
||||
const envVar = Object.keys(GIT_TOKENS).find(envVar => !isNil(env[envVar]));
|
||||
const gitCredentials = `${GIT_TOKENS[envVar] || ''}${env[envVar] || ''}`;
|
||||
const {protocols, ...parsed} = gitUrlParse(repositoryUrl);
|
||||
const protocol = protocols.includes('https') ? 'https' : protocols.includes('http') ? 'http' : 'https';
|
||||
|
||||
// If credentials are set via anvironment variables, convert the URL to http/https and add basic auth, otherwise return `repositoryUrl` as is
|
||||
return gitCredentials ? {...parsed, protocols: [protocol], user: gitCredentials}.toString(protocol) : repositoryUrl;
|
||||
console.log(`-------- envVar -------- `);
|
||||
console.log(envVar);
|
||||
console.log(`-------- GIT_TOKENS[envVar] -------- `);
|
||||
console.log(GIT_TOKENS[envVar]);
|
||||
console.log(`-------- env[envVar].substr(5) -------- `);
|
||||
console.log((env[envVar] || '').substr(5));
|
||||
|
||||
if (gitCredentials) {
|
||||
// If credentials are set via environment variables, convert the URL to http/https and add basic auth, otherwise return `repositoryUrl` as is
|
||||
const [match, auth, host, path] = /^(?!.+:\/\/)(?:(.*)@)?(.*?):(.*)$/.exec(repositoryUrl) || [];
|
||||
return format({
|
||||
...parse(match ? `ssh://${auth ? `${auth}@` : ''}${host}/${path}` : repositoryUrl),
|
||||
auth: gitCredentials,
|
||||
protocol: protocol && /http[^s]/.test(protocol) ? 'http' : 'https',
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return repositoryUrl;
|
||||
|
||||
@@ -2,7 +2,7 @@ const {escapeRegExp, template} = require('lodash');
|
||||
const semver = require('semver');
|
||||
const pLocate = require('p-locate');
|
||||
const debug = require('debug')('semantic-release:get-last-release');
|
||||
const {gitTags, isRefInHistory, gitTagHead} = require('./git');
|
||||
const {getTags, isRefInHistory, getTagHead} = require('./git');
|
||||
|
||||
/**
|
||||
* Last release.
|
||||
@@ -28,9 +28,9 @@ module.exports = async ({cwd, env, options: {tagFormat}, logger}) => {
|
||||
// Generate a regex to parse tags formatted with `tagFormat`
|
||||
// by replacing the `version` variable in the template by `(.+)`.
|
||||
// The `tagFormat` is compiled with space as the `version` as it's an invalid tag character,
|
||||
// so it's guaranteed to no be present in the `tagFormat`.
|
||||
// so it's guaranteed to not be present in the `tagFormat`.
|
||||
const tagRegexp = `^${escapeRegExp(template(tagFormat)({version: ' '})).replace(' ', '(.+)')}`;
|
||||
const tags = (await gitTags({cwd, env}))
|
||||
const tags = (await getTags({cwd, env}))
|
||||
.map(tag => ({gitTag: tag, version: (tag.match(tagRegexp) || new Array(2))[1]}))
|
||||
.filter(
|
||||
tag => tag.version && semver.valid(semver.clean(tag.version)) && !semver.prerelease(semver.clean(tag.version))
|
||||
@@ -43,7 +43,7 @@ module.exports = async ({cwd, env, options: {tagFormat}, logger}) => {
|
||||
|
||||
if (tag) {
|
||||
logger.log(`Found git tag ${tag.gitTag} associated with version ${tag.version}`);
|
||||
return {gitHead: await gitTagHead(tag.gitTag, {cwd, env}), ...tag};
|
||||
return {gitHead: await getTagHead(tag.gitTag, {cwd, env}), ...tag};
|
||||
}
|
||||
|
||||
logger.log('No git tag version found');
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@ const figures = require('figures');
|
||||
|
||||
module.exports = ({stdout, stderr}) =>
|
||||
new Signale({
|
||||
config: {displayTimestamp: true, underlineMessage: true, displayLabel: false},
|
||||
config: {displayTimestamp: true, underlineMessage: false, displayLabel: false},
|
||||
disabled: false,
|
||||
interactive: false,
|
||||
scope: 'semantic-release',
|
||||
|
||||
+17
-20
@@ -4,12 +4,12 @@ const debug = require('debug')('semantic-release:git');
|
||||
/**
|
||||
* Get the commit sha for a given tag.
|
||||
*
|
||||
* @param {string} tagName Tag name for which to retrieve the commit sha.
|
||||
* @param {String} tagName Tag name for which to retrieve the commit sha.
|
||||
* @param {Object} [execaOpts] Options to pass to `execa`.
|
||||
*
|
||||
* @return {string} The commit sha of the tag in parameter or `null`.
|
||||
*/
|
||||
async function gitTagHead(tagName, execaOpts) {
|
||||
async function getTagHead(tagName, execaOpts) {
|
||||
try {
|
||||
return await execa.stdout('git', ['rev-list', '-1', tagName], execaOpts);
|
||||
} catch (error) {
|
||||
@@ -25,20 +25,20 @@ async function gitTagHead(tagName, execaOpts) {
|
||||
* @return {Array<String>} List of git tags.
|
||||
* @throws {Error} If the `git` command fails.
|
||||
*/
|
||||
async function gitTags(execaOpts) {
|
||||
async function getTags(execaOpts) {
|
||||
return (await execa.stdout('git', ['tag'], execaOpts))
|
||||
.split('\n')
|
||||
.map(tag => tag.trim())
|
||||
.filter(tag => Boolean(tag));
|
||||
.filter(Boolean);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify if the `ref` is in the direct history of the current branch.
|
||||
*
|
||||
* @param {string} ref The reference to look for.
|
||||
* @param {String} ref The reference to look for.
|
||||
* @param {Object} [execaOpts] Options to pass to `execa`.
|
||||
*
|
||||
* @return {boolean} `true` if the reference is in the history of the current branch, falsy otherwise.
|
||||
* @return {Boolean} `true` if the reference is in the history of the current branch, falsy otherwise.
|
||||
*/
|
||||
async function isRefInHistory(ref, execaOpts) {
|
||||
try {
|
||||
@@ -73,9 +73,9 @@ async function fetch(repositoryUrl, execaOpts) {
|
||||
*
|
||||
* @param {Object} [execaOpts] Options to pass to `execa`.
|
||||
*
|
||||
* @return {string} the sha of the HEAD commit.
|
||||
* @return {String} the sha of the HEAD commit.
|
||||
*/
|
||||
function gitHead(execaOpts) {
|
||||
function getGitHead(execaOpts) {
|
||||
return execa.stdout('git', ['rev-parse', 'HEAD'], execaOpts);
|
||||
}
|
||||
|
||||
@@ -143,22 +143,21 @@ async function tag(tagName, execaOpts) {
|
||||
* Push to the remote repository.
|
||||
*
|
||||
* @param {String} repositoryUrl The remote repository URL.
|
||||
* @param {String} branch The branch to push.
|
||||
* @param {Object} [execaOpts] Options to pass to `execa`.
|
||||
*
|
||||
* @throws {Error} if the push failed.
|
||||
*/
|
||||
async function push(repositoryUrl, branch, execaOpts) {
|
||||
await execa('git', ['push', '--tags', repositoryUrl, `HEAD:${branch}`], execaOpts);
|
||||
async function push(repositoryUrl, execaOpts) {
|
||||
await execa('git', ['push', '--tags', repositoryUrl], execaOpts);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify a tag name is a valid Git reference.
|
||||
*
|
||||
* @param {string} tagName the tag name to verify.
|
||||
* @param {String} tagName the tag name to verify.
|
||||
* @param {Object} [execaOpts] Options to pass to `execa`.
|
||||
*
|
||||
* @return {boolean} `true` if valid, falsy otherwise.
|
||||
* @return {Boolean} `true` if valid, falsy otherwise.
|
||||
*/
|
||||
async function verifyTagName(tagName, execaOpts) {
|
||||
try {
|
||||
@@ -177,22 +176,20 @@ async function verifyTagName(tagName, execaOpts) {
|
||||
* @return {Boolean} `true` is the HEAD of the current local branch is the same as the HEAD of the remote branch, falsy otherwise.
|
||||
*/
|
||||
async function isBranchUpToDate(branch, execaOpts) {
|
||||
const remoteHead = await execa.stdout('git', ['ls-remote', '--heads', 'origin', branch], execaOpts);
|
||||
try {
|
||||
return await isRefInHistory(
|
||||
(await execa.stdout('git', ['ls-remote', '--heads', 'origin', branch], execaOpts)).match(/^(\w+)?/)[1],
|
||||
execaOpts
|
||||
);
|
||||
return await isRefInHistory(remoteHead.match(/^(\w+)?/)[1], execaOpts);
|
||||
} catch (error) {
|
||||
debug(error);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
gitTagHead,
|
||||
gitTags,
|
||||
getTagHead,
|
||||
getTags,
|
||||
isRefInHistory,
|
||||
fetch,
|
||||
gitHead,
|
||||
getGitHead,
|
||||
repoUrl,
|
||||
isGitRepo,
|
||||
verifyAuth,
|
||||
|
||||
+63
-22
@@ -1,52 +1,93 @@
|
||||
const {identity, isPlainObject, omit, castArray, isUndefined} = require('lodash');
|
||||
const {identity, isPlainObject, omit, castArray, isNil, isString} = require('lodash');
|
||||
const AggregateError = require('aggregate-error');
|
||||
const getError = require('../get-error');
|
||||
const PLUGINS_DEFINITIONS = require('../definitions/plugins');
|
||||
const {validateConfig} = require('./utils');
|
||||
const {validatePlugin, validateStep, loadPlugin, parseConfig} = require('./utils');
|
||||
const pipeline = require('./pipeline');
|
||||
const normalize = require('./normalize');
|
||||
|
||||
module.exports = (context, pluginsPath) => {
|
||||
const {options, logger} = context;
|
||||
let {options, logger} = context;
|
||||
const errors = [];
|
||||
const plugins = Object.entries(PLUGINS_DEFINITIONS).reduce(
|
||||
(
|
||||
plugins,
|
||||
[type, {multiple, required, default: def, pipelineConfig, postprocess = identity, preprocess = identity}]
|
||||
) => {
|
||||
|
||||
const plugins = options.plugins
|
||||
? castArray(options.plugins).reduce((plugins, plugin) => {
|
||||
if (validatePlugin(plugin)) {
|
||||
const [name, config] = parseConfig(plugin);
|
||||
plugin = isString(name) ? loadPlugin(context, name, pluginsPath) : name;
|
||||
|
||||
if (isPlainObject(plugin)) {
|
||||
Object.entries(plugin).forEach(([type, func]) => {
|
||||
if (PLUGINS_DEFINITIONS[type]) {
|
||||
Reflect.defineProperty(func, 'pluginName', {
|
||||
value: isPlainObject(name) ? 'Inline plugin' : name,
|
||||
writable: false,
|
||||
enumerable: true,
|
||||
});
|
||||
plugins[type] = [...(plugins[type] || []), [func, config]];
|
||||
}
|
||||
});
|
||||
} else {
|
||||
errors.push(getError('EPLUGINSCONF', {plugin}));
|
||||
}
|
||||
} else {
|
||||
errors.push(getError('EPLUGINSCONF', {plugin}));
|
||||
}
|
||||
|
||||
return plugins;
|
||||
}, {})
|
||||
: [];
|
||||
|
||||
if (errors.length > 0) {
|
||||
throw new AggregateError(errors);
|
||||
}
|
||||
|
||||
options = {...plugins, ...options};
|
||||
|
||||
const pluginsConf = Object.entries(PLUGINS_DEFINITIONS).reduce(
|
||||
(pluginsConf, [type, {required, default: def, pipelineConfig, postprocess = identity, preprocess = identity}]) => {
|
||||
let pluginOpts;
|
||||
|
||||
if (isUndefined(options[type])) {
|
||||
if (isNil(options[type]) && def) {
|
||||
pluginOpts = def;
|
||||
} else {
|
||||
const defaultPaths = castArray(def);
|
||||
// If an object is passed and the path is missing, set the default one for single plugins
|
||||
if (isPlainObject(options[type]) && !options[type].path && defaultPaths.length === 1) {
|
||||
[options[type].path] = defaultPaths;
|
||||
// If an object is passed and the path is missing, merge it with step options
|
||||
if (isPlainObject(options[type]) && !options[type].path) {
|
||||
options[type] = castArray(plugins[type]).map(plugin =>
|
||||
plugin ? [plugin[0], Object.assign(plugin[1], options[type])] : plugin
|
||||
);
|
||||
}
|
||||
if (!validateConfig({multiple, required}, options[type])) {
|
||||
errors.push(getError('EPLUGINCONF', {type, multiple, required, pluginConf: options[type]}));
|
||||
return plugins;
|
||||
|
||||
if (!validateStep({required}, options[type])) {
|
||||
errors.push(getError('EPLUGINCONF', {type, required, pluginConf: options[type]}));
|
||||
return pluginsConf;
|
||||
}
|
||||
|
||||
pluginOpts = options[type];
|
||||
}
|
||||
|
||||
const steps = castArray(pluginOpts).map(pluginOpt =>
|
||||
normalize({...context, options: omit(options, Object.keys(PLUGINS_DEFINITIONS))}, type, pluginOpt, pluginsPath)
|
||||
normalize(
|
||||
{...context, options: omit(options, Object.keys(PLUGINS_DEFINITIONS), 'plugins')},
|
||||
type,
|
||||
pluginOpt,
|
||||
pluginsPath
|
||||
)
|
||||
);
|
||||
|
||||
plugins[type] = async input =>
|
||||
pluginsConf[type] = async input =>
|
||||
postprocess(
|
||||
await pipeline(steps, pipelineConfig && pipelineConfig(plugins, logger))(await preprocess(input)),
|
||||
await pipeline(steps, pipelineConfig && pipelineConfig(pluginsConf, logger))(await preprocess(input)),
|
||||
input
|
||||
);
|
||||
|
||||
return plugins;
|
||||
return pluginsConf;
|
||||
},
|
||||
{}
|
||||
plugins
|
||||
);
|
||||
if (errors.length > 0) {
|
||||
throw new AggregateError(errors);
|
||||
}
|
||||
return plugins;
|
||||
|
||||
return pluginsConf;
|
||||
};
|
||||
|
||||
+29
-25
@@ -1,22 +1,21 @@
|
||||
const {dirname} = require('path');
|
||||
const {isString, isPlainObject, isFunction, noop, cloneDeep, omit} = require('lodash');
|
||||
const resolveFrom = require('resolve-from');
|
||||
const {isPlainObject, isFunction, noop, cloneDeep, omit} = require('lodash');
|
||||
const debug = require('debug')('semantic-release:plugins');
|
||||
const getError = require('../get-error');
|
||||
const {extractErrors} = require('../utils');
|
||||
const PLUGINS_DEFINITIONS = require('../definitions/plugins');
|
||||
const {loadPlugin, parseConfig} = require('./utils');
|
||||
|
||||
module.exports = ({cwd, stdout, stderr, options, logger}, type, pluginOpt, pluginsPath) => {
|
||||
module.exports = (context, type, pluginOpt, pluginsPath) => {
|
||||
const {stdout, stderr, options, logger} = context;
|
||||
if (!pluginOpt) {
|
||||
return noop;
|
||||
}
|
||||
|
||||
const {path, ...config} = isString(pluginOpt) || isFunction(pluginOpt) ? {path: pluginOpt} : pluginOpt;
|
||||
const pluginName = isFunction(path) ? `[Function: ${path.name}]` : path;
|
||||
const [name, config] = parseConfig(pluginOpt);
|
||||
const pluginName = name.pluginName ? name.pluginName : isFunction(name) ? `[Function: ${name.name}]` : name;
|
||||
const plugin = loadPlugin(context, name, pluginsPath);
|
||||
|
||||
const basePath = pluginsPath[path]
|
||||
? dirname(resolveFrom.silent(__dirname, pluginsPath[path]) || resolveFrom(cwd, pluginsPath[path]))
|
||||
: __dirname;
|
||||
const plugin = isFunction(path) ? path : require(resolveFrom.silent(basePath, path) || resolveFrom(cwd, path));
|
||||
debug(`options for ${pluginName}/${type}: %O`, config);
|
||||
|
||||
let func;
|
||||
if (isFunction(plugin)) {
|
||||
@@ -28,20 +27,25 @@ module.exports = ({cwd, stdout, stderr, options, logger}, type, pluginOpt, plugi
|
||||
}
|
||||
|
||||
const validator = async input => {
|
||||
const {outputValidator} = PLUGINS_DEFINITIONS[type] || {};
|
||||
const {dryRun, outputValidator} = PLUGINS_DEFINITIONS[type] || {};
|
||||
try {
|
||||
logger.log(`Start step "${type}" of plugin "${pluginName}"`);
|
||||
const result = await func({
|
||||
...cloneDeep(omit(input, ['stdout', 'stderr', 'logger'])),
|
||||
stdout,
|
||||
stderr,
|
||||
logger: logger.scope(logger.scopeName, pluginName),
|
||||
});
|
||||
if (outputValidator && !outputValidator(result)) {
|
||||
throw getError(`E${type.toUpperCase()}OUTPUT`, {result, pluginName});
|
||||
if (!input.options.dryRun || dryRun) {
|
||||
logger.log(`Start step "${type}" of plugin "${pluginName}"`);
|
||||
const result = await func({
|
||||
...cloneDeep(omit(input, ['stdout', 'stderr', 'logger'])),
|
||||
stdout,
|
||||
stderr,
|
||||
logger: logger.scope(logger.scopeName, pluginName),
|
||||
});
|
||||
if (outputValidator && !outputValidator(result)) {
|
||||
throw getError(`E${type.toUpperCase()}OUTPUT`, {result, pluginName});
|
||||
}
|
||||
|
||||
logger.success(`Completed step "${type}" of plugin "${pluginName}"`);
|
||||
return result;
|
||||
}
|
||||
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}"`);
|
||||
extractErrors(error).forEach(err => Object.assign(err, {pluginName}));
|
||||
@@ -52,10 +56,10 @@ module.exports = ({cwd, stdout, stderr, options, logger}, type, pluginOpt, plugi
|
||||
Reflect.defineProperty(validator, 'pluginName', {value: pluginName, writable: false, enumerable: true});
|
||||
|
||||
if (!isFunction(pluginOpt)) {
|
||||
if (pluginsPath[path]) {
|
||||
logger.success(`Loaded plugin "${type}" from "${path}" in shareable config "${pluginsPath[path]}"`);
|
||||
if (pluginsPath[name]) {
|
||||
logger.success(`Loaded plugin "${type}" from "${pluginName}" in shareable config "${pluginsPath[name]}"`);
|
||||
} else {
|
||||
logger.success(`Loaded plugin "${type}" from "${path}"`);
|
||||
logger.success(`Loaded plugin "${type}" from "${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;
|
||||
};
|
||||
|
||||
+60
-10
@@ -1,18 +1,68 @@
|
||||
const {isString, isFunction, castArray} = require('lodash');
|
||||
const {dirname} = require('path');
|
||||
const {isString, isFunction, castArray, isArray, isPlainObject, isNil} = require('lodash');
|
||||
const resolveFrom = require('resolve-from');
|
||||
|
||||
const validateSingleConfig = conf => {
|
||||
conf = castArray(conf);
|
||||
return conf.length === 1 && (isString(conf[0]) || isString(conf[0].path) || isFunction(conf[0]));
|
||||
const validateSteps = conf => {
|
||||
return conf.every(conf => {
|
||||
if (
|
||||
isArray(conf) &&
|
||||
(conf.length === 1 || conf.length === 2) &&
|
||||
(isString(conf[0]) || isFunction(conf[0])) &&
|
||||
(isNil(conf[1]) || isPlainObject(conf[1]))
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
conf = castArray(conf);
|
||||
|
||||
if (conf.length !== 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const [name, config] = parseConfig(conf[0]);
|
||||
return (isString(name) || isFunction(name)) && isPlainObject(config);
|
||||
});
|
||||
};
|
||||
|
||||
const validateMultipleConfig = conf => castArray(conf).every(conf => validateSingleConfig(conf));
|
||||
function validatePlugin(conf) {
|
||||
return (
|
||||
isString(conf) ||
|
||||
(isArray(conf) &&
|
||||
(conf.length === 1 || conf.length === 2) &&
|
||||
(isString(conf[0]) || isPlainObject(conf[0])) &&
|
||||
(isNil(conf[1]) || isPlainObject(conf[1]))) ||
|
||||
(isPlainObject(conf) && (isNil(conf.path) || isString(conf.path) || isPlainObject(conf.path)))
|
||||
);
|
||||
}
|
||||
|
||||
const validateConfig = ({multiple, required}, conf) => {
|
||||
function validateStep({required}, conf) {
|
||||
conf = castArray(conf).filter(Boolean);
|
||||
if (required) {
|
||||
return Boolean(conf) && conf.length >= 1 && (multiple ? validateMultipleConfig : validateSingleConfig)(conf);
|
||||
return conf.length >= 1 && validateSteps(conf);
|
||||
}
|
||||
return conf.length === 0 || (multiple ? validateMultipleConfig : validateSingleConfig)(conf);
|
||||
};
|
||||
|
||||
module.exports = {validateConfig};
|
||||
return conf.length === 0 || validateSteps(conf);
|
||||
}
|
||||
|
||||
function loadPlugin({cwd}, name, pluginsPath) {
|
||||
const basePath = pluginsPath[name]
|
||||
? dirname(resolveFrom.silent(__dirname, pluginsPath[name]) || resolveFrom(cwd, pluginsPath[name]))
|
||||
: __dirname;
|
||||
return isFunction(name) ? name : require(resolveFrom.silent(basePath, name) || resolveFrom(cwd, name));
|
||||
}
|
||||
|
||||
function parseConfig(plugin) {
|
||||
let path;
|
||||
let config;
|
||||
if (isArray(plugin)) {
|
||||
[path, config] = plugin;
|
||||
} else if (isPlainObject(plugin) && !isNil(plugin.path)) {
|
||||
({path, ...config} = plugin);
|
||||
} else {
|
||||
path = plugin;
|
||||
}
|
||||
|
||||
return [path, config || {}];
|
||||
}
|
||||
|
||||
module.exports = {validatePlugin, validateStep, loadPlugin, parseConfig};
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ module.exports = async ({cwd, env, options: {repositoryUrl, tagFormat}}) => {
|
||||
const errors = [];
|
||||
|
||||
if (!(await isGitRepo({cwd, env}))) {
|
||||
errors.push(getError('ENOGITREPO'));
|
||||
errors.push(getError('ENOGITREPO', {cwd}));
|
||||
} else if (!repositoryUrl) {
|
||||
errors.push(getError('ENOREPOURL'));
|
||||
}
|
||||
|
||||
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 |
+26
-30
@@ -19,55 +19,54 @@
|
||||
"Pierre Vanduynslager (https://twitter.com/@pvdlg_)"
|
||||
],
|
||||
"dependencies": {
|
||||
"@semantic-release/commit-analyzer": "^6.0.0",
|
||||
"@semantic-release/commit-analyzer": "^6.1.0",
|
||||
"@semantic-release/error": "^2.2.0",
|
||||
"@semantic-release/github": "^5.0.0",
|
||||
"@semantic-release/npm": "^5.0.1",
|
||||
"@semantic-release/release-notes-generator": "^7.0.0",
|
||||
"aggregate-error": "^1.0.0",
|
||||
"@semantic-release/github": "^5.1.0",
|
||||
"@semantic-release/npm": "^5.0.5",
|
||||
"@semantic-release/release-notes-generator": "^7.1.2",
|
||||
"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",
|
||||
"find-versions": "^2.0.0",
|
||||
"get-stream": "^4.0.0",
|
||||
"figures": "^3.0.0",
|
||||
"find-versions": "^3.0.0",
|
||||
"get-stream": "^5.0.0",
|
||||
"git-log-parser": "^1.2.0",
|
||||
"git-url-parse": "^10.0.1",
|
||||
"hook-std": "^1.1.0",
|
||||
"hook-std": "^2.0.0",
|
||||
"hosted-git-info": "^2.7.1",
|
||||
"lodash": "^4.17.4",
|
||||
"marked": "^0.5.0",
|
||||
"marked-terminal": "^3.0.0",
|
||||
"p-locate": "^3.0.0",
|
||||
"p-reduce": "^1.0.0",
|
||||
"read-pkg-up": "^4.0.0",
|
||||
"resolve-from": "^4.0.0",
|
||||
"semver": "^5.4.1",
|
||||
"marked": "^0.6.0",
|
||||
"marked-terminal": "^3.2.0",
|
||||
"p-locate": "^4.0.0",
|
||||
"p-reduce": "^2.0.0",
|
||||
"read-pkg-up": "^6.0.0",
|
||||
"resolve-from": "^5.0.0",
|
||||
"semver": "^6.0.0",
|
||||
"signale": "^1.2.1",
|
||||
"yargs": "^12.0.0"
|
||||
"yargs": "^13.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"ava": "^0.25.0",
|
||||
"ava": "^1.3.1",
|
||||
"clear-module": "^3.0.0",
|
||||
"codecov": "^3.0.0",
|
||||
"commitizen": "^2.9.6",
|
||||
"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",
|
||||
"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": "^12.0.1",
|
||||
"p-retry": "^2.0.0",
|
||||
"nyc": "^14.0.0",
|
||||
"p-retry": "^4.0.0",
|
||||
"proxyquire": "^2.0.0",
|
||||
"sinon": "^6.0.0",
|
||||
"sinon": "^7.2.7",
|
||||
"stream-buffers": "^3.0.2",
|
||||
"tempy": "^0.2.1",
|
||||
"xo": "^0.23.0"
|
||||
"tempy": "^0.3.0",
|
||||
"xo": "^0.24.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=8.3"
|
||||
@@ -113,9 +112,6 @@
|
||||
"publishConfig": {
|
||||
"tag": "next"
|
||||
},
|
||||
"release": {
|
||||
"branch": "caribou"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/semantic-release/semantic-release.git"
|
||||
|
||||
+11
-13
@@ -33,6 +33,9 @@ test.serial('Pass options to semantic-release API', async t => {
|
||||
'https://github/com/owner/repo.git',
|
||||
'-t',
|
||||
`v\${version}`,
|
||||
'-p',
|
||||
'plugin1',
|
||||
'plugin2',
|
||||
'-e',
|
||||
'config1',
|
||||
'config2',
|
||||
@@ -68,6 +71,7 @@ test.serial('Pass options to semantic-release API', async t => {
|
||||
t.is(run.args[0][0].branch, 'master');
|
||||
t.is(run.args[0][0].repositoryUrl, 'https://github/com/owner/repo.git');
|
||||
t.is(run.args[0][0].tagFormat, `v\${version}`);
|
||||
t.deepEqual(run.args[0][0].plugins, ['plugin1', 'plugin2']);
|
||||
t.deepEqual(run.args[0][0].extends, ['config1', 'config2']);
|
||||
t.deepEqual(run.args[0][0].verifyConditions, ['condition1', 'condition2']);
|
||||
t.is(run.args[0][0].analyzeCommits, 'analyze');
|
||||
@@ -94,6 +98,9 @@ test.serial('Pass options to semantic-release API with alias arguments', async t
|
||||
'https://github/com/owner/repo.git',
|
||||
'--tag-format',
|
||||
`v\${version}`,
|
||||
'--plugins',
|
||||
'plugin1',
|
||||
'plugin2',
|
||||
'--extends',
|
||||
'config1',
|
||||
'config2',
|
||||
@@ -106,6 +113,7 @@ test.serial('Pass options to semantic-release API with alias arguments', async t
|
||||
t.is(run.args[0][0].branch, 'master');
|
||||
t.is(run.args[0][0].repositoryUrl, 'https://github/com/owner/repo.git');
|
||||
t.is(run.args[0][0].tagFormat, `v\${version}`);
|
||||
t.deepEqual(run.args[0][0].plugins, ['plugin1', 'plugin2']);
|
||||
t.deepEqual(run.args[0][0].extends, ['config1', 'config2']);
|
||||
t.is(run.args[0][0].dryRun, true);
|
||||
|
||||
@@ -151,18 +159,8 @@ test.serial('Do not set properties in option for which arg is not in command lin
|
||||
t.false('debug' in run.args[0][0]);
|
||||
t.false('r' in run.args[0][0]);
|
||||
t.false('t' in run.args[0][0]);
|
||||
});
|
||||
|
||||
test.serial('Set "noCi" options to "true" with "--no-ci"', async t => {
|
||||
const run = stub().resolves(true);
|
||||
const argv = ['', '', '--no-ci'];
|
||||
const cli = requireNoCache('../cli', {'.': run, process: {...process, argv}});
|
||||
|
||||
const exitCode = await cli();
|
||||
|
||||
t.is(run.args[0][0].noCi, true);
|
||||
|
||||
t.is(exitCode, 0);
|
||||
t.false('p' in run.args[0][0]);
|
||||
t.false('e' in run.args[0][0]);
|
||||
});
|
||||
|
||||
test.serial('Display help', async t => {
|
||||
@@ -176,7 +174,7 @@ test.serial('Display help', async t => {
|
||||
t.is(exitCode, 0);
|
||||
});
|
||||
|
||||
test.serial('Returns error code and prints help if called with a command', async t => {
|
||||
test.serial('Return error code 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}});
|
||||
|
||||
@@ -22,7 +22,7 @@ test('The "generateNotes" plugin output, if defined, must be a string', t => {
|
||||
t.true(plugins.generateNotes.outputValidator('string'));
|
||||
});
|
||||
|
||||
test('The "publish" plugin output, if defined, must be an object', t => {
|
||||
test('The "publish" plugin output, if defined, must be an object or "false"', t => {
|
||||
t.false(plugins.publish.outputValidator(1));
|
||||
t.false(plugins.publish.outputValidator('string'));
|
||||
|
||||
@@ -30,6 +30,7 @@ test('The "publish" plugin output, if defined, must be an object', t => {
|
||||
t.true(plugins.publish.outputValidator());
|
||||
t.true(plugins.publish.outputValidator(null));
|
||||
t.true(plugins.publish.outputValidator(''));
|
||||
t.true(plugins.publish.outputValidator(false));
|
||||
});
|
||||
|
||||
test('The "generateNotes" plugins output are concatenated with separator and sensitive data is hidden', t => {
|
||||
@@ -51,3 +52,13 @@ test('The "generateNotes" plugins output are concatenated with separator and sen
|
||||
`Note 1: Exposing token ${SECRET_REPLACEMENT}${RELEASE_NOTES_SEPARATOR}Note 2: Exposing token ${SECRET_REPLACEMENT}`
|
||||
);
|
||||
});
|
||||
|
||||
test('The "analyzeCommits" plugins output are reduced to the highest release type', t => {
|
||||
t.is(plugins.analyzeCommits.postprocess(['major', 'minor']), 'major');
|
||||
t.is(plugins.analyzeCommits.postprocess(['', 'minor']), 'minor');
|
||||
t.is(plugins.analyzeCommits.postprocess([undefined, 'patch']), 'patch');
|
||||
t.is(plugins.analyzeCommits.postprocess([null, 'patch']), 'patch');
|
||||
t.is(plugins.analyzeCommits.postprocess(['wrong_type', 'minor']), 'minor');
|
||||
t.is(plugins.analyzeCommits.postprocess([]), undefined);
|
||||
t.is(plugins.analyzeCommits.postprocess(['wrong_type']), undefined);
|
||||
});
|
||||
|
||||
+45
-4
@@ -8,6 +8,13 @@ import {stub} from 'sinon';
|
||||
import yaml from 'js-yaml';
|
||||
import {gitRepo, gitCommits, gitShallowClone, gitAddConfig} from './helpers/git-utils';
|
||||
|
||||
const DEFAULT_PLUGINS = [
|
||||
'@semantic-release/commit-analyzer',
|
||||
'@semantic-release/release-notes-generator',
|
||||
'@semantic-release/npm',
|
||||
'@semantic-release/github',
|
||||
];
|
||||
|
||||
test.beforeEach(t => {
|
||||
t.context.plugins = stub().returns({});
|
||||
t.context.getConfig = proxyquire('../lib/get-config', {'./plugins': t.context.plugins});
|
||||
@@ -60,6 +67,18 @@ test('Default values, reading repositoryUrl (http url) from package.json if not
|
||||
t.is(result.tagFormat, `v\${version}`);
|
||||
});
|
||||
|
||||
test('Convert "ci" option to "noCi"', async t => {
|
||||
const pkg = {repository: 'https://host.null/owner/module.git', release: {ci: false}};
|
||||
// Create a git repository, set the current working directory at the root of the repo
|
||||
const {cwd} = await gitRepo();
|
||||
// Create package.json in repository root
|
||||
await outputJson(path.resolve(cwd, 'package.json'), pkg);
|
||||
|
||||
const {options: result} = await t.context.getConfig({cwd});
|
||||
|
||||
t.is(result.noCi, true);
|
||||
});
|
||||
|
||||
test('Read options from package.json', async t => {
|
||||
// Create a git repository, set the current working directory at the root of the repo
|
||||
const {cwd} = await gitRepo();
|
||||
@@ -69,6 +88,7 @@ test('Read options from package.json', async t => {
|
||||
branch: 'test_branch',
|
||||
repositoryUrl: 'https://host.null/owner/module.git',
|
||||
tagFormat: `v\${version}`,
|
||||
plugins: false,
|
||||
};
|
||||
// Create package.json in repository root
|
||||
await outputJson(path.resolve(cwd, 'package.json'), {release: options});
|
||||
@@ -89,6 +109,7 @@ test('Read options from .releaserc.yml', async t => {
|
||||
branch: 'test_branch',
|
||||
repositoryUrl: 'https://host.null/owner/module.git',
|
||||
tagFormat: `v\${version}`,
|
||||
plugins: false,
|
||||
};
|
||||
// Create package.json in repository root
|
||||
await writeFile(path.resolve(cwd, '.releaserc.yml'), yaml.safeDump(options));
|
||||
@@ -109,6 +130,7 @@ test('Read options from .releaserc.json', async t => {
|
||||
branch: 'test_branch',
|
||||
repositoryUrl: 'https://host.null/owner/module.git',
|
||||
tagFormat: `v\${version}`,
|
||||
plugins: false,
|
||||
};
|
||||
// Create package.json in repository root
|
||||
await outputJson(path.resolve(cwd, '.releaserc.json'), options);
|
||||
@@ -129,6 +151,7 @@ test('Read options from .releaserc.js', async t => {
|
||||
branch: 'test_branch',
|
||||
repositoryUrl: 'https://host.null/owner/module.git',
|
||||
tagFormat: `v\${version}`,
|
||||
plugins: false,
|
||||
};
|
||||
// Create package.json in repository root
|
||||
await writeFile(path.resolve(cwd, '.releaserc.js'), `module.exports = ${JSON.stringify(options)}`);
|
||||
@@ -149,6 +172,7 @@ test('Read options from release.config.js', async t => {
|
||||
branch: 'test_branch',
|
||||
repositoryUrl: 'https://host.null/owner/module.git',
|
||||
tagFormat: `v\${version}`,
|
||||
plugins: false,
|
||||
};
|
||||
// Create package.json in repository root
|
||||
await writeFile(path.resolve(cwd, 'release.config.js'), `module.exports = ${JSON.stringify(options)}`);
|
||||
@@ -176,6 +200,7 @@ test('Prioritise CLI/API parameters over file configuration and git repo', async
|
||||
branch: 'branch_cli',
|
||||
repositoryUrl: 'http://cli-url.com/owner/package',
|
||||
tagFormat: `cli\${version}`,
|
||||
plugins: false,
|
||||
};
|
||||
const pkg = {release: pkgOptions, repository: 'git@host.null:owner/module.git'};
|
||||
// Create package.json in repository root
|
||||
@@ -199,6 +224,7 @@ test('Read configuration from file path in "extends"', async t => {
|
||||
branch: 'test_branch',
|
||||
repositoryUrl: 'https://host.null/owner/module.git',
|
||||
tagFormat: `v\${version}`,
|
||||
plugins: ['plugin-1', ['plugin-2', {plugin2Opt: 'value'}]],
|
||||
};
|
||||
// Create package.json and shareable.json in repository root
|
||||
await outputJson(path.resolve(cwd, 'package.json'), {release: pkgOptions});
|
||||
@@ -213,6 +239,8 @@ test('Read configuration from file path in "extends"', async t => {
|
||||
t.deepEqual(t.context.plugins.args[0][1], {
|
||||
analyzeCommits: './shareable.json',
|
||||
generateNotes: './shareable.json',
|
||||
'plugin-1': './shareable.json',
|
||||
'plugin-2': './shareable.json',
|
||||
});
|
||||
});
|
||||
|
||||
@@ -226,6 +254,7 @@ test('Read configuration from module path in "extends"', async t => {
|
||||
branch: 'test_branch',
|
||||
repositoryUrl: 'https://host.null/owner/module.git',
|
||||
tagFormat: `v\${version}`,
|
||||
plugins: false,
|
||||
};
|
||||
// Create package.json and shareable.json in repository root
|
||||
await outputJson(path.resolve(cwd, 'package.json'), {release: pkgOptions});
|
||||
@@ -259,6 +288,7 @@ test('Read configuration from an array of paths in "extends"', async t => {
|
||||
analyzeCommits: {path: 'analyzeCommits2', param: 'analyzeCommits_param2'},
|
||||
branch: 'test_branch',
|
||||
tagFormat: `v\${version}`,
|
||||
plugins: false,
|
||||
};
|
||||
// Create package.json and shareable.json in repository root
|
||||
await outputJson(path.resolve(cwd, 'package.json'), {release: pkgOptions});
|
||||
@@ -296,6 +326,7 @@ test('Prioritize configuration from config file over "extends"', async t => {
|
||||
branch: 'test_branch',
|
||||
repositoryUrl: 'https://host.null/owner/module.git',
|
||||
tagFormat: `v\${version}`,
|
||||
plugins: false,
|
||||
};
|
||||
// Create package.json and shareable.json in repository root
|
||||
await outputJson(path.resolve(cwd, 'package.json'), {release: pkgOptions});
|
||||
@@ -341,6 +372,7 @@ test('Prioritize configuration from cli/API options over "extends"', async t =>
|
||||
publish: [{path: 'publishShareable', param: 'publishShareable_param2'}],
|
||||
branch: 'test_branch2',
|
||||
tagFormat: `v\${version}`,
|
||||
plugins: false,
|
||||
};
|
||||
// Create package.json, shareable1.json and shareable2.json in repository root
|
||||
await outputJson(path.resolve(cwd, 'package.json'), {release: pkgOptions});
|
||||
@@ -366,11 +398,13 @@ test('Allow to unset properties defined in shareable config with "null"', async
|
||||
analyzeCommits: null,
|
||||
branch: 'test_branch',
|
||||
repositoryUrl: 'https://host.null/owner/module.git',
|
||||
plugins: null,
|
||||
};
|
||||
const options1 = {
|
||||
generateNotes: 'generateNotes',
|
||||
analyzeCommits: {path: 'analyzeCommits', param: 'analyzeCommits_param'},
|
||||
tagFormat: `v\${version}`,
|
||||
plugins: ['test-plugin'],
|
||||
};
|
||||
// Create package.json and shareable.json in repository root
|
||||
await outputJson(path.resolve(cwd, 'package.json'), {release: pkgOptions});
|
||||
@@ -378,19 +412,25 @@ test('Allow to unset properties defined in shareable config with "null"', async
|
||||
|
||||
const {options} = await t.context.getConfig({cwd});
|
||||
|
||||
// Verify the options contains the plugin config from shareable.json
|
||||
t.deepEqual(options, {...omit(options1, 'analyzeCommits'), ...omit(pkgOptions, ['extends', 'analyzeCommits'])});
|
||||
// Verify the plugins module is called with the plugin options from shareable.json
|
||||
// Verify the options contains the plugin config from shareable.json and the default `plugins`
|
||||
t.deepEqual(options, {
|
||||
...omit(options1, ['analyzeCommits']),
|
||||
...omit(pkgOptions, ['extends', 'analyzeCommits']),
|
||||
plugins: DEFAULT_PLUGINS,
|
||||
});
|
||||
// Verify the plugins module is called with the plugin options from shareable.json and the default `plugins`
|
||||
t.deepEqual(t.context.plugins.args[0][0], {
|
||||
options: {
|
||||
...omit(options1, 'analyzeCommits'),
|
||||
...omit(pkgOptions, ['extends', 'analyzeCommits']),
|
||||
plugins: DEFAULT_PLUGINS,
|
||||
},
|
||||
cwd,
|
||||
});
|
||||
t.deepEqual(t.context.plugins.args[0][1], {
|
||||
generateNotes: './shareable.json',
|
||||
analyzeCommits: './shareable.json',
|
||||
'test-plugin': './shareable.json',
|
||||
});
|
||||
});
|
||||
|
||||
@@ -407,6 +447,7 @@ test('Allow to unset properties defined in shareable config with "undefined"', a
|
||||
generateNotes: 'generateNotes',
|
||||
analyzeCommits: {path: 'analyzeCommits', param: 'analyzeCommits_param'},
|
||||
tagFormat: `v\${version}`,
|
||||
plugins: false,
|
||||
};
|
||||
// Create package.json and release.config.js in repository root
|
||||
await writeFile(path.resolve(cwd, 'release.config.js'), `module.exports = ${format(pkgOptions)}`);
|
||||
@@ -439,7 +480,7 @@ test('Throw an Error if one of the shareable config cannot be found', async t =>
|
||||
await outputJson(path.resolve(cwd, 'package.json'), {release: pkhOptions});
|
||||
await outputJson(path.resolve(cwd, 'shareable1.json'), options1);
|
||||
|
||||
const error = await t.throws(t.context.getConfig({cwd}), Error);
|
||||
const error = await t.throwsAsync(t.context.getConfig({cwd}), Error);
|
||||
|
||||
t.is(error.message, "Cannot find module 'non-existing-path'");
|
||||
t.is(error.code, 'MODULE_NOT_FOUND');
|
||||
|
||||
@@ -101,6 +101,19 @@ test('Return the "https" formatted URL if "gitCredentials" is defined and reposi
|
||||
);
|
||||
});
|
||||
|
||||
test('Return the "https" formatted URL if "gitCredentials" is defined and repositoryUrl is a "git" URL without user', async t => {
|
||||
const {cwd} = await gitRepo();
|
||||
|
||||
t.is(
|
||||
await getAuthUrl({
|
||||
cwd,
|
||||
env: {...env, GIT_CREDENTIALS: 'user:pass'},
|
||||
options: {branch: 'master', repositoryUrl: 'host.null:owner/repo.git'},
|
||||
}),
|
||||
'https://user:pass@host.null/owner/repo.git'
|
||||
);
|
||||
});
|
||||
|
||||
test('Return the "https" formatted URL if "gitCredentials" is defined and repositoryUrl is a "https" URL', async t => {
|
||||
const {cwd} = await gitRepo();
|
||||
|
||||
@@ -231,6 +244,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();
|
||||
|
||||
|
||||
+32
-19
@@ -1,14 +1,14 @@
|
||||
import test from 'ava';
|
||||
import tempy from 'tempy';
|
||||
import {
|
||||
gitTagHead,
|
||||
getTagHead,
|
||||
isRefInHistory,
|
||||
fetch,
|
||||
gitHead,
|
||||
getGitHead,
|
||||
repoUrl,
|
||||
tag,
|
||||
push,
|
||||
gitTags,
|
||||
getTags,
|
||||
isGitRepo,
|
||||
verifyTagName,
|
||||
isBranchUpToDate,
|
||||
@@ -33,7 +33,7 @@ test('Get the last commit sha', async t => {
|
||||
// Add commits to the master branch
|
||||
const commits = await gitCommits(['First'], {cwd});
|
||||
|
||||
const result = await gitHead({cwd});
|
||||
const result = await getGitHead({cwd});
|
||||
|
||||
t.is(result, commits[0].hash);
|
||||
});
|
||||
@@ -42,7 +42,7 @@ test('Throw error if the last commit sha cannot be found', async t => {
|
||||
// Create a git repository, set the current working directory at the root of the repo
|
||||
const {cwd} = await gitRepo();
|
||||
|
||||
await t.throws(gitHead({cwd}), Error);
|
||||
await t.throwsAsync(getGitHead({cwd}), Error);
|
||||
});
|
||||
|
||||
test('Unshallow and fetch repository', async t => {
|
||||
@@ -67,7 +67,7 @@ test('Do not throw error when unshallow a complete repository', async t => {
|
||||
const {cwd, repositoryUrl} = await gitRepo();
|
||||
// Add commits to the master branch
|
||||
await gitCommits(['First'], {cwd});
|
||||
await t.notThrows(fetch(repositoryUrl, {cwd}));
|
||||
await t.notThrowsAsync(fetch(repositoryUrl, {cwd}));
|
||||
});
|
||||
|
||||
test('Fetch all tags on a detached head repository', async t => {
|
||||
@@ -84,7 +84,7 @@ test('Fetch all tags on a detached head repository', async t => {
|
||||
|
||||
await fetch(repositoryUrl, {cwd});
|
||||
|
||||
t.deepEqual((await gitTags({cwd})).sort(), ['v1.0.0', 'v1.0.1', 'v1.1.0'].sort());
|
||||
t.deepEqual((await getTags({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 => {
|
||||
@@ -100,7 +100,7 @@ test('Verify if the commit `sha` is in the direct history of the current branch'
|
||||
|
||||
t.true(await isRefInHistory(commits[0].hash, {cwd}));
|
||||
t.falsy(await isRefInHistory(otherCommits[0].hash, {cwd}));
|
||||
await t.throws(isRefInHistory('non-existant-sha', {cwd}));
|
||||
await t.throwsAsync(isRefInHistory('non-existant-sha', {cwd}));
|
||||
});
|
||||
|
||||
test('Get the commit sha for a given tag or falsy if the tag does not exists', async t => {
|
||||
@@ -111,8 +111,8 @@ test('Get the commit sha for a given tag or falsy if the tag does not exists', a
|
||||
// Create the tag corresponding to version 1.0.0
|
||||
await gitTagVersion('v1.0.0', undefined, {cwd});
|
||||
|
||||
t.is(await gitTagHead('v1.0.0', {cwd}), commits[0].hash);
|
||||
t.falsy(await gitTagHead('missing_tag', {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 => {
|
||||
@@ -151,13 +151,27 @@ test('Add tag on head commit', async t => {
|
||||
await t.is(await gitCommitTag(commits[0].hash, {cwd}), 'tag_name');
|
||||
});
|
||||
|
||||
test('Push tag and commit to remote repository', async t => {
|
||||
test('Push tag to remote repository', async t => {
|
||||
// Create a git repository with a remote, set the current working directory at the root of the repo
|
||||
const {cwd, repositoryUrl} = await gitRepo(true);
|
||||
const commits = await gitCommits(['Test commit'], {cwd});
|
||||
|
||||
await tag('tag_name', {cwd});
|
||||
await push(repositoryUrl, 'master', {cwd});
|
||||
await push(repositoryUrl, {cwd});
|
||||
|
||||
t.is(await gitRemoteTagHead(repositoryUrl, 'tag_name', {cwd}), commits[0].hash);
|
||||
});
|
||||
|
||||
test('Push tag to remote repository with remote branch ahaed', async t => {
|
||||
const {cwd, repositoryUrl} = await gitRepo(true);
|
||||
const commits = await gitCommits(['First'], {cwd});
|
||||
await gitPush(repositoryUrl, 'master', {cwd});
|
||||
const tmpRepo = await gitShallowClone(repositoryUrl);
|
||||
await gitCommits(['Second'], {cwd: tmpRepo});
|
||||
await gitPush('origin', 'master', {cwd: tmpRepo});
|
||||
|
||||
await tag('tag_name', {cwd});
|
||||
await push(repositoryUrl, {cwd});
|
||||
|
||||
t.is(await gitRemoteTagHead(repositoryUrl, 'tag_name', {cwd}), commits[0].hash);
|
||||
});
|
||||
@@ -192,7 +206,7 @@ test('Return falsy for invalid tag names', async t => {
|
||||
test('Throws error if obtaining the tags fails', async t => {
|
||||
const cwd = tempy.directory();
|
||||
|
||||
await t.throws(gitTags({cwd}));
|
||||
await t.throwsAsync(getTags({cwd}));
|
||||
});
|
||||
|
||||
test('Return "true" if repository is up to date', async t => {
|
||||
@@ -204,19 +218,18 @@ test('Return "true" if repository is up to date', async t => {
|
||||
});
|
||||
|
||||
test('Return falsy if repository is not up to date', async t => {
|
||||
let {cwd, repositoryUrl} = await gitRepo(true);
|
||||
const repoDir = cwd;
|
||||
const {cwd, repositoryUrl} = await gitRepo(true);
|
||||
await gitCommits(['First'], {cwd});
|
||||
await gitCommits(['Second'], {cwd});
|
||||
await gitPush(repositoryUrl, 'master', {cwd});
|
||||
|
||||
t.true(await isBranchUpToDate('master', {cwd}));
|
||||
|
||||
cwd = await gitShallowClone(repositoryUrl);
|
||||
await gitCommits(['Third'], {cwd});
|
||||
await gitPush('origin', 'master', {cwd});
|
||||
const tmpRepo = await gitShallowClone(repositoryUrl);
|
||||
await gitCommits(['Third'], {cwd: tmpRepo});
|
||||
await gitPush('origin', 'master', {cwd: tmpRepo});
|
||||
|
||||
t.falsy(await isBranchUpToDate('master', {cwd: repoDir}));
|
||||
t.falsy(await isBranchUpToDate('master', {cwd}));
|
||||
});
|
||||
|
||||
test('Return "true" if local repository is ahead', async t => {
|
||||
|
||||
@@ -26,7 +26,7 @@ import getStream from 'get-stream';
|
||||
export async function gitRepo(withRemote, branch = 'master') {
|
||||
let cwd = tempy.directory();
|
||||
|
||||
await execa('git', ['init'].concat(withRemote ? ['--bare'] : []), {cwd});
|
||||
await execa('git', ['init', ...(withRemote ? ['--bare'] : [])], {cwd});
|
||||
|
||||
const repositoryUrl = fileUrl(cwd);
|
||||
if (withRemote) {
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
import nock from 'nock';
|
||||
|
||||
/**
|
||||
* Retun a `nock` object setup to respond to a github authentication request. Other expectation and responses can be chained.
|
||||
*
|
||||
* @param {String} [githubToken='GH_TOKEN'] The github token to return in the authentication response.
|
||||
* @param {String} [githubUrl='https://api.github.com'] The url on which to intercept http requests.
|
||||
* @return {Object} A `nock` object ready to respond to a github authentication request.
|
||||
*/
|
||||
export default function authenticate({
|
||||
githubToken = 'GH_TOKEN',
|
||||
githubUrl = 'https://api.github.com',
|
||||
githubApiPathPrefix = '',
|
||||
} = {}) {
|
||||
return nock(`${githubUrl}/${githubApiPathPrefix}`, {reqheaders: {Authorization: `token ${githubToken}`}});
|
||||
}
|
||||
+55
-34
@@ -1,5 +1,5 @@
|
||||
import test from 'ava';
|
||||
import {escapeRegExp, isString} from 'lodash';
|
||||
import {escapeRegExp, isString, sortBy} from 'lodash';
|
||||
import proxyquire from 'proxyquire';
|
||||
import {spy, stub} from 'sinon';
|
||||
import {WritableStreamBuffer} from 'stream-buffers';
|
||||
@@ -25,10 +25,12 @@ test.beforeEach(t => {
|
||||
t.context.log = spy();
|
||||
t.context.error = spy();
|
||||
t.context.success = spy();
|
||||
t.context.warn = spy();
|
||||
t.context.logger = {
|
||||
log: t.context.log,
|
||||
error: t.context.error,
|
||||
success: t.context.success,
|
||||
warn: t.context.warn,
|
||||
scope: () => t.context.logger,
|
||||
};
|
||||
});
|
||||
@@ -64,6 +66,7 @@ test('Plugins are called with expected values', async t => {
|
||||
const config = {branch: 'master', repositoryUrl, globalOpt: 'global', tagFormat: `v\${version}`};
|
||||
const options = {
|
||||
...config,
|
||||
plugins: false,
|
||||
verifyConditions: [verifyConditions1, verifyConditions2],
|
||||
analyzeCommits,
|
||||
verifyRelease,
|
||||
@@ -166,7 +169,7 @@ test('Plugins are called with expected values', async t => {
|
||||
t.deepEqual(success.args[0][1].commits[0].message, commits[0].message);
|
||||
t.deepEqual(success.args[0][1].nextRelease, {...nextRelease, notes: `${notes1}\n\n${notes2}\n\n${notes3}`});
|
||||
t.deepEqual(success.args[0][1].releases, [
|
||||
{...release1, ...nextRelease, notes: `${notes1}\n\n${notes2}\n\n${notes3}`, pluginName: '[Function: proxy]'},
|
||||
{...release1, ...nextRelease, notes: `${notes1}\n\n${notes2}\n\n${notes3}`, pluginName: '[Function: functionStub]'},
|
||||
{...nextRelease, notes: `${notes1}\n\n${notes2}\n\n${notes3}`, pluginName: pluginNoop},
|
||||
]);
|
||||
|
||||
@@ -175,7 +178,12 @@ test('Plugins are called with expected values', async t => {
|
||||
commits: [commits[0]],
|
||||
nextRelease: {...nextRelease, notes: `${notes1}\n\n${notes2}\n\n${notes3}`},
|
||||
releases: [
|
||||
{...release1, ...nextRelease, notes: `${notes1}\n\n${notes2}\n\n${notes3}`, pluginName: '[Function: proxy]'},
|
||||
{
|
||||
...release1,
|
||||
...nextRelease,
|
||||
notes: `${notes1}\n\n${notes2}\n\n${notes3}`,
|
||||
pluginName: '[Function: functionStub]',
|
||||
},
|
||||
{...nextRelease, notes: `${notes1}\n\n${notes2}\n\n${notes3}`, pluginName: pluginNoop},
|
||||
],
|
||||
});
|
||||
@@ -334,15 +342,19 @@ test('Call all "success" plugins even if one errors out', async t => {
|
||||
'env-ci': () => ({isCi: true, branch: 'master', isPr: false}),
|
||||
});
|
||||
|
||||
await t.throws(
|
||||
await t.throwsAsync(
|
||||
semanticRelease(options, {cwd, env: {}, stdout: new WritableStreamBuffer(), stderr: new WritableStreamBuffer()})
|
||||
);
|
||||
|
||||
t.is(success1.callCount, 1);
|
||||
t.deepEqual(success1.args[0][1].releases, [{...release, ...nextRelease, notes, pluginName: '[Function: proxy]'}]);
|
||||
t.deepEqual(success1.args[0][1].releases, [
|
||||
{...release, ...nextRelease, notes, pluginName: '[Function: functionStub]'},
|
||||
]);
|
||||
|
||||
t.is(success2.callCount, 1);
|
||||
t.deepEqual(success2.args[0][1].releases, [{...release, ...nextRelease, notes, pluginName: '[Function: proxy]'}]);
|
||||
t.deepEqual(success2.args[0][1].releases, [
|
||||
{...release, ...nextRelease, notes, pluginName: '[Function: functionStub]'},
|
||||
]);
|
||||
});
|
||||
|
||||
test('Log all "verifyConditions" errors', async t => {
|
||||
@@ -359,6 +371,7 @@ test('Log all "verifyConditions" errors', async t => {
|
||||
const config = {branch: 'master', repositoryUrl, tagFormat: `v\${version}`};
|
||||
const options = {
|
||||
...config,
|
||||
plugins: false,
|
||||
verifyConditions: [stub().rejects(new AggregateError([error1, error2])), stub().rejects(error3)],
|
||||
fail,
|
||||
};
|
||||
@@ -368,18 +381,15 @@ test('Log all "verifyConditions" errors', async t => {
|
||||
'env-ci': () => ({isCi: true, branch: 'master', isPr: false}),
|
||||
});
|
||||
const errors = [
|
||||
...(await t.throws(
|
||||
...(await t.throwsAsync(
|
||||
semanticRelease(options, {cwd, env: {}, stdout: new WritableStreamBuffer(), stderr: new WritableStreamBuffer()})
|
||||
)),
|
||||
];
|
||||
|
||||
t.deepEqual(errors, [error1, error2, error3]);
|
||||
t.deepEqual(t.context.error.args[t.context.error.args.length - 2], ['ERR2 error 2']);
|
||||
t.deepEqual(t.context.error.args[t.context.error.args.length - 1], ['ERR3 error 3']);
|
||||
t.deepEqual(t.context.error.args[t.context.error.args.length - 3], [
|
||||
'An error occurred while running semantic-release: %O',
|
||||
error1,
|
||||
]);
|
||||
t.deepEqual(sortBy(errors, ['message']), sortBy([error1, error2, error3], ['message']));
|
||||
t.true(t.context.error.calledWith('An error occurred while running semantic-release: %O', error1));
|
||||
t.true(t.context.error.calledWith('ERR2 error 2'));
|
||||
t.true(t.context.error.calledWith('ERR3 error 3'));
|
||||
t.true(t.context.error.calledAfter(t.context.log));
|
||||
t.is(fail.callCount, 1);
|
||||
t.deepEqual(fail.args[0][0], config);
|
||||
@@ -416,20 +426,20 @@ test('Log all "verifyRelease" errors', async t => {
|
||||
'env-ci': () => ({isCi: true, branch: 'master', isPr: false}),
|
||||
});
|
||||
const errors = [
|
||||
...(await t.throws(
|
||||
...(await t.throwsAsync(
|
||||
semanticRelease(options, {cwd, env: {}, stdout: new WritableStreamBuffer(), stderr: new WritableStreamBuffer()})
|
||||
)),
|
||||
];
|
||||
|
||||
t.deepEqual(errors, [error1, error2]);
|
||||
t.deepEqual(t.context.error.args[t.context.error.args.length - 2], ['ERR1 error 1']);
|
||||
t.deepEqual(t.context.error.args[t.context.error.args.length - 1], ['ERR2 error 2']);
|
||||
t.deepEqual(sortBy(errors, ['message']), sortBy([error1, error2], ['message']));
|
||||
t.true(t.context.error.calledWith('ERR1 error 1'));
|
||||
t.true(t.context.error.calledWith('ERR2 error 2'));
|
||||
t.is(fail.callCount, 1);
|
||||
t.deepEqual(fail.args[0][0], config);
|
||||
t.deepEqual(fail.args[0][1].errors, [error1, error2]);
|
||||
});
|
||||
|
||||
test('Dry-run skips publish and success', async t => {
|
||||
test('Dry-run skips prepare, publish and success', async t => {
|
||||
// Create a git repository, set the current working directory at the root of the repo
|
||||
const {cwd, repositoryUrl} = await gitRepo(true);
|
||||
// Add commits to the master branch
|
||||
@@ -447,6 +457,7 @@ test('Dry-run skips publish and success', async t => {
|
||||
const analyzeCommits = stub().resolves(nextRelease.type);
|
||||
const verifyRelease = stub().resolves();
|
||||
const generateNotes = stub().resolves(notes);
|
||||
const prepare = stub().resolves();
|
||||
const publish = stub().resolves();
|
||||
const success = stub().resolves();
|
||||
|
||||
@@ -458,7 +469,7 @@ test('Dry-run skips publish and success', async t => {
|
||||
analyzeCommits,
|
||||
verifyRelease,
|
||||
generateNotes,
|
||||
prepare: stub().resolves(),
|
||||
prepare,
|
||||
publish,
|
||||
success,
|
||||
};
|
||||
@@ -476,13 +487,17 @@ test('Dry-run skips publish and success', async t => {
|
||||
})
|
||||
);
|
||||
|
||||
t.not(t.context.log.args[0][0], 'This run was not triggered in a known CI environment, running in dry-run mode.');
|
||||
t.not(t.context.warn.args[0][0], 'This run was not triggered in a known CI environment, running in dry-run mode.');
|
||||
t.is(verifyConditions.callCount, 1);
|
||||
t.is(analyzeCommits.callCount, 1);
|
||||
t.is(verifyRelease.callCount, 1);
|
||||
t.is(generateNotes.callCount, 1);
|
||||
t.is(prepare.callCount, 0);
|
||||
t.true(t.context.warn.calledWith(`Skip step "prepare" of plugin "[Function: ${prepare.name}]" in dry-run mode`));
|
||||
t.is(publish.callCount, 0);
|
||||
t.true(t.context.warn.calledWith(`Skip step "publish" of plugin "[Function: ${publish.name}]" in dry-run mode`));
|
||||
t.is(success.callCount, 0);
|
||||
t.true(t.context.warn.calledWith(`Skip step "success" of plugin "[Function: ${success.name}]" in dry-run mode`));
|
||||
});
|
||||
|
||||
test('Dry-run skips fail', async t => {
|
||||
@@ -513,15 +528,16 @@ test('Dry-run skips fail', async t => {
|
||||
'env-ci': () => ({isCi: true, branch: 'master', isPr: false}),
|
||||
});
|
||||
const errors = [
|
||||
...(await t.throws(
|
||||
...(await t.throwsAsync(
|
||||
semanticRelease(options, {cwd, env: {}, stdout: new WritableStreamBuffer(), stderr: new WritableStreamBuffer()})
|
||||
)),
|
||||
];
|
||||
|
||||
t.deepEqual(errors, [error1, error2]);
|
||||
t.deepEqual(t.context.error.args[t.context.error.args.length - 2], ['ERR1 error 1']);
|
||||
t.deepEqual(t.context.error.args[t.context.error.args.length - 1], ['ERR2 error 2']);
|
||||
t.deepEqual(sortBy(errors, ['message']), sortBy([error1, error2], ['message']));
|
||||
t.true(t.context.error.calledWith('ERR1 error 1'));
|
||||
t.true(t.context.error.calledWith('ERR2 error 2'));
|
||||
t.is(fail.callCount, 0);
|
||||
t.true(t.context.warn.calledWith(`Skip step "fail" of plugin "[Function: ${fail.name}]" in dry-run mode`));
|
||||
});
|
||||
|
||||
test('Force a dry-run if not on a CI and "noCi" is not explicitly set', async t => {
|
||||
@@ -572,7 +588,7 @@ test('Force a dry-run if not on a CI and "noCi" is not explicitly set', async t
|
||||
})
|
||||
);
|
||||
|
||||
t.is(t.context.log.args[1][0], 'This run was not triggered in a known CI environment, running in dry-run mode.');
|
||||
t.true(t.context.warn.calledWith('This run was not triggered in a known CI environment, running in dry-run mode.'));
|
||||
t.is(verifyConditions.callCount, 1);
|
||||
t.is(analyzeCommits.callCount, 1);
|
||||
t.is(verifyRelease.callCount, 1);
|
||||
@@ -686,7 +702,7 @@ test('Allow local releases with "noCi" option', async t => {
|
||||
t.is(success.callCount, 1);
|
||||
});
|
||||
|
||||
test('Accept "undefined" value returned by the "generateNotes" plugins', async t => {
|
||||
test('Accept "undefined" value returned by "generateNotes" and "false" by "publish"', async t => {
|
||||
// Create a git repository, set the current working directory at the root of the repo
|
||||
const {cwd, repositoryUrl} = await gitRepo(true);
|
||||
// Add commits to the master branch
|
||||
@@ -704,7 +720,8 @@ test('Accept "undefined" value returned by the "generateNotes" plugins', async t
|
||||
const generateNotes1 = stub().resolves();
|
||||
const notes2 = 'Release notes 2';
|
||||
const generateNotes2 = stub().resolves(notes2);
|
||||
const publish = stub().resolves();
|
||||
const publish = stub().resolves(false);
|
||||
const success = stub().resolves();
|
||||
|
||||
const options = {
|
||||
branch: 'master',
|
||||
@@ -715,7 +732,7 @@ test('Accept "undefined" value returned by the "generateNotes" plugins', async t
|
||||
generateNotes: [generateNotes1, generateNotes2],
|
||||
prepare: stub().resolves(),
|
||||
publish,
|
||||
success: stub().resolves(),
|
||||
success,
|
||||
fail: stub().resolves(),
|
||||
};
|
||||
|
||||
@@ -747,6 +764,9 @@ test('Accept "undefined" value returned by the "generateNotes" plugins', async t
|
||||
t.is(publish.callCount, 1);
|
||||
t.deepEqual(publish.args[0][1].lastRelease, lastRelease);
|
||||
t.is(publish.args[0][1].nextRelease.notes, notes2);
|
||||
|
||||
t.is(success.callCount, 1);
|
||||
t.deepEqual(success.args[0][1].releases, [{pluginName: '[Function: functionStub]'}]);
|
||||
});
|
||||
|
||||
test('Returns false if triggered by a PR', async t => {
|
||||
@@ -946,7 +966,7 @@ test('Log both plugins errors and errors thrown by "fail" plugin', async t => {
|
||||
'env-ci': () => ({isCi: true, branch: 'master', isPr: false}),
|
||||
});
|
||||
|
||||
await t.throws(
|
||||
await t.throwsAsync(
|
||||
semanticRelease(options, {cwd, env: {}, stdout: new WritableStreamBuffer(), stderr: new WritableStreamBuffer()})
|
||||
);
|
||||
|
||||
@@ -971,7 +991,7 @@ test('Call "fail" only if a plugin returns a SemanticReleaseError', async t => {
|
||||
'env-ci': () => ({isCi: true, branch: 'master', isPr: false}),
|
||||
});
|
||||
|
||||
await t.throws(
|
||||
await t.throwsAsync(
|
||||
semanticRelease(options, {cwd, env: {}, stdout: new WritableStreamBuffer(), stderr: new WritableStreamBuffer()})
|
||||
);
|
||||
|
||||
@@ -988,7 +1008,7 @@ test('Throw SemanticReleaseError if repositoryUrl is not set and cannot be found
|
||||
'env-ci': () => ({isCi: true, branch: 'master', isPr: false}),
|
||||
});
|
||||
const errors = [
|
||||
...(await t.throws(
|
||||
...(await t.throwsAsync(
|
||||
semanticRelease({}, {cwd, env: {}, stdout: new WritableStreamBuffer(), stderr: new WritableStreamBuffer()})
|
||||
)),
|
||||
];
|
||||
@@ -1025,7 +1045,7 @@ test('Throw an Error if plugin returns an unexpected value', async t => {
|
||||
'./lib/get-logger': () => t.context.logger,
|
||||
'env-ci': () => ({isCi: true, branch: 'master', isPr: false}),
|
||||
});
|
||||
const error = await t.throws(
|
||||
const error = await t.throwsAsync(
|
||||
semanticRelease(options, {cwd, env: {}, stdout: new WritableStreamBuffer(), stderr: new WritableStreamBuffer()}),
|
||||
Error
|
||||
);
|
||||
@@ -1055,7 +1075,7 @@ test('Hide sensitive information passed to "fail" plugin', async t => {
|
||||
'./lib/get-logger': () => t.context.logger,
|
||||
'env-ci': () => ({isCi: true, branch: 'master', isPr: false}),
|
||||
});
|
||||
await t.throws(
|
||||
await t.throwsAsync(
|
||||
semanticRelease(options, {cwd, env, stdout: new WritableStreamBuffer(), stderr: new WritableStreamBuffer()}),
|
||||
Error
|
||||
);
|
||||
@@ -1087,6 +1107,7 @@ test('Hide sensitive information passed to "success" plugin', async t => {
|
||||
verifyConditions: false,
|
||||
verifyRelease: false,
|
||||
prepare: false,
|
||||
generateNotes: stub().resolves(`Exposing token ${env.MY_TOKEN}`),
|
||||
publish: stub().resolves({
|
||||
name: `Name: Exposing token ${env.MY_TOKEN}`,
|
||||
url: `URL: Exposing token ${env.MY_TOKEN}`,
|
||||
|
||||
+39
-39
@@ -6,7 +6,7 @@ import {writeJson, readJson} from 'fs-extra';
|
||||
import execa from 'execa';
|
||||
import {WritableStreamBuffer} from 'stream-buffers';
|
||||
import {SECRET_REPLACEMENT} from '../lib/definitions/constants';
|
||||
import {gitHead as getGitHead, gitTagHead, gitRepo, gitCommits, gitRemoteTagHead, gitPush} from './helpers/git-utils';
|
||||
import {gitHead, gitTagHead, gitRepo, gitCommits, gitRemoteTagHead, gitPush} from './helpers/git-utils';
|
||||
import gitbox from './helpers/gitbox';
|
||||
import mockServer from './helpers/mockserver';
|
||||
import npmRegistry from './helpers/npm-registry';
|
||||
@@ -108,12 +108,12 @@ test('Release patch, minor and major versions', async t => {
|
||||
let [, releasedVersion, releasedGitHead] = /^version = '(.+)'\s+gitHead = '(.+)'$/.exec(
|
||||
(await execa('npm', ['show', packageName, 'version', 'gitHead'], {env: testEnv, cwd})).stdout
|
||||
);
|
||||
let gitHead = await getGitHead({cwd});
|
||||
let head = await gitHead({cwd});
|
||||
t.is(releasedVersion, version);
|
||||
t.is(releasedGitHead, gitHead);
|
||||
t.is(await gitTagHead(`v${version}`, {cwd}), gitHead);
|
||||
t.is(await gitRemoteTagHead(authUrl, `v${version}`, {cwd}), gitHead);
|
||||
t.log(`+ released ${releasedVersion} with gitHead ${releasedGitHead}`);
|
||||
t.is(releasedGitHead, head);
|
||||
t.is(await gitTagHead(`v${version}`, {cwd}), head);
|
||||
t.is(await gitRemoteTagHead(authUrl, `v${version}`, {cwd}), head);
|
||||
t.log(`+ released ${releasedVersion} with head ${releasedGitHead}`);
|
||||
|
||||
await mockServer.verify(verifyMock);
|
||||
await mockServer.verify(createReleaseMock);
|
||||
@@ -150,12 +150,12 @@ test('Release patch, minor and major versions', async t => {
|
||||
[, releasedVersion, releasedGitHead] = /^version = '(.+)'\s+gitHead = '(.+)'$/.exec(
|
||||
(await execa('npm', ['show', packageName, 'version', 'gitHead'], {env: testEnv, cwd})).stdout
|
||||
);
|
||||
gitHead = await getGitHead({cwd});
|
||||
head = await gitHead({cwd});
|
||||
t.is(releasedVersion, version);
|
||||
t.is(releasedGitHead, gitHead);
|
||||
t.is(await gitTagHead(`v${version}`, {cwd}), gitHead);
|
||||
t.is(await gitRemoteTagHead(authUrl, `v${version}`, {cwd}), gitHead);
|
||||
t.log(`+ released ${releasedVersion} with gitHead ${releasedGitHead}`);
|
||||
t.is(releasedGitHead, head);
|
||||
t.is(await gitTagHead(`v${version}`, {cwd}), head);
|
||||
t.is(await gitRemoteTagHead(authUrl, `v${version}`, {cwd}), head);
|
||||
t.log(`+ released ${releasedVersion} with head ${releasedGitHead}`);
|
||||
|
||||
await mockServer.verify(verifyMock);
|
||||
await mockServer.verify(createReleaseMock);
|
||||
@@ -192,12 +192,12 @@ test('Release patch, minor and major versions', async t => {
|
||||
[, releasedVersion, releasedGitHead] = /^version = '(.+)'\s+gitHead = '(.+)'$/.exec(
|
||||
(await execa('npm', ['show', packageName, 'version', 'gitHead'], {env: testEnv, cwd})).stdout
|
||||
);
|
||||
gitHead = await getGitHead({cwd});
|
||||
head = await gitHead({cwd});
|
||||
t.is(releasedVersion, version);
|
||||
t.is(releasedGitHead, gitHead);
|
||||
t.is(await gitTagHead(`v${version}`, {cwd}), gitHead);
|
||||
t.is(await gitRemoteTagHead(authUrl, `v${version}`, {cwd}), gitHead);
|
||||
t.log(`+ released ${releasedVersion} with gitHead ${releasedGitHead}`);
|
||||
t.is(releasedGitHead, head);
|
||||
t.is(await gitTagHead(`v${version}`, {cwd}), head);
|
||||
t.is(await gitRemoteTagHead(authUrl, `v${version}`, {cwd}), head);
|
||||
t.log(`+ released ${releasedVersion} with head ${releasedGitHead}`);
|
||||
|
||||
await mockServer.verify(verifyMock);
|
||||
await mockServer.verify(createReleaseMock);
|
||||
@@ -234,12 +234,12 @@ test('Release patch, minor and major versions', async t => {
|
||||
[, releasedVersion, releasedGitHead] = /^version = '(.+)'\s+gitHead = '(.+)'$/.exec(
|
||||
(await execa('npm', ['show', packageName, 'version', 'gitHead'], {env: testEnv, cwd})).stdout
|
||||
);
|
||||
gitHead = await getGitHead({cwd});
|
||||
head = await gitHead({cwd});
|
||||
t.is(releasedVersion, version);
|
||||
t.is(releasedGitHead, gitHead);
|
||||
t.is(await gitTagHead(`v${version}`, {cwd}), gitHead);
|
||||
t.is(await gitRemoteTagHead(authUrl, `v${version}`, {cwd}), gitHead);
|
||||
t.log(`+ released ${releasedVersion} with gitHead ${releasedGitHead}`);
|
||||
t.is(releasedGitHead, head);
|
||||
t.is(await gitTagHead(`v${version}`, {cwd}), head);
|
||||
t.is(await gitRemoteTagHead(authUrl, `v${version}`, {cwd}), head);
|
||||
t.log(`+ released ${releasedVersion} with head ${releasedGitHead}`);
|
||||
|
||||
await mockServer.verify(verifyMock);
|
||||
await mockServer.verify(createReleaseMock);
|
||||
@@ -258,7 +258,7 @@ test('Exit with 1 if a plugin is not found', async t => {
|
||||
release: {analyzeCommits: 'non-existing-path', success: false, fail: false},
|
||||
});
|
||||
|
||||
const {code, stderr} = await t.throws(execa(cli, [], {env, cwd}));
|
||||
const {code, stderr} = await t.throwsAsync(execa(cli, [], {env, cwd}));
|
||||
t.is(code, 1);
|
||||
t.regex(stderr, /Cannot find module/);
|
||||
});
|
||||
@@ -276,7 +276,7 @@ test('Exit with 1 if a shareable config is not found', async t => {
|
||||
release: {extends: 'non-existing-path', success: false, fail: false},
|
||||
});
|
||||
|
||||
const {code, stderr} = await t.throws(execa(cli, [], {env, cwd}));
|
||||
const {code, stderr} = await t.throwsAsync(execa(cli, [], {env, cwd}));
|
||||
t.is(code, 1);
|
||||
t.regex(stderr, /Cannot find module/);
|
||||
});
|
||||
@@ -297,7 +297,7 @@ test('Exit with 1 if a shareable config reference a not found plugin', async t =
|
||||
});
|
||||
await writeJson(path.resolve(cwd, 'shareable.json'), shareable);
|
||||
|
||||
const {code, stderr} = await t.throws(execa(cli, [], {env, cwd}));
|
||||
const {code, stderr} = await t.throwsAsync(execa(cli, [], {env, cwd}));
|
||||
t.is(code, 1);
|
||||
t.regex(stderr, /Cannot find module/);
|
||||
});
|
||||
@@ -388,12 +388,12 @@ test('Allow local releases with "noCi" option', async t => {
|
||||
(await execa('npm', ['show', packageName, 'version', 'gitHead'], {env: testEnv, cwd})).stdout
|
||||
);
|
||||
|
||||
const gitHead = await getGitHead({cwd});
|
||||
const head = await gitHead({cwd});
|
||||
t.is(releasedVersion, version);
|
||||
t.is(releasedGitHead, gitHead);
|
||||
t.is(await gitTagHead(`v${version}`, {cwd}), gitHead);
|
||||
t.is(await gitRemoteTagHead(authUrl, `v${version}`, {cwd}), gitHead);
|
||||
t.log(`+ released ${releasedVersion} with gitHead ${releasedGitHead}`);
|
||||
t.is(releasedGitHead, head);
|
||||
t.is(await gitTagHead(`v${version}`, {cwd}), head);
|
||||
t.is(await gitRemoteTagHead(authUrl, `v${version}`, {cwd}), head);
|
||||
t.log(`+ released ${releasedVersion} with head ${releasedGitHead}`);
|
||||
|
||||
await mockServer.verify(verifyMock);
|
||||
await mockServer.verify(createReleaseMock);
|
||||
@@ -442,12 +442,12 @@ test('Pass options via CLI arguments', async t => {
|
||||
const [, releasedVersion, releasedGitHead] = /^version = '(.+)'\s+gitHead = '(.+)'$/.exec(
|
||||
(await execa('npm', ['show', packageName, 'version', 'gitHead'], {env: testEnv, cwd})).stdout
|
||||
);
|
||||
const gitHead = await getGitHead({cwd});
|
||||
const head = await gitHead({cwd});
|
||||
t.is(releasedVersion, version);
|
||||
t.is(releasedGitHead, gitHead);
|
||||
t.is(await gitTagHead(`v${version}`, {cwd}), gitHead);
|
||||
t.is(await gitRemoteTagHead(authUrl, `v${version}`, {cwd}), gitHead);
|
||||
t.log(`+ released ${releasedVersion} with gitHead ${releasedGitHead}`);
|
||||
t.is(releasedGitHead, head);
|
||||
t.is(await gitTagHead(`v${version}`, {cwd}), head);
|
||||
t.is(await gitRemoteTagHead(authUrl, `v${version}`, {cwd}), head);
|
||||
t.log(`+ released ${releasedVersion} with head ${releasedGitHead}`);
|
||||
});
|
||||
|
||||
test('Run via JS API', async t => {
|
||||
@@ -500,12 +500,12 @@ test('Run via JS API', async t => {
|
||||
const [, releasedVersion, releasedGitHead] = /^version = '(.+)'\s+gitHead = '(.+)'$/.exec(
|
||||
(await execa('npm', ['show', packageName, 'version', 'gitHead'], {env: testEnv, cwd})).stdout
|
||||
);
|
||||
const gitHead = await getGitHead({cwd});
|
||||
const head = await gitHead({cwd});
|
||||
t.is(releasedVersion, version);
|
||||
t.is(releasedGitHead, gitHead);
|
||||
t.is(await gitTagHead(`v${version}`, {cwd}), gitHead);
|
||||
t.is(await gitRemoteTagHead(authUrl, `v${version}`, {cwd}), gitHead);
|
||||
t.log(`+ released ${releasedVersion} with gitHead ${releasedGitHead}`);
|
||||
t.is(releasedGitHead, head);
|
||||
t.is(await gitTagHead(`v${version}`, {cwd}), head);
|
||||
t.is(await gitRemoteTagHead(authUrl, `v${version}`, {cwd}), head);
|
||||
t.log(`+ released ${releasedVersion} with head ${releasedGitHead}`);
|
||||
|
||||
await mockServer.verify(verifyMock);
|
||||
await mockServer.verify(createReleaseMock);
|
||||
|
||||
@@ -62,7 +62,7 @@ test('Wrap plugin in a function that add the "pluginName" to the error"', async
|
||||
'./plugin-error': './test/fixtures',
|
||||
});
|
||||
|
||||
const error = await t.throws(plugin());
|
||||
const error = await t.throwsAsync(plugin({options: {}}));
|
||||
|
||||
t.is(error.pluginName, './plugin-error');
|
||||
});
|
||||
@@ -72,7 +72,7 @@ test('Wrap plugin in a function that add the "pluginName" to multiple errors"',
|
||||
'./plugin-errors': './test/fixtures',
|
||||
});
|
||||
|
||||
const errors = [...(await t.throws(plugin()))];
|
||||
const errors = [...(await t.throwsAsync(plugin({options: {}})))];
|
||||
for (const error of errors) {
|
||||
t.is(error.pluginName, './plugin-errors');
|
||||
}
|
||||
@@ -107,7 +107,7 @@ test('Wrap "analyzeCommits" plugin in a function that validate the output of the
|
||||
{}
|
||||
);
|
||||
|
||||
const error = await t.throws(plugin());
|
||||
const error = await t.throwsAsync(plugin({options: {}}));
|
||||
|
||||
t.is(error.code, 'EANALYZECOMMITSOUTPUT');
|
||||
t.is(error.name, 'SemanticReleaseError');
|
||||
@@ -125,7 +125,7 @@ test('Wrap "generateNotes" plugin in a function that validate the output of the
|
||||
{}
|
||||
);
|
||||
|
||||
const error = await t.throws(plugin());
|
||||
const error = await t.throwsAsync(plugin({options: {}}));
|
||||
|
||||
t.is(error.code, 'EGENERATENOTESOUTPUT');
|
||||
t.is(error.name, 'SemanticReleaseError');
|
||||
@@ -143,7 +143,7 @@ test('Wrap "publish" plugin in a function that validate the output of the plugin
|
||||
{}
|
||||
);
|
||||
|
||||
const error = await t.throws(plugin());
|
||||
const error = await t.throwsAsync(plugin({options: {}}));
|
||||
|
||||
t.is(error.code, 'EPUBLISHOUTPUT');
|
||||
t.is(error.name, 'SemanticReleaseError');
|
||||
@@ -152,12 +152,27 @@ test('Wrap "publish" plugin in a function that validate the output of the plugin
|
||||
t.regex(error.details, /2/);
|
||||
});
|
||||
|
||||
test('Plugin is called with "pluginConfig" (omitting "path", adding global config) and input', async t => {
|
||||
test('Plugin is called with "pluginConfig" (with object definition) and input', async t => {
|
||||
const pluginFunction = stub().resolves();
|
||||
const pluginConf = {path: pluginFunction, conf: 'confValue'};
|
||||
const options = {global: 'globalValue'};
|
||||
const plugin = normalize({cwd, options, logger: t.context.logger}, '', pluginConf, {});
|
||||
await plugin({param: 'param'});
|
||||
await plugin({options: {}, param: 'param'});
|
||||
|
||||
t.true(
|
||||
pluginFunction.calledWithMatch(
|
||||
{conf: 'confValue', global: 'globalValue'},
|
||||
{param: 'param', logger: t.context.logger}
|
||||
)
|
||||
);
|
||||
});
|
||||
|
||||
test('Plugin is called with "pluginConfig" (with array definition) and input', async t => {
|
||||
const pluginFunction = stub().resolves();
|
||||
const pluginConf = [pluginFunction, {conf: 'confValue'}];
|
||||
const options = {global: 'globalValue'};
|
||||
const plugin = normalize({cwd, options, logger: t.context.logger}, '', pluginConf, {});
|
||||
await plugin({options: {}, param: 'param'});
|
||||
|
||||
t.true(
|
||||
pluginFunction.calledWithMatch(
|
||||
@@ -174,7 +189,7 @@ test('Prevent plugins to modify "pluginConfig"', async t => {
|
||||
const pluginConf = {path: pluginFunction, conf: {subConf: 'originalConf'}};
|
||||
const options = {globalConf: {globalSubConf: 'originalGlobalConf'}};
|
||||
const plugin = normalize({cwd, options, logger: t.context.logger}, '', pluginConf, {});
|
||||
await plugin();
|
||||
await plugin({options: {}});
|
||||
|
||||
t.is(pluginConf.conf.subConf, 'originalConf');
|
||||
t.is(options.globalConf.globalSubConf, 'originalGlobalConf');
|
||||
@@ -184,7 +199,7 @@ test('Prevent plugins to modify its input', async t => {
|
||||
const pluginFunction = stub().callsFake((pluginConfig, options) => {
|
||||
options.param.subParam = 'otherParam';
|
||||
});
|
||||
const input = {param: {subParam: 'originalSubParam'}};
|
||||
const input = {param: {subParam: 'originalSubParam'}, options: {}};
|
||||
const plugin = normalize({cwd, options: {}, logger: t.context.logger}, '', pluginFunction, {});
|
||||
await plugin(input);
|
||||
|
||||
@@ -205,7 +220,7 @@ test('Always pass a defined "pluginConfig" for plugin defined with string', asyn
|
||||
'./test/fixtures/plugin-result-config',
|
||||
{}
|
||||
);
|
||||
const pluginResult = await plugin();
|
||||
const pluginResult = await plugin({options: {}});
|
||||
|
||||
t.deepEqual(pluginResult.pluginConfig, {});
|
||||
});
|
||||
@@ -218,7 +233,7 @@ test('Always pass a defined "pluginConfig" for plugin defined with path', async
|
||||
{path: './test/fixtures/plugin-result-config'},
|
||||
{}
|
||||
);
|
||||
const pluginResult = await plugin();
|
||||
const pluginResult = await plugin({options: {}});
|
||||
|
||||
t.deepEqual(pluginResult.pluginConfig, {});
|
||||
});
|
||||
|
||||
@@ -83,7 +83,7 @@ test('Stop execution and throw error if a step rejects', async t => {
|
||||
const step2 = stub().rejects(new Error('test error'));
|
||||
const step3 = stub().resolves(3);
|
||||
|
||||
const error = await t.throws(pipeline([step1, step2, step3])(0), Error);
|
||||
const error = await t.throwsAsync(pipeline([step1, step2, step3])(0), Error);
|
||||
t.is(error.message, 'test error');
|
||||
t.true(step1.calledWith(0));
|
||||
t.true(step2.calledWith(0));
|
||||
@@ -98,7 +98,7 @@ test('Throw all errors from the first step throwing an AggregateError', async t
|
||||
const step2 = stub().rejects(new AggregateError([error1, error2]));
|
||||
const step3 = stub().resolves(3);
|
||||
|
||||
const errors = await t.throws(pipeline([step1, step2, step3])(0));
|
||||
const errors = await t.throwsAsync(pipeline([step1, step2, step3])(0));
|
||||
|
||||
t.deepEqual([...errors], [error1, error2]);
|
||||
t.true(step1.calledWith(0));
|
||||
@@ -113,7 +113,7 @@ test('Execute all even if a Promise rejects', async t => {
|
||||
const step2 = stub().rejects(error1);
|
||||
const step3 = stub().rejects(error2);
|
||||
|
||||
const errors = await t.throws(pipeline([step1, step2, step3], {settleAll: true})(0));
|
||||
const errors = await t.throwsAsync(pipeline([step1, step2, step3], {settleAll: true})(0));
|
||||
|
||||
t.deepEqual([...errors], [error1, error2]);
|
||||
t.true(step1.calledWith(0));
|
||||
@@ -129,7 +129,7 @@ test('Throw all errors from all steps throwing an AggregateError', async t => {
|
||||
const step1 = stub().rejects(new AggregateError([error1, error2]));
|
||||
const step2 = stub().rejects(new AggregateError([error3, error4]));
|
||||
|
||||
const errors = await t.throws(pipeline([step1, step2], {settleAll: true})(0));
|
||||
const errors = await t.throwsAsync(pipeline([step1, step2], {settleAll: true})(0));
|
||||
|
||||
t.deepEqual([...errors], [error1, error2, error3, error4]);
|
||||
t.true(step1.calledWith(0));
|
||||
@@ -145,7 +145,7 @@ test('Execute each function in series passing a transformed input even if a step
|
||||
const step4 = stub().resolves(4);
|
||||
const getNextInput = (prevResult, result) => prevResult + result;
|
||||
|
||||
const errors = await t.throws(pipeline([step1, step2, step3, step4], {settleAll: true, getNextInput})(0));
|
||||
const errors = await t.throwsAsync(pipeline([step1, step2, step3, step4], {settleAll: true, getNextInput})(0));
|
||||
|
||||
t.deepEqual([...errors], [error2, error3]);
|
||||
t.true(step1.calledWith(0));
|
||||
|
||||
@@ -29,7 +29,7 @@ test('Export default plugins', t => {
|
||||
t.is(typeof plugins.fail, 'function');
|
||||
});
|
||||
|
||||
test('Export plugins based on config', t => {
|
||||
test('Export plugins based on steps config', t => {
|
||||
const plugins = getPlugins(
|
||||
{
|
||||
cwd,
|
||||
@@ -55,6 +55,88 @@ test('Export plugins based on config', t => {
|
||||
t.is(typeof plugins.fail, 'function');
|
||||
});
|
||||
|
||||
test('Export plugins based on "plugins" config (array)', async t => {
|
||||
const plugin1 = {verifyConditions: stub(), publish: stub()};
|
||||
const plugin2 = {verifyConditions: stub(), verifyRelease: stub()};
|
||||
const plugins = getPlugins(
|
||||
{cwd, logger: t.context.logger, options: {plugins: [plugin1, [plugin2, {}]], verifyRelease: () => {}}},
|
||||
{}
|
||||
);
|
||||
|
||||
await plugins.verifyConditions({options: {}});
|
||||
t.true(plugin1.verifyConditions.calledOnce);
|
||||
t.true(plugin2.verifyConditions.calledOnce);
|
||||
|
||||
await plugins.publish({options: {}});
|
||||
t.true(plugin1.publish.calledOnce);
|
||||
|
||||
await plugins.verifyRelease({options: {}});
|
||||
t.true(plugin2.verifyRelease.notCalled);
|
||||
|
||||
// Verify the module returns a function for each plugin
|
||||
t.is(typeof plugins.verifyConditions, 'function');
|
||||
t.is(typeof plugins.analyzeCommits, 'function');
|
||||
t.is(typeof plugins.verifyRelease, 'function');
|
||||
t.is(typeof plugins.generateNotes, 'function');
|
||||
t.is(typeof plugins.prepare, 'function');
|
||||
t.is(typeof plugins.publish, 'function');
|
||||
t.is(typeof plugins.success, 'function');
|
||||
t.is(typeof plugins.fail, 'function');
|
||||
});
|
||||
|
||||
test('Export plugins based on "plugins" config (single definition)', async t => {
|
||||
const plugin1 = {verifyConditions: stub(), publish: stub()};
|
||||
const plugins = getPlugins({cwd, logger: t.context.logger, options: {plugins: plugin1}}, {});
|
||||
|
||||
await plugins.verifyConditions({options: {}});
|
||||
t.true(plugin1.verifyConditions.calledOnce);
|
||||
|
||||
await plugins.publish({options: {}});
|
||||
t.true(plugin1.publish.calledOnce);
|
||||
|
||||
// Verify the module returns a function for each plugin
|
||||
t.is(typeof plugins.verifyConditions, 'function');
|
||||
t.is(typeof plugins.analyzeCommits, 'function');
|
||||
t.is(typeof plugins.verifyRelease, 'function');
|
||||
t.is(typeof plugins.generateNotes, 'function');
|
||||
t.is(typeof plugins.prepare, 'function');
|
||||
t.is(typeof plugins.publish, 'function');
|
||||
t.is(typeof plugins.success, 'function');
|
||||
t.is(typeof plugins.fail, 'function');
|
||||
});
|
||||
|
||||
test('Merge global options, "plugins" options and step options', async t => {
|
||||
const plugin1 = [{verifyConditions: stub(), publish: stub()}, {pluginOpt1: 'plugin1'}];
|
||||
const plugin2 = [{verifyConditions: stub()}, {pluginOpt2: 'plugin2'}];
|
||||
const plugin3 = [stub(), {pluginOpt3: 'plugin3'}];
|
||||
const plugins = getPlugins(
|
||||
{
|
||||
cwd,
|
||||
logger: t.context.logger,
|
||||
options: {globalOpt: 'global', plugins: [plugin1, plugin2], verifyRelease: [plugin3]},
|
||||
},
|
||||
{}
|
||||
);
|
||||
|
||||
await plugins.verifyConditions({options: {}});
|
||||
t.deepEqual(plugin1[0].verifyConditions.args[0][0], {globalOpt: 'global', pluginOpt1: 'plugin1'});
|
||||
t.deepEqual(plugin2[0].verifyConditions.args[0][0], {globalOpt: 'global', pluginOpt2: 'plugin2'});
|
||||
|
||||
await plugins.publish({options: {}});
|
||||
t.deepEqual(plugin1[0].publish.args[0][0], {globalOpt: 'global', pluginOpt1: 'plugin1'});
|
||||
|
||||
await plugins.verifyRelease({options: {}});
|
||||
t.deepEqual(plugin3[0].args[0][0], {globalOpt: 'global', pluginOpt3: 'plugin3'});
|
||||
});
|
||||
|
||||
test('Unknown steps of plugins configured in "plugins" are ignored', t => {
|
||||
const plugin1 = {verifyConditions: () => {}, unknown: () => {}};
|
||||
const plugins = getPlugins({cwd, logger: t.context.logger, options: {plugins: [plugin1]}}, {});
|
||||
|
||||
t.is(typeof plugins.verifyConditions, 'function');
|
||||
t.is(plugins.unknown, undefined);
|
||||
});
|
||||
|
||||
test('Export plugins loaded from the dependency of a shareable config module', async t => {
|
||||
const cwd = tempy.directory();
|
||||
await copy(
|
||||
@@ -121,11 +203,23 @@ test('Export plugins loaded from the dependency of a shareable config file', asy
|
||||
test('Use default when only options are passed for a single plugin', t => {
|
||||
const analyzeCommits = {};
|
||||
const generateNotes = {};
|
||||
const publish = {};
|
||||
const success = () => {};
|
||||
const fail = [() => {}];
|
||||
|
||||
const plugins = getPlugins(
|
||||
{cwd, logger: t.context.logger, options: {analyzeCommits, generateNotes, success, fail}},
|
||||
{
|
||||
cwd,
|
||||
logger: t.context.logger,
|
||||
options: {
|
||||
plugins: ['@semantic-release/commit-analyzer', '@semantic-release/release-notes-generator'],
|
||||
analyzeCommits,
|
||||
generateNotes,
|
||||
publish,
|
||||
success,
|
||||
fail,
|
||||
},
|
||||
},
|
||||
{}
|
||||
);
|
||||
|
||||
@@ -154,19 +248,25 @@ test('Merge global options with plugin options', async t => {
|
||||
{}
|
||||
);
|
||||
|
||||
const [result] = await plugins.verifyRelease();
|
||||
const [result] = await plugins.verifyRelease({options: {}});
|
||||
|
||||
t.deepEqual(result.pluginConfig, {localOpt: 'local', globalOpt: 'global', otherOpt: 'locally-defined'});
|
||||
});
|
||||
|
||||
test('Throw an error if plugins configuration are invalid', t => {
|
||||
test('Throw an error for each invalid plugin configuration', t => {
|
||||
const errors = [
|
||||
...t.throws(() =>
|
||||
getPlugins(
|
||||
{
|
||||
cwd,
|
||||
logger: t.context.logger,
|
||||
options: {verifyConditions: {}, analyzeCommits: [], verifyRelease: [{}], generateNotes: [{path: null}]},
|
||||
options: {
|
||||
plugins: ['@semantic-release/commit-analyzer', '@semantic-release/release-notes-generator'],
|
||||
verifyConditions: 1,
|
||||
analyzeCommits: [],
|
||||
verifyRelease: [{}],
|
||||
generateNotes: [{path: null}],
|
||||
},
|
||||
},
|
||||
{}
|
||||
)
|
||||
@@ -182,3 +282,38 @@ test('Throw an error if plugins configuration are invalid', t => {
|
||||
t.is(errors[3].name, 'SemanticReleaseError');
|
||||
t.is(errors[3].code, 'EPLUGINCONF');
|
||||
});
|
||||
|
||||
test('Throw EPLUGINSCONF error if the "plugins" option contains an old plugin definition (returns a function)', t => {
|
||||
const errors = [
|
||||
...t.throws(() =>
|
||||
getPlugins(
|
||||
{
|
||||
cwd,
|
||||
logger: t.context.logger,
|
||||
options: {plugins: ['./test/fixtures/multi-plugin', './test/fixtures/plugin-noop', () => {}]},
|
||||
},
|
||||
{}
|
||||
)
|
||||
),
|
||||
];
|
||||
|
||||
t.is(errors[0].name, 'SemanticReleaseError');
|
||||
t.is(errors[0].code, 'EPLUGINSCONF');
|
||||
t.is(errors[1].name, 'SemanticReleaseError');
|
||||
t.is(errors[1].code, 'EPLUGINSCONF');
|
||||
});
|
||||
|
||||
test('Throw EPLUGINSCONF error for each invalid definition if the "plugins" option', t => {
|
||||
const errors = [
|
||||
...t.throws(() =>
|
||||
getPlugins({cwd, logger: t.context.logger, options: {plugins: [1, {path: 1}, [() => {}, {}, {}]]}}, {})
|
||||
),
|
||||
];
|
||||
|
||||
t.is(errors[0].name, 'SemanticReleaseError');
|
||||
t.is(errors[0].code, 'EPLUGINSCONF');
|
||||
t.is(errors[1].name, 'SemanticReleaseError');
|
||||
t.is(errors[1].code, 'EPLUGINSCONF');
|
||||
t.is(errors[2].name, 'SemanticReleaseError');
|
||||
t.is(errors[2].code, 'EPLUGINSCONF');
|
||||
});
|
||||
|
||||
+200
-44
@@ -1,58 +1,214 @@
|
||||
import test from 'ava';
|
||||
import {validateConfig} from '../../lib/plugins/utils';
|
||||
import {validatePlugin, validateStep, loadPlugin, parseConfig} from '../../lib/plugins/utils';
|
||||
|
||||
test('Validate multiple/optional plugin configuration', t => {
|
||||
test('validatePlugin', t => {
|
||||
const path = 'plugin-module';
|
||||
const options = {option1: 'value1', option2: 'value2'};
|
||||
|
||||
t.true(validatePlugin(path), 'String definition');
|
||||
t.true(validatePlugin({publish: () => {}}), 'Object definition');
|
||||
t.true(validatePlugin([path]), 'Array definition');
|
||||
t.true(validatePlugin([path, options]), 'Array definition with options');
|
||||
t.true(validatePlugin([{publish: () => {}}, options]), 'Array definition with options and path as object');
|
||||
t.true(validatePlugin({path}), 'Object with path definition');
|
||||
t.true(validatePlugin({path, ...options}), 'Object with path definition with options');
|
||||
t.true(
|
||||
validatePlugin({path: {publish: () => {}}, ...options}),
|
||||
'Object with path definition with options and path as object'
|
||||
);
|
||||
|
||||
t.false(validatePlugin(1), 'String definition, wrong path');
|
||||
t.false(validatePlugin([]), 'Array definition, missing path');
|
||||
t.false(validatePlugin([path, options, {}]), 'Array definition, additional parameter');
|
||||
t.false(validatePlugin([1]), 'Array definition, wrong path');
|
||||
t.false(validatePlugin([path, 1]), 'Array definition, wrong options');
|
||||
t.false(validatePlugin({path: 1}), 'Object definition, wrong path');
|
||||
});
|
||||
|
||||
test('validateStep: optional plugin configuration', t => {
|
||||
const type = {multiple: true, required: false};
|
||||
t.false(validateConfig(type, {}));
|
||||
t.false(validateConfig(type, {path: null}));
|
||||
|
||||
t.true(validateConfig(type, {path: 'plugin-path.js'}));
|
||||
t.true(validateConfig(type));
|
||||
t.true(validateConfig(type, 'plugin-path.js'));
|
||||
t.true(validateConfig(type, ['plugin-path.js']));
|
||||
t.true(validateConfig(type, () => {}));
|
||||
t.true(validateConfig(type, [{path: 'plugin-path.js'}, 'plugin-path.js', () => {}]));
|
||||
// Empty config
|
||||
t.true(validateStep(type));
|
||||
t.true(validateStep(type, []));
|
||||
|
||||
// Single value definition
|
||||
t.true(validateStep(type, 'plugin-path.js'));
|
||||
t.true(validateStep(type, () => {}));
|
||||
t.true(validateStep(type, ['plugin-path.js']));
|
||||
t.true(validateStep(type, [() => {}]));
|
||||
t.false(validateStep(type, {}));
|
||||
t.false(validateStep(type, [{}]));
|
||||
|
||||
// Array type definition
|
||||
t.true(validateStep(type, [['plugin-path.js']]));
|
||||
t.true(validateStep(type, [['plugin-path.js', {options: 'value'}]]));
|
||||
t.true(validateStep(type, [[() => {}, {options: 'value'}]]));
|
||||
t.false(validateStep(type, [['plugin-path.js', 1]]));
|
||||
|
||||
// Object type definition
|
||||
t.true(validateStep(type, {path: 'plugin-path.js'}));
|
||||
t.true(validateStep(type, {path: 'plugin-path.js', options: 'value'}));
|
||||
t.true(validateStep(type, {path: () => {}, options: 'value'}));
|
||||
t.false(validateStep(type, {path: null}));
|
||||
|
||||
// Considered as an Array of 2 definitions and not as one Array definition in case of a muliple plugin type
|
||||
t.false(validateStep(type, [() => {}, {options: 'value'}]));
|
||||
t.false(validateStep(type, ['plugin-path.js', {options: 'value'}]));
|
||||
|
||||
// Multiple definitions
|
||||
t.true(
|
||||
validateStep(type, [
|
||||
'plugin-path.js',
|
||||
() => {},
|
||||
['plugin-path.js'],
|
||||
['plugin-path.js', {options: 'value'}],
|
||||
[() => {}, {options: 'value'}],
|
||||
{path: 'plugin-path.js'},
|
||||
{path: 'plugin-path.js', options: 'value'},
|
||||
{path: () => {}, options: 'value'},
|
||||
])
|
||||
);
|
||||
t.false(
|
||||
validateStep(type, [
|
||||
'plugin-path.js',
|
||||
() => {},
|
||||
['plugin-path.js'],
|
||||
['plugin-path.js', 1],
|
||||
[() => {}, {options: 'value'}],
|
||||
{path: 'plugin-path.js'},
|
||||
{path: 'plugin-path.js', options: 'value'},
|
||||
{path: () => {}, options: 'value'},
|
||||
])
|
||||
);
|
||||
t.false(
|
||||
validateStep(type, [
|
||||
'plugin-path.js',
|
||||
{},
|
||||
['plugin-path.js'],
|
||||
['plugin-path.js', {options: 'value'}],
|
||||
[() => {}, {options: 'value'}],
|
||||
{path: 'plugin-path.js'},
|
||||
{path: 'plugin-path.js', options: 'value'},
|
||||
{path: () => {}, options: 'value'},
|
||||
])
|
||||
);
|
||||
t.false(
|
||||
validateStep(type, [
|
||||
'plugin-path.js',
|
||||
() => {},
|
||||
['plugin-path.js'],
|
||||
['plugin-path.js', {options: 'value'}],
|
||||
[() => {}, {options: 'value'}],
|
||||
{path: null},
|
||||
{path: 'plugin-path.js', options: 'value'},
|
||||
{path: () => {}, options: 'value'},
|
||||
])
|
||||
);
|
||||
});
|
||||
|
||||
test('Validate multiple/required plugin configuration', t => {
|
||||
const type = {multiple: true, required: true};
|
||||
t.false(validateConfig(type, {}));
|
||||
t.false(validateConfig(type, {path: null}));
|
||||
t.false(validateConfig(type));
|
||||
test('validateStep: required plugin configuration', t => {
|
||||
const type = {required: true};
|
||||
|
||||
t.true(validateConfig(type, {path: 'plugin-path.js'}));
|
||||
t.true(validateConfig(type, 'plugin-path.js'));
|
||||
t.true(validateConfig(type, ['plugin-path.js']));
|
||||
t.true(validateConfig(type, () => {}));
|
||||
t.true(validateConfig(type, [{path: 'plugin-path.js'}, 'plugin-path.js', () => {}]));
|
||||
// Empty config
|
||||
t.false(validateStep(type));
|
||||
t.false(validateStep(type, []));
|
||||
|
||||
// Single value definition
|
||||
t.true(validateStep(type, 'plugin-path.js'));
|
||||
t.true(validateStep(type, () => {}));
|
||||
t.true(validateStep(type, ['plugin-path.js']));
|
||||
t.true(validateStep(type, [() => {}]));
|
||||
t.false(validateStep(type, {}));
|
||||
t.false(validateStep(type, [{}]));
|
||||
|
||||
// Array type definition
|
||||
t.true(validateStep(type, [['plugin-path.js']]));
|
||||
t.true(validateStep(type, [['plugin-path.js', {options: 'value'}]]));
|
||||
t.true(validateStep(type, [[() => {}, {options: 'value'}]]));
|
||||
t.false(validateStep(type, [['plugin-path.js', 1]]));
|
||||
|
||||
// Object type definition
|
||||
t.true(validateStep(type, {path: 'plugin-path.js'}));
|
||||
t.true(validateStep(type, {path: 'plugin-path.js', options: 'value'}));
|
||||
t.true(validateStep(type, {path: () => {}, options: 'value'}));
|
||||
t.false(validateStep(type, {path: null}));
|
||||
|
||||
// Considered as an Array of 2 definitions and not as one Array definition in the case of a muliple plugin type
|
||||
t.false(validateStep(type, [() => {}, {options: 'value'}]));
|
||||
t.false(validateStep(type, ['plugin-path.js', {options: 'value'}]));
|
||||
|
||||
// Multiple definitions
|
||||
t.true(
|
||||
validateStep(type, [
|
||||
'plugin-path.js',
|
||||
() => {},
|
||||
['plugin-path.js'],
|
||||
['plugin-path.js', {options: 'value'}],
|
||||
[() => {}, {options: 'value'}],
|
||||
{path: 'plugin-path.js'},
|
||||
{path: 'plugin-path.js', options: 'value'},
|
||||
{path: () => {}, options: 'value'},
|
||||
])
|
||||
);
|
||||
t.false(
|
||||
validateStep(type, [
|
||||
'plugin-path.js',
|
||||
() => {},
|
||||
['plugin-path.js'],
|
||||
['plugin-path.js', 1],
|
||||
[() => {}, {options: 'value'}],
|
||||
{path: 'plugin-path.js'},
|
||||
{path: 'plugin-path.js', options: 'value'},
|
||||
{path: () => {}, options: 'value'},
|
||||
])
|
||||
);
|
||||
t.false(
|
||||
validateStep(type, [
|
||||
'plugin-path.js',
|
||||
{},
|
||||
['plugin-path.js'],
|
||||
['plugin-path.js', {options: 'value'}],
|
||||
[() => {}, {options: 'value'}],
|
||||
{path: 'plugin-path.js'},
|
||||
{path: 'plugin-path.js', options: 'value'},
|
||||
{path: () => {}, options: 'value'},
|
||||
])
|
||||
);
|
||||
t.false(
|
||||
validateStep(type, [
|
||||
'plugin-path.js',
|
||||
() => {},
|
||||
['plugin-path.js'],
|
||||
['plugin-path.js', {options: 'value'}],
|
||||
[() => {}, {options: 'value'}],
|
||||
{path: null},
|
||||
{path: 'plugin-path.js', options: 'value'},
|
||||
{path: () => {}, options: 'value'},
|
||||
])
|
||||
);
|
||||
});
|
||||
|
||||
test('Validate single/required plugin configuration', t => {
|
||||
const type = {multiple: false, required: true};
|
||||
test('loadPlugin', t => {
|
||||
const cwd = process.cwd();
|
||||
const func = () => {};
|
||||
|
||||
t.false(validateConfig(type, {}));
|
||||
t.false(validateConfig(type, {path: null}));
|
||||
t.false(validateConfig(type, []));
|
||||
t.false(validateConfig(type));
|
||||
t.false(validateConfig(type, [{path: 'plugin-path.js'}, 'plugin-path.js', () => {}]));
|
||||
|
||||
t.true(validateConfig(type, {path: 'plugin-path.js'}));
|
||||
t.true(validateConfig(type, 'plugin-path.js'));
|
||||
t.true(validateConfig(type, ['plugin-path.js']));
|
||||
t.true(validateConfig(type, () => {}));
|
||||
t.is(require('../fixtures/plugin-noop'), loadPlugin({cwd: './test/fixtures'}, './plugin-noop', {}), 'From cwd');
|
||||
t.is(
|
||||
require('../fixtures/plugin-noop'),
|
||||
loadPlugin({cwd}, './plugin-noop', {'./plugin-noop': './test/fixtures'}),
|
||||
'From a shareable config context'
|
||||
);
|
||||
t.is(func, loadPlugin({cwd}, func, {}), 'Defined as a function');
|
||||
});
|
||||
|
||||
test('Validate single/optional plugin configuration', t => {
|
||||
const type = {multiple: false, required: false};
|
||||
test('parseConfig', t => {
|
||||
const path = 'plugin-module';
|
||||
const options = {option1: 'value1', option2: 'value2'};
|
||||
|
||||
t.false(validateConfig(type, {}));
|
||||
t.false(validateConfig(type, {path: null}));
|
||||
t.false(validateConfig(type, [{path: 'plugin-path.js'}, 'plugin-path.js', () => {}]));
|
||||
|
||||
t.true(validateConfig(type));
|
||||
t.true(validateConfig(type, []));
|
||||
t.true(validateConfig(type, {path: 'plugin-path.js'}));
|
||||
t.true(validateConfig(type, 'plugin-path.js'));
|
||||
t.true(validateConfig(type, ['plugin-path.js']));
|
||||
t.true(validateConfig(type, () => {}));
|
||||
t.deepEqual(parseConfig(path), [path, {}], 'String definition');
|
||||
t.deepEqual(parseConfig({path}), [path, {}], 'Object definition');
|
||||
t.deepEqual(parseConfig({path, ...options}), [path, options], 'Object definition with options');
|
||||
t.deepEqual(parseConfig([path]), [path, {}], 'Array definition');
|
||||
t.deepEqual(parseConfig([path, options]), [path, options], 'Array definition with options');
|
||||
});
|
||||
|
||||
+20
-6
@@ -7,59 +7,73 @@ test('Throw a AggregateError', async t => {
|
||||
const {cwd} = await gitRepo();
|
||||
const options = {};
|
||||
|
||||
const errors = [...(await t.throws(verify({cwd, options})))];
|
||||
const errors = [...(await t.throwsAsync(verify({cwd, options})))];
|
||||
|
||||
t.is(errors[0].name, 'SemanticReleaseError');
|
||||
t.is(errors[0].code, 'ENOREPOURL');
|
||||
t.truthy(errors[0].message);
|
||||
t.truthy(errors[0].details);
|
||||
t.is(errors[1].name, 'SemanticReleaseError');
|
||||
t.is(errors[1].code, 'EINVALIDTAGFORMAT');
|
||||
t.truthy(errors[1].message);
|
||||
t.truthy(errors[1].details);
|
||||
t.is(errors[2].name, 'SemanticReleaseError');
|
||||
t.is(errors[2].code, 'ETAGNOVERSION');
|
||||
t.truthy(errors[2].message);
|
||||
t.truthy(errors[2].details);
|
||||
});
|
||||
|
||||
test('Throw a SemanticReleaseError if does not run on a git repository', async t => {
|
||||
const cwd = tempy.directory();
|
||||
const options = {};
|
||||
|
||||
const errors = [...(await t.throws(verify({cwd, options})))];
|
||||
const errors = [...(await t.throwsAsync(verify({cwd, options})))];
|
||||
|
||||
t.is(errors[0].name, 'SemanticReleaseError');
|
||||
t.is(errors[0].code, 'ENOGITREPO');
|
||||
t.truthy(errors[0].message);
|
||||
t.truthy(errors[0].details);
|
||||
});
|
||||
|
||||
test('Throw a SemanticReleaseError if the "tagFormat" is not valid', async t => {
|
||||
const {cwd, repositoryUrl} = await gitRepo(true);
|
||||
const options = {repositoryUrl, tagFormat: `?\${version}`};
|
||||
|
||||
const errors = [...(await t.throws(verify({cwd, options})))];
|
||||
const errors = [...(await t.throwsAsync(verify({cwd, options})))];
|
||||
|
||||
t.is(errors[0].name, 'SemanticReleaseError');
|
||||
t.is(errors[0].code, 'EINVALIDTAGFORMAT');
|
||||
t.truthy(errors[0].message);
|
||||
t.truthy(errors[0].details);
|
||||
});
|
||||
|
||||
test('Throw a SemanticReleaseError if the "tagFormat" does not contains the "version" variable', async t => {
|
||||
const {cwd, repositoryUrl} = await gitRepo(true);
|
||||
const options = {repositoryUrl, tagFormat: 'test'};
|
||||
|
||||
const errors = [...(await t.throws(verify({cwd, options})))];
|
||||
const errors = [...(await t.throwsAsync(verify({cwd, options})))];
|
||||
|
||||
t.is(errors[0].name, 'SemanticReleaseError');
|
||||
t.is(errors[0].code, 'ETAGNOVERSION');
|
||||
t.truthy(errors[0].message);
|
||||
t.truthy(errors[0].details);
|
||||
});
|
||||
|
||||
test('Throw a SemanticReleaseError if the "tagFormat" contains multiple "version" variables', async t => {
|
||||
const {cwd, repositoryUrl} = await gitRepo(true);
|
||||
const options = {repositoryUrl, tagFormat: `\${version}v\${version}`};
|
||||
|
||||
const errors = [...(await t.throws(verify({cwd, options})))];
|
||||
const errors = [...(await t.throwsAsync(verify({cwd, options})))];
|
||||
|
||||
t.is(errors[0].name, 'SemanticReleaseError');
|
||||
t.is(errors[0].code, 'ETAGNOVERSION');
|
||||
t.truthy(errors[0].message);
|
||||
t.truthy(errors[0].details);
|
||||
});
|
||||
|
||||
test('Return "true" if all verification pass', async t => {
|
||||
const {cwd, repositoryUrl} = await gitRepo(true);
|
||||
const options = {repositoryUrl, tagFormat: `v\${version}`};
|
||||
|
||||
await t.notThrows(verify({cwd, options}));
|
||||
await t.notThrowsAsync(verify({cwd, options}));
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user