Compare commits
51
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cf6befa2e8 | ||
|
|
0ab8d9a4bc | ||
|
|
1b6254880c | ||
|
|
78ea3ba966 | ||
|
|
f7c85e3fff | ||
|
|
9eab1adb9d | ||
|
|
4012f75386 | ||
|
|
e675b79ea0 | ||
|
|
ca495c99fe | ||
|
|
16795ed543 | ||
|
|
4cd3641dbf | ||
|
|
466898b3b4 | ||
|
|
7b7728c33c | ||
|
|
866e8ca4f7 | ||
|
|
e5167489be | ||
|
|
762d0f531b | ||
|
|
0bd223835f | ||
|
|
0916886872 | ||
|
|
2832bbffef | ||
|
|
3bb4aec454 | ||
|
|
ee841a47c4 | ||
|
|
2a2db0c99d | ||
|
|
9a513a38f7 | ||
|
|
5eea7c948e | ||
|
|
8f075227eb | ||
|
|
2f4bcef33a | ||
|
|
f419080fbf | ||
|
|
3bbf08c9d0 | ||
|
|
846f4c23b9 | ||
|
|
bd294eb63e | ||
|
|
c69445ebea | ||
|
|
d80e2eab27 | ||
|
|
9589a96239 | ||
|
|
ec89babb95 | ||
|
|
db620aa799 | ||
|
|
dd77f1f603 | ||
|
|
e66b4b59c0 | ||
|
|
3387fb756d | ||
|
|
587bb91c9a | ||
|
|
05c9360475 | ||
|
|
f1d7ad4e35 | ||
|
|
58a226f29c | ||
|
|
17d60d310e | ||
|
|
ab45ab1f8d | ||
|
|
ea389c3c88 | ||
|
|
fa994db054 | ||
|
|
b79116bf6d | ||
|
|
6fd7e56eb8 | ||
|
|
2b94bb4e09 | ||
|
|
b4bc1918cb | ||
|
|
2c30e268f9 |
@@ -1,21 +0,0 @@
|
||||
---
|
||||
name: Bug report
|
||||
about: Something not working as expected
|
||||
|
||||
---
|
||||
|
||||
## Current behavior
|
||||
|
||||
<!-- Describe how the issue manifests. -->
|
||||
|
||||
## Expected behavior
|
||||
|
||||
<!-- Describe what the desired behavior would be. -->
|
||||
|
||||
## Environment
|
||||
|
||||
- **semantic-release** version: <!-- Version set in package.json devDpendencies -->
|
||||
- CI environment: <!-- CI service name -->
|
||||
- Plugins used: <!-- List semantic-release plugin used if any -->
|
||||
- **semantic-release** configuration: <!-- link to your repository or relevant part of the semantic-release config -->
|
||||
- CI logs: <!-- link to your CI logs or semantic-release logs -->
|
||||
@@ -0,0 +1,51 @@
|
||||
name: Bug Report
|
||||
description: Something not working as expected
|
||||
body:
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: Current behavior
|
||||
description: Describe how the issue manifests.
|
||||
validations:
|
||||
required: true
|
||||
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: Expected behavior
|
||||
description: Describe what the desired behavior would be.
|
||||
validations:
|
||||
required: true
|
||||
|
||||
- type: input
|
||||
attributes:
|
||||
label: "`semantic-release` version"
|
||||
description: Version set in `package.json` `devDpendencies`.
|
||||
validations:
|
||||
required: true
|
||||
|
||||
- type: input
|
||||
attributes:
|
||||
label: CI environment
|
||||
description: CI service name.
|
||||
validations:
|
||||
required: true
|
||||
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: Plugins used
|
||||
description: List `semantic-release` plugin used, if any.
|
||||
validations:
|
||||
required: false
|
||||
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: "`semantic-release` configuration"
|
||||
description: Link to your repository or relevant part of the `semantic-release` config.
|
||||
validations:
|
||||
required: true
|
||||
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: CI logs
|
||||
description: Link to your CI logs or `semantic-release` logs.
|
||||
validations:
|
||||
required: true
|
||||
@@ -1,17 +0,0 @@
|
||||
---
|
||||
name: Feature request
|
||||
about: Wouldn’t it be nice if semantic-release could ...
|
||||
|
||||
---
|
||||
|
||||
## New feature motivation
|
||||
|
||||
<!-- Describe the context, the use-case and the advantages of the feature request. -->
|
||||
|
||||
## New feature description
|
||||
|
||||
<!-- Describe the functional changes that would have to be made in semantic-release or its plugins. -->
|
||||
|
||||
## New feature implementation
|
||||
|
||||
<!-- Optionally describe the technical changes to be made in semantic-release or its plugins. -->
|
||||
@@ -0,0 +1,23 @@
|
||||
name: Feature request
|
||||
description: Wouldn't it be nice if `semantic-release` could ...
|
||||
body:
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: New feature motivation
|
||||
description: Describe the context, the use-case and the advantages of the feature request.
|
||||
validations:
|
||||
required: true
|
||||
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: New feature description
|
||||
description: Describe the functional changes that would have to be made in `semantic-release` or its plugins.
|
||||
validations:
|
||||
required: true
|
||||
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: New feature implementation
|
||||
description: Optionally describe the technical changes to be made in `semantic-release` or its plugins.
|
||||
validations:
|
||||
required: false
|
||||
@@ -1,13 +0,0 @@
|
||||
---
|
||||
name: New plugin suggestion
|
||||
about: Integrate with a new platform, etc
|
||||
|
||||
---
|
||||
|
||||
## New plugin motivation
|
||||
|
||||
<!-- Describe the reasons to create a new plugin and why it's not covered by the existing ones. -->
|
||||
|
||||
## Third-party documentation
|
||||
|
||||
<!-- Provide explanation and documentation links for the platform to integrate with. -->
|
||||
@@ -0,0 +1,16 @@
|
||||
name: New plugin suggestion
|
||||
description: Integrate with a new platform, etc
|
||||
body:
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: New plugin motivation
|
||||
description: Describe the reasons to create a new plugin and why it's not covered by the existing ones.
|
||||
validations:
|
||||
required: true
|
||||
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: Third-party documentation
|
||||
description: Provide explanation and documentation links for the platform to integrate with.
|
||||
validations:
|
||||
required: true
|
||||
@@ -11,8 +11,8 @@ jobs:
|
||||
name: release
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/setup-node@v2
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/setup-node@v3
|
||||
with:
|
||||
cache: npm
|
||||
node-version: 16
|
||||
|
||||
@@ -24,11 +24,11 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v3
|
||||
- run: git config --global user.name github-actions
|
||||
- run: git config --global user.email github-actions@github.com
|
||||
- name: Use Node.js ${{ matrix.node-version }}
|
||||
uses: actions/setup-node@v2
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: ${{ matrix.node-version }}
|
||||
cache: npm
|
||||
@@ -41,8 +41,8 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
needs: test_matrix
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/setup-node@v2
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: 16
|
||||
cache: npm
|
||||
|
||||
+15
-14
@@ -1,20 +1,22 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
// 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 */
|
||||
|
||||
var semver = require('semver');
|
||||
var execa = require('execa');
|
||||
var findVersions = require('find-versions');
|
||||
var pkg = require('../package.json');
|
||||
import semver from 'semver';
|
||||
import { execa } from 'execa';
|
||||
import findVersions from 'find-versions';
|
||||
import cli from '../cli.js';
|
||||
import {createRequire} from 'node:module';
|
||||
|
||||
var MIN_GIT_VERSION = '2.7.1';
|
||||
const require = createRequire(import.meta.url);
|
||||
const { engines } = require('../package.json');
|
||||
const { satisfies, lt } = semver;
|
||||
|
||||
if (!semver.satisfies(process.version, pkg.engines.node)) {
|
||||
const MIN_GIT_VERSION = '2.7.1';
|
||||
|
||||
if (!satisfies(process.version, engines.node)) {
|
||||
console.error(
|
||||
`[semantic-release]: node version ${pkg.engines.node} is required. Found ${process.version}.
|
||||
`[semantic-release]: node version ${engines.node} is required. Found ${process.version}.
|
||||
|
||||
See https://github.com/semantic-release/semantic-release/blob/master/docs/support/node-version.md for more details and solutions.`
|
||||
);
|
||||
@@ -23,8 +25,8 @@ See https://github.com/semantic-release/semantic-release/blob/master/docs/suppor
|
||||
|
||||
execa('git', ['--version'])
|
||||
.then(({stdout}) => {
|
||||
var gitVersion = findVersions(stdout)[0];
|
||||
if (semver.lt(gitVersion, MIN_GIT_VERSION)) {
|
||||
const gitVersion = findVersions(stdout)[0];
|
||||
if (lt(gitVersion, MIN_GIT_VERSION)) {
|
||||
console.error(`[semantic-release]: Git version ${MIN_GIT_VERSION} is required. Found ${gitVersion}.`);
|
||||
process.exit(1);
|
||||
}
|
||||
@@ -35,8 +37,7 @@ execa('git', ['--version'])
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
// Node 10+ from this point on
|
||||
require('../cli')()
|
||||
cli()
|
||||
.then((exitCode) => {
|
||||
process.exitCode = exitCode;
|
||||
})
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
const {argv, env, stderr} = require('process'); // eslint-disable-line node/prefer-global/process
|
||||
const util = require('util');
|
||||
const hideSensitive = require('./lib/hide-sensitive');
|
||||
import util from 'node:util';
|
||||
import yargs from 'yargs';
|
||||
import {hideBin} from 'yargs/helpers';
|
||||
import hideSensitive from './lib/hide-sensitive.js';
|
||||
|
||||
const stringList = {
|
||||
type: 'string',
|
||||
@@ -11,8 +12,8 @@ const stringList = {
|
||||
: values.reduce((values, value) => values.concat(value.split(',').map((value) => value.trim())), []),
|
||||
};
|
||||
|
||||
module.exports = async () => {
|
||||
const cli = require('yargs')
|
||||
export default async () => {
|
||||
const cli = yargs(hideBin(process.argv))
|
||||
.command('$0', 'Run automated package publishing', (yargs) => {
|
||||
yargs.demandCommand(0, 0).usage(`Run automated package publishing
|
||||
|
||||
@@ -36,12 +37,11 @@ Usage:
|
||||
.option('debug', {describe: 'Output debugging information', type: 'boolean', group: 'Options'})
|
||||
.option('d', {alias: 'dry-run', describe: 'Skip publishing', type: 'boolean', group: 'Options'})
|
||||
.option('h', {alias: 'help', group: 'Options'})
|
||||
.option('v', {alias: 'version', group: 'Options'})
|
||||
.strict(false)
|
||||
.exitProcess(false);
|
||||
|
||||
try {
|
||||
const {help, version, ...options} = cli.parse(argv.slice(2));
|
||||
const {help, version, ...options} = cli.parse(process.argv.slice(2));
|
||||
|
||||
if (Boolean(help) || Boolean(version)) {
|
||||
return 0;
|
||||
@@ -49,16 +49,16 @@ Usage:
|
||||
|
||||
if (options.debug) {
|
||||
// Debug must be enabled before other requires in order to work
|
||||
require('debug').enable('semantic-release:*');
|
||||
(await import('debug')).default.enable('semantic-release:*');
|
||||
}
|
||||
|
||||
await require('.')(options);
|
||||
await (await import('./index.js')).default(options);
|
||||
return 0;
|
||||
} catch (error) {
|
||||
if (error.name !== 'YError') {
|
||||
stderr.write(hideSensitive(env)(util.inspect(error, {colors: true})));
|
||||
process.stderr.write(hideSensitive(process.env)(util.inspect(error, {colors: true})));
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -12,9 +12,9 @@ To create a plugin for `semantic-release`, you need to decide which parts of the
|
||||
- `success`
|
||||
- `fail`
|
||||
|
||||
`semantic-release` will require the plugin via `node` and look through the required object for methods named like the lifecyles stated above. For example, if your plugin only had a `verifyConditions` and `success` step, the `main` file for your object would need to `export` an object with `verifyConditions` and `success` functions.
|
||||
`semantic-release` will require the plugin via `node` and look through the required object for methods named like the lifecycles stated above. For example, if your plugin only had a `verifyConditions` and `success` step, the `main` file for your object would need to `export` an object with `verifyConditions` and `success` functions.
|
||||
|
||||
In addition to the lifecycle methods, each lifecyle is passed two objects:
|
||||
In addition to the lifecycle methods, each lifecycle is passed two objects:
|
||||
|
||||
1. `pluginConfig` - an object containing the options that a user may pass in via their `release.config.js` file (or similar)
|
||||
2. `context` - provided by `semantic-release` for access to things like `env` variables set on the running process.
|
||||
|
||||
@@ -55,12 +55,12 @@
|
||||
- [@semantic-release-plus/docker](https://github.com/semantic-release-plus/semantic-release-plus/tree/master/packages/plugins/docker)
|
||||
- `verifyConditions`: Verify that all needed configuration is present and login to the configured docker registry.
|
||||
- `publish`: Tag the image specified by `name` with the new version and channel and push it to the configured docker registry.
|
||||
- `addChannel`: Updates a release published on one channel with the destinations channel tag and pushes to the registry ie: next to latest.
|
||||
- `addChannel`: Updates a release published on one channel with the destinations channel tag and pushes to the registry i.e.: next to latest.
|
||||
- [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
|
||||
- `verifyConditions`: Verify the presence and the validity of the "VS Code extension" 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)
|
||||
@@ -84,7 +84,7 @@
|
||||
- `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
|
||||
- `prepare`: Stores the version number as an Azure DevOps pipeline variable available 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`
|
||||
@@ -157,3 +157,16 @@
|
||||
- `verifyConditions`: Verify plugin configuration and login to Helm registry
|
||||
- `prepare`: Package Helm chart to local folder
|
||||
- `publish`: Publish Helm chart to OCI registry
|
||||
- [semantic-release-space](https://github.com/123FLO321/semantic-release-space)
|
||||
- `verifyConditions` Verifies that all required options are set.
|
||||
- `prepare` Creates a JetBrains Space Deployment Target if it does not yet exist.
|
||||
- `publish` Starts a JetBrains Space Deployment.
|
||||
- `success` Marks the JetBrains Space Deployment as completed.
|
||||
- `fail` Marks the JetBrains Space Deployment as failed.
|
||||
- [semantic-release-react-native](https://github.com/alexandermendes/semantic-release-react-native)
|
||||
- `verifyConditions` Validate configuration.
|
||||
- `prepare` Version native iOS and Android files.
|
||||
- [semantic-release-cargo](https://github.com/buehler/semantic-release-cargo)
|
||||
- `verifyConditions` Validate configuration, `Cargo.toml`, and local cargo executable. Also, logs in into `crates.io`.
|
||||
- `prepare` Write the new version number into `Cargo.toml` file and perform `cargo check` if configured.
|
||||
- `publish` Publish the Rust crate to `crates.io`
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
## Community configurations
|
||||
- [@jedmao/semantic-release-npm-github-config](https://github.com/jedmao/semantic-release-npm-github-config)
|
||||
- Provides an informative [git](https://github.com/semantic-release/git) commit message for the release commit that does not trigger continuous integration and conforms to the [conventional commits specification](https://www.conventionalcommits.org/) (e.g., "chore(release): 1.2.3 [skip ci]\n\nnotes").
|
||||
- Provides an informative [Git](https://github.com/semantic-release/git) commit message for the release commit that does not trigger continuous integration and conforms to the [conventional commits specification](https://www.conventionalcommits.org/) (e.g., `chore(release): 1.2.3 [skip ci]\n\nnotes`).
|
||||
- Creates a tarball that gets uploaded with each [GitHub release](https://github.com/semantic-release/github).
|
||||
- Publishes the same tarball to [npm](https://github.com/semantic-release/npm).
|
||||
- Commits the version change in `package.json`.
|
||||
@@ -18,4 +18,3 @@
|
||||
- Updates GitHub release with release-notes.
|
||||
- Bumps a version in package.json.
|
||||
- Publishes the new version to [NPM](https://npmjs.org).
|
||||
|
||||
|
||||
@@ -22,14 +22,12 @@ Finally, we call our release job with a `requires` parameter so that `release` w
|
||||
```yaml
|
||||
version: 2.1
|
||||
orbs:
|
||||
node: circleci/node@4.5
|
||||
node: circleci/node@5.0.0
|
||||
jobs:
|
||||
release:
|
||||
executor: node/default
|
||||
steps:
|
||||
- checkout
|
||||
- node/install
|
||||
lts: true
|
||||
- node/install-packages # Install and automatically cache packages
|
||||
# Run optional required steps before releasing
|
||||
# - run: npm run build-script
|
||||
|
||||
@@ -14,7 +14,7 @@ GitLab CI supports [Pipelines](https://docs.gitlab.com/ee/ci/pipelines.html) all
|
||||
|
||||
### `.gitlab-ci.yml` configuration for Node projects
|
||||
|
||||
This example is a minimal configuration for **semantic-release** with a build running Node 10 and 12. See [GitLab CI - Configuration of your jobs with .gitlab-ci.yml](https://docs.gitlab.com/ee/ci/yaml/README.html) for additional configuration options.
|
||||
This example is a minimal configuration for **semantic-release** with a build running Node 10 and 12. See [GitLab CI - Configuration of your jobs with `.gitlab-ci.yml`](https://docs.gitlab.com/ee/ci/yaml/README.html) for additional configuration options.
|
||||
|
||||
**Note**: The`semantic-release` execution command varies depending on whether you are using a [local](../../usage/installation.md#local-installation) or [global](../../usage/installation.md#global-installation) **semantic-release** installation.
|
||||
|
||||
@@ -48,7 +48,7 @@ publish:
|
||||
|
||||
### `.gitlab-ci.yml` configuration for all projects
|
||||
|
||||
This example is a minimal configuration for **semantic-release** with a build running Node 10 and 12. See [GitLab CI - Configuration of your jobs with .gitlab-ci.yml](https://docs.gitlab.com/ee/ci/yaml/README.html) for additional configuration options.
|
||||
This example is a minimal configuration for **semantic-release** with a build running Node 10 and 12. See [GitLab CI - Configuration of your jobs with `.gitlab-ci.yml`](https://docs.gitlab.com/ee/ci/yaml/README.html) for additional configuration options.
|
||||
|
||||
**Note**: The`semantic-release` execution command varies depending if you are using a [local](../../usage/installation.md#local-installation) or [global](../../usage/installation.md#global-installation) **semantic-release** installation.
|
||||
|
||||
@@ -66,8 +66,8 @@ release:
|
||||
- npm install -g semantic-release @semantic-release/gitlab
|
||||
script:
|
||||
- semantic-release
|
||||
only:
|
||||
- master
|
||||
rules:
|
||||
- if: $CI_COMMIT_BRANCH == "master"
|
||||
|
||||
release:
|
||||
image: node:12-buster-slim
|
||||
@@ -77,8 +77,8 @@ release:
|
||||
- npm install -g semantic-release @semantic-release/gitlab
|
||||
script:
|
||||
- semantic-release
|
||||
only:
|
||||
- master
|
||||
rules:
|
||||
- if: $CI_COMMIT_BRANCH == "master"
|
||||
```
|
||||
|
||||
### `package.json` configuration
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# Publishing on distribution channels
|
||||
|
||||
This recipe will walk you through a simple example that uses distribution channels to make releases available only to a subset of users, in order to collect feedbacks before distributing the release to all users.
|
||||
This recipe will walk you through a simple example that uses distribution channels to make releases available only to a subset of users, in order to collect feedback before distributing the release to all users.
|
||||
|
||||
This example uses the **semantic-release** default configuration:
|
||||
- [branches](../../usage/configuration.md#branches): `['+([0-9])?(.{+([0-9]),x}).x', 'master', 'next', 'next-major', {name: 'beta', prerelease: true}, {name: 'alpha', prerelease: true}]`
|
||||
|
||||
+2
-2
@@ -44,7 +44,7 @@ Yes, **semantic-release** is a Node CLI application, but it can be used to publi
|
||||
|
||||
To publish a non-Node package (without a `package.json`) you would need to:
|
||||
- Use a [global](../usage/installation.md#global-installation) **semantic-release** installation
|
||||
- Set **semantic-release** [options](../usage/configuration.md#options) via [CLI arguments or rc file](../usage/configuration.md#configuration)
|
||||
- Set **semantic-release** [options](../usage/configuration.md#options) via [CLI arguments or `.rc` file](../usage/configuration.md#configuration)
|
||||
- Make sure your CI job executing the `semantic-release` command has access to a version of Node that [meets our version requirement](./node-version.md) to execute the `semantic-release` command
|
||||
|
||||
See the [CI configuration recipes](../recipes/release-workflow/README.md#ci-configurations) for more details on specific CI environments.
|
||||
@@ -153,7 +153,7 @@ Any npm compatible registry is supported with the [`@semantic-release/npm`](http
|
||||
|
||||
See [npm registry authentication](https://github.com/semantic-release/npm#npm-registry-authentication) for more details.
|
||||
|
||||
See [Artifactory - npm Registry](https://www.jfrog.com/confluence/display/RTF/Npm+Registry#NpmRegistry-AuthenticatingthenpmClient) documentation for Artifactiry configuration.
|
||||
See [Artifactory - npm Registry](https://www.jfrog.com/confluence/display/RTF/Npm+Registry#NpmRegistry-AuthenticatingthenpmClient) documentation for Artifactory configuration.
|
||||
|
||||
## Can I manually trigger the release of a specific version?
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# Node version requirement
|
||||
|
||||
**semantic-release** is written using the latest [ECMAScript 2017](https://www.ecma-international.org/publications/standards/Ecma-262.htm) features, without transpilation which requires **requires Node version 14.17 or higher**.
|
||||
**semantic-release** is written using the latest [ECMAScript 2017](https://www.ecma-international.org/publications/standards/Ecma-262.htm) features, without transpilation which **requires Node version 14.17 or higher**.
|
||||
|
||||
**semantic-release** is meant to be used in a CI environment as a development support tool, not as a production dependency.
|
||||
Therefore, the only constraint is to run the `semantic-release` in a CI environment providing version of Node that meets our version requirement.
|
||||
|
||||
@@ -30,7 +30,7 @@ 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).
|
||||
**Note**: if the resulting squashed commit 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
|
||||
|
||||
@@ -63,7 +63,7 @@ After a git history rewrite due to a `git push --force`, the git tags and notes
|
||||
|
||||
To recover from that situation, do the following:
|
||||
|
||||
1. Delete the tag(s) for the release(s) that have been lost from the git history. You can delete each tag from remote using `git push origin :[TAG NAME]`, e.g. `git push origin :v2.0.0-beta.1`. You can delete tags locally using `git tag -d [TAG NAME]`, e.g. `git tag -d v2.0.0-beta.1`.
|
||||
1. Delete the tag(s) for the release(s) that have been lost from the git history. You can delete each tag from remote using `git push origin -d :[TAG NAME]`, e.g. `git push origin -d :v2.0.0-beta.1`. You can delete tags locally using `git tag -d [TAG NAME]`, e.g. `git tag -d v2.0.0-beta.1`.
|
||||
2. Re-create the tags locally: `git tag [TAG NAME] [COMMIT HASH]`, where `[COMMIT HASH]` is the new commit that created the release for the lost tag. E.g. `git tag v2.0.0-beta.1 abcdef0`
|
||||
3. Re-create the git notes for each release tag, e.g. `git notes --ref semantic-release add -f -m '{"channels":["beta"]}' v2.0.0-beta.1`. If the release was also published in the default channel (usually `master`), then set the first channel to `null`, e.g. `git notes --ref semantic-release add -f -m '{"channels":[null, "beta"]}'`
|
||||
4. Push the local notes: `git push --force origin refs/notes/semantic-release`. The `--force` is needed after the rebase. Be careful.
|
||||
|
||||
@@ -3,7 +3,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.
|
||||
Here is a few example of the CI services that can be used to achieve this:
|
||||
Here are a few examples of the CI services that can be used to achieve this:
|
||||
- [Travis Build Stages](https://docs.travis-ci.com/user/build-stages)
|
||||
- [CircleCI Workflows](https://circleci.com/docs/2.0/workflows)
|
||||
- [GitHub Actions](https://github.com/features/actions)
|
||||
@@ -13,7 +13,7 @@ Here is a few example of the CI services that can be used to achieve this:
|
||||
- [Wercker Workflows](http://devcenter.wercker.com/docs/workflows)
|
||||
- [GoCD Pipelines](https://docs.gocd.org/current/introduction/concepts_in_go.html#pipeline).
|
||||
|
||||
See [CI configuration recipes](../recipes/ci-configurations/README.md) for more details.
|
||||
See [CI configuration recipes](../recipes/ci-configurations#ci-configurations) for more details.
|
||||
|
||||
## Authentication
|
||||
|
||||
@@ -26,7 +26,7 @@ See [CI configuration recipes](../recipes/ci-configurations/README.md) for more
|
||||
| `GH_TOKEN` or `GITHUB_TOKEN` | A GitHub [personal access token](https://help.github.com/articles/creating-a-personal-access-token-for-the-command-line). |
|
||||
| `GL_TOKEN` or `GITLAB_TOKEN` | A GitLab [personal access token](https://docs.gitlab.com/ce/user/profile/personal_access_tokens.html). |
|
||||
| `BB_TOKEN` or `BITBUCKET_TOKEN` | A Bitbucket [personal access token](https://confluence.atlassian.com/bitbucketserver/personal-access-tokens-939515499.html). |
|
||||
| `BB_TOKEN_BASIC_AUTH` or `BITBUCKET_TOKEN_BASIC_AUTH` | A Bitbucket [personal access token](https://confluence.atlassian.com/bitbucketserver/personal-access-tokens-939515499.html) with basic auth support. For clearification `user:token` has to be the value of this env. |
|
||||
| `BB_TOKEN_BASIC_AUTH` or `BITBUCKET_TOKEN_BASIC_AUTH` | A Bitbucket [personal access token](https://confluence.atlassian.com/bitbucketserver/personal-access-tokens-939515499.html) with basic auth support. For clarification `user:token` has to be the value of this env. |
|
||||
| `GIT_CREDENTIALS` | [URL encoded](https://en.wikipedia.org/wiki/Percent-encoding) Git username and password in the format `<username>:<password>`. The username and password must each be individually URL encoded, not the `:` separating them. |
|
||||
|
||||
Alternatively the Git authentication can be set up via [SSH keys](../recipes/git-hosted-services/git-auth-ssh-keys.md).
|
||||
@@ -44,6 +44,6 @@ 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/ci-configurations/README.md) for more details on how to configure environment variables in your CI service.
|
||||
See [CI configuration recipes](../recipes/ci-configurations#ci-configurations) for more details on how to configure environment variables in your CI service.
|
||||
|
||||
**Note**: The environment variables `GH_TOKEN`, `GITHUB_TOKEN`, `GL_TOKEN` and `GITLAB_TOKEN` can be used for both the Git authentication and the API authentication required by [@semantic-release/github](https://github.com/semantic-release/github) and [@semantic-release/gitlab](https://github.com/semantic-release/gitlab).
|
||||
|
||||
@@ -12,8 +12,8 @@ Additionally, metadata of Git tags generated by **semantic-release** can be cust
|
||||
## Configuration file
|
||||
|
||||
**semantic-release**’s [options](#options), mode and [plugins](plugins.md) can be set via either:
|
||||
- A `.releaserc` file, written in YAML or JSON, with optional extensions: .`yaml`/`.yml`/`.json`/`.js`
|
||||
- A `release.config.js` file that exports an object
|
||||
- A `.releaserc` file, written in YAML or JSON, with optional extensions: `.yaml`/`.yml`/`.json`/`.js`/`.cjs`
|
||||
- A `release.config.(js|cjs)` file that exports an object
|
||||
- A `release` key in the project's `package.json` file
|
||||
|
||||
Alternatively, some options can be set via CLI arguments.
|
||||
@@ -45,7 +45,7 @@ $ semantic-release --branches next
|
||||
|
||||
**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.
|
||||
**Note**: When configuring via `package.json`, the configuration must be under the `release` property. However, when using a `.releaserc` or a `release.config` file, the configuration must be set without a `release` property.
|
||||
|
||||
## Options
|
||||
|
||||
@@ -69,8 +69,8 @@ The branches on which releases should happen. By default **semantic-release** wi
|
||||
- regular releases to a distribution channel matching the branch name from any existing branch with a name matching a maintenance release range (`N.N.x` or `N.x.x` or `N.x` with `N` being a number)
|
||||
- regular releases to the `next` distribution channel from the branch `next` if it exists
|
||||
- regular releases to the `next-major` distribution channel from the branch `next-major` if it exists
|
||||
- prereleases to the `beta` distribution channel from the branch `beta` if it exists
|
||||
- prereleases to the `alpha` distribution channel from the branch `alpha` if it exists
|
||||
- pre-releases to the `beta` distribution channel from the branch `beta` if it exists
|
||||
- pre-releases to the `alpha` distribution channel from the branch `alpha` if it exists
|
||||
|
||||
**Note**: If your repository does not have a release branch, then **semantic-release** will fail with an `ERELEASEBRANCHES` error message. If you are using the default configuration, you can fix this error by pushing a `master` branch.
|
||||
|
||||
@@ -116,7 +116,7 @@ Type: `Boolean`<br>
|
||||
Default: `false` if running in a CI environment, `true` otherwise<br>
|
||||
CLI arguments: `-d`, `--dry-run`
|
||||
|
||||
The objective of the dry-run mode is to get a preview of the pending release. Dry-run mode skips the following steps: prepare, publish, success and fail. In addition to this it prints the next version and release notes to the console.
|
||||
The objective of the dry-run mode is to get a preview of the pending release. Dry-run mode skips the following steps: prepare, publish, addChannel, success and fail. In addition to this it prints the next version and release notes to the console.
|
||||
|
||||
**Note**: The Dry-run mode verifies the repository push permission, even though nothing will be pushed. The verification is done to help user to figure out potential configuration issues.
|
||||
|
||||
|
||||
@@ -1,24 +1,27 @@
|
||||
const {pick} = require('lodash');
|
||||
const marked = require('marked');
|
||||
const envCi = require('env-ci');
|
||||
const hookStd = require('hook-std');
|
||||
const semver = require('semver');
|
||||
const AggregateError = require('aggregate-error');
|
||||
import {createRequire} from 'node:module';
|
||||
import {pick} from 'lodash-es';
|
||||
import * as marked from 'marked';
|
||||
import envCi from 'env-ci';
|
||||
import {hookStd} from 'hook-std';
|
||||
import semver from 'semver';
|
||||
import AggregateError from 'aggregate-error';
|
||||
import hideSensitive from './lib/hide-sensitive.js';
|
||||
import getConfig from './lib/get-config.js';
|
||||
import verify from './lib/verify.js';
|
||||
import getNextVersion from './lib/get-next-version.js';
|
||||
import getCommits from './lib/get-commits.js';
|
||||
import getLastRelease from './lib/get-last-release.js';
|
||||
import getReleaseToAdd from './lib/get-release-to-add.js';
|
||||
import {extractErrors, makeTag} from './lib/utils.js';
|
||||
import getGitAuthUrl from './lib/get-git-auth-url.js';
|
||||
import getBranches from './lib/branches/index.js';
|
||||
import getLogger from './lib/get-logger.js';
|
||||
import {addNote, getGitHead, getTagHead, isBranchUpToDate, push, pushNotes, tag, verifyAuth} from './lib/git.js';
|
||||
import getError from './lib/get-error.js';
|
||||
import {COMMIT_EMAIL, COMMIT_NAME} from './lib/definitions/constants.js';
|
||||
|
||||
const require = createRequire(import.meta.url);
|
||||
const pkg = require('./package.json');
|
||||
const hideSensitive = require('./lib/hide-sensitive');
|
||||
const getConfig = require('./lib/get-config');
|
||||
const verify = require('./lib/verify');
|
||||
const getNextVersion = require('./lib/get-next-version');
|
||||
const getCommits = require('./lib/get-commits');
|
||||
const getLastRelease = require('./lib/get-last-release');
|
||||
const getReleaseToAdd = require('./lib/get-release-to-add');
|
||||
const {extractErrors, makeTag} = require('./lib/utils');
|
||||
const getGitAuthUrl = require('./lib/get-git-auth-url');
|
||||
const getBranches = require('./lib/branches');
|
||||
const getLogger = require('./lib/get-logger');
|
||||
const {verifyAuth, isBranchUpToDate, getGitHead, tag, push, pushNotes, getTagHead, addNote} = require('./lib/git');
|
||||
const getError = require('./lib/get-error');
|
||||
const {COMMIT_NAME, COMMIT_EMAIL} = require('./lib/definitions/constants');
|
||||
|
||||
let markedOptionsSet = false;
|
||||
async function terminalOutput(text) {
|
||||
@@ -33,15 +36,15 @@ async function terminalOutput(text) {
|
||||
|
||||
/* eslint complexity: off */
|
||||
async function run(context, plugins) {
|
||||
const {cwd, env, options, logger} = context;
|
||||
const {isCi, branch, prBranch, isPr} = context.envCi;
|
||||
const {cwd, env, options, logger, envCi} = context;
|
||||
const {isCi, branch, prBranch, isPr} = envCi;
|
||||
const ciBranch = isPr ? prBranch : branch;
|
||||
|
||||
if (!isCi && !options.dryRun && !options.noCi) {
|
||||
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.
|
||||
// When running on CI, set the commits author and committer info and prevent the `git` CLI to prompt for username/password. See #703.
|
||||
Object.assign(env, {
|
||||
GIT_AUTHOR_NAME: COMMIT_NAME,
|
||||
GIT_AUTHOR_EMAIL: COMMIT_EMAIL,
|
||||
@@ -75,7 +78,7 @@ async function run(context, plugins) {
|
||||
}
|
||||
|
||||
logger[options.dryRun ? 'warn' : 'success'](
|
||||
`Run automated release from branch ${ciBranch} on repository ${options.repositoryUrl}${
|
||||
`Run automated release from branch ${ciBranch} on repository ${options.originalRepositoryURL}${
|
||||
options.dryRun ? ' in dry-run mode' : ''
|
||||
}`
|
||||
);
|
||||
@@ -247,7 +250,7 @@ async function callFail(context, plugins, err) {
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = async (cliOptions = {}, {cwd = process.cwd(), env = process.env, stdout, stderr} = {}) => {
|
||||
export default async (cliOptions = {}, {cwd = process.cwd(), env = process.env, stdout, stderr} = {}) => {
|
||||
const {unhook} = hookStd(
|
||||
{silent: false, streams: [process.stdout, process.stderr, stdout, stderr].filter(Boolean)},
|
||||
hideSensitive(env)
|
||||
@@ -263,6 +266,7 @@ module.exports = async (cliOptions = {}, {cwd = process.cwd(), env = process.env
|
||||
context.logger.log(`Running ${pkg.name} version ${pkg.version}`);
|
||||
try {
|
||||
const {plugins, options} = await getConfig(context, cliOptions);
|
||||
options.originalRepositoryURL = options.repositoryUrl;
|
||||
context.options = options;
|
||||
try {
|
||||
const result = await run(context, plugins);
|
||||
@@ -277,4 +281,4 @@ module.exports = async (cliOptions = {}, {cwd = process.cwd(), env = process.env
|
||||
unhook();
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
const {isString, remove, omit, mapValues, template} = require('lodash');
|
||||
const micromatch = require('micromatch');
|
||||
const {getBranches} = require('../git');
|
||||
import {isString, mapValues, omit, remove, template} from 'lodash-es';
|
||||
import micromatch from 'micromatch';
|
||||
import {getBranches} from '../git.js';
|
||||
|
||||
module.exports = async (repositoryUrl, {cwd}, branches) => {
|
||||
export default async (repositoryUrl, {cwd}, branches) => {
|
||||
const gitBranches = await getBranches(repositoryUrl, {cwd});
|
||||
|
||||
return branches.reduce(
|
||||
@@ -15,4 +15,4 @@ module.exports = async (repositoryUrl, {cwd}, branches) => {
|
||||
],
|
||||
[]
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
const {template, escapeRegExp} = require('lodash');
|
||||
const semver = require('semver');
|
||||
const pReduce = require('p-reduce');
|
||||
const debug = require('debug')('semantic-release:get-tags');
|
||||
const {getTags, getNote} = require('../../lib/git');
|
||||
import {escapeRegExp, template} from 'lodash-es';
|
||||
import semver from 'semver';
|
||||
import pReduce from 'p-reduce';
|
||||
import debugTags from 'debug';
|
||||
import {getNote, getTags} from '../../lib/git.js';
|
||||
|
||||
module.exports = async ({cwd, env, options: {tagFormat}}, branches) => {
|
||||
const debug = debugTags('semantic-release:get-tags');
|
||||
|
||||
|
||||
export default async ({cwd, env, options: {tagFormat}}, branches) => {
|
||||
// Generate a regex to parse tags formatted with `tagFormat`
|
||||
// by replacing the `version` variable in the template by `(.+)`.
|
||||
// The `tagFormat` is compiled with space as the `version` as it's an invalid tag character,
|
||||
@@ -30,4 +33,4 @@ module.exports = async ({cwd, env, options: {tagFormat}}, branches) => {
|
||||
},
|
||||
[]
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
+12
-11
@@ -1,14 +1,14 @@
|
||||
const {isString, isRegExp} = require('lodash');
|
||||
const AggregateError = require('aggregate-error');
|
||||
const pEachSeries = require('p-each-series');
|
||||
const DEFINITIONS = require('../definitions/branches');
|
||||
const getError = require('../get-error');
|
||||
const {fetch, fetchNotes, verifyBranchName} = require('../git');
|
||||
const expand = require('./expand');
|
||||
const getTags = require('./get-tags');
|
||||
const normalize = require('./normalize');
|
||||
import {isRegExp, isString} from 'lodash-es';
|
||||
import AggregateError from 'aggregate-error';
|
||||
import pEachSeries from 'p-each-series';
|
||||
import * as DEFINITIONS from '../definitions/branches.js';
|
||||
import getError from '../get-error.js';
|
||||
import {fetch, fetchNotes, verifyBranchName} from '../git.js';
|
||||
import expand from './expand.js';
|
||||
import getTags from './get-tags.js';
|
||||
import * as normalize from './normalize.js';
|
||||
|
||||
module.exports = async (repositoryUrl, ciBranch, context) => {
|
||||
export default async (repositoryUrl, ciBranch, context) => {
|
||||
const {cwd, env} = context;
|
||||
|
||||
const remoteBranches = await expand(
|
||||
@@ -27,6 +27,7 @@ module.exports = async (repositoryUrl, ciBranch, context) => {
|
||||
|
||||
const errors = [];
|
||||
const branchesByType = Object.entries(DEFINITIONS).reduce(
|
||||
// eslint-disable-next-line unicorn/no-fn-reference-in-iterator
|
||||
(branchesByType, [type, {filter}]) => ({[type]: branches.filter(filter), ...branchesByType}),
|
||||
{}
|
||||
);
|
||||
@@ -67,4 +68,4 @@ module.exports = async (repositoryUrl, ciBranch, context) => {
|
||||
}
|
||||
|
||||
return [...result.maintenance, ...result.release, ...result.prerelease];
|
||||
};
|
||||
}
|
||||
|
||||
+15
-18
@@ -1,19 +1,18 @@
|
||||
const {sortBy, isNil} = require('lodash');
|
||||
const semverDiff = require('semver-diff');
|
||||
const {FIRST_RELEASE, RELEASE_TYPE} = require('../definitions/constants');
|
||||
const {
|
||||
tagsToVersions,
|
||||
isMajorRange,
|
||||
getUpperBound,
|
||||
getLowerBound,
|
||||
highest,
|
||||
lowest,
|
||||
getLatestVersion,
|
||||
import {isNil, sortBy} from 'lodash-es';
|
||||
import semverDiff from 'semver-diff';
|
||||
import {FIRST_RELEASE, RELEASE_TYPE} from '../definitions/constants.js';
|
||||
import {
|
||||
getFirstVersion,
|
||||
getRange,
|
||||
} = require('../utils');
|
||||
getLatestVersion,
|
||||
getLowerBound, getRange,
|
||||
getUpperBound,
|
||||
highest,
|
||||
isMajorRange,
|
||||
lowest,
|
||||
tagsToVersions
|
||||
} from '../utils.js';
|
||||
|
||||
function maintenance({maintenance, release}) {
|
||||
export function maintenance({maintenance, release}) {
|
||||
return sortBy(
|
||||
maintenance.map(({name, range, channel, ...rest}) => ({
|
||||
...rest,
|
||||
@@ -55,7 +54,7 @@ function maintenance({maintenance, release}) {
|
||||
});
|
||||
}
|
||||
|
||||
function release({release}) {
|
||||
export function release({release}) {
|
||||
if (release.length === 0) {
|
||||
return release;
|
||||
}
|
||||
@@ -89,7 +88,7 @@ function release({release}) {
|
||||
});
|
||||
}
|
||||
|
||||
function prerelease({prerelease}) {
|
||||
export function prerelease({prerelease}) {
|
||||
return prerelease.map(({name, prerelease, channel, tags, ...rest}) => {
|
||||
const preid = prerelease === true ? name : prerelease;
|
||||
return {
|
||||
@@ -102,5 +101,3 @@ function prerelease({prerelease}) {
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = {maintenance, release, prerelease};
|
||||
|
||||
@@ -1,23 +1,22 @@
|
||||
const {isNil, uniqBy} = require('lodash');
|
||||
const semver = require('semver');
|
||||
const {isMaintenanceRange} = require('../utils');
|
||||
import {isNil, uniqBy} from 'lodash-es';
|
||||
import semver from 'semver';
|
||||
import {isMaintenanceRange} from '../utils.js';
|
||||
|
||||
const maintenance = {
|
||||
export const maintenance = {
|
||||
filter: ({name, range}) => (!isNil(range) && range !== false) || isMaintenanceRange(name),
|
||||
branchValidator: ({range}) => (isNil(range) ? true : isMaintenanceRange(range)),
|
||||
branchesValidator: (branches) => uniqBy(branches, ({range}) => semver.validRange(range)).length === branches.length,
|
||||
};
|
||||
|
||||
const prerelease = {
|
||||
export const prerelease = {
|
||||
filter: ({prerelease}) => !isNil(prerelease) && prerelease !== false,
|
||||
branchValidator: ({name, prerelease}) =>
|
||||
Boolean(prerelease) && Boolean(semver.valid(`1.0.0-${prerelease === true ? name : prerelease}.1`)),
|
||||
branchesValidator: (branches) => uniqBy(branches, 'prerelease').length === branches.length,
|
||||
};
|
||||
|
||||
const release = {
|
||||
export const release = {
|
||||
// eslint-disable-next-line unicorn/no-fn-reference-in-iterator
|
||||
filter: (branch) => !maintenance.filter(branch) && !prerelease.filter(branch),
|
||||
branchesValidator: (branches) => branches.length <= 3 && branches.length > 0,
|
||||
};
|
||||
|
||||
module.exports = {maintenance, prerelease, release};
|
||||
|
||||
@@ -1,29 +1,17 @@
|
||||
const RELEASE_TYPE = ['patch', 'minor', 'major'];
|
||||
export const RELEASE_TYPE = ['patch', 'minor', 'major'];
|
||||
|
||||
const FIRST_RELEASE = '1.0.0';
|
||||
export const FIRST_RELEASE = '1.0.0';
|
||||
|
||||
const FIRSTPRERELEASE = '1';
|
||||
export const FIRSTPRERELEASE = '1';
|
||||
|
||||
const COMMIT_NAME = 'semantic-release-bot';
|
||||
export const COMMIT_NAME = 'semantic-release-bot';
|
||||
|
||||
const COMMIT_EMAIL = 'semantic-release-bot@martynus.net';
|
||||
export const COMMIT_EMAIL = 'semantic-release-bot@martynus.net';
|
||||
|
||||
const RELEASE_NOTES_SEPARATOR = '\n\n';
|
||||
export const RELEASE_NOTES_SEPARATOR = '\n\n';
|
||||
|
||||
const SECRET_REPLACEMENT = '[secure]';
|
||||
export const SECRET_REPLACEMENT = '[secure]';
|
||||
|
||||
const SECRET_MIN_SIZE = 5;
|
||||
export const SECRET_MIN_SIZE = 5;
|
||||
|
||||
const GIT_NOTE_REF = 'semantic-release';
|
||||
|
||||
module.exports = {
|
||||
RELEASE_TYPE,
|
||||
FIRST_RELEASE,
|
||||
FIRSTPRERELEASE,
|
||||
COMMIT_NAME,
|
||||
COMMIT_EMAIL,
|
||||
RELEASE_NOTES_SEPARATOR,
|
||||
SECRET_REPLACEMENT,
|
||||
SECRET_MIN_SIZE,
|
||||
GIT_NOTE_REF,
|
||||
};
|
||||
export const GIT_NOTE_REF = 'semantic-release';
|
||||
|
||||
+120
-54
@@ -1,7 +1,10 @@
|
||||
const {inspect} = require('util');
|
||||
const {toLower, isString, trim} = require('lodash');
|
||||
import {inspect} from 'node:util';
|
||||
import {createRequire} from 'node:module';
|
||||
import {isString, toLower, trim} from 'lodash-es';
|
||||
import {RELEASE_TYPE} from './constants.js';
|
||||
|
||||
const require = createRequire(import.meta.url);
|
||||
const pkg = require('../../package.json');
|
||||
const {RELEASE_TYPE} = require('./constants');
|
||||
|
||||
const [homepage] = pkg.homepage.split('#');
|
||||
const stringify = (object) =>
|
||||
@@ -10,16 +13,19 @@ const linkify = (file) => `${homepage}/blob/master/${file}`;
|
||||
const wordsList = (words) =>
|
||||
`${words.slice(0, -1).join(', ')}${words.length > 1 ? ` or ${words[words.length - 1]}` : trim(words[0])}`;
|
||||
|
||||
module.exports = {
|
||||
ENOGITREPO: ({cwd}) => ({
|
||||
export function ENOGITREPO({cwd}) {
|
||||
return {
|
||||
message: 'Not running from a git repository.',
|
||||
details: `The \`semantic-release\` command must be executed from a Git repository.
|
||||
|
||||
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.`,
|
||||
}),
|
||||
ENOREPOURL: () => ({
|
||||
};
|
||||
}
|
||||
|
||||
export function ENOREPOURL() {
|
||||
return {
|
||||
message: 'The `repositoryUrl` option is required.',
|
||||
details: `The [repositoryUrl option](${linkify(
|
||||
'docs/usage/configuration.md#repositoryurl'
|
||||
@@ -28,8 +34,11 @@ Please verify your CI configuration to make sure the \`semantic-release\` comman
|
||||
Please make sure to add the \`repositoryUrl\` to the [semantic-release configuration] (${linkify(
|
||||
'docs/usage/configuration.md'
|
||||
)}).`,
|
||||
}),
|
||||
EGITNOPERMISSION: ({options: {repositoryUrl}, branch: {name}}) => ({
|
||||
};
|
||||
}
|
||||
|
||||
export function EGITNOPERMISSION({options: {repositoryUrl}, branch: {name}}) {
|
||||
return {
|
||||
message: 'Cannot push to the Git repository.',
|
||||
details: `**semantic-release** cannot push the version tag to the branch \`${name}\` on the remote Git repository with URL \`${repositoryUrl}\`.
|
||||
|
||||
@@ -37,42 +46,57 @@ This can be caused by:
|
||||
- a misconfiguration of the [repositoryUrl](${linkify('docs/usage/configuration.md#repositoryurl')}) option
|
||||
- the repository being unavailable
|
||||
- or missing push permission for the user configured via the [Git credentials on your CI environment](${linkify(
|
||||
'docs/usage/ci-configuration.md#authentication'
|
||||
)})`,
|
||||
}),
|
||||
EINVALIDTAGFORMAT: ({options: {tagFormat}}) => ({
|
||||
'docs/usage/ci-configuration.md#authentication'
|
||||
)})`,
|
||||
};
|
||||
}
|
||||
|
||||
export function EINVALIDTAGFORMAT({options: {tagFormat}}) {
|
||||
return {
|
||||
message: 'Invalid `tagFormat` option.',
|
||||
details: `The [tagFormat](${linkify(
|
||||
'docs/usage/configuration.md#tagformat'
|
||||
)}) must compile to a [valid Git reference](https://git-scm.com/docs/git-check-ref-format#_description).
|
||||
|
||||
Your configuration for the \`tagFormat\` option is \`${stringify(tagFormat)}\`.`,
|
||||
}),
|
||||
ETAGNOVERSION: ({options: {tagFormat}}) => ({
|
||||
};
|
||||
}
|
||||
|
||||
export function ETAGNOVERSION({options: {tagFormat}}) {
|
||||
return {
|
||||
message: 'Invalid `tagFormat` option.',
|
||||
details: `The [tagFormat](${linkify(
|
||||
'docs/usage/configuration.md#tagformat'
|
||||
)}) option must contain the variable \`version\` exactly once.
|
||||
|
||||
Your configuration for the \`tagFormat\` option is \`${stringify(tagFormat)}\`.`,
|
||||
}),
|
||||
EPLUGINCONF: ({type, required, pluginConf}) => ({
|
||||
};
|
||||
}
|
||||
|
||||
export function EPLUGINCONF({type, required, pluginConf}) {
|
||||
return {
|
||||
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 a single or an array of plugins definition. A plugin definition is an npm module name, optionally wrapped in an array with an object.
|
||||
|
||||
Your configuration for the \`${type}\` plugin is \`${stringify(pluginConf)}\`.`,
|
||||
}),
|
||||
EPLUGINSCONF: ({plugin}) => ({
|
||||
};
|
||||
}
|
||||
|
||||
export function EPLUGINSCONF({plugin}) {
|
||||
return {
|
||||
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, optionally wrapped in an array with an object.
|
||||
)}) option must be an array of plugin definitions. A plugin definition is an npm module name, optionally wrapped in an array with an object.
|
||||
|
||||
The invalid configuration is \`${stringify(plugin)}\`.`,
|
||||
}),
|
||||
EPLUGIN: ({pluginName, type}) => ({
|
||||
};
|
||||
}
|
||||
|
||||
export function EPLUGIN({pluginName, type}) {
|
||||
return {
|
||||
message: `A plugin configured in the step ${type} is not a valid semantic-release plugin.`,
|
||||
details: `A valid \`${type}\` **semantic-release** plugin must be a function or an object with a function in the property \`${type}\`.
|
||||
|
||||
@@ -81,8 +105,11 @@ The plugin \`${pluginName}\` doesn't have the property \`${type}\` and cannot be
|
||||
Please refer to the \`${pluginName}\` and [semantic-release plugins configuration](${linkify(
|
||||
'docs/usage/plugins.md'
|
||||
)}) documentation for more details.`,
|
||||
}),
|
||||
EANALYZECOMMITSOUTPUT: ({result, pluginName}) => ({
|
||||
};
|
||||
}
|
||||
|
||||
export function EANALYZECOMMITSOUTPUT({result, pluginName}) {
|
||||
return {
|
||||
message: 'The `analyzeCommits` plugin returned an invalid value. It must return a valid semver release type.',
|
||||
details: `The \`analyzeCommits\` plugin must return a valid [semver](https://semver.org) release type. The valid values are: ${RELEASE_TYPE.map(
|
||||
(type) => `\`${type}\``
|
||||
@@ -97,8 +124,11 @@ We recommend to report the issue to the \`${pluginName}\` authors, providing the
|
||||
- A link to the **semantic-release** plugin developer guide: [${linkify('docs/developer-guide/plugin.md')}](${linkify(
|
||||
'docs/developer-guide/plugin.md'
|
||||
)})`,
|
||||
}),
|
||||
EGENERATENOTESOUTPUT: ({result, pluginName}) => ({
|
||||
};
|
||||
}
|
||||
|
||||
export function EGENERATENOTESOUTPUT({result, pluginName}) {
|
||||
return {
|
||||
message: 'The `generateNotes` plugin returned an invalid value. It must return a `String`.',
|
||||
details: `The \`generateNotes\` plugin must return a \`String\`.
|
||||
|
||||
@@ -111,8 +141,11 @@ We recommend to report the issue to the \`${pluginName}\` authors, providing the
|
||||
- A link to the **semantic-release** plugin developer guide: [${linkify('docs/developer-guide/plugin.md')}](${linkify(
|
||||
'docs/developer-guide/plugin.md'
|
||||
)})`,
|
||||
}),
|
||||
EPUBLISHOUTPUT: ({result, pluginName}) => ({
|
||||
};
|
||||
}
|
||||
|
||||
export function EPUBLISHOUTPUT({result, pluginName}) {
|
||||
return {
|
||||
message: 'A `publish` plugin returned an invalid value. It must return an `Object`.',
|
||||
details: `The \`publish\` plugins must return an \`Object\`.
|
||||
|
||||
@@ -125,8 +158,11 @@ We recommend to report the issue to the \`${pluginName}\` authors, providing the
|
||||
- A link to the **semantic-release** plugin developer guide: [${linkify('docs/developer-guide/plugin.md')}](${linkify(
|
||||
'docs/developer-guide/plugin.md'
|
||||
)})`,
|
||||
}),
|
||||
EADDCHANNELOUTPUT: ({result, pluginName}) => ({
|
||||
};
|
||||
}
|
||||
|
||||
export function EADDCHANNELOUTPUT({result, pluginName}) {
|
||||
return {
|
||||
message: 'A `addChannel` plugin returned an invalid value. It must return an `Object`.',
|
||||
details: `The \`addChannel\` plugins must return an \`Object\`.
|
||||
|
||||
@@ -139,48 +175,66 @@ We recommend to report the issue to the \`${pluginName}\` authors, providing the
|
||||
- A link to the **semantic-release** plugin developer guide: [${linkify('docs/developer-guide/plugin.md')}](${linkify(
|
||||
'docs/developer-guide/plugin.md'
|
||||
)})`,
|
||||
}),
|
||||
EINVALIDBRANCH: ({branch}) => ({
|
||||
};
|
||||
}
|
||||
|
||||
export function EINVALIDBRANCH({branch}) {
|
||||
return {
|
||||
message: 'A branch is invalid in the `branches` configuration.',
|
||||
details: `Each branch in the [branches configuration](${linkify(
|
||||
'docs/usage/configuration.md#branches'
|
||||
)}) must be either a string, a regexp or an object with a \`name\` property.
|
||||
|
||||
Your configuration for the problematic branch is \`${stringify(branch)}\`.`,
|
||||
}),
|
||||
EINVALIDBRANCHNAME: ({branch}) => ({
|
||||
};
|
||||
}
|
||||
|
||||
export function EINVALIDBRANCHNAME({branch}) {
|
||||
return {
|
||||
message: 'A branch name is invalid in the `branches` configuration.',
|
||||
details: `Each branch in the [branches configuration](${linkify(
|
||||
'docs/usage/configuration.md#branches'
|
||||
)}) must be a [valid Git reference](https://git-scm.com/docs/git-check-ref-format#_description).
|
||||
|
||||
Your configuration for the problematic branch is \`${stringify(branch)}\`.`,
|
||||
}),
|
||||
EDUPLICATEBRANCHES: ({duplicates}) => ({
|
||||
};
|
||||
}
|
||||
|
||||
export function EDUPLICATEBRANCHES({duplicates}) {
|
||||
return {
|
||||
message: 'The `branches` configuration has duplicate branches.',
|
||||
details: `Each branch in the [branches configuration](${linkify(
|
||||
'docs/usage/configuration.md#branches'
|
||||
)}) must havea unique name.
|
||||
|
||||
Your configuration contains duplicates for the following branch names: \`${stringify(duplicates)}\`.`,
|
||||
}),
|
||||
EMAINTENANCEBRANCH: ({branch}) => ({
|
||||
};
|
||||
}
|
||||
|
||||
export function EMAINTENANCEBRANCH({branch}) {
|
||||
return {
|
||||
message: 'A maintenance branch is invalid in the `branches` configuration.',
|
||||
details: `Each maintenance branch in the [branches configuration](${linkify(
|
||||
'docs/usage/configuration.md#branches'
|
||||
)}) must have a \`range\` property formatted like \`N.x\`, \`N.x.x\` or \`N.N.x\` (\`N\` is a number).
|
||||
|
||||
Your configuration for the problematic branch is \`${stringify(branch)}\`.`,
|
||||
}),
|
||||
EMAINTENANCEBRANCHES: ({branches}) => ({
|
||||
};
|
||||
}
|
||||
|
||||
export function EMAINTENANCEBRANCHES({branches}) {
|
||||
return {
|
||||
message: 'The maintenance branches are invalid in the `branches` configuration.',
|
||||
details: `Each maintenance branch in the [branches configuration](${linkify(
|
||||
'docs/usage/configuration.md#branches'
|
||||
)}) must have a unique \`range\` property.
|
||||
|
||||
Your configuration for the problematic branches is \`${stringify(branches)}\`.`,
|
||||
}),
|
||||
ERELEASEBRANCHES: ({branches}) => ({
|
||||
};
|
||||
}
|
||||
|
||||
export function ERELEASEBRANCHES({branches}) {
|
||||
return {
|
||||
message: 'The release branches are invalid in the `branches` configuration.',
|
||||
details: `A minimum of 1 and a maximum of 3 release branches are required in the [branches configuration](${linkify(
|
||||
'docs/usage/configuration.md#branches'
|
||||
@@ -189,24 +243,33 @@ Your configuration for the problematic branches is \`${stringify(branches)}\`.`,
|
||||
This may occur if your repository does not have a release branch, such as \`master\`.
|
||||
|
||||
Your configuration for the problematic branches is \`${stringify(branches)}\`.`,
|
||||
}),
|
||||
EPRERELEASEBRANCH: ({branch}) => ({
|
||||
};
|
||||
}
|
||||
|
||||
export function EPRERELEASEBRANCH({branch}) {
|
||||
return {
|
||||
message: 'A pre-release branch configuration is invalid in the `branches` configuration.',
|
||||
details: `Each pre-release branch in the [branches configuration](${linkify(
|
||||
'docs/usage/configuration.md#branches'
|
||||
)}) must have a \`prerelease\` property valid per the [Semantic Versioning Specification](https://semver.org/#spec-item-9). If the \`prerelease\` property is set to \`true\`, then the \`name\` property is used instead.
|
||||
|
||||
Your configuration for the problematic branch is \`${stringify(branch)}\`.`,
|
||||
}),
|
||||
EPRERELEASEBRANCHES: ({branches}) => ({
|
||||
};
|
||||
}
|
||||
|
||||
export function EPRERELEASEBRANCHES({branches}) {
|
||||
return {
|
||||
message: 'The pre-release branches are invalid in the `branches` configuration.',
|
||||
details: `Each pre-release branch in the [branches configuration](${linkify(
|
||||
'docs/usage/configuration.md#branches'
|
||||
)}) must have a unique \`prerelease\` property. If the \`prerelease\` property is set to \`true\`, then the \`name\` property is used instead.
|
||||
|
||||
Your configuration for the problematic branches is \`${stringify(branches)}\`.`,
|
||||
}),
|
||||
EINVALIDNEXTVERSION: ({nextRelease: {version}, branch: {name, range}, commits, validBranches}) => ({
|
||||
};
|
||||
}
|
||||
|
||||
export function EINVALIDNEXTVERSION({nextRelease: {version}, branch: {name, range}, commits, validBranches}) {
|
||||
return {
|
||||
message: `The release \`${version}\` on branch \`${name}\` cannot be published as it is out of range.`,
|
||||
details: `Based on the releases published on other branches, only versions within the range \`${range}\` can be published from branch \`${name}\`.
|
||||
|
||||
@@ -214,19 +277,22 @@ The following commit${commits.length > 1 ? 's are' : ' is'} responsible for the
|
||||
${commits.map(({commit: {short}, subject}) => `- ${subject} (${short})`).join('\n')}
|
||||
|
||||
${
|
||||
commits.length > 1 ? 'Those commits' : 'This commit'
|
||||
} should be moved to a valid branch with [git merge](https://git-scm.com/docs/git-merge) or [git cherry-pick](https://git-scm.com/docs/git-cherry-pick) and removed from branch \`${name}\` with [git revert](https://git-scm.com/docs/git-revert) or [git reset](https://git-scm.com/docs/git-reset).
|
||||
commits.length > 1 ? 'Those commits' : 'This commit'
|
||||
} should be moved to a valid branch with [git merge](https://git-scm.com/docs/git-merge) or [git cherry-pick](https://git-scm.com/docs/git-cherry-pick) and removed from branch \`${name}\` with [git revert](https://git-scm.com/docs/git-revert) or [git reset](https://git-scm.com/docs/git-reset).
|
||||
|
||||
A valid branch could be ${wordsList(validBranches.map(({name}) => `\`${name}\``))}.
|
||||
|
||||
See the [workflow configuration documentation](${linkify('docs/usage/workflow-configuration.md')}) for more details.`,
|
||||
}),
|
||||
EINVALIDMAINTENANCEMERGE: ({nextRelease: {channel, gitTag, version}, branch: {mergeRange, name}}) => ({
|
||||
};
|
||||
}
|
||||
|
||||
export function EINVALIDMAINTENANCEMERGE({nextRelease: {channel, gitTag, version}, branch: {mergeRange, name}}) {
|
||||
return {
|
||||
message: `The release \`${version}\` on branch \`${name}\` cannot be published as it is out of range.`,
|
||||
details: `Only releases within the range \`${mergeRange}\` can be merged into the maintenance branch \`${name}\` and published to the \`${channel}\` distribution channel.
|
||||
|
||||
The branch \`${name}\` head should be [reset](https://git-scm.com/docs/git-reset) to a previous commit so the commit with tag \`${gitTag}\` is removed from the branch history.
|
||||
|
||||
See the [workflow configuration documentation](${linkify('docs/usage/workflow-configuration.md')}) for more details.`,
|
||||
}),
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/* eslint require-atomic-updates: off */
|
||||
|
||||
const {isString, isPlainObject} = require('lodash');
|
||||
const {getGitHead} = require('../git');
|
||||
const hideSensitive = require('../hide-sensitive');
|
||||
const {hideSensitiveValues} = require('../utils');
|
||||
const {RELEASE_TYPE, RELEASE_NOTES_SEPARATOR} = require('./constants');
|
||||
import {isPlainObject, isString} from 'lodash-es';
|
||||
import {getGitHead} from '../git.js';
|
||||
import hideSensitive from '../hide-sensitive.js';
|
||||
import {hideSensitiveValues} from '../utils.js';
|
||||
import {RELEASE_NOTES_SEPARATOR, RELEASE_TYPE} from './constants.js';
|
||||
|
||||
module.exports = {
|
||||
export default {
|
||||
verifyConditions: {
|
||||
required: false,
|
||||
dryRun: true,
|
||||
|
||||
+6
-4
@@ -1,5 +1,7 @@
|
||||
const debug = require('debug')('semantic-release:get-commits');
|
||||
const {getCommits} = require('./git');
|
||||
import debugCommits from 'debug';
|
||||
import {getCommits} from './git.js';
|
||||
|
||||
const debug = debugCommits('semantic-release:get-commits');
|
||||
|
||||
/**
|
||||
* Retrieve the list of commits on the current branch since the commit sha associated with the last release, or all the commits of the current branch if there is no last released version.
|
||||
@@ -8,7 +10,7 @@ const {getCommits} = require('./git');
|
||||
*
|
||||
* @return {Promise<Array<Object>>} The list of commits on the branch `branch` since the last release.
|
||||
*/
|
||||
module.exports = async ({cwd, env, lastRelease: {gitHead: from}, nextRelease: {gitHead: to = 'HEAD'} = {}, logger}) => {
|
||||
export default async ({cwd, env, lastRelease: {gitHead: from}, nextRelease: {gitHead: to = 'HEAD'} = {}, logger}) => {
|
||||
if (from) {
|
||||
debug('Use from: %s', from);
|
||||
} else {
|
||||
@@ -20,4 +22,4 @@ module.exports = async ({cwd, env, lastRelease: {gitHead: from}, nextRelease: {g
|
||||
logger.log(`Found ${commits.length} commits since last release`);
|
||||
debug('Parsed commits: %o', commits);
|
||||
return commits;
|
||||
};
|
||||
}
|
||||
|
||||
+25
-16
@@ -1,16 +1,24 @@
|
||||
const {castArray, pickBy, isNil, isString, isPlainObject} = require('lodash');
|
||||
const readPkgUp = require('read-pkg-up');
|
||||
const {cosmiconfig} = require('cosmiconfig');
|
||||
const resolveFrom = require('resolve-from');
|
||||
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');
|
||||
import {dirname, resolve} from 'node:path';
|
||||
import {fileURLToPath} from 'node:url';
|
||||
import {createRequire} from 'node:module';
|
||||
|
||||
import {castArray, isNil, isPlainObject, isString, pickBy} from 'lodash-es';
|
||||
import {readPackageUp} from 'read-pkg-up';
|
||||
import {cosmiconfig} from 'cosmiconfig';
|
||||
import resolveFrom from 'resolve-from';
|
||||
import debugConfig from 'debug';
|
||||
import {repoUrl} from './git.js';
|
||||
import PLUGINS_DEFINITIONS from './definitions/plugins.js';
|
||||
import plugins from './plugins/index.js';
|
||||
import {parseConfig, validatePlugin} from './plugins/utils.js';
|
||||
|
||||
const debug = debugConfig('semantic-release:config');
|
||||
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||
const require = createRequire(import.meta.url);
|
||||
|
||||
const CONFIG_NAME = 'release';
|
||||
|
||||
module.exports = async (context, cliOptions) => {
|
||||
export default async (context, cliOptions) => {
|
||||
const {cwd, env} = context;
|
||||
const {config, filepath} = (await cosmiconfig(CONFIG_NAME).search(cwd)) || {};
|
||||
|
||||
@@ -25,11 +33,12 @@ module.exports = async (context, cliOptions) => {
|
||||
if (extendPaths) {
|
||||
// If `extends` is defined, load and merge each shareable config with `options`
|
||||
options = {
|
||||
...castArray(extendPaths).reduce((result, extendPath) => {
|
||||
...await (castArray(extendPaths).reduce(async(eventualResult, extendPath) => {
|
||||
const result = await eventualResult;
|
||||
const extendsOptions = require(resolveFrom.silent(__dirname, extendPath) || resolveFrom(cwd, extendPath));
|
||||
|
||||
// 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
|
||||
// so those plugin will be loaded relative to the config file
|
||||
Object.entries(extendsOptions)
|
||||
.filter(([, value]) => Boolean(value))
|
||||
.reduce((pluginsPath, [option, value]) => {
|
||||
@@ -47,7 +56,7 @@ module.exports = async (context, cliOptions) => {
|
||||
}, pluginsPath);
|
||||
|
||||
return {...result, ...extendsOptions};
|
||||
}, {}),
|
||||
}, {})),
|
||||
...options,
|
||||
};
|
||||
}
|
||||
@@ -70,7 +79,7 @@ module.exports = async (context, cliOptions) => {
|
||||
'@semantic-release/npm',
|
||||
'@semantic-release/github',
|
||||
],
|
||||
// Remove `null` and `undefined` options so they can be replaced with default ones
|
||||
// Remove `null` and `undefined` options, so they can be replaced with default ones
|
||||
...pickBy(options, (option) => !isNil(option)),
|
||||
...(options.branches ? {branches: castArray(options.branches)} : {}),
|
||||
};
|
||||
@@ -82,9 +91,9 @@ module.exports = async (context, cliOptions) => {
|
||||
debug('options values: %O', options);
|
||||
|
||||
return {options, plugins: await plugins({...context, options}, pluginsPath)};
|
||||
};
|
||||
}
|
||||
|
||||
async function pkgRepoUrl(options) {
|
||||
const {packageJson} = (await readPkgUp(options)) || {};
|
||||
const {packageJson} = (await readPackageUp(options)) || {};
|
||||
return packageJson && (isPlainObject(packageJson.repository) ? packageJson.repository.url : packageJson.repository);
|
||||
}
|
||||
|
||||
+4
-4
@@ -1,7 +1,7 @@
|
||||
const SemanticReleaseError = require('@semantic-release/error');
|
||||
const ERROR_DEFINITIONS = require('./definitions/errors');
|
||||
import SemanticReleaseError from '@semantic-release/error';
|
||||
import * as ERROR_DEFINITIONS from './definitions/errors.js';
|
||||
|
||||
module.exports = (code, ctx = {}) => {
|
||||
export default (code, ctx = {}) => {
|
||||
const {message, details} = ERROR_DEFINITIONS[code](ctx);
|
||||
return new SemanticReleaseError(message, code, details);
|
||||
};
|
||||
}
|
||||
|
||||
+10
-8
@@ -1,8 +1,10 @@
|
||||
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 debug = require('debug')('semantic-release:get-git-auth-url');
|
||||
import {format, parse} from 'node:url';
|
||||
import {isNil} from 'lodash-es';
|
||||
import hostedGitInfo from 'hosted-git-info';
|
||||
import debugAuthUrl from 'debug';
|
||||
import {verifyAuth} from './git.js';
|
||||
|
||||
const debug = debugAuthUrl('semantic-release:get-git-auth-url');
|
||||
|
||||
/**
|
||||
* Machinery to format a repository URL with the given credentials
|
||||
@@ -57,7 +59,7 @@ async function ensureValidAuthUrl({cwd, env, branch}, authUrl) {
|
||||
*
|
||||
* @return {String} The formatted Git repository URL.
|
||||
*/
|
||||
module.exports = async (context) => {
|
||||
export default async (context) => {
|
||||
const {cwd, env, branch} = context;
|
||||
const GIT_TOKENS = {
|
||||
GIT_CREDENTIALS: undefined,
|
||||
@@ -89,7 +91,7 @@ module.exports = async (context) => {
|
||||
try {
|
||||
debug('Verifying ssh auth by attempting to push to %s', repositoryUrl);
|
||||
await verifyAuth(repositoryUrl, branch.name, {cwd, env});
|
||||
} catch (_) {
|
||||
} catch {
|
||||
debug('SSH key auth failed, falling back to https.');
|
||||
const envVars = Object.keys(GIT_TOKENS).filter((envVar) => !isNil(env[envVar]));
|
||||
|
||||
@@ -119,4 +121,4 @@ module.exports = async (context) => {
|
||||
}
|
||||
|
||||
return repositoryUrl;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
const {isUndefined} = require('lodash');
|
||||
const semver = require('semver');
|
||||
const {makeTag, isSameChannel} = require('./utils');
|
||||
import {isUndefined} from 'lodash-es';
|
||||
import semver from 'semver';
|
||||
import {isSameChannel, makeTag} from './utils.js';
|
||||
|
||||
/**
|
||||
* Last release.
|
||||
@@ -18,7 +18,7 @@ const {makeTag, isSameChannel} = require('./utils');
|
||||
*
|
||||
* - Filter out the branch tags that are not valid semantic version
|
||||
* - Sort the versions
|
||||
* - Retrive the highest version
|
||||
* - Retrieve the highest version
|
||||
*
|
||||
* @param {Object} context semantic-release context.
|
||||
* @param {Object} params Function parameters.
|
||||
@@ -26,7 +26,7 @@ const {makeTag, isSameChannel} = require('./utils');
|
||||
*
|
||||
* @return {LastRelease} The last tagged release or empty object if none is found.
|
||||
*/
|
||||
module.exports = ({branch, options: {tagFormat}}, {before} = {}) => {
|
||||
export default ({branch, options: {tagFormat}}, {before} = {}) => {
|
||||
const [{version, gitTag, channels} = {}] = branch.tags
|
||||
.filter(
|
||||
(tag) =>
|
||||
@@ -41,4 +41,4 @@ module.exports = ({branch, options: {tagFormat}}, {before} = {}) => {
|
||||
}
|
||||
|
||||
return {};
|
||||
};
|
||||
}
|
||||
|
||||
+6
-4
@@ -1,7 +1,9 @@
|
||||
const {Signale} = require('signale');
|
||||
const figures = require('figures');
|
||||
import signale from 'signale';
|
||||
import figures from 'figures';
|
||||
|
||||
module.exports = ({stdout, stderr}) =>
|
||||
const {Signale} = signale;
|
||||
|
||||
export default ({stdout, stderr}) =>
|
||||
new Signale({
|
||||
config: {displayTimestamp: true, underlineMessage: false, displayLabel: false},
|
||||
disabled: false,
|
||||
@@ -13,4 +15,4 @@ module.exports = ({stdout, stderr}) =>
|
||||
log: {badge: figures.info, color: 'magenta', label: '', stream: [stdout]},
|
||||
success: {badge: figures.tick, color: 'green', label: '', stream: [stdout]},
|
||||
},
|
||||
});
|
||||
})
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
const semver = require('semver');
|
||||
const {FIRST_RELEASE, FIRSTPRERELEASE} = require('./definitions/constants');
|
||||
const {isSameChannel, getLatestVersion, tagsToVersions, highest} = require('./utils');
|
||||
import semver from 'semver';
|
||||
import {FIRST_RELEASE, FIRSTPRERELEASE} from './definitions/constants.js';
|
||||
import {getLatestVersion, highest, isSameChannel, tagsToVersions} from './utils.js';
|
||||
|
||||
module.exports = ({branch, nextRelease: {type, channel}, lastRelease, logger}) => {
|
||||
export default ({branch, nextRelease: {type, channel}, lastRelease, logger}) => {
|
||||
let version;
|
||||
if (lastRelease.version) {
|
||||
const {major, minor, patch} = semver.parse(lastRelease.version);
|
||||
@@ -32,4 +32,4 @@ module.exports = ({branch, nextRelease: {type, channel}, lastRelease, logger}) =
|
||||
}
|
||||
|
||||
return version;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
const {uniqBy, intersection} = require('lodash');
|
||||
const semver = require('semver');
|
||||
const semverDiff = require('semver-diff');
|
||||
const getLastRelease = require('./get-last-release');
|
||||
const {makeTag, getLowerBound} = require('./utils');
|
||||
import {intersection, uniqBy} from 'lodash-es';
|
||||
import semver from 'semver';
|
||||
import semverDiff from 'semver-diff';
|
||||
import getLastRelease from './get-last-release.js';
|
||||
import {getLowerBound, makeTag} from './utils.js';
|
||||
|
||||
/**
|
||||
* Find releases that have been merged from from a higher branch but not added on the channel of the current branch.
|
||||
@@ -11,7 +11,7 @@ const {makeTag, getLowerBound} = require('./utils');
|
||||
*
|
||||
* @return {Array<Object>} Last release and next release to be added on the channel of the current branch.
|
||||
*/
|
||||
module.exports = (context) => {
|
||||
export default (context) => {
|
||||
const {
|
||||
branch,
|
||||
branches,
|
||||
@@ -57,4 +57,4 @@ module.exports = (context) => {
|
||||
},
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
+28
-48
@@ -1,8 +1,10 @@
|
||||
const gitLogParser = require('git-log-parser');
|
||||
const getStream = require('get-stream');
|
||||
const execa = require('execa');
|
||||
const debug = require('debug')('semantic-release:git');
|
||||
const {GIT_NOTE_REF} = require('./definitions/constants');
|
||||
import gitLogParser from 'git-log-parser';
|
||||
import getStream from 'get-stream';
|
||||
import {execa} from 'execa';
|
||||
import debugGit from 'debug';
|
||||
import {GIT_NOTE_REF} from './definitions/constants.js';
|
||||
|
||||
const debug = debugGit('semantic-release:git');
|
||||
|
||||
Object.assign(gitLogParser.fields, {hash: 'H', message: 'B', gitTags: 'd', committerDate: {key: 'ci', type: Date}});
|
||||
|
||||
@@ -14,7 +16,7 @@ Object.assign(gitLogParser.fields, {hash: 'H', message: 'B', gitTags: 'd', commi
|
||||
*
|
||||
* @return {String} The commit sha of the tag in parameter or `null`.
|
||||
*/
|
||||
async function getTagHead(tagName, execaOptions) {
|
||||
export async function getTagHead(tagName, execaOptions) {
|
||||
return (await execa('git', ['rev-list', '-1', tagName], execaOptions)).stdout;
|
||||
}
|
||||
|
||||
@@ -27,7 +29,7 @@ async function getTagHead(tagName, execaOptions) {
|
||||
* @return {Array<String>} List of git tags.
|
||||
* @throws {Error} If the `git` command fails.
|
||||
*/
|
||||
async function getTags(branch, execaOptions) {
|
||||
export async function getTags(branch, execaOptions) {
|
||||
return (await execa('git', ['tag', '--merged', branch], execaOptions)).stdout
|
||||
.split('\n')
|
||||
.map((tag) => tag.trim())
|
||||
@@ -42,7 +44,7 @@ async function getTags(branch, execaOptions) {
|
||||
* @param {Object} [execaOpts] Options to pass to `execa`.
|
||||
* @return {Promise<Array<Object>>} The list of commits between `from` and `to`.
|
||||
*/
|
||||
async function getCommits(from, to, execaOptions) {
|
||||
export async function getCommits(from, to, execaOptions) {
|
||||
return (
|
||||
await getStream.array(
|
||||
gitLogParser.parse(
|
||||
@@ -62,7 +64,7 @@ async function getCommits(from, to, execaOptions) {
|
||||
* @return {Array<String>} List of git branches.
|
||||
* @throws {Error} If the `git` command fails.
|
||||
*/
|
||||
async function getBranches(repositoryUrl, execaOptions) {
|
||||
export async function getBranches(repositoryUrl, execaOptions) {
|
||||
return (await execa('git', ['ls-remote', '--heads', repositoryUrl], execaOptions)).stdout
|
||||
.split('\n')
|
||||
.filter(Boolean)
|
||||
@@ -77,7 +79,7 @@ async function getBranches(repositoryUrl, execaOptions) {
|
||||
*
|
||||
* @return {Boolean} `true` if the reference exists, falsy otherwise.
|
||||
*/
|
||||
async function isRefExists(ref, execaOptions) {
|
||||
export async function isRefExists(ref, execaOptions) {
|
||||
try {
|
||||
return (await execa('git', ['rev-parse', '--verify', ref], execaOptions)).exitCode === 0;
|
||||
} catch (error) {
|
||||
@@ -99,7 +101,7 @@ async function isRefExists(ref, execaOptions) {
|
||||
* @param {String} branch The repository branch to fetch.
|
||||
* @param {Object} [execaOpts] Options to pass to `execa`.
|
||||
*/
|
||||
async function fetch(repositoryUrl, branch, ciBranch, execaOptions) {
|
||||
export async function fetch(repositoryUrl, branch, ciBranch, execaOptions) {
|
||||
const isDetachedHead =
|
||||
(await execa('git', ['rev-parse', '--abbrev-ref', 'HEAD'], {...execaOptions, reject: false})).stdout === 'HEAD';
|
||||
|
||||
@@ -116,7 +118,7 @@ async function fetch(repositoryUrl, branch, ciBranch, execaOptions) {
|
||||
],
|
||||
execaOptions
|
||||
);
|
||||
} catch (_) {
|
||||
} catch {
|
||||
await execa(
|
||||
'git',
|
||||
[
|
||||
@@ -137,14 +139,14 @@ async function fetch(repositoryUrl, branch, ciBranch, execaOptions) {
|
||||
* @param {String} repositoryUrl The remote repository URL.
|
||||
* @param {Object} [execaOpts] Options to pass to `execa`.
|
||||
*/
|
||||
async function fetchNotes(repositoryUrl, execaOptions) {
|
||||
export async function fetchNotes(repositoryUrl, execaOptions) {
|
||||
try {
|
||||
await execa(
|
||||
'git',
|
||||
['fetch', '--unshallow', repositoryUrl, `+refs/notes/${GIT_NOTE_REF}:refs/notes/${GIT_NOTE_REF}`],
|
||||
execaOptions
|
||||
);
|
||||
} catch (_) {
|
||||
} catch {
|
||||
await execa('git', ['fetch', repositoryUrl, `+refs/notes/${GIT_NOTE_REF}:refs/notes/${GIT_NOTE_REF}`], {
|
||||
...execaOptions,
|
||||
reject: false,
|
||||
@@ -159,7 +161,7 @@ async function fetchNotes(repositoryUrl, execaOptions) {
|
||||
*
|
||||
* @return {String} the sha of the HEAD commit.
|
||||
*/
|
||||
async function getGitHead(execaOptions) {
|
||||
export async function getGitHead(execaOptions) {
|
||||
return (await execa('git', ['rev-parse', 'HEAD'], execaOptions)).stdout;
|
||||
}
|
||||
|
||||
@@ -170,7 +172,7 @@ async function getGitHead(execaOptions) {
|
||||
*
|
||||
* @return {string} The value of the remote git URL.
|
||||
*/
|
||||
async function repoUrl(execaOptions) {
|
||||
export async function repoUrl(execaOptions) {
|
||||
try {
|
||||
return (await execa('git', ['config', '--get', 'remote.origin.url'], execaOptions)).stdout;
|
||||
} catch (error) {
|
||||
@@ -185,7 +187,7 @@ async function repoUrl(execaOptions) {
|
||||
*
|
||||
* @return {Boolean} `true` if the current working directory is in a git repository, falsy otherwise.
|
||||
*/
|
||||
async function isGitRepo(execaOptions) {
|
||||
export async function isGitRepo(execaOptions) {
|
||||
try {
|
||||
return (await execa('git', ['rev-parse', '--git-dir'], execaOptions)).exitCode === 0;
|
||||
} catch (error) {
|
||||
@@ -202,7 +204,7 @@ async function isGitRepo(execaOptions) {
|
||||
*
|
||||
* @throws {Error} if not authorized to push.
|
||||
*/
|
||||
async function verifyAuth(repositoryUrl, branch, execaOptions) {
|
||||
export async function verifyAuth(repositoryUrl, branch, execaOptions) {
|
||||
try {
|
||||
await execa('git', ['push', '--dry-run', '--no-verify', repositoryUrl, `HEAD:${branch}`], execaOptions);
|
||||
} catch (error) {
|
||||
@@ -220,7 +222,7 @@ async function verifyAuth(repositoryUrl, branch, execaOptions) {
|
||||
*
|
||||
* @throws {Error} if the tag creation failed.
|
||||
*/
|
||||
async function tag(tagName, ref, execaOptions) {
|
||||
export async function tag(tagName, ref, execaOptions) {
|
||||
await execa('git', ['tag', tagName, ref], execaOptions);
|
||||
}
|
||||
|
||||
@@ -232,7 +234,7 @@ async function tag(tagName, ref, execaOptions) {
|
||||
*
|
||||
* @throws {Error} if the push failed.
|
||||
*/
|
||||
async function push(repositoryUrl, execaOptions) {
|
||||
export async function push(repositoryUrl, execaOptions) {
|
||||
await execa('git', ['push', '--tags', repositoryUrl], execaOptions);
|
||||
}
|
||||
|
||||
@@ -244,7 +246,7 @@ async function push(repositoryUrl, execaOptions) {
|
||||
*
|
||||
* @throws {Error} if the push failed.
|
||||
*/
|
||||
async function pushNotes(repositoryUrl, execaOptions) {
|
||||
export async function pushNotes(repositoryUrl, execaOptions) {
|
||||
await execa('git', ['push', repositoryUrl, `refs/notes/${GIT_NOTE_REF}`], execaOptions);
|
||||
}
|
||||
|
||||
@@ -256,7 +258,7 @@ async function pushNotes(repositoryUrl, execaOptions) {
|
||||
*
|
||||
* @return {Boolean} `true` if valid, falsy otherwise.
|
||||
*/
|
||||
async function verifyTagName(tagName, execaOptions) {
|
||||
export async function verifyTagName(tagName, execaOptions) {
|
||||
try {
|
||||
return (await execa('git', ['check-ref-format', `refs/tags/${tagName}`], execaOptions)).exitCode === 0;
|
||||
} catch (error) {
|
||||
@@ -272,7 +274,7 @@ async function verifyTagName(tagName, execaOptions) {
|
||||
*
|
||||
* @return {Boolean} `true` if valid, falsy otherwise.
|
||||
*/
|
||||
async function verifyBranchName(branch, execaOptions) {
|
||||
export async function verifyBranchName(branch, execaOptions) {
|
||||
try {
|
||||
return (await execa('git', ['check-ref-format', `refs/heads/${branch}`], execaOptions)).exitCode === 0;
|
||||
} catch (error) {
|
||||
@@ -289,7 +291,7 @@ async function verifyBranchName(branch, execaOptions) {
|
||||
*
|
||||
* @return {Boolean} `true` is the HEAD of the current local branch is the same as the HEAD of the remote branch, falsy otherwise.
|
||||
*/
|
||||
async function isBranchUpToDate(repositoryUrl, branch, execaOptions) {
|
||||
export async function isBranchUpToDate(repositoryUrl, branch, execaOptions) {
|
||||
return (
|
||||
(await getGitHead(execaOptions)) ===
|
||||
(await execa('git', ['ls-remote', '--heads', repositoryUrl, branch], execaOptions)).stdout.match(/^(?<ref>\w+)?/)[1]
|
||||
@@ -304,7 +306,7 @@ async function isBranchUpToDate(repositoryUrl, branch, execaOptions) {
|
||||
*
|
||||
* @return {Object} the parsed JSON note if there is one, an empty object otherwise.
|
||||
*/
|
||||
async function getNote(ref, execaOptions) {
|
||||
export async function getNote(ref, execaOptions) {
|
||||
try {
|
||||
return JSON.parse((await execa('git', ['notes', '--ref', GIT_NOTE_REF, 'show', ref], execaOptions)).stdout);
|
||||
} catch (error) {
|
||||
@@ -324,28 +326,6 @@ async function getNote(ref, execaOptions) {
|
||||
* @param {String} ref The Git reference to add the note to.
|
||||
* @param {Object} [execaOpts] Options to pass to `execa`.
|
||||
*/
|
||||
async function addNote(note, ref, execaOptions) {
|
||||
export async function addNote(note, ref, execaOptions) {
|
||||
await execa('git', ['notes', '--ref', GIT_NOTE_REF, 'add', '-f', '-m', JSON.stringify(note), ref], execaOptions);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getTagHead,
|
||||
getTags,
|
||||
getCommits,
|
||||
getBranches,
|
||||
isRefExists,
|
||||
fetch,
|
||||
fetchNotes,
|
||||
getGitHead,
|
||||
repoUrl,
|
||||
isGitRepo,
|
||||
verifyAuth,
|
||||
tag,
|
||||
push,
|
||||
pushNotes,
|
||||
verifyTagName,
|
||||
isBranchUpToDate,
|
||||
verifyBranchName,
|
||||
getNote,
|
||||
addNote,
|
||||
};
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
const {escapeRegExp, size, isString} = require('lodash');
|
||||
const {SECRET_REPLACEMENT, SECRET_MIN_SIZE} = require('./definitions/constants');
|
||||
import {escapeRegExp, isString, size} from 'lodash-es';
|
||||
import {SECRET_MIN_SIZE, SECRET_REPLACEMENT} from './definitions/constants.js';
|
||||
|
||||
module.exports = (env) => {
|
||||
export default (env) => {
|
||||
const toReplace = Object.keys(env).filter((envVar) => {
|
||||
// https://github.com/semantic-release/semantic-release/issues/1558
|
||||
if (envVar === 'GOPRIVATE') {
|
||||
@@ -17,4 +17,4 @@ module.exports = (env) => {
|
||||
);
|
||||
return (output) =>
|
||||
output && isString(output) && toReplace.length > 0 ? output.toString().replace(regexp, SECRET_REPLACEMENT) : output;
|
||||
};
|
||||
}
|
||||
|
||||
+36
-26
@@ -1,20 +1,21 @@
|
||||
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 {validatePlugin, validateStep, loadPlugin, parseConfig} = require('./utils');
|
||||
const pipeline = require('./pipeline');
|
||||
const normalize = require('./normalize');
|
||||
import {castArray, identity, isNil, isPlainObject, isString, omit} from 'lodash-es';
|
||||
import AggregateError from 'aggregate-error';
|
||||
import getError from '../get-error.js';
|
||||
import PLUGINS_DEFINITIONS from '../definitions/plugins.js';
|
||||
import {loadPlugin, parseConfig, validatePlugin, validateStep} from './utils.js';
|
||||
import pipeline from './pipeline.js';
|
||||
import normalize from './normalize.js';
|
||||
|
||||
module.exports = (context, pluginsPath) => {
|
||||
export default async (context, pluginsPath) => {
|
||||
let {options, logger} = context;
|
||||
const errors = [];
|
||||
|
||||
const plugins = options.plugins
|
||||
? castArray(options.plugins).reduce((plugins, plugin) => {
|
||||
? await castArray(options.plugins).reduce(async (eventualPluginsList, plugin) => {
|
||||
const pluginsList = await eventualPluginsList;
|
||||
if (validatePlugin(plugin)) {
|
||||
const [name, config] = parseConfig(plugin);
|
||||
plugin = isString(name) ? loadPlugin(context, name, pluginsPath) : name;
|
||||
plugin = isString(name) ? await loadPlugin(context, name, pluginsPath) : name;
|
||||
|
||||
if (isPlainObject(plugin)) {
|
||||
Object.entries(plugin).forEach(([type, func]) => {
|
||||
@@ -24,7 +25,7 @@ module.exports = (context, pluginsPath) => {
|
||||
writable: false,
|
||||
enumerable: true,
|
||||
});
|
||||
plugins[type] = [...(plugins[type] || []), [func, config]];
|
||||
pluginsList[type] = [...(pluginsList[type] || []), [func, config]];
|
||||
}
|
||||
});
|
||||
} else {
|
||||
@@ -34,7 +35,7 @@ module.exports = (context, pluginsPath) => {
|
||||
errors.push(getError('EPLUGINSCONF', {plugin}));
|
||||
}
|
||||
|
||||
return plugins;
|
||||
return pluginsList;
|
||||
}, {})
|
||||
: [];
|
||||
|
||||
@@ -44,9 +45,13 @@ module.exports = (context, pluginsPath) => {
|
||||
|
||||
options = {...plugins, ...options};
|
||||
|
||||
const pluginsConf = Object.entries(PLUGINS_DEFINITIONS).reduce(
|
||||
(pluginsConf, [type, {required, default: def, pipelineConfig, postprocess = identity, preprocess = identity}]) => {
|
||||
const pluginsConfig = await Object.entries(PLUGINS_DEFINITIONS).reduce(
|
||||
async (
|
||||
eventualPluginsConfigAccumulator,
|
||||
[type, {required, default: def, pipelineConfig, postprocess = identity, preprocess = identity}]
|
||||
) => {
|
||||
let pluginOptions;
|
||||
const pluginsConfigAccumulator = await eventualPluginsConfigAccumulator;
|
||||
|
||||
if (isNil(options[type]) && def) {
|
||||
pluginOptions = def;
|
||||
@@ -60,28 +65,33 @@ module.exports = (context, pluginsPath) => {
|
||||
|
||||
if (!validateStep({required}, options[type])) {
|
||||
errors.push(getError('EPLUGINCONF', {type, required, pluginConf: options[type]}));
|
||||
return pluginsConf;
|
||||
return pluginsConfigAccumulator;
|
||||
}
|
||||
|
||||
pluginOptions = options[type];
|
||||
}
|
||||
|
||||
const steps = castArray(pluginOptions).map((pluginOpt) =>
|
||||
normalize(
|
||||
{...context, options: omit(options, Object.keys(PLUGINS_DEFINITIONS), 'plugins')},
|
||||
type,
|
||||
pluginOpt,
|
||||
pluginsPath
|
||||
const steps = await Promise.all(
|
||||
castArray(pluginOptions).map(async (pluginOpt) =>
|
||||
normalize(
|
||||
{...context, options: omit(options, Object.keys(PLUGINS_DEFINITIONS), 'plugins')},
|
||||
type,
|
||||
pluginOpt,
|
||||
pluginsPath
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
pluginsConf[type] = async (input) =>
|
||||
pluginsConfigAccumulator[type] = async (input) =>
|
||||
postprocess(
|
||||
await pipeline(steps, pipelineConfig && pipelineConfig(pluginsConf, logger))(await preprocess(input)),
|
||||
await pipeline(
|
||||
steps,
|
||||
pipelineConfig && pipelineConfig(pluginsConfigAccumulator, logger)
|
||||
)(await preprocess(input)),
|
||||
input
|
||||
);
|
||||
|
||||
return pluginsConf;
|
||||
return pluginsConfigAccumulator;
|
||||
},
|
||||
plugins
|
||||
);
|
||||
@@ -89,5 +99,5 @@ module.exports = (context, pluginsPath) => {
|
||||
throw new AggregateError(errors);
|
||||
}
|
||||
|
||||
return pluginsConf;
|
||||
};
|
||||
return pluginsConfig;
|
||||
}
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
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');
|
||||
import {cloneDeep, isFunction, isPlainObject, noop, omit} from 'lodash-es';
|
||||
import debugPlugins from 'debug';
|
||||
import getError from '../get-error.js';
|
||||
import {extractErrors} from '../utils.js';
|
||||
import PLUGINS_DEFINITIONS from '../definitions/plugins.js';
|
||||
import {loadPlugin, parseConfig} from './utils.js';
|
||||
|
||||
module.exports = (context, type, pluginOpt, pluginsPath) => {
|
||||
const debug = debugPlugins('semantic-release:plugins');
|
||||
|
||||
export default async (context, type, pluginOpt, pluginsPath) => {
|
||||
const {stdout, stderr, options, logger} = context;
|
||||
if (!pluginOpt) {
|
||||
return noop;
|
||||
@@ -13,7 +15,7 @@ module.exports = (context, type, pluginOpt, pluginsPath) => {
|
||||
|
||||
const [name, config] = parseConfig(pluginOpt);
|
||||
const pluginName = name.pluginName ? name.pluginName : isFunction(name) ? `[Function: ${name.name}]` : name;
|
||||
const plugin = loadPlugin(context, name, pluginsPath);
|
||||
const plugin = await loadPlugin(context, name, pluginsPath);
|
||||
|
||||
debug(`options for ${pluginName}/${type}: %O`, config);
|
||||
|
||||
@@ -64,4 +66,4 @@ module.exports = (context, type, pluginOpt, pluginsPath) => {
|
||||
}
|
||||
|
||||
return validator;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
const {identity} = require('lodash');
|
||||
const pReduce = require('p-reduce');
|
||||
const AggregateError = require('aggregate-error');
|
||||
const {extractErrors} = require('../utils');
|
||||
import {identity} from 'lodash-es';
|
||||
import pReduce from 'p-reduce';
|
||||
import AggregateError from 'aggregate-error';
|
||||
import {extractErrors} from '../utils.js';
|
||||
|
||||
/**
|
||||
* 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.
|
||||
@@ -23,9 +23,9 @@ const {extractErrors} = require('../utils');
|
||||
* @param {Function} [options.getNextInput=identity] Function called after each step is executed, with the last step input and the current current step result; the returned value will be used as the input of the next step.
|
||||
* @param {Function} [options.transform=identity] Function called after each step is executed, with the current step result, the step function and the last step input; the returned value will be saved in the pipeline results.
|
||||
*
|
||||
* @return {Pipeline} A Function that execute the `steps` sequencially
|
||||
* @return {Pipeline} A Function that execute the `steps` sequentially
|
||||
*/
|
||||
module.exports = (steps, {settleAll = false, getNextInput = identity, transform = identity} = {}) => async (input) => {
|
||||
export default (steps, {settleAll = false, getNextInput = identity, transform = identity} = {}) => async (input) => {
|
||||
const results = [];
|
||||
const errors = [];
|
||||
await pReduce(
|
||||
@@ -55,4 +55,4 @@ module.exports = (steps, {settleAll = false, getNextInput = identity, transform
|
||||
}
|
||||
|
||||
return results;
|
||||
};
|
||||
}
|
||||
|
||||
+14
-10
@@ -1,6 +1,9 @@
|
||||
const {dirname} = require('path');
|
||||
const {isString, isFunction, castArray, isArray, isPlainObject, isNil} = require('lodash');
|
||||
const resolveFrom = require('resolve-from');
|
||||
import {dirname} from 'node:path';
|
||||
import {fileURLToPath} from 'node:url';
|
||||
import {castArray, isArray, isFunction, isNil, isPlainObject, isString} from 'lodash-es';
|
||||
import resolveFrom from 'resolve-from';
|
||||
|
||||
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||
|
||||
const validateSteps = (conf) => {
|
||||
return conf.every((conf) => {
|
||||
@@ -24,7 +27,7 @@ const validateSteps = (conf) => {
|
||||
});
|
||||
};
|
||||
|
||||
function validatePlugin(conf) {
|
||||
export function validatePlugin(conf) {
|
||||
return (
|
||||
isString(conf) ||
|
||||
(isArray(conf) &&
|
||||
@@ -35,7 +38,7 @@ function validatePlugin(conf) {
|
||||
);
|
||||
}
|
||||
|
||||
function validateStep({required}, conf) {
|
||||
export function validateStep({required}, conf) {
|
||||
conf = castArray(conf).filter(Boolean);
|
||||
if (required) {
|
||||
return conf.length >= 1 && validateSteps(conf);
|
||||
@@ -44,14 +47,17 @@ function validateStep({required}, conf) {
|
||||
return conf.length === 0 || validateSteps(conf);
|
||||
}
|
||||
|
||||
function loadPlugin({cwd}, name, pluginsPath) {
|
||||
export async 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));
|
||||
|
||||
// See https://github.com/mysticatea/eslint-plugin-node/issues/250
|
||||
// eslint-disable-next-line node/no-unsupported-features/es-syntax
|
||||
return isFunction(name) ? name : (await import(resolveFrom.silent(basePath, name) || resolveFrom(cwd, name))).default;
|
||||
}
|
||||
|
||||
function parseConfig(plugin) {
|
||||
export function parseConfig(plugin) {
|
||||
let path;
|
||||
let config;
|
||||
if (isArray(plugin)) {
|
||||
@@ -64,5 +70,3 @@ function parseConfig(plugin) {
|
||||
|
||||
return [path, config || {}];
|
||||
}
|
||||
|
||||
module.exports = {validatePlugin, validateStep, loadPlugin, parseConfig};
|
||||
|
||||
+19
-37
@@ -1,12 +1,12 @@
|
||||
const {isFunction, union, template} = require('lodash');
|
||||
const semver = require('semver');
|
||||
const hideSensitive = require('./hide-sensitive');
|
||||
import {isFunction, template, union} from 'lodash-es';
|
||||
import semver from 'semver';
|
||||
import hideSensitive from './hide-sensitive.js';
|
||||
|
||||
function extractErrors(err) {
|
||||
return err && isFunction(err[Symbol.iterator]) ? [...err] : [err];
|
||||
export function extractErrors(err) {
|
||||
return err && err.errors ? [...err.errors] : [err];
|
||||
}
|
||||
|
||||
function hideSensitiveValues(env, objs) {
|
||||
export function hideSensitiveValues(env, objs) {
|
||||
const hideFunction = hideSensitive(env);
|
||||
return objs.map((object) => {
|
||||
Object.getOwnPropertyNames(object).forEach((prop) => {
|
||||
@@ -18,19 +18,19 @@ function hideSensitiveValues(env, objs) {
|
||||
});
|
||||
}
|
||||
|
||||
function tagsToVersions(tags) {
|
||||
export function tagsToVersions(tags) {
|
||||
return tags.map(({version}) => version);
|
||||
}
|
||||
|
||||
function isMajorRange(range) {
|
||||
export function isMajorRange(range) {
|
||||
return /^\d+\.x(?:\.x)?$/i.test(range);
|
||||
}
|
||||
|
||||
function isMaintenanceRange(range) {
|
||||
export function isMaintenanceRange(range) {
|
||||
return /^\d+\.(?:\d+|x)(?:\.x)?$/i.test(range);
|
||||
}
|
||||
|
||||
function getUpperBound(range) {
|
||||
export function getUpperBound(range) {
|
||||
const result = semver.valid(range)
|
||||
? range
|
||||
: ((semver.validRange(range) || '').match(/<(?<upperBound>\d+\.\d+\.\d+(-\d+)?)$/) || [])[1];
|
||||
@@ -41,27 +41,27 @@ function getUpperBound(range) {
|
||||
: result;
|
||||
}
|
||||
|
||||
function getLowerBound(range) {
|
||||
export function getLowerBound(range) {
|
||||
return ((semver.validRange(range) || '').match(/(?<lowerBound>\d+\.\d+\.\d+)/) || [])[1];
|
||||
}
|
||||
|
||||
function highest(version1, version2) {
|
||||
export function highest(version1, version2) {
|
||||
return version1 && version2 ? (semver.gt(version1, version2) ? version1 : version2) : version1 || version2;
|
||||
}
|
||||
|
||||
function lowest(version1, version2) {
|
||||
export function lowest(version1, version2) {
|
||||
return version1 && version2 ? (semver.lt(version1, version2) ? version1 : version2) : version1 || version2;
|
||||
}
|
||||
|
||||
function getLatestVersion(versions, {withPrerelease} = {}) {
|
||||
export function getLatestVersion(versions, {withPrerelease} = {}) {
|
||||
return versions.filter((version) => withPrerelease || !semver.prerelease(version)).sort(semver.rcompare)[0];
|
||||
}
|
||||
|
||||
function getEarliestVersion(versions, {withPrerelease} = {}) {
|
||||
export function getEarliestVersion(versions, {withPrerelease} = {}) {
|
||||
return versions.filter((version) => withPrerelease || !semver.prerelease(version)).sort(semver.compare)[0];
|
||||
}
|
||||
|
||||
function getFirstVersion(versions, lowerBranches) {
|
||||
export function getFirstVersion(versions, lowerBranches) {
|
||||
const lowerVersion = union(...lowerBranches.map(({tags}) => tagsToVersions(tags))).sort(semver.rcompare);
|
||||
if (lowerVersion[0]) {
|
||||
return versions.sort(semver.compare).find((version) => semver.gt(version, lowerVersion[0]));
|
||||
@@ -70,32 +70,14 @@ function getFirstVersion(versions, lowerBranches) {
|
||||
return getEarliestVersion(versions);
|
||||
}
|
||||
|
||||
function getRange(min, max) {
|
||||
export function getRange(min, max) {
|
||||
return `>=${min}${max ? ` <${max}` : ''}`;
|
||||
}
|
||||
|
||||
function makeTag(tagFormat, version) {
|
||||
export function makeTag(tagFormat, version) {
|
||||
return template(tagFormat)({version});
|
||||
}
|
||||
|
||||
function isSameChannel(channel, otherChannel) {
|
||||
export function isSameChannel(channel, otherChannel) {
|
||||
return channel === otherChannel || (!channel && !otherChannel);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
extractErrors,
|
||||
hideSensitiveValues,
|
||||
tagsToVersions,
|
||||
isMajorRange,
|
||||
isMaintenanceRange,
|
||||
getUpperBound,
|
||||
getLowerBound,
|
||||
highest,
|
||||
lowest,
|
||||
getLatestVersion,
|
||||
getEarliestVersion,
|
||||
getFirstVersion,
|
||||
getRange,
|
||||
makeTag,
|
||||
isSameChannel,
|
||||
};
|
||||
|
||||
+6
-6
@@ -1,9 +1,9 @@
|
||||
const {template, isString, isPlainObject} = require('lodash');
|
||||
const AggregateError = require('aggregate-error');
|
||||
const {isGitRepo, verifyTagName} = require('./git');
|
||||
const getError = require('./get-error');
|
||||
import {isPlainObject, isString, template} from 'lodash-es';
|
||||
import AggregateError from 'aggregate-error';
|
||||
import {isGitRepo, verifyTagName} from './git.js';
|
||||
import getError from './get-error.js';
|
||||
|
||||
module.exports = async (context) => {
|
||||
export default async (context) => {
|
||||
const {
|
||||
cwd,
|
||||
env,
|
||||
@@ -40,4 +40,4 @@ module.exports = async (context) => {
|
||||
if (errors.length > 0) {
|
||||
throw new AggregateError(errors);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Generated
+5868
-6792
File diff suppressed because it is too large
Load Diff
+41
-31
@@ -2,11 +2,16 @@
|
||||
"name": "semantic-release",
|
||||
"description": "Automated semver compliant package publishing",
|
||||
"version": "0.0.0-development",
|
||||
"type": "module",
|
||||
"author": "Stephan Bönnemann <stephan@boennemann.me> (http://boennemann.me)",
|
||||
"ava": {
|
||||
"files": [
|
||||
"test/**/*.test.js"
|
||||
],
|
||||
"nodeArguments": [
|
||||
"--loader=testdouble",
|
||||
"--no-warnings"
|
||||
],
|
||||
"timeout": "2m"
|
||||
},
|
||||
"bin": {
|
||||
@@ -17,7 +22,8 @@
|
||||
},
|
||||
"contributors": [
|
||||
"Gregor Martynus (https://twitter.com/gr2m)",
|
||||
"Pierre Vanduynslager (https://twitter.com/@pvdlg_)"
|
||||
"Pierre Vanduynslager (https://twitter.com/@pvdlg_)",
|
||||
"Matt Travi <npm@travi.org> (https://matt.travi.org/)"
|
||||
],
|
||||
"dependencies": {
|
||||
"@semantic-release/commit-analyzer": "^9.0.2",
|
||||
@@ -25,49 +31,52 @@
|
||||
"@semantic-release/github": "^8.0.0",
|
||||
"@semantic-release/npm": "^9.0.0",
|
||||
"@semantic-release/release-notes-generator": "^10.0.0",
|
||||
"aggregate-error": "^3.0.0",
|
||||
"aggregate-error": "^4.0.1",
|
||||
"cosmiconfig": "^7.0.0",
|
||||
"debug": "^4.0.0",
|
||||
"env-ci": "^5.0.0",
|
||||
"execa": "^5.0.0",
|
||||
"figures": "^3.0.0",
|
||||
"find-versions": "^4.0.0",
|
||||
"env-ci": "8.0.0-beta.1",
|
||||
"execa": "^6.1.0",
|
||||
"figures": "^5.0.0",
|
||||
"find-versions": "^5.1.0",
|
||||
"get-stream": "^6.0.0",
|
||||
"git-log-parser": "^1.2.0",
|
||||
"hook-std": "^2.0.0",
|
||||
"hosted-git-info": "^4.0.0",
|
||||
"lodash": "^4.17.21",
|
||||
"marked": "^4.0.10",
|
||||
"marked-terminal": "^5.0.0",
|
||||
"hook-std": "^3.0.0",
|
||||
"hosted-git-info": "^5.1.0",
|
||||
"lodash-es": "^4.17.21",
|
||||
"marked": "^4.1.0",
|
||||
"marked-terminal": "^5.1.1",
|
||||
"micromatch": "^4.0.2",
|
||||
"p-each-series": "^2.1.0",
|
||||
"p-reduce": "^2.0.0",
|
||||
"read-pkg-up": "^7.0.0",
|
||||
"p-each-series": "^3.0.0",
|
||||
"p-reduce": "^3.0.0",
|
||||
"read-pkg-up": "^9.1.0",
|
||||
"resolve-from": "^5.0.0",
|
||||
"semver": "^7.3.2",
|
||||
"semver-diff": "^3.1.1",
|
||||
"signale": "^1.2.1",
|
||||
"yargs": "^16.2.0"
|
||||
"yargs": "^17.5.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"ava": "3.15.0",
|
||||
"ava": "4.3.3",
|
||||
"c8": "7.12.0",
|
||||
"clear-module": "4.1.2",
|
||||
"codecov": "3.8.3",
|
||||
"delay": "5.0.0",
|
||||
"dockerode": "3.3.1",
|
||||
"file-url": "3.0.0",
|
||||
"fs-extra": "9.1.0",
|
||||
"got": "11.8.3",
|
||||
"dockerode": "3.3.4",
|
||||
"file-url": "^4.0.0",
|
||||
"fs-extra": "^10.1.0",
|
||||
"got": "^12.5.0",
|
||||
"js-yaml": "4.1.0",
|
||||
"mockserver-client": "5.11.2",
|
||||
"nock": "13.2.1",
|
||||
"nyc": "15.1.0",
|
||||
"p-retry": "4.6.1",
|
||||
"proxyquire": "2.1.3",
|
||||
"sinon": "12.0.1",
|
||||
"mockserver-client": "5.14.0",
|
||||
"nock": "13.2.9",
|
||||
"p-retry": "^5.1.1",
|
||||
"sinon": "14.0.0",
|
||||
"stream-buffers": "3.0.2",
|
||||
"tempy": "1.0.1",
|
||||
"xo": "0.29.1"
|
||||
"tempy": "^3.0.0",
|
||||
"testdouble": "3.16.6",
|
||||
"xo": "0.32.1"
|
||||
},
|
||||
"overrides": {
|
||||
"semantic-release": "20.0.0-beta.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=16 || ^14.17"
|
||||
@@ -93,7 +102,7 @@
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "index.js",
|
||||
"nyc": {
|
||||
"c8": {
|
||||
"include": [
|
||||
"lib/**/*.js",
|
||||
"index.js",
|
||||
@@ -122,13 +131,14 @@
|
||||
"lint": "xo",
|
||||
"pretest": "npm run lint",
|
||||
"semantic-release": "./bin/semantic-release.js",
|
||||
"test": "nyc ava -v",
|
||||
"test:ci": "nyc ava -v"
|
||||
"test": "c8 ava --verbose",
|
||||
"test:ci": "c8 ava --verbose"
|
||||
},
|
||||
"xo": {
|
||||
"prettier": true,
|
||||
"space": true,
|
||||
"rules": {
|
||||
"unicorn/no-reduce": "off",
|
||||
"unicorn/string-content": "off"
|
||||
}
|
||||
},
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
const test = require('ava');
|
||||
const {union} = require('lodash');
|
||||
const semver = require('semver');
|
||||
const proxyquire = require('proxyquire');
|
||||
import test from 'ava';
|
||||
import {union} from 'lodash-es';
|
||||
import semver from 'semver';
|
||||
import * as td from 'testdouble';
|
||||
|
||||
const getBranch = (branches, branch) => branches.find(({name}) => name === branch);
|
||||
const release = (branches, name, version) => getBranch(branches, name).tags.push({version});
|
||||
@@ -11,8 +11,21 @@ const merge = (branches, source, target, tag) => {
|
||||
getBranch(branches, target).tags
|
||||
);
|
||||
};
|
||||
const remoteBranches = [];
|
||||
const repositoryUrl = 'repositoryUrl';
|
||||
let expand, getTags, getBranches;
|
||||
|
||||
test('Enforce ranges with branching release workflow', async (t) => {
|
||||
test.beforeEach(async (t) => {
|
||||
getTags = (await td.replaceEsm('../../lib/branches/get-tags.js')).default;
|
||||
expand = (await td.replaceEsm('../../lib/branches/expand.js')).default;
|
||||
getBranches = (await import('../../lib/branches/index.js')).default;
|
||||
})
|
||||
|
||||
test.afterEach.always((t) => {
|
||||
td.reset();
|
||||
});
|
||||
|
||||
test.serial('Enforce ranges with branching release workflow', async (t) => {
|
||||
const branches = [
|
||||
{name: '1.x', tags: []},
|
||||
{name: '1.0.x', tags: []},
|
||||
@@ -22,12 +35,11 @@ test('Enforce ranges with branching release workflow', async (t) => {
|
||||
{name: 'beta', prerelease: true, tags: []},
|
||||
{name: 'alpha', prerelease: true, tags: []},
|
||||
];
|
||||
const getBranches = proxyquire('../../lib/branches', {'./get-tags': () => branches, './expand': () => []});
|
||||
const context = {options: {branches}};
|
||||
td.when(expand(repositoryUrl, context, branches)).thenResolve(remoteBranches);
|
||||
td.when(getTags(context, remoteBranches)).thenResolve(branches);
|
||||
|
||||
let result = (await getBranches('repositoryUrl', 'master', {options: {branches}})).map(({name, range}) => ({
|
||||
name,
|
||||
range,
|
||||
}));
|
||||
let result = (await getBranches(repositoryUrl, 'master', context)).map(({name, range}) => ({name, range,}));
|
||||
t.is(getBranch(result, '1.0.x').range, '>=1.0.0 <1.0.0', 'Cannot release on 1.0.x before a releasing on master');
|
||||
t.is(getBranch(result, '1.x').range, '>=1.1.0 <1.0.0', 'Cannot release on 1.x before a releasing on master');
|
||||
t.is(getBranch(result, 'master').range, '>=1.0.0');
|
||||
@@ -35,10 +47,7 @@ test('Enforce ranges with branching release workflow', async (t) => {
|
||||
t.is(getBranch(result, 'next-major').range, '>=1.0.0');
|
||||
|
||||
release(branches, 'master', '1.0.0');
|
||||
result = (await getBranches('repositoryUrl', 'master', {options: {branches}})).map(({name, range}) => ({
|
||||
name,
|
||||
range,
|
||||
}));
|
||||
result = (await getBranches('repositoryUrl', 'master', context)).map(({name, range}) => ({name, range}));
|
||||
t.is(getBranch(result, '1.0.x').range, '>=1.0.0 <1.0.0', 'Cannot release on 1.0.x before a releasing on master');
|
||||
t.is(getBranch(result, '1.x').range, '>=1.1.0 <1.0.0', 'Cannot release on 1.x before a releasing on master');
|
||||
t.is(getBranch(result, 'master').range, '>=1.0.0');
|
||||
@@ -189,7 +198,7 @@ test('Enforce ranges with branching release workflow', async (t) => {
|
||||
t.is(getBranch(result, '1.x').range, '>=1.2.0 <2.0.0', 'Can release on 1.x only within range');
|
||||
});
|
||||
|
||||
test('Throw SemanticReleaseError for invalid configurations', async (t) => {
|
||||
test.serial('Throw SemanticReleaseError for invalid configurations', async (t) => {
|
||||
const branches = [
|
||||
{name: '123', range: '123', tags: []},
|
||||
{name: '1.x', tags: []},
|
||||
@@ -199,8 +208,12 @@ test('Throw SemanticReleaseError for invalid configurations', async (t) => {
|
||||
{name: 'alpha', prerelease: 'alpha', tags: []},
|
||||
{name: 'preview', prerelease: 'alpha', tags: []},
|
||||
];
|
||||
const getBranches = proxyquire('../../lib/branches', {'./get-tags': () => branches, './expand': () => []});
|
||||
const errors = [...(await t.throwsAsync(getBranches('repositoryUrl', 'master', {options: {branches}})))];
|
||||
const context = {options: {branches}};
|
||||
td.when(expand(repositoryUrl, context, branches)).thenResolve(remoteBranches);
|
||||
td.when(getTags(context, remoteBranches)).thenResolve(branches);
|
||||
|
||||
const error = await t.throwsAsync(getBranches(repositoryUrl, 'master', context));
|
||||
const errors = [...error.errors];
|
||||
|
||||
t.is(errors[0].name, 'SemanticReleaseError');
|
||||
t.is(errors[0].code, 'EMAINTENANCEBRANCH');
|
||||
@@ -224,14 +237,16 @@ test('Throw SemanticReleaseError for invalid configurations', async (t) => {
|
||||
t.truthy(errors[4].details);
|
||||
});
|
||||
|
||||
test('Throw a SemanticReleaseError if there is duplicate branches', async (t) => {
|
||||
test.serial('Throw a SemanticReleaseError if there is duplicate branches', async (t) => {
|
||||
const branches = [
|
||||
{name: 'master', tags: []},
|
||||
{name: 'master', tags: []},
|
||||
];
|
||||
const getBranches = proxyquire('../../lib/branches', {'./get-tags': () => branches, './expand': () => []});
|
||||
const context = {options: {branches}};
|
||||
td.when(expand(repositoryUrl, context, branches)).thenResolve(remoteBranches);
|
||||
td.when(getTags(context, remoteBranches)).thenResolve(branches);
|
||||
|
||||
const errors = [...(await t.throwsAsync(getBranches('repositoryUrl', 'master', {options: {branches}})))];
|
||||
const errors = [...(await t.throwsAsync(getBranches(repositoryUrl, 'master', context))).errors];
|
||||
|
||||
t.is(errors[0].name, 'SemanticReleaseError');
|
||||
t.is(errors[0].code, 'EDUPLICATEBRANCHES');
|
||||
@@ -239,14 +254,17 @@ test('Throw a SemanticReleaseError if there is duplicate branches', async (t) =>
|
||||
t.truthy(errors[0].details);
|
||||
});
|
||||
|
||||
test('Throw a SemanticReleaseError for each invalid branch name', async (t) => {
|
||||
test.serial('Throw a SemanticReleaseError for each invalid branch name', async (t) => {
|
||||
const branches = [
|
||||
{name: '~master', tags: []},
|
||||
{name: '^master', tags: []},
|
||||
];
|
||||
const getBranches = proxyquire('../../lib/branches', {'./get-tags': () => branches, './expand': () => []});
|
||||
const context = {options: {branches}};
|
||||
const remoteBranches = [];
|
||||
td.when(expand(repositoryUrl, context, branches)).thenResolve(remoteBranches);
|
||||
td.when(getTags(context, remoteBranches)).thenResolve(branches);
|
||||
|
||||
const errors = [...(await t.throwsAsync(getBranches('repositoryUrl', 'master', {options: {branches}})))];
|
||||
const errors = [...(await t.throwsAsync(getBranches(repositoryUrl, 'master', context))).errors];
|
||||
|
||||
t.is(errors[0].name, 'SemanticReleaseError');
|
||||
t.is(errors[0].code, 'EINVALIDBRANCHNAME');
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
const test = require('ava');
|
||||
const expand = require('../../lib/branches/expand');
|
||||
const {gitRepo, gitCommits, gitCheckout, gitPush} = require('../helpers/git-utils');
|
||||
import test from 'ava';
|
||||
import expand from '../../lib/branches/expand.js';
|
||||
import {gitCheckout, gitCommits, gitPush, gitRepo} from '../helpers/git-utils.js';
|
||||
|
||||
test('Expand branches defined with globs', async (t) => {
|
||||
const {cwd, repositoryUrl} = await gitRepo(true);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
const test = require('ava');
|
||||
const getTags = require('../../lib/branches/get-tags');
|
||||
const {gitRepo, gitCommits, gitTagVersion, gitCheckout, gitAddNote} = require('../helpers/git-utils');
|
||||
import test from 'ava';
|
||||
import getTags from '../../lib/branches/get-tags.js';
|
||||
import {gitAddNote, gitCheckout, gitCommits, gitRepo, gitTagVersion} from '../helpers/git-utils.js';
|
||||
|
||||
test('Get the valid tags', async (t) => {
|
||||
const {cwd} = await gitRepo();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
const test = require('ava');
|
||||
const normalize = require('../../lib/branches/normalize');
|
||||
import test from 'ava';
|
||||
import * as normalize from '../../lib/branches/normalize.js';
|
||||
|
||||
const toTags = (versions) => versions.map((version) => ({version}));
|
||||
|
||||
|
||||
+110
-46
@@ -1,8 +1,11 @@
|
||||
const test = require('ava');
|
||||
const {escapeRegExp} = require('lodash');
|
||||
const proxyquire = require('proxyquire').noPreserveCache();
|
||||
const {stub} = require('sinon');
|
||||
const {SECRET_REPLACEMENT} = require('../lib/definitions/constants');
|
||||
import test from 'ava';
|
||||
import {escapeRegExp} from 'lodash-es';
|
||||
import * as td from 'testdouble';
|
||||
import {stub} from 'sinon';
|
||||
import {SECRET_REPLACEMENT} from '../lib/definitions/constants.js';
|
||||
|
||||
let previousArgv;
|
||||
let previousEnv;
|
||||
|
||||
test.beforeEach((t) => {
|
||||
t.context.logs = '';
|
||||
@@ -13,15 +16,22 @@ test.beforeEach((t) => {
|
||||
t.context.stderr = stub(process.stderr, 'write').callsFake((value) => {
|
||||
t.context.errors += value.toString();
|
||||
});
|
||||
|
||||
previousArgv = process.argv;
|
||||
previousEnv = process.env;
|
||||
});
|
||||
|
||||
test.afterEach.always((t) => {
|
||||
t.context.stdout.restore();
|
||||
t.context.stderr.restore();
|
||||
|
||||
process.argv = previousArgv;
|
||||
process.env = previousEnv;
|
||||
|
||||
td.reset();
|
||||
});
|
||||
|
||||
test.serial('Pass options to semantic-release API', async (t) => {
|
||||
const run = stub().resolves(true);
|
||||
const argv = [
|
||||
'',
|
||||
'',
|
||||
@@ -63,31 +73,49 @@ test.serial('Pass options to semantic-release API', async (t) => {
|
||||
'--debug',
|
||||
'-d',
|
||||
];
|
||||
const cli = proxyquire('../cli', {'.': run, process: {...process, argv}});
|
||||
const index = await td.replaceEsm('../index.js');
|
||||
process.argv = argv;
|
||||
const cli = (await import('../cli.js')).default;
|
||||
|
||||
const exitCode = await cli();
|
||||
|
||||
t.deepEqual(run.args[0][0].branches, ['master', 'next']);
|
||||
t.is(run.args[0][0].repositoryUrl, 'https://github/com/owner/repo.git');
|
||||
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');
|
||||
t.deepEqual(run.args[0][0].verifyRelease, ['verify1', 'verify2']);
|
||||
t.deepEqual(run.args[0][0].generateNotes, ['notes']);
|
||||
t.deepEqual(run.args[0][0].prepare, ['prepare1', 'prepare2']);
|
||||
t.deepEqual(run.args[0][0].publish, ['publish1', 'publish2']);
|
||||
t.deepEqual(run.args[0][0].success, ['success1', 'success2']);
|
||||
t.deepEqual(run.args[0][0].fail, ['fail1', 'fail2']);
|
||||
t.is(run.args[0][0].debug, true);
|
||||
t.is(run.args[0][0].dryRun, true);
|
||||
td.verify(index.default({
|
||||
branches: ['master', 'next'],
|
||||
b: ['master', 'next'],
|
||||
'repository-url': 'https://github/com/owner/repo.git',
|
||||
repositoryUrl: 'https://github/com/owner/repo.git',
|
||||
r: 'https://github/com/owner/repo.git',
|
||||
'tag-format': `v\${version}`,
|
||||
tagFormat: `v\${version}`,
|
||||
t: `v\${version}`,
|
||||
plugins: ['plugin1', 'plugin2'],
|
||||
p: ['plugin1', 'plugin2'],
|
||||
extends: ['config1', 'config2'],
|
||||
e: ['config1', 'config2'],
|
||||
'dry-run': true,
|
||||
dryRun: true,
|
||||
d: true,
|
||||
verifyConditions: ['condition1', 'condition2'],
|
||||
'verify-conditions': ['condition1', 'condition2'],
|
||||
analyzeCommits: 'analyze',
|
||||
'analyze-commits': 'analyze',
|
||||
verifyRelease: ['verify1', 'verify2'],
|
||||
'verify-release': ['verify1', 'verify2'],
|
||||
generateNotes: ['notes'],
|
||||
'generate-notes': ['notes'],
|
||||
prepare: ['prepare1', 'prepare2'],
|
||||
publish: ['publish1', 'publish2'],
|
||||
success: ['success1', 'success2'],
|
||||
fail: ['fail1', 'fail2'],
|
||||
debug: true,
|
||||
_: [],
|
||||
'$0': ''
|
||||
}));
|
||||
|
||||
t.is(exitCode, 0);
|
||||
});
|
||||
|
||||
test.serial('Pass options to semantic-release API with alias arguments', async (t) => {
|
||||
const run = stub().resolves(true);
|
||||
const argv = [
|
||||
'',
|
||||
'',
|
||||
@@ -105,42 +133,65 @@ test.serial('Pass options to semantic-release API with alias arguments', async (
|
||||
'config2',
|
||||
'--dry-run',
|
||||
];
|
||||
const cli = proxyquire('../cli', {'.': run, process: {...process, argv}});
|
||||
const index = await td.replaceEsm('../index.js');
|
||||
process.argv = argv;
|
||||
const cli = (await import('../cli.js')).default;
|
||||
|
||||
const exitCode = await cli();
|
||||
|
||||
t.deepEqual(run.args[0][0].branches, ['master']);
|
||||
t.is(run.args[0][0].repositoryUrl, 'https://github/com/owner/repo.git');
|
||||
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);
|
||||
td.verify(index.default({
|
||||
branches: ['master'],
|
||||
b: ['master'],
|
||||
'repository-url': 'https://github/com/owner/repo.git',
|
||||
repositoryUrl: 'https://github/com/owner/repo.git',
|
||||
r: 'https://github/com/owner/repo.git',
|
||||
'tag-format': `v\${version}`,
|
||||
tagFormat: `v\${version}`,
|
||||
t: `v\${version}`,
|
||||
plugins: ['plugin1', 'plugin2'],
|
||||
p: ['plugin1', 'plugin2'],
|
||||
extends: ['config1', 'config2'],
|
||||
e: ['config1', 'config2'],
|
||||
'dry-run': true,
|
||||
dryRun: true,
|
||||
d: true,
|
||||
_: [],
|
||||
'$0': ''
|
||||
}));
|
||||
|
||||
t.is(exitCode, 0);
|
||||
});
|
||||
|
||||
test.serial('Pass unknown options to semantic-release API', async (t) => {
|
||||
const run = stub().resolves(true);
|
||||
const argv = ['', '', '--bool', '--first-option', 'value1', '--second-option', 'value2', '--second-option', 'value3'];
|
||||
const cli = proxyquire('../cli', {'.': run, process: {...process, argv}});
|
||||
const index = await td.replaceEsm('../index.js');
|
||||
process.argv = argv;
|
||||
const cli = (await import('../cli.js')).default;
|
||||
|
||||
const exitCode = await cli();
|
||||
|
||||
t.is(run.args[0][0].bool, true);
|
||||
t.is(run.args[0][0].firstOption, 'value1');
|
||||
t.deepEqual(run.args[0][0].secondOption, ['value2', 'value3']);
|
||||
td.verify(index.default({
|
||||
bool: true,
|
||||
firstOption: 'value1',
|
||||
'first-option': 'value1',
|
||||
secondOption: ['value2', 'value3'],
|
||||
'second-option': ['value2', 'value3'],
|
||||
_: [],
|
||||
'$0': ''
|
||||
}));
|
||||
|
||||
t.is(exitCode, 0);
|
||||
});
|
||||
|
||||
test.serial('Pass empty Array to semantic-release API for list option set to "false"', async (t) => {
|
||||
const run = stub().resolves(true);
|
||||
const argv = ['', '', '--publish', 'false'];
|
||||
const cli = proxyquire('../cli', {'.': run, process: {...process, argv}});
|
||||
const index = await td.replaceEsm('../index.js');
|
||||
process.argv = argv;
|
||||
const cli = (await import('../cli.js')).default;
|
||||
|
||||
const exitCode = await cli();
|
||||
|
||||
t.deepEqual(run.args[0][0].publish, []);
|
||||
td.verify(index.default({publish: [], _: [], '$0': ''}));
|
||||
|
||||
t.is(exitCode, 0);
|
||||
});
|
||||
@@ -148,7 +199,9 @@ test.serial('Pass empty Array to semantic-release API for list option set to "fa
|
||||
test.serial('Do not set properties in option for which arg is not in command line', async (t) => {
|
||||
const run = stub().resolves(true);
|
||||
const argv = ['', '', '-b', 'master'];
|
||||
const cli = proxyquire('../cli', {'.': run, process: {...process, argv}});
|
||||
await td.replaceEsm('../index.js', null, run);
|
||||
process.argv = argv;
|
||||
const cli = (await import('../cli.js')).default;
|
||||
|
||||
await cli();
|
||||
|
||||
@@ -165,7 +218,9 @@ test.serial('Do not set properties in option for which arg is not in command lin
|
||||
test.serial('Display help', async (t) => {
|
||||
const run = stub().resolves(true);
|
||||
const argv = ['', '', '--help'];
|
||||
const cli = proxyquire('../cli', {'.': run, process: {...process, argv}});
|
||||
await td.replaceEsm('../index.js', null, run);
|
||||
process.argv = argv;
|
||||
const cli = (await import('../cli.js')).default;
|
||||
|
||||
const exitCode = await cli();
|
||||
|
||||
@@ -176,7 +231,9 @@ test.serial('Display help', async (t) => {
|
||||
test.serial('Return error exitCode and prints help if called with a command', async (t) => {
|
||||
const run = stub().resolves(true);
|
||||
const argv = ['', '', 'pre'];
|
||||
const cli = proxyquire('../cli', {'.': run, process: {...process, argv}});
|
||||
await td.replaceEsm('../index.js', null, run);
|
||||
process.argv = argv;
|
||||
const cli = (await import('../cli.js')).default;
|
||||
|
||||
const exitCode = await cli();
|
||||
|
||||
@@ -188,7 +245,9 @@ test.serial('Return error exitCode and prints help if called with a command', as
|
||||
test.serial('Return error exitCode if multiple plugin are set for single plugin', async (t) => {
|
||||
const run = stub().resolves(true);
|
||||
const argv = ['', '', '--analyze-commits', 'analyze1', 'analyze2'];
|
||||
const cli = proxyquire('../cli', {'.': run, process: {...process, argv}});
|
||||
await td.replaceEsm('../index.js', null, run);
|
||||
process.argv = argv;
|
||||
const cli = (await import('../cli.js')).default;
|
||||
|
||||
const exitCode = await cli();
|
||||
|
||||
@@ -198,9 +257,11 @@ test.serial('Return error exitCode if multiple plugin are set for single plugin'
|
||||
});
|
||||
|
||||
test.serial('Return error exitCode if semantic-release throw error', async (t) => {
|
||||
const run = stub().rejects(new Error('semantic-release error'));
|
||||
const argv = ['', ''];
|
||||
const cli = proxyquire('../cli', {'.': run, process: {...process, argv}});
|
||||
const index = await td.replaceEsm('../index.js');
|
||||
td.when(index.default({_: [], '$0': ''})).thenReject(new Error('semantic-release error'));
|
||||
process.argv = argv;
|
||||
const cli = (await import('../cli.js')).default;
|
||||
|
||||
const exitCode = await cli();
|
||||
|
||||
@@ -210,9 +271,12 @@ test.serial('Return error exitCode if semantic-release throw error', async (t) =
|
||||
|
||||
test.serial('Hide sensitive environment variable values from the logs', async (t) => {
|
||||
const env = {MY_TOKEN: 'secret token'};
|
||||
const run = stub().rejects(new Error(`Throw error: Exposing token ${env.MY_TOKEN}`));
|
||||
const argv = ['', ''];
|
||||
const cli = proxyquire('../cli', {'.': run, process: {...process, argv, env: {...process.env, ...env}}});
|
||||
const index = await td.replaceEsm('../index.js');
|
||||
td.when(index.default({_: [], '$0': ''})).thenReject(new Error(`Throw error: Exposing token ${env.MY_TOKEN}`));
|
||||
process.argv = argv;
|
||||
process.env = {...process.env, ...env};
|
||||
const cli = (await import('../cli.js')).default;
|
||||
|
||||
const exitCode = await cli();
|
||||
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
const test = require('ava');
|
||||
const {maintenance, prerelease, release} = require('../../lib/definitions/branches');
|
||||
import test from 'ava';
|
||||
import {maintenance, prerelease, release} from '../../lib/definitions/branches.js';
|
||||
|
||||
test('A "maintenance" branch is identified by having a "range" property or a "name" formatted like "N.x", "N.x.x" or "N.N.x"', (t) => {
|
||||
/* eslint-disable unicorn/no-fn-reference-in-iterator */
|
||||
t.true(maintenance.filter({name: '1.x.x'}));
|
||||
t.true(maintenance.filter({name: '1.0.x'}));
|
||||
t.true(maintenance.filter({name: '1.x'}));
|
||||
@@ -15,6 +16,7 @@ test('A "maintenance" branch is identified by having a "range" property or a "na
|
||||
t.false(maintenance.filter({name: 'some-name'}));
|
||||
t.false(maintenance.filter({name: '1.0.0'}));
|
||||
t.false(maintenance.filter({name: 'x.x.x'}));
|
||||
/* eslint-enable unicorn/no-fn-reference-in-iterator */
|
||||
});
|
||||
|
||||
test('A "maintenance" branches must have a "range" property formatted like "N.x", "N.x.x" or "N.N.x"', (t) => {
|
||||
@@ -37,6 +39,7 @@ test('The "maintenance" branches must have unique ranges', (t) => {
|
||||
});
|
||||
|
||||
test('A "prerelease" branch is identified by having a thruthy "prerelease" property', (t) => {
|
||||
/* eslint-disable unicorn/no-fn-reference-in-iterator */
|
||||
t.true(prerelease.filter({name: 'some-name', prerelease: true}));
|
||||
t.true(prerelease.filter({name: 'some-name', prerelease: 'beta'}));
|
||||
t.true(prerelease.filter({name: 'some-name', prerelease: ''}));
|
||||
@@ -44,6 +47,7 @@ test('A "prerelease" branch is identified by having a thruthy "prerelease" prope
|
||||
t.false(prerelease.filter({name: 'some-name', prerelease: null}));
|
||||
t.false(prerelease.filter({name: 'some-name', prerelease: false}));
|
||||
t.false(prerelease.filter({name: 'some-name'}));
|
||||
/* eslint-enable unicorn/no-fn-reference-in-iterator */
|
||||
});
|
||||
|
||||
test('A "prerelease" branch must have a valid prerelease detonation in "prerelease" property or in "name" if "prerelease" is "true"', (t) => {
|
||||
@@ -66,6 +70,7 @@ test('The "prerelease" branches must have unique "prerelease" property', (t) =>
|
||||
});
|
||||
|
||||
test('A "release" branch is identified by not havin a "range" or "prerelease" property or a "name" formatted like "N.x", "N.x.x" or "N.N.x"', (t) => {
|
||||
/* eslint-disable unicorn/no-fn-reference-in-iterator */
|
||||
t.true(release.filter({name: 'some-name'}));
|
||||
|
||||
t.false(release.filter({name: '1.x.x'}));
|
||||
@@ -74,6 +79,7 @@ test('A "release" branch is identified by not havin a "range" or "prerelease" pr
|
||||
t.false(release.filter({name: 'some-name', range: '1.1.x'}));
|
||||
t.false(release.filter({name: 'some-name', prerelease: true}));
|
||||
t.false(release.filter({name: 'some-name', prerelease: 'beta'}));
|
||||
/* eslint-enable unicorn/no-fn-reference-in-iterator */
|
||||
});
|
||||
|
||||
test('There must be between 1 and 3 release branches', (t) => {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
const test = require('ava');
|
||||
const plugins = require('../../lib/definitions/plugins');
|
||||
const {RELEASE_NOTES_SEPARATOR, SECRET_REPLACEMENT} = require('../../lib/definitions/constants');
|
||||
import test from 'ava';
|
||||
import plugins from '../../lib/definitions/plugins.js';
|
||||
import {RELEASE_NOTES_SEPARATOR, SECRET_REPLACEMENT} from '../../lib/definitions/constants.js';
|
||||
|
||||
test('The "analyzeCommits" plugin output must be either undefined or a valid semver release type', (t) => {
|
||||
t.false(plugins.analyzeCommits.outputValidator('invalid'));
|
||||
|
||||
Vendored
+1
-1
@@ -1 +1 @@
|
||||
module.exports = () => {};
|
||||
export default () => {}
|
||||
|
||||
+3
-3
@@ -1,4 +1,4 @@
|
||||
const SemanticReleaseError = require('@semantic-release/error');
|
||||
import SemanticReleaseError from '@semantic-release/error';
|
||||
|
||||
class InheritedError extends SemanticReleaseError {
|
||||
constructor(message, code) {
|
||||
@@ -9,6 +9,6 @@ class InheritedError extends SemanticReleaseError {
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = () => {
|
||||
export default () => {
|
||||
throw new InheritedError('Inherited error', 'EINHERITED');
|
||||
};
|
||||
}
|
||||
|
||||
Vendored
+2
-2
@@ -1,5 +1,5 @@
|
||||
module.exports = () => {
|
||||
export default () => {
|
||||
const error = new Error('a');
|
||||
error.errorProperty = 'errorProperty';
|
||||
throw error;
|
||||
};
|
||||
}
|
||||
|
||||
Vendored
+3
-3
@@ -1,5 +1,5 @@
|
||||
const AggregateError = require('aggregate-error');
|
||||
import AggregateError from 'aggregate-error';
|
||||
|
||||
module.exports = () => {
|
||||
export default () => {
|
||||
throw new AggregateError([new Error('a'), new Error('b')]);
|
||||
};
|
||||
}
|
||||
|
||||
Vendored
+1
-1
@@ -1 +1 @@
|
||||
module.exports = (pluginConfig, context) => context;
|
||||
export default (pluginConfig, context) => context
|
||||
|
||||
Vendored
+2
-2
@@ -1,6 +1,6 @@
|
||||
module.exports = (pluginConfig, {env, logger}) => {
|
||||
export default (pluginConfig, {env, logger}) => {
|
||||
console.log(`Console: Exposing token ${env.MY_TOKEN}`);
|
||||
logger.log(`Log: Exposing token ${env.MY_TOKEN}`);
|
||||
logger.error(`Error: Console token ${env.MY_TOKEN}`);
|
||||
throw new Error(`Throw error: Exposing ${env.MY_TOKEN}`);
|
||||
};
|
||||
}
|
||||
|
||||
Vendored
+3
@@ -0,0 +1,3 @@
|
||||
module.exports = function noop() {
|
||||
|
||||
};
|
||||
Vendored
-1
@@ -1 +0,0 @@
|
||||
module.exports = () => {};
|
||||
+1
-1
@@ -1 +1 @@
|
||||
module.exports = (pluginConfig, context) => ({pluginConfig, context});
|
||||
export default (pluginConfig, context) => ({pluginConfig, context})
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
const test = require('ava');
|
||||
const {stub} = require('sinon');
|
||||
const getCommits = require('../lib/get-commits');
|
||||
const {gitRepo, gitCommits, gitDetachedHead} = require('./helpers/git-utils');
|
||||
import test from 'ava';
|
||||
import {stub} from 'sinon';
|
||||
import getCommits from '../lib/get-commits.js';
|
||||
import {gitCommits, gitDetachedHead, gitRepo} from './helpers/git-utils.js';
|
||||
|
||||
test.beforeEach((t) => {
|
||||
// Stub the logger functions
|
||||
|
||||
+177
-166
@@ -1,12 +1,15 @@
|
||||
const path = require('path');
|
||||
const {format} = require('util');
|
||||
const test = require('ava');
|
||||
const {writeFile, outputJson} = require('fs-extra');
|
||||
const {omit} = require('lodash');
|
||||
const proxyquire = require('proxyquire');
|
||||
const {stub} = require('sinon');
|
||||
const yaml = require('js-yaml');
|
||||
const {gitRepo, gitTagVersion, gitCommits, gitShallowClone, gitAddConfig} = require('./helpers/git-utils');
|
||||
import path from 'node:path';
|
||||
import {format} from 'node:util';
|
||||
import test from 'ava';
|
||||
import fsExtra from 'fs-extra';
|
||||
import {omit} from 'lodash-es';
|
||||
import * as td from 'testdouble';
|
||||
import yaml from 'js-yaml';
|
||||
import {gitAddConfig, gitCommits, gitRepo, gitShallowClone, gitTagVersion} from './helpers/git-utils.js';
|
||||
|
||||
const {outputJson, writeFile} = fsExtra;
|
||||
const pluginsConfig = {foo: 'bar', baz: 'qux'};
|
||||
let plugins;
|
||||
|
||||
const DEFAULT_PLUGINS = [
|
||||
'@semantic-release/commit-analyzer',
|
||||
@@ -15,9 +18,13 @@ const DEFAULT_PLUGINS = [
|
||||
'@semantic-release/github',
|
||||
];
|
||||
|
||||
test.beforeEach((t) => {
|
||||
t.context.plugins = stub().returns({});
|
||||
t.context.getConfig = proxyquire('../lib/get-config', {'./plugins': t.context.plugins});
|
||||
test.beforeEach(async (t) => {
|
||||
plugins = (await td.replaceEsm('../lib/plugins/index.js')).default;
|
||||
t.context.getConfig = (await import('../lib/get-config.js')).default;
|
||||
});
|
||||
|
||||
test.afterEach.always((t) => {
|
||||
td.reset();
|
||||
});
|
||||
|
||||
test('Default values, reading repositoryUrl from package.json', async (t) => {
|
||||
@@ -102,7 +109,7 @@ test('Convert "ci" option to "noCi"', async (t) => {
|
||||
t.is(result.noCi, true);
|
||||
});
|
||||
|
||||
test('Read options from package.json', async (t) => {
|
||||
test.serial('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();
|
||||
const options = {
|
||||
@@ -113,19 +120,18 @@ test('Read options from package.json', async (t) => {
|
||||
tagFormat: `v\${version}`,
|
||||
plugins: false,
|
||||
};
|
||||
// Verify the plugins module is called with the plugin options from package.json
|
||||
td.when(plugins({cwd, options}, {})).thenResolve(pluginsConfig);
|
||||
// Create package.json in repository root
|
||||
await outputJson(path.resolve(cwd, 'package.json'), {release: options});
|
||||
|
||||
const {options: result} = await t.context.getConfig({cwd});
|
||||
const result = await t.context.getConfig({cwd});
|
||||
|
||||
const expected = {...options, branches: ['test_branch']};
|
||||
// Verify the options contains the plugin config from package.json
|
||||
t.deepEqual(result, expected);
|
||||
// Verify the plugins module is called with the plugin options from package.json
|
||||
t.deepEqual(t.context.plugins.args[0][0], {options: expected, cwd});
|
||||
t.deepEqual(result, {options, plugins: pluginsConfig});
|
||||
});
|
||||
|
||||
test('Read options from .releaserc.yml', async (t) => {
|
||||
test.serial('Read options from .releaserc.yml', async (t) => {
|
||||
// Create a git repository, set the current working directory at the root of the repo
|
||||
const {cwd} = await gitRepo();
|
||||
const options = {
|
||||
@@ -137,17 +143,16 @@ test('Read options from .releaserc.yml', async (t) => {
|
||||
};
|
||||
// Create package.json in repository root
|
||||
await writeFile(path.resolve(cwd, '.releaserc.yml'), yaml.dump(options));
|
||||
|
||||
const {options: result} = await t.context.getConfig({cwd});
|
||||
|
||||
const expected = {...options, branches: ['test_branch']};
|
||||
// Verify the options contains the plugin config from package.json
|
||||
t.deepEqual(result, expected);
|
||||
// Verify the plugins module is called with the plugin options from package.json
|
||||
t.deepEqual(t.context.plugins.args[0][0], {options: expected, cwd});
|
||||
td.when(plugins({cwd, options}, {})).thenResolve(pluginsConfig);
|
||||
|
||||
const result = await t.context.getConfig({cwd});
|
||||
|
||||
// Verify the options contains the plugin config from package.json
|
||||
t.deepEqual(result, {options, plugins: pluginsConfig});
|
||||
});
|
||||
|
||||
test('Read options from .releaserc.json', async (t) => {
|
||||
test.serial('Read options from .releaserc.json', async (t) => {
|
||||
// Create a git repository, set the current working directory at the root of the repo
|
||||
const {cwd} = await gitRepo();
|
||||
const options = {
|
||||
@@ -159,17 +164,16 @@ test('Read options from .releaserc.json', async (t) => {
|
||||
};
|
||||
// Create package.json in repository root
|
||||
await outputJson(path.resolve(cwd, '.releaserc.json'), options);
|
||||
|
||||
const {options: result} = await t.context.getConfig({cwd});
|
||||
|
||||
const expected = {...options, branches: ['test_branch']};
|
||||
// Verify the options contains the plugin config from package.json
|
||||
t.deepEqual(result, expected);
|
||||
// Verify the plugins module is called with the plugin options from package.json
|
||||
t.deepEqual(t.context.plugins.args[0][0], {options: expected, cwd});
|
||||
td.when(plugins({cwd, options}, {})).thenResolve(pluginsConfig);
|
||||
|
||||
const result = await t.context.getConfig({cwd});
|
||||
|
||||
// Verify the options contains the plugin config from package.json
|
||||
t.deepEqual(result, {options, plugins: pluginsConfig});
|
||||
});
|
||||
|
||||
test('Read options from .releaserc.js', async (t) => {
|
||||
test.serial('Read options from .releaserc.js', async (t) => {
|
||||
// Create a git repository, set the current working directory at the root of the repo
|
||||
const {cwd} = await gitRepo();
|
||||
const options = {
|
||||
@@ -181,17 +185,16 @@ test('Read options from .releaserc.js', async (t) => {
|
||||
};
|
||||
// Create package.json in repository root
|
||||
await writeFile(path.resolve(cwd, '.releaserc.js'), `module.exports = ${JSON.stringify(options)}`);
|
||||
|
||||
const {options: result} = await t.context.getConfig({cwd});
|
||||
|
||||
const expected = {...options, branches: ['test_branch']};
|
||||
// Verify the options contains the plugin config from package.json
|
||||
t.deepEqual(result, expected);
|
||||
// Verify the plugins module is called with the plugin options from package.json
|
||||
t.deepEqual(t.context.plugins.args[0][0], {options: expected, cwd});
|
||||
td.when(plugins({cwd, options}, {})).thenResolve(pluginsConfig);
|
||||
|
||||
const result = await t.context.getConfig({cwd});
|
||||
|
||||
// Verify the options contains the plugin config from package.json
|
||||
t.deepEqual(result, {options, plugins: pluginsConfig});
|
||||
});
|
||||
|
||||
test('Read options from .releaserc.cjs', async (t) => {
|
||||
test.serial('Read options from .releaserc.cjs', async (t) => {
|
||||
// Create a git repository, set the current working directory at the root of the repo
|
||||
const {cwd} = await gitRepo();
|
||||
const options = {
|
||||
@@ -203,17 +206,16 @@ test('Read options from .releaserc.cjs', async (t) => {
|
||||
};
|
||||
// Create .releaserc.cjs in repository root
|
||||
await writeFile(path.resolve(cwd, '.releaserc.cjs'), `module.exports = ${JSON.stringify(options)}`);
|
||||
|
||||
const {options: result} = await t.context.getConfig({cwd});
|
||||
|
||||
const expected = {...options, branches: ['test_branch']};
|
||||
// Verify the options contains the plugin config from .releaserc.cjs
|
||||
t.deepEqual(result, expected);
|
||||
// Verify the plugins module is called with the plugin options from .releaserc.cjs
|
||||
t.deepEqual(t.context.plugins.args[0][0], {options: expected, cwd});
|
||||
td.when(plugins({cwd, options}, {})).thenResolve(pluginsConfig);
|
||||
|
||||
const result = await t.context.getConfig({cwd});
|
||||
|
||||
// Verify the options contains the plugin config from .releaserc.cjs
|
||||
t.deepEqual(result, {options, plugins: pluginsConfig});
|
||||
});
|
||||
|
||||
test('Read options from release.config.js', async (t) => {
|
||||
test.serial('Read options from release.config.js', async (t) => {
|
||||
// Create a git repository, set the current working directory at the root of the repo
|
||||
const {cwd} = await gitRepo();
|
||||
const options = {
|
||||
@@ -225,17 +227,16 @@ test('Read options from release.config.js', async (t) => {
|
||||
};
|
||||
// Create package.json in repository root
|
||||
await writeFile(path.resolve(cwd, 'release.config.js'), `module.exports = ${JSON.stringify(options)}`);
|
||||
|
||||
const {options: result} = await t.context.getConfig({cwd});
|
||||
|
||||
const expected = {...options, branches: ['test_branch']};
|
||||
// Verify the options contains the plugin config from package.json
|
||||
t.deepEqual(result, expected);
|
||||
// Verify the plugins module is called with the plugin options from package.json
|
||||
t.deepEqual(t.context.plugins.args[0][0], {options: expected, cwd});
|
||||
td.when(plugins({cwd, options}, {})).thenResolve(pluginsConfig);
|
||||
|
||||
const result = await t.context.getConfig({cwd});
|
||||
|
||||
// Verify the options contains the plugin config from package.json
|
||||
t.deepEqual(result, {options, plugins: pluginsConfig});
|
||||
});
|
||||
|
||||
test('Read options from release.config.cjs', async (t) => {
|
||||
test.serial('Read options from release.config.cjs', async (t) => {
|
||||
// Create a git repository, set the current working directory at the root of the repo
|
||||
const {cwd} = await gitRepo();
|
||||
const options = {
|
||||
@@ -245,19 +246,18 @@ test('Read options from release.config.cjs', async (t) => {
|
||||
tagFormat: `v\${version}`,
|
||||
plugins: false,
|
||||
};
|
||||
// Verify the plugins module is called with the plugin options from release.config.cjs
|
||||
td.when(plugins({cwd, options}, {})).thenResolve(pluginsConfig);
|
||||
// Create release.config.cjs in repository root
|
||||
await writeFile(path.resolve(cwd, 'release.config.cjs'), `module.exports = ${JSON.stringify(options)}`);
|
||||
|
||||
const {options: result} = await t.context.getConfig({cwd});
|
||||
const result = await t.context.getConfig({cwd});
|
||||
|
||||
const expected = {...options, branches: ['test_branch']};
|
||||
// Verify the options contains the plugin config from release.config.cjs
|
||||
t.deepEqual(result, expected);
|
||||
// Verify the plugins module is called with the plugin options from release.config.cjs
|
||||
t.deepEqual(t.context.plugins.args[0][0], {options: expected, cwd});
|
||||
t.deepEqual(result, {options, plugins: pluginsConfig});
|
||||
});
|
||||
|
||||
test('Prioritise CLI/API parameters over file configuration and git repo', async (t) => {
|
||||
test.serial('Prioritise CLI/API parameters over file configuration and git repo', async (t) => {
|
||||
// Create a git repository, set the current working directory at the root of the repo
|
||||
let {cwd, repositoryUrl} = await gitRepo();
|
||||
await gitCommits(['First'], {cwd});
|
||||
@@ -274,20 +274,19 @@ test('Prioritise CLI/API parameters over file configuration and git repo', async
|
||||
tagFormat: `cli\${version}`,
|
||||
plugins: false,
|
||||
};
|
||||
// Verify the plugins module is called with the plugin options from CLI/API
|
||||
td.when(plugins({cwd, options}, {})).thenResolve(pluginsConfig);
|
||||
const pkg = {release: pkgOptions, repository: 'git@host.null:owner/module.git'};
|
||||
// Create package.json in repository root
|
||||
await outputJson(path.resolve(cwd, 'package.json'), pkg);
|
||||
|
||||
const result = await t.context.getConfig({cwd}, options);
|
||||
|
||||
const expected = {...options, branches: ['branch_cli']};
|
||||
// Verify the options contains the plugin config from CLI/API
|
||||
t.deepEqual(result.options, expected);
|
||||
// Verify the plugins module is called with the plugin options from CLI/API
|
||||
t.deepEqual(t.context.plugins.args[0][0], {options: expected, cwd});
|
||||
t.deepEqual(result, {options, plugins: pluginsConfig});
|
||||
});
|
||||
|
||||
test('Read configuration from file path in "extends"', async (t) => {
|
||||
test.serial('Read configuration from file path in "extends"', async (t) => {
|
||||
// Create a git repository, set the current working directory at the root of the repo
|
||||
const {cwd} = await gitRepo();
|
||||
const pkgOptions = {extends: './shareable.json'};
|
||||
@@ -302,23 +301,24 @@ test('Read configuration from file path in "extends"', async (t) => {
|
||||
// Create package.json and shareable.json in repository root
|
||||
await outputJson(path.resolve(cwd, 'package.json'), {release: pkgOptions});
|
||||
await outputJson(path.resolve(cwd, 'shareable.json'), options);
|
||||
|
||||
const {options: result} = await t.context.getConfig({cwd});
|
||||
|
||||
const expected = {...options, branches: ['test_branch']};
|
||||
// Verify the options contains the plugin config from shareable.json
|
||||
t.deepEqual(result, expected);
|
||||
// Verify the plugins module is called with the plugin options from shareable.json
|
||||
t.deepEqual(t.context.plugins.args[0][0], {options: expected, cwd});
|
||||
t.deepEqual(t.context.plugins.args[0][1], {
|
||||
analyzeCommits: './shareable.json',
|
||||
generateNotes: './shareable.json',
|
||||
'plugin-1': './shareable.json',
|
||||
'plugin-2': './shareable.json',
|
||||
});
|
||||
td.when(plugins(
|
||||
{cwd, options},
|
||||
{
|
||||
analyzeCommits: './shareable.json',
|
||||
generateNotes: './shareable.json',
|
||||
'plugin-1': './shareable.json',
|
||||
'plugin-2': './shareable.json',
|
||||
}
|
||||
)).thenResolve(pluginsConfig);
|
||||
|
||||
const result = await t.context.getConfig({cwd});
|
||||
|
||||
// Verify the options contains the plugin config from shareable.json
|
||||
t.deepEqual(result, {options, plugins: pluginsConfig});
|
||||
});
|
||||
|
||||
test('Read configuration from module path in "extends"', async (t) => {
|
||||
test.serial('Read configuration from module path in "extends"', async (t) => {
|
||||
// Create a git repository, set the current working directory at the root of the repo
|
||||
const {cwd} = await gitRepo();
|
||||
const pkgOptions = {extends: 'shareable'};
|
||||
@@ -333,21 +333,19 @@ test('Read configuration from module path in "extends"', async (t) => {
|
||||
// Create package.json and shareable.json in repository root
|
||||
await outputJson(path.resolve(cwd, 'package.json'), {release: pkgOptions});
|
||||
await outputJson(path.resolve(cwd, 'node_modules/shareable/index.json'), options);
|
||||
|
||||
const {options: result} = await t.context.getConfig({cwd});
|
||||
|
||||
const expected = {...options, branches: ['test_branch']};
|
||||
// Verify the options contains the plugin config from shareable.json
|
||||
t.deepEqual(result, expected);
|
||||
// Verify the plugins module is called with the plugin options from shareable.json
|
||||
t.deepEqual(t.context.plugins.args[0][0], {options: expected, cwd});
|
||||
t.deepEqual(t.context.plugins.args[0][1], {
|
||||
analyzeCommits: 'shareable',
|
||||
generateNotes: 'shareable',
|
||||
});
|
||||
td.when(plugins(
|
||||
{cwd, options},
|
||||
{analyzeCommits: 'shareable', generateNotes: 'shareable'}
|
||||
)).thenResolve(pluginsConfig);
|
||||
|
||||
const result = await t.context.getConfig({cwd});
|
||||
|
||||
// Verify the options contains the plugin config from shareable.json
|
||||
t.deepEqual(result, {options, plugins: pluginsConfig});
|
||||
});
|
||||
|
||||
test('Read configuration from an array of paths in "extends"', async (t) => {
|
||||
test.serial('Read configuration from an array of paths in "extends"', async (t) => {
|
||||
// Create a git repository, set the current working directory at the root of the repo
|
||||
const {cwd} = await gitRepo();
|
||||
const pkgOptions = {extends: ['./shareable1.json', './shareable2.json']};
|
||||
@@ -369,24 +367,26 @@ test('Read configuration from an array of paths in "extends"', async (t) => {
|
||||
await outputJson(path.resolve(cwd, 'package.json'), {release: pkgOptions});
|
||||
await outputJson(path.resolve(cwd, 'shareable1.json'), options1);
|
||||
await outputJson(path.resolve(cwd, 'shareable2.json'), options2);
|
||||
|
||||
const {options: result} = await t.context.getConfig({cwd});
|
||||
|
||||
const expected = {...options1, ...options2, branches: ['test_branch']};
|
||||
// Verify the options contains the plugin config from shareable1.json and shareable2.json
|
||||
t.deepEqual(result, expected);
|
||||
const expectedOptions = {...options1, ...options2, branches: ['test_branch']};
|
||||
// Verify the plugins module is called with the plugin options from shareable1.json and shareable2.json
|
||||
t.deepEqual(t.context.plugins.args[0][0], {options: expected, cwd});
|
||||
t.deepEqual(t.context.plugins.args[0][1], {
|
||||
verifyRelease1: './shareable1.json',
|
||||
verifyRelease2: './shareable2.json',
|
||||
generateNotes2: './shareable2.json',
|
||||
analyzeCommits1: './shareable1.json',
|
||||
analyzeCommits2: './shareable2.json',
|
||||
});
|
||||
td.when(plugins(
|
||||
{options: expectedOptions, cwd},
|
||||
{
|
||||
verifyRelease1: './shareable1.json',
|
||||
verifyRelease2: './shareable2.json',
|
||||
generateNotes2: './shareable2.json',
|
||||
analyzeCommits1: './shareable1.json',
|
||||
analyzeCommits2: './shareable2.json',
|
||||
}
|
||||
)).thenResolve(pluginsConfig);
|
||||
|
||||
const result = await t.context.getConfig({cwd});
|
||||
|
||||
// Verify the options contains the plugin config from shareable1.json and shareable2.json
|
||||
t.deepEqual(result, {options: expectedOptions, plugins: pluginsConfig});
|
||||
});
|
||||
|
||||
test('Prioritize configuration from config file over "extends"', async (t) => {
|
||||
test.serial('Prioritize configuration from config file over "extends"', async (t) => {
|
||||
// Create a git repository, set the current working directory at the root of the repo
|
||||
const {cwd} = await gitRepo();
|
||||
const pkgOptions = {
|
||||
@@ -407,22 +407,24 @@ test('Prioritize configuration from config file over "extends"', async (t) => {
|
||||
// Create package.json and shareable.json in repository root
|
||||
await outputJson(path.resolve(cwd, 'package.json'), {release: pkgOptions});
|
||||
await outputJson(path.resolve(cwd, 'shareable.json'), options1);
|
||||
|
||||
const {options: result} = await t.context.getConfig({cwd});
|
||||
|
||||
const expected = omit({...options1, ...pkgOptions, branches: ['test_pkg']}, 'extends');
|
||||
// Verify the options contains the plugin config from package.json and shareable.json
|
||||
t.deepEqual(result, expected);
|
||||
const expectedOptions = omit({...options1, ...pkgOptions, branches: ['test_pkg']}, 'extends');
|
||||
// Verify the plugins module is called with the plugin options from package.json and shareable.json
|
||||
t.deepEqual(t.context.plugins.args[0][0], {options: expected, cwd});
|
||||
t.deepEqual(t.context.plugins.args[0][1], {
|
||||
analyzeCommits: './shareable.json',
|
||||
generateNotesShareable: './shareable.json',
|
||||
publishShareable: './shareable.json',
|
||||
});
|
||||
td.when(plugins(
|
||||
{cwd, options: expectedOptions},
|
||||
{
|
||||
analyzeCommits: './shareable.json',
|
||||
generateNotesShareable: './shareable.json',
|
||||
publishShareable: './shareable.json',
|
||||
}
|
||||
)).thenResolve(pluginsConfig);
|
||||
|
||||
const result = await t.context.getConfig({cwd});
|
||||
|
||||
// Verify the options contains the plugin config from package.json and shareable.json
|
||||
t.deepEqual(result, {options: expectedOptions, plugins: pluginsConfig});
|
||||
});
|
||||
|
||||
test('Prioritize configuration from cli/API options over "extends"', async (t) => {
|
||||
test.serial('Prioritize configuration from cli/API options over "extends"', async (t) => {
|
||||
// Create a git repository, set the current working directory at the root of the repo
|
||||
const {cwd} = await gitRepo();
|
||||
const cliOptions = {
|
||||
@@ -455,17 +457,20 @@ test('Prioritize configuration from cli/API options over "extends"', async (t) =
|
||||
await outputJson(path.resolve(cwd, 'package.json'), {release: pkgOptions});
|
||||
await outputJson(path.resolve(cwd, 'shareable1.json'), options1);
|
||||
await outputJson(path.resolve(cwd, 'shareable2.json'), options2);
|
||||
|
||||
const {options: result} = await t.context.getConfig({cwd}, cliOptions);
|
||||
|
||||
const expected = omit({...options2, ...pkgOptions, ...cliOptions, branches: ['branch_opts']}, 'extends');
|
||||
// Verify the options contains the plugin config from package.json and shareable2.json
|
||||
t.deepEqual(result, expected);
|
||||
const expectedOptions = omit({...options2, ...pkgOptions, ...cliOptions, branches: ['branch_opts']}, 'extends');
|
||||
// Verify the plugins module is called with the plugin options from package.json and shareable2.json
|
||||
t.deepEqual(t.context.plugins.args[0][0], {options: expected, cwd});
|
||||
td.when(plugins(
|
||||
{cwd, options: expectedOptions},
|
||||
{analyzeCommits2: './shareable2.json', publishShareable: './shareable2.json'}
|
||||
)).thenResolve(pluginsConfig);
|
||||
|
||||
const result = await t.context.getConfig({cwd}, cliOptions);
|
||||
|
||||
// Verify the options contains the plugin config from package.json and shareable2.json
|
||||
t.deepEqual(result, {options: expectedOptions, plugins: pluginsConfig});
|
||||
});
|
||||
|
||||
test('Allow to unset properties defined in shareable config with "null"', async (t) => {
|
||||
test.serial('Allow to unset properties defined in shareable config with "null"', async (t) => {
|
||||
// Create a git repository, set the current working directory at the root of the repo
|
||||
const {cwd} = await gitRepo();
|
||||
const pkgOptions = {
|
||||
@@ -484,33 +489,40 @@ test('Allow to unset properties defined in shareable config with "null"', async
|
||||
// Create package.json and shareable.json in repository root
|
||||
await outputJson(path.resolve(cwd, 'package.json'), {release: pkgOptions});
|
||||
await outputJson(path.resolve(cwd, 'shareable.json'), options1);
|
||||
// Verify the plugins module is called with the plugin options from shareable.json and the default `plugins`
|
||||
td.when(plugins(
|
||||
{
|
||||
options: {
|
||||
...omit(options1, 'analyzeCommits'),
|
||||
...omit(pkgOptions, ['extends', 'analyzeCommits']),
|
||||
plugins: DEFAULT_PLUGINS,
|
||||
},
|
||||
cwd,
|
||||
},
|
||||
{
|
||||
generateNotes: './shareable.json',
|
||||
analyzeCommits: './shareable.json',
|
||||
'test-plugin': './shareable.json',
|
||||
}
|
||||
)).thenResolve(pluginsConfig);
|
||||
|
||||
const {options} = await t.context.getConfig({cwd});
|
||||
const result = await t.context.getConfig({cwd});
|
||||
|
||||
// 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',
|
||||
});
|
||||
t.deepEqual(
|
||||
result,
|
||||
{
|
||||
options: {
|
||||
...omit(options1, ['analyzeCommits']),
|
||||
...omit(pkgOptions, ['extends', 'analyzeCommits']),
|
||||
plugins: DEFAULT_PLUGINS,
|
||||
},
|
||||
plugins: pluginsConfig
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
test('Allow to unset properties defined in shareable config with "undefined"', async (t) => {
|
||||
test.serial('Allow to unset properties defined in shareable config with "undefined"', async (t) => {
|
||||
// Create a git repository, set the current working directory at the root of the repo
|
||||
const {cwd} = await gitRepo();
|
||||
const pkgOptions = {
|
||||
@@ -525,25 +537,24 @@ test('Allow to unset properties defined in shareable config with "undefined"', a
|
||||
tagFormat: `v\${version}`,
|
||||
plugins: false,
|
||||
};
|
||||
// Create package.json and release.config.js in repository root
|
||||
// Create release.config.js and shareable.json in repository root
|
||||
await writeFile(path.resolve(cwd, 'release.config.js'), `module.exports = ${format(pkgOptions)}`);
|
||||
await outputJson(path.resolve(cwd, 'shareable.json'), options1);
|
||||
|
||||
const {options: result} = await t.context.getConfig({cwd});
|
||||
|
||||
const expected = {
|
||||
const expectedOptions = {
|
||||
...omit(options1, 'analyzeCommits'),
|
||||
...omit(pkgOptions, ['extends', 'analyzeCommits']),
|
||||
branches: ['test_branch'],
|
||||
};
|
||||
// Verify the options contains the plugin config from shareable.json
|
||||
t.deepEqual(result, expected);
|
||||
// Verify the plugins module is called with the plugin options from shareable.json
|
||||
t.deepEqual(t.context.plugins.args[0][0], {options: expected, cwd});
|
||||
t.deepEqual(t.context.plugins.args[0][1], {
|
||||
generateNotes: './shareable.json',
|
||||
analyzeCommits: './shareable.json',
|
||||
});
|
||||
td.when(plugins(
|
||||
{options: expectedOptions, cwd},
|
||||
{generateNotes: './shareable.json', analyzeCommits: './shareable.json'}
|
||||
)).thenResolve(pluginsConfig);
|
||||
|
||||
const result = await t.context.getConfig({cwd});
|
||||
|
||||
// Verify the options contains the plugin config from shareable.json
|
||||
t.deepEqual(result, {options: expectedOptions, plugins: pluginsConfig});
|
||||
});
|
||||
|
||||
test('Throw an Error if one of the shareable config cannot be found', async (t) => {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
const test = require('ava');
|
||||
const getAuthUrl = require('../lib/get-git-auth-url');
|
||||
const {gitRepo} = require('./helpers/git-utils');
|
||||
import test from 'ava';
|
||||
import getAuthUrl from '../lib/get-git-auth-url.js';
|
||||
import {gitRepo} from './helpers/git-utils.js';
|
||||
|
||||
const env = {GIT_ASKPASS: 'echo', GIT_TERMINAL_PROMPT: 0};
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
const test = require('ava');
|
||||
const getLastRelease = require('../lib/get-last-release');
|
||||
import test from 'ava';
|
||||
import getLastRelease from '../lib/get-last-release.js';
|
||||
|
||||
test('Get the highest non-prerelease valid tag', (t) => {
|
||||
const result = getLastRelease({
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
const test = require('ava');
|
||||
const {spy} = require('sinon');
|
||||
const getLogger = require('../lib/get-logger');
|
||||
import test from 'ava';
|
||||
import {spy} from 'sinon';
|
||||
import getLogger from '../lib/get-logger.js';
|
||||
|
||||
test('Expose "error", "success" and "log" functions', (t) => {
|
||||
const stdout = spy();
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
const test = require('ava');
|
||||
const {stub} = require('sinon');
|
||||
const getNextVersion = require('../lib/get-next-version');
|
||||
import test from 'ava';
|
||||
import {stub} from 'sinon';
|
||||
import getNextVersion from '../lib/get-next-version.js';
|
||||
|
||||
test.beforeEach((t) => {
|
||||
// Stub the logger functions
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
const test = require('ava');
|
||||
const getReleaseToAdd = require('../lib/get-release-to-add');
|
||||
import test from 'ava';
|
||||
import getReleaseToAdd from '../lib/get-release-to-add.js';
|
||||
|
||||
test('Return versions merged from release to maintenance branch, excluding lower than branch start range', (t) => {
|
||||
const result = getReleaseToAdd({
|
||||
|
||||
+30
-30
@@ -1,40 +1,40 @@
|
||||
const test = require('ava');
|
||||
const tempy = require('tempy');
|
||||
const {
|
||||
getTagHead,
|
||||
isRefExists,
|
||||
import test from 'ava';
|
||||
import {temporaryDirectory} from 'tempy';
|
||||
import {
|
||||
addNote,
|
||||
fetch,
|
||||
fetchNotes,
|
||||
getBranches,
|
||||
getGitHead,
|
||||
getNote,
|
||||
getTagHead,
|
||||
getTags,
|
||||
isBranchUpToDate,
|
||||
isGitRepo,
|
||||
isRefExists,
|
||||
push,
|
||||
repoUrl,
|
||||
tag,
|
||||
push,
|
||||
getTags,
|
||||
getBranches,
|
||||
isGitRepo,
|
||||
verifyTagName,
|
||||
isBranchUpToDate,
|
||||
getNote,
|
||||
addNote,
|
||||
fetchNotes,
|
||||
} = require('../lib/git');
|
||||
const {
|
||||
gitRepo,
|
||||
gitCommits,
|
||||
gitCheckout,
|
||||
gitTagVersion,
|
||||
gitShallowClone,
|
||||
gitGetCommits,
|
||||
verifyTagName
|
||||
} from '../lib/git.js';
|
||||
import {
|
||||
gitAddConfig,
|
||||
gitAddNote,
|
||||
gitCheckout,
|
||||
gitCommits,
|
||||
gitCommitTag,
|
||||
gitRemoteTagHead,
|
||||
gitPush,
|
||||
gitDetachedHead,
|
||||
gitDetachedHeadFromBranch,
|
||||
gitAddNote,
|
||||
gitGetNote,
|
||||
gitFetch,
|
||||
initGit,
|
||||
} = require('./helpers/git-utils');
|
||||
gitGetCommits,
|
||||
gitGetNote,
|
||||
gitPush,
|
||||
gitRemoteTagHead,
|
||||
gitRepo,
|
||||
gitShallowClone,
|
||||
gitTagVersion,
|
||||
initGit
|
||||
} from './helpers/git-utils.js';
|
||||
|
||||
test('Get the last commit sha', async (t) => {
|
||||
// Create a git repository, set the current working directory at the root of the repo
|
||||
@@ -268,7 +268,7 @@ test('Return "true" if in a Git repository', async (t) => {
|
||||
});
|
||||
|
||||
test('Return falsy if not in a Git repository', async (t) => {
|
||||
const cwd = tempy.directory();
|
||||
const cwd = temporaryDirectory();
|
||||
|
||||
t.falsy(await isGitRepo({cwd}));
|
||||
});
|
||||
@@ -288,7 +288,7 @@ test('Return falsy for invalid tag names', async (t) => {
|
||||
});
|
||||
|
||||
test('Throws error if obtaining the tags fails', async (t) => {
|
||||
const cwd = tempy.directory();
|
||||
const cwd = temporaryDirectory();
|
||||
|
||||
await t.throwsAsync(getTags('master', {cwd}));
|
||||
});
|
||||
|
||||
+34
-59
@@ -1,10 +1,10 @@
|
||||
const tempy = require('tempy');
|
||||
const execa = require('execa');
|
||||
const fileUrl = require('file-url');
|
||||
const pEachSeries = require('p-each-series');
|
||||
const gitLogParser = require('git-log-parser');
|
||||
const getStream = require('get-stream');
|
||||
const {GIT_NOTE_REF} = require('../../lib/definitions/constants');
|
||||
import {temporaryDirectory} from 'tempy';
|
||||
import {execa} from 'execa';
|
||||
import fileUrl from 'file-url';
|
||||
import pEachSeries from 'p-each-series';
|
||||
import gitLogParser from 'git-log-parser';
|
||||
import getStream from 'get-stream';
|
||||
import {GIT_NOTE_REF} from '../../lib/definitions/constants.js';
|
||||
|
||||
/**
|
||||
* Commit message information.
|
||||
@@ -23,8 +23,8 @@ const {GIT_NOTE_REF} = require('../../lib/definitions/constants');
|
||||
* @param {Boolean} withRemote `true` to create a shallow clone of a bare repository.
|
||||
* @return {String} The path of the repository
|
||||
*/
|
||||
async function initGit(withRemote) {
|
||||
const cwd = tempy.directory();
|
||||
export async function initGit(withRemote) {
|
||||
const cwd = temporaryDirectory();
|
||||
const args = withRemote ? ['--bare', '--initial-branch=master'] : ['--initial-branch=master'];
|
||||
|
||||
await execa('git', ['init', ...args], {cwd}).catch(() => {
|
||||
@@ -45,7 +45,7 @@ async function initGit(withRemote) {
|
||||
* @param {String} [branch='master'] The branch to initialize.
|
||||
* @return {String} The path of the clone if `withRemote` is `true`, the path of the repository otherwise.
|
||||
*/
|
||||
async function gitRepo(withRemote, branch = 'master') {
|
||||
export async function gitRepo(withRemote, branch = 'master') {
|
||||
let {cwd, repositoryUrl} = await initGit(withRemote);
|
||||
if (withRemote) {
|
||||
await initBareRepo(repositoryUrl, branch);
|
||||
@@ -70,8 +70,8 @@ async function gitRepo(withRemote, branch = 'master') {
|
||||
* @param {String} repositoryUrl The URL of the bare repository.
|
||||
* @param {String} [branch='master'] the branch to initialize.
|
||||
*/
|
||||
async function initBareRepo(repositoryUrl, branch = 'master') {
|
||||
const cwd = tempy.directory();
|
||||
export async function initBareRepo(repositoryUrl, branch = 'master') {
|
||||
const cwd = temporaryDirectory();
|
||||
await execa('git', ['clone', '--no-hardlinks', repositoryUrl, cwd], {cwd});
|
||||
await gitCheckout(branch, true, {cwd});
|
||||
await gitCommits(['Initial commit'], {cwd});
|
||||
@@ -86,7 +86,7 @@ async function initBareRepo(repositoryUrl, branch = 'master') {
|
||||
*
|
||||
* @returns {Array<Commit>} The created commits, in reverse order (to match `git log` order).
|
||||
*/
|
||||
async function gitCommits(messages, execaOptions) {
|
||||
export async function gitCommits(messages, execaOptions) {
|
||||
await pEachSeries(
|
||||
messages,
|
||||
async (message) =>
|
||||
@@ -103,7 +103,7 @@ async function gitCommits(messages, execaOptions) {
|
||||
*
|
||||
* @return {Array<Object>} The list of parsed commits.
|
||||
*/
|
||||
async function gitGetCommits(from, execaOptions) {
|
||||
export async function gitGetCommits(from, execaOptions) {
|
||||
Object.assign(gitLogParser.fields, {hash: 'H', message: 'B', gitTags: 'd', committerDate: {key: 'ci', type: Date}});
|
||||
return (
|
||||
await getStream.array(
|
||||
@@ -126,7 +126,7 @@ async function gitGetCommits(from, execaOptions) {
|
||||
* @param {Boolean} create to create the branch, `false` to checkout an existing branch.
|
||||
* @param {Object} [execaOpts] Options to pass to `execa`.
|
||||
*/
|
||||
async function gitCheckout(branch, create, execaOptions) {
|
||||
export async function gitCheckout(branch, create, execaOptions) {
|
||||
await execa('git', create ? ['checkout', '-b', branch] : ['checkout', branch], execaOptions);
|
||||
}
|
||||
|
||||
@@ -136,7 +136,7 @@ async function gitCheckout(branch, create, execaOptions) {
|
||||
* @param {String} repositoryUrl The repository remote URL.
|
||||
* @param {Object} [execaOpts] Options to pass to `execa`.
|
||||
*/
|
||||
async function gitFetch(repositoryUrl, execaOptions) {
|
||||
export async function gitFetch(repositoryUrl, execaOptions) {
|
||||
await execa('git', ['fetch', repositoryUrl], execaOptions);
|
||||
}
|
||||
|
||||
@@ -147,7 +147,7 @@ async function gitFetch(repositoryUrl, execaOptions) {
|
||||
*
|
||||
* @return {String} The sha of the head commit in the current git repository.
|
||||
*/
|
||||
async function gitHead(execaOptions) {
|
||||
export async function gitHead(execaOptions) {
|
||||
return (await execa('git', ['rev-parse', 'HEAD'], execaOptions)).stdout;
|
||||
}
|
||||
|
||||
@@ -158,7 +158,7 @@ async function gitHead(execaOptions) {
|
||||
* @param {String} [sha] The commit on which to create the tag. If undefined the tag is created on the last commit.
|
||||
* @param {Object} [execaOpts] Options to pass to `execa`.
|
||||
*/
|
||||
async function gitTagVersion(tagName, sha, execaOptions) {
|
||||
export async function gitTagVersion(tagName, sha, execaOptions) {
|
||||
await execa('git', sha ? ['tag', '-f', tagName, sha] : ['tag', tagName], execaOptions);
|
||||
}
|
||||
|
||||
@@ -171,8 +171,8 @@ async function gitTagVersion(tagName, sha, execaOptions) {
|
||||
* @param {Number} [depth=1] The number of commit to clone.
|
||||
* @return {String} The path of the cloned repository.
|
||||
*/
|
||||
async function gitShallowClone(repositoryUrl, branch = 'master', depth = 1) {
|
||||
const cwd = tempy.directory();
|
||||
export async function gitShallowClone(repositoryUrl, branch = 'master', depth = 1) {
|
||||
const cwd = temporaryDirectory();
|
||||
|
||||
await execa('git', ['clone', '--no-hardlinks', '--no-tags', '-b', branch, '--depth', depth, repositoryUrl, cwd], {
|
||||
cwd,
|
||||
@@ -187,8 +187,8 @@ async function gitShallowClone(repositoryUrl, branch = 'master', depth = 1) {
|
||||
* @param {Number} head A commit sha of the remote repo that will become the detached head of the new one.
|
||||
* @return {String} The path of the new repository.
|
||||
*/
|
||||
async function gitDetachedHead(repositoryUrl, head) {
|
||||
const cwd = tempy.directory();
|
||||
export async function gitDetachedHead(repositoryUrl, head) {
|
||||
const cwd = temporaryDirectory();
|
||||
|
||||
await execa('git', ['init'], {cwd});
|
||||
await execa('git', ['remote', 'add', 'origin', repositoryUrl], {cwd});
|
||||
@@ -197,8 +197,8 @@ async function gitDetachedHead(repositoryUrl, head) {
|
||||
return cwd;
|
||||
}
|
||||
|
||||
async function gitDetachedHeadFromBranch(repositoryUrl, branch, head) {
|
||||
const cwd = tempy.directory();
|
||||
export async function gitDetachedHeadFromBranch(repositoryUrl, branch, head) {
|
||||
const cwd = temporaryDirectory();
|
||||
|
||||
await execa('git', ['init'], {cwd});
|
||||
await execa('git', ['remote', 'add', 'origin', repositoryUrl], {cwd});
|
||||
@@ -215,7 +215,7 @@ async function gitDetachedHeadFromBranch(repositoryUrl, branch, head) {
|
||||
* @param {String} value Config value.
|
||||
* @param {Object} [execaOpts] Options to pass to `execa`.
|
||||
*/
|
||||
async function gitAddConfig(name, value, execaOptions) {
|
||||
export async function gitAddConfig(name, value, execaOptions) {
|
||||
await execa('git', ['config', '--add', name, value], execaOptions);
|
||||
}
|
||||
|
||||
@@ -227,7 +227,7 @@ async function gitAddConfig(name, value, execaOptions) {
|
||||
*
|
||||
* @return {String} The sha of the commit associated with `tagName` on the local repository.
|
||||
*/
|
||||
async function gitTagHead(tagName, execaOptions) {
|
||||
export async function gitTagHead(tagName, execaOptions) {
|
||||
return (await execa('git', ['rev-list', '-1', tagName], execaOptions)).stdout;
|
||||
}
|
||||
|
||||
@@ -240,7 +240,7 @@ async function gitTagHead(tagName, execaOptions) {
|
||||
*
|
||||
* @return {String} The sha of the commit associated with `tagName` on the remote repository.
|
||||
*/
|
||||
async function gitRemoteTagHead(repositoryUrl, tagName, execaOptions) {
|
||||
export async function gitRemoteTagHead(repositoryUrl, tagName, execaOptions) {
|
||||
return (await execa('git', ['ls-remote', '--tags', repositoryUrl, tagName], execaOptions)).stdout
|
||||
.split('\n')
|
||||
.filter((tag) => Boolean(tag))
|
||||
@@ -255,7 +255,7 @@ async function gitRemoteTagHead(repositoryUrl, tagName, execaOptions) {
|
||||
*
|
||||
* @return {String} The tag associatedwith the sha in parameter or `null`.
|
||||
*/
|
||||
async function gitCommitTag(gitHead, execaOptions) {
|
||||
export async function gitCommitTag(gitHead, execaOptions) {
|
||||
return (await execa('git', ['describe', '--tags', '--exact-match', gitHead], execaOptions)).stdout;
|
||||
}
|
||||
|
||||
@@ -268,7 +268,7 @@ async function gitCommitTag(gitHead, execaOptions) {
|
||||
*
|
||||
* @throws {Error} if the push failed.
|
||||
*/
|
||||
async function gitPush(repositoryUrl, branch, execaOptions) {
|
||||
export async function gitPush(repositoryUrl, branch, execaOptions) {
|
||||
await execa('git', ['push', '--tags', repositoryUrl, `HEAD:${branch}`], execaOptions);
|
||||
}
|
||||
|
||||
@@ -278,7 +278,7 @@ async function gitPush(repositoryUrl, branch, execaOptions) {
|
||||
* @param {String} ref The ref to merge.
|
||||
* @param {Object} [execaOpts] Options to pass to `execa`.
|
||||
*/
|
||||
async function merge(ref, execaOptions) {
|
||||
export async function merge(ref, execaOptions) {
|
||||
await execa('git', ['merge', '--no-ff', ref], execaOptions);
|
||||
}
|
||||
|
||||
@@ -288,7 +288,7 @@ async function merge(ref, execaOptions) {
|
||||
* @param {String} ref The ref to merge.
|
||||
* @param {Object} [execaOpts] Options to pass to `execa`.
|
||||
*/
|
||||
async function mergeFf(ref, execaOptions) {
|
||||
export async function mergeFf(ref, execaOptions) {
|
||||
await execa('git', ['merge', '--ff', ref], execaOptions);
|
||||
}
|
||||
|
||||
@@ -298,7 +298,7 @@ async function mergeFf(ref, execaOptions) {
|
||||
* @param {String} ref The ref to merge.
|
||||
* @param {Object} [execaOpts] Options to pass to `execa`.
|
||||
*/
|
||||
async function rebase(ref, execaOptions) {
|
||||
export async function rebase(ref, execaOptions) {
|
||||
await execa('git', ['rebase', ref], execaOptions);
|
||||
}
|
||||
|
||||
@@ -309,7 +309,7 @@ async function rebase(ref, execaOptions) {
|
||||
* @param {String} ref The ref to add the note to.
|
||||
* @param {Object} [execaOpts] Options to pass to `execa`.
|
||||
*/
|
||||
async function gitAddNote(note, ref, execaOptions) {
|
||||
export async function gitAddNote(note, ref, execaOptions) {
|
||||
await execa('git', ['notes', '--ref', GIT_NOTE_REF, 'add', '-m', note, ref], execaOptions);
|
||||
}
|
||||
|
||||
@@ -319,31 +319,6 @@ async function gitAddNote(note, ref, execaOptions) {
|
||||
* @param {String} ref The ref to get the note from.
|
||||
* @param {Object} [execaOpts] Options to pass to `execa`.
|
||||
*/
|
||||
async function gitGetNote(ref, execaOptions) {
|
||||
export async function gitGetNote(ref, execaOptions) {
|
||||
return (await execa('git', ['notes', '--ref', GIT_NOTE_REF, 'show', ref], execaOptions)).stdout;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
initGit,
|
||||
gitRepo,
|
||||
initBareRepo,
|
||||
gitCommits,
|
||||
gitGetCommits,
|
||||
gitCheckout,
|
||||
gitFetch,
|
||||
gitHead,
|
||||
gitTagVersion,
|
||||
gitShallowClone,
|
||||
gitDetachedHead,
|
||||
gitDetachedHeadFromBranch,
|
||||
gitAddConfig,
|
||||
gitTagHead,
|
||||
gitRemoteTagHead,
|
||||
gitCommitTag,
|
||||
gitPush,
|
||||
merge,
|
||||
mergeFf,
|
||||
rebase,
|
||||
gitAddNote,
|
||||
gitGetNote,
|
||||
};
|
||||
|
||||
+9
-11
@@ -1,9 +1,9 @@
|
||||
const Docker = require('dockerode');
|
||||
const getStream = require('get-stream');
|
||||
const pRetry = require('p-retry');
|
||||
const {initBareRepo, gitShallowClone} = require('./git-utils');
|
||||
import Docker from 'dockerode';
|
||||
import getStream from 'get-stream';
|
||||
import pRetry from 'p-retry';
|
||||
import {gitShallowClone, initBareRepo} from './git-utils.js';
|
||||
|
||||
const IMAGE = 'pvdlg/docker-gitbox:latest';
|
||||
const IMAGE = 'semanticrelease/docker-gitbox:latest';
|
||||
const SERVER_PORT = 80;
|
||||
const HOST_PORT = 2080;
|
||||
const SERVER_HOST = 'localhost';
|
||||
@@ -12,12 +12,12 @@ const GIT_PASSWORD = 'suchsecure';
|
||||
const docker = new Docker();
|
||||
let container;
|
||||
|
||||
const gitCredential = `${GIT_USERNAME}:${GIT_PASSWORD}`;
|
||||
export const gitCredential = `${GIT_USERNAME}:${GIT_PASSWORD}`;
|
||||
|
||||
/**
|
||||
* Download the `gitbox` Docker image, create a new container and start it.
|
||||
*/
|
||||
async function start() {
|
||||
export async function start() {
|
||||
await getStream(await docker.pull(IMAGE));
|
||||
|
||||
container = await docker.createContainer({
|
||||
@@ -38,7 +38,7 @@ async function start() {
|
||||
/**
|
||||
* Stop and remote the `mockserver` Docker container.
|
||||
*/
|
||||
async function stop() {
|
||||
export async function stop() {
|
||||
await container.stop();
|
||||
await container.remove();
|
||||
}
|
||||
@@ -51,7 +51,7 @@ async function stop() {
|
||||
* @param {String} [description=`Repository ${name}`] The repository description.
|
||||
* @return {Object} The `repositoryUrl` (URL without auth) and `authUrl` (URL with auth).
|
||||
*/
|
||||
async function createRepo(name, branch = 'master', description = `Repository ${name}`) {
|
||||
export async function createRepo(name, branch = 'master', description = `Repository ${name}`) {
|
||||
const exec = await container.exec({
|
||||
Cmd: ['repo-admin', '-n', name, '-d', description],
|
||||
AttachStdout: true,
|
||||
@@ -68,5 +68,3 @@ async function createRepo(name, branch = 'master', description = `Repository ${n
|
||||
|
||||
return {cwd, repositoryUrl, authUrl};
|
||||
}
|
||||
|
||||
module.exports = {start, stop, gitCredential, createRepo};
|
||||
|
||||
+14
-16
@@ -1,10 +1,10 @@
|
||||
const Docker = require('dockerode');
|
||||
const getStream = require('get-stream');
|
||||
const got = require('got');
|
||||
const pRetry = require('p-retry');
|
||||
const {mockServerClient} = require('mockserver-client');
|
||||
import Docker from 'dockerode';
|
||||
import getStream from 'get-stream';
|
||||
import got from 'got';
|
||||
import pRetry from 'p-retry';
|
||||
import {mockServerClient} from 'mockserver-client';
|
||||
|
||||
const IMAGE = 'jamesdbloom/mockserver:latest';
|
||||
const IMAGE = 'mockserver/mockserver:latest';
|
||||
const MOCK_SERVER_PORT = 1080;
|
||||
const MOCK_SERVER_HOST = 'localhost';
|
||||
const docker = new Docker();
|
||||
@@ -13,7 +13,7 @@ let container;
|
||||
/**
|
||||
* Download the `mockserver` Docker image, create a new container and start it.
|
||||
*/
|
||||
async function start() {
|
||||
export async function start() {
|
||||
await getStream(await docker.pull(IMAGE));
|
||||
|
||||
container = await docker.createContainer({
|
||||
@@ -30,15 +30,15 @@ async function start() {
|
||||
minTimeout: 1000,
|
||||
factor: 2,
|
||||
});
|
||||
} catch (_) {
|
||||
} catch {
|
||||
throw new Error(`Couldn't start mock-server after 2 min`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop and remote the `mockserver` Docker container.
|
||||
* Stop and remove the `mockserver` Docker container.
|
||||
*/
|
||||
async function stop() {
|
||||
export async function stop() {
|
||||
await container.stop();
|
||||
await container.remove();
|
||||
}
|
||||
@@ -50,7 +50,7 @@ const client = mockServerClient(MOCK_SERVER_HOST, MOCK_SERVER_PORT);
|
||||
/**
|
||||
* @type {string} the url of the `mockserver` instance
|
||||
*/
|
||||
const url = `http://${MOCK_SERVER_HOST}:${MOCK_SERVER_PORT}`;
|
||||
export const url = `http://${MOCK_SERVER_HOST}:${MOCK_SERVER_PORT}`;
|
||||
|
||||
/**
|
||||
* Set up the `mockserver` instance response for a specific request.
|
||||
@@ -65,7 +65,7 @@ const url = `http://${MOCK_SERVER_HOST}:${MOCK_SERVER_PORT}`;
|
||||
* @param {Object} response.body The JSON object to respond in the response body.
|
||||
* @return {Object} An object representation the expectation. Pass to the `verify` function to validate the `mockserver` has been called with a `request` matching the expectations.
|
||||
*/
|
||||
async function mock(
|
||||
export async function mock(
|
||||
path,
|
||||
{body: requestBody, headers: requestHeaders},
|
||||
{method = 'POST', statusCode = 200, body: responseBody}
|
||||
@@ -91,13 +91,11 @@ async function mock(
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify the `mockserver` has been called with a requestion matching expectations. The `expectation` is created with the `mock` function.
|
||||
* Verify the `mockserver` has been called with a request matching expectations. The `expectation` is created with the `mock` function.
|
||||
*
|
||||
* @param {Object} expectation The expectation created with `mock` function.
|
||||
* @return {Promise} A Promise that resolves if the expectation is met or reject otherwise.
|
||||
*/
|
||||
function verify(expectation) {
|
||||
export function verify(expectation) {
|
||||
return client.verify(expectation);
|
||||
}
|
||||
|
||||
module.exports = {start, stop, mock, verify, url};
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
const Docker = require('dockerode');
|
||||
const getStream = require('get-stream');
|
||||
const got = require('got');
|
||||
const path = require('path');
|
||||
const delay = require('delay');
|
||||
const pRetry = require('p-retry');
|
||||
import path, {dirname} from 'node:path';
|
||||
import {fileURLToPath} from 'node:url';
|
||||
import Docker from 'dockerode';
|
||||
import getStream from 'get-stream';
|
||||
import got from 'got';
|
||||
import delay from 'delay';
|
||||
import pRetry from 'p-retry';
|
||||
|
||||
const IMAGE = 'verdaccio/verdaccio:4';
|
||||
const REGISTRY_PORT = 4873;
|
||||
@@ -12,12 +13,13 @@ const NPM_USERNAME = 'integration';
|
||||
const NPM_PASSWORD = 'suchsecure';
|
||||
const NPM_EMAIL = 'integration@test.com';
|
||||
const docker = new Docker();
|
||||
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||
let container;
|
||||
|
||||
/**
|
||||
* Download the `npm-registry-docker` Docker image, create a new container and start it.
|
||||
*/
|
||||
async function start() {
|
||||
export async function start() {
|
||||
await getStream(await docker.pull(IMAGE));
|
||||
|
||||
container = await docker.createContainer({
|
||||
@@ -37,7 +39,7 @@ async function start() {
|
||||
minTimeout: 1000,
|
||||
factor: 2,
|
||||
});
|
||||
} catch (_) {
|
||||
} catch {
|
||||
throw new Error(`Couldn't start npm-registry-docker after 2 min`);
|
||||
}
|
||||
|
||||
@@ -55,9 +57,9 @@ async function start() {
|
||||
});
|
||||
}
|
||||
|
||||
const url = `http://${REGISTRY_HOST}:${REGISTRY_PORT}/`;
|
||||
export const url = `http://${REGISTRY_HOST}:${REGISTRY_PORT}/`;
|
||||
|
||||
const authEnv = {
|
||||
export const authEnv = {
|
||||
npm_config_registry: url, // eslint-disable-line camelcase
|
||||
NPM_USERNAME,
|
||||
NPM_PASSWORD,
|
||||
@@ -67,9 +69,7 @@ const authEnv = {
|
||||
/**
|
||||
* Stop and remote the `npm-registry-docker` Docker container.
|
||||
*/
|
||||
async function stop() {
|
||||
export async function stop() {
|
||||
await container.stop();
|
||||
await container.remove();
|
||||
}
|
||||
|
||||
module.exports = {start, stop, authEnv, url};
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
const execa = require('execa');
|
||||
import {execa} from 'execa';
|
||||
|
||||
async function npmView(packageName, env) {
|
||||
export async function npmView(packageName, env) {
|
||||
return JSON.parse((await execa('npm', ['view', packageName, '--json'], {env})).stdout);
|
||||
}
|
||||
|
||||
module.exports = {npmView};
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
const test = require('ava');
|
||||
const {repeat} = require('lodash');
|
||||
const hideSensitive = require('../lib/hide-sensitive');
|
||||
const {SECRET_REPLACEMENT, SECRET_MIN_SIZE} = require('../lib/definitions/constants');
|
||||
import test from 'ava';
|
||||
import {repeat} from 'lodash-es';
|
||||
import hideSensitive from '../lib/hide-sensitive.js';
|
||||
import {SECRET_MIN_SIZE, SECRET_REPLACEMENT} from '../lib/definitions/constants.js';
|
||||
|
||||
test('Replace multiple sensitive environment variable values', (t) => {
|
||||
const env = {SOME_PASSWORD: 'password', SOME_TOKEN: 'secret'};
|
||||
|
||||
+211
-224
@@ -1,30 +1,28 @@
|
||||
const test = require('ava');
|
||||
const {escapeRegExp, isString, sortBy, omit} = require('lodash');
|
||||
const proxyquire = require('proxyquire');
|
||||
const {spy, stub} = require('sinon');
|
||||
const {WritableStreamBuffer} = require('stream-buffers');
|
||||
const AggregateError = require('aggregate-error');
|
||||
const SemanticReleaseError = require('@semantic-release/error');
|
||||
const {COMMIT_NAME, COMMIT_EMAIL, SECRET_REPLACEMENT} = require('../lib/definitions/constants');
|
||||
const {
|
||||
gitHead: getGitHead,
|
||||
import test from 'ava';
|
||||
import {escapeRegExp, isString, omit, sortBy} from 'lodash-es';
|
||||
import * as td from 'testdouble';
|
||||
import {spy, stub} from 'sinon';
|
||||
import {WritableStreamBuffer} from 'stream-buffers';
|
||||
import AggregateError from 'aggregate-error';
|
||||
import SemanticReleaseError from '@semantic-release/error';
|
||||
import {COMMIT_EMAIL, COMMIT_NAME, SECRET_REPLACEMENT} from '../lib/definitions/constants.js';
|
||||
import {
|
||||
gitAddNote,
|
||||
gitCheckout,
|
||||
gitTagHead,
|
||||
gitRepo,
|
||||
gitCommits,
|
||||
gitTagVersion,
|
||||
gitRemoteTagHead,
|
||||
gitGetNote,
|
||||
gitHead as getGitHead,
|
||||
gitPush,
|
||||
gitRemoteTagHead,
|
||||
gitRepo,
|
||||
gitShallowClone,
|
||||
gitTagHead,
|
||||
gitTagVersion,
|
||||
merge,
|
||||
mergeFf,
|
||||
rebase,
|
||||
gitAddNote,
|
||||
gitGetNote,
|
||||
} = require('./helpers/git-utils');
|
||||
|
||||
const requireNoCache = proxyquire.noPreserveCache();
|
||||
const pluginNoop = require.resolve('./fixtures/plugin-noop');
|
||||
rebase
|
||||
} from './helpers/git-utils.js';
|
||||
import pluginNoop from './fixtures/plugin-noop.cjs';
|
||||
|
||||
test.beforeEach((t) => {
|
||||
// Stub the logger functions
|
||||
@@ -90,6 +88,7 @@ test('Plugins are called with expected values', async (t) => {
|
||||
const config = {
|
||||
branches: [{name: 'master'}, {name: 'next'}],
|
||||
repositoryUrl,
|
||||
originalRepositoryURL: repositoryUrl,
|
||||
globalOpt: 'global',
|
||||
tagFormat: `v\${version}`,
|
||||
};
|
||||
@@ -126,7 +125,7 @@ test('Plugins are called with expected values', async (t) => {
|
||||
publish: [publish, pluginNoop],
|
||||
success,
|
||||
};
|
||||
const envCi = {branch: 'master', isCi: true, isPr: false};
|
||||
const envCiResults = {branch: 'master', isCi: true, isPr: false};
|
||||
|
||||
const releases = [
|
||||
{
|
||||
@@ -140,13 +139,13 @@ test('Plugins are called with expected values', async (t) => {
|
||||
pluginName: '[Function: functionStub]',
|
||||
},
|
||||
{...nextRelease, ...release2, notes: `${notes1}\n\n${notes2}\n\n${notes3}`, pluginName: '[Function: functionStub]'},
|
||||
{...nextRelease, notes: `${notes1}\n\n${notes2}\n\n${notes3}`, pluginName: pluginNoop},
|
||||
{...nextRelease, notes: `${notes1}\n\n${notes2}\n\n${notes3}`, pluginName: '[Function: noop]'},
|
||||
];
|
||||
|
||||
const semanticRelease = requireNoCache('..', {
|
||||
'./lib/get-logger': () => t.context.logger,
|
||||
'env-ci': () => envCi,
|
||||
});
|
||||
await td.replaceEsm('../lib/get-logger.js', null, () => t.context.logger);
|
||||
const envCi = (await td.replaceEsm('env-ci')).default;
|
||||
td.when(envCi({env, cwd})).thenReturn(envCiResults);
|
||||
const semanticRelease = (await import('../index.js')).default;
|
||||
const result = await semanticRelease(options, {
|
||||
cwd,
|
||||
env,
|
||||
@@ -161,7 +160,7 @@ test('Plugins are called with expected values', async (t) => {
|
||||
t.deepEqual(verifyConditions1.args[0][1].branch, branch);
|
||||
t.deepEqual(verifyConditions1.args[0][1].branches, branches);
|
||||
t.deepEqual(verifyConditions1.args[0][1].logger, t.context.logger);
|
||||
t.deepEqual(verifyConditions1.args[0][1].envCi, envCi);
|
||||
t.deepEqual(verifyConditions1.args[0][1].envCi, envCiResults);
|
||||
t.is(verifyConditions2.callCount, 1);
|
||||
t.deepEqual(verifyConditions2.args[0][0], config);
|
||||
t.deepEqual(verifyConditions2.args[0][1].cwd, cwd);
|
||||
@@ -169,7 +168,7 @@ test('Plugins are called with expected values', async (t) => {
|
||||
t.deepEqual(verifyConditions2.args[0][1].branch, branch);
|
||||
t.deepEqual(verifyConditions2.args[0][1].branches, branches);
|
||||
t.deepEqual(verifyConditions2.args[0][1].logger, t.context.logger);
|
||||
t.deepEqual(verifyConditions2.args[0][1].envCi, envCi);
|
||||
t.deepEqual(verifyConditions2.args[0][1].envCi, envCiResults);
|
||||
|
||||
t.is(generateNotes1.callCount, 2);
|
||||
t.is(generateNotes2.callCount, 2);
|
||||
@@ -191,7 +190,7 @@ test('Plugins are called with expected values', async (t) => {
|
||||
gitTag: 'v1.0.0',
|
||||
name: 'v1.0.0',
|
||||
});
|
||||
t.deepEqual(generateNotes2.args[0][1].envCi, envCi);
|
||||
t.deepEqual(generateNotes2.args[0][1].envCi, envCiResults);
|
||||
|
||||
t.deepEqual(generateNotes2.args[0][0], config);
|
||||
t.deepEqual(generateNotes2.args[0][1].options, options);
|
||||
@@ -210,7 +209,7 @@ test('Plugins are called with expected values', async (t) => {
|
||||
name: 'v1.0.0',
|
||||
notes: notes1,
|
||||
});
|
||||
t.deepEqual(generateNotes2.args[0][1].envCi, envCi);
|
||||
t.deepEqual(generateNotes2.args[0][1].envCi, envCiResults);
|
||||
|
||||
t.deepEqual(generateNotes3.args[0][0], config);
|
||||
t.deepEqual(generateNotes3.args[0][1].options, options);
|
||||
@@ -229,7 +228,7 @@ test('Plugins are called with expected values', async (t) => {
|
||||
name: 'v1.0.0',
|
||||
notes: `${notes1}\n\n${notes2}`,
|
||||
});
|
||||
t.deepEqual(generateNotes3.args[0][1].envCi, envCi);
|
||||
t.deepEqual(generateNotes3.args[0][1].envCi, envCiResults);
|
||||
|
||||
branch.tags.push({
|
||||
version: '1.0.0',
|
||||
@@ -257,7 +256,7 @@ test('Plugins are called with expected values', async (t) => {
|
||||
});
|
||||
t.deepEqual(addChannel.args[0][1].commits[0].hash, commits[1].hash);
|
||||
t.deepEqual(addChannel.args[0][1].commits[0].message, commits[1].message);
|
||||
t.deepEqual(addChannel.args[0][1].envCi, envCi);
|
||||
t.deepEqual(addChannel.args[0][1].envCi, envCiResults);
|
||||
|
||||
t.is(analyzeCommits.callCount, 1);
|
||||
t.deepEqual(analyzeCommits.args[0][0], config);
|
||||
@@ -268,7 +267,7 @@ test('Plugins are called with expected values', async (t) => {
|
||||
t.deepEqual(analyzeCommits.args[0][1].lastRelease, lastRelease);
|
||||
t.deepEqual(analyzeCommits.args[0][1].commits[0].hash, commits[0].hash);
|
||||
t.deepEqual(analyzeCommits.args[0][1].commits[0].message, commits[0].message);
|
||||
t.deepEqual(analyzeCommits.args[0][1].envCi, envCi);
|
||||
t.deepEqual(analyzeCommits.args[0][1].envCi, envCiResults);
|
||||
|
||||
t.is(verifyRelease.callCount, 1);
|
||||
t.deepEqual(verifyRelease.args[0][0], config);
|
||||
@@ -280,7 +279,7 @@ test('Plugins are called with expected values', async (t) => {
|
||||
t.deepEqual(verifyRelease.args[0][1].commits[0].hash, commits[0].hash);
|
||||
t.deepEqual(verifyRelease.args[0][1].commits[0].message, commits[0].message);
|
||||
t.deepEqual(verifyRelease.args[0][1].nextRelease, nextRelease);
|
||||
t.deepEqual(verifyRelease.args[0][1].envCi, envCi);
|
||||
t.deepEqual(verifyRelease.args[0][1].envCi, envCiResults);
|
||||
|
||||
t.deepEqual(generateNotes1.args[1][0], config);
|
||||
t.deepEqual(generateNotes1.args[1][1].options, options);
|
||||
@@ -291,7 +290,7 @@ test('Plugins are called with expected values', async (t) => {
|
||||
t.deepEqual(generateNotes1.args[1][1].commits[0].hash, commits[0].hash);
|
||||
t.deepEqual(generateNotes1.args[1][1].commits[0].message, commits[0].message);
|
||||
t.deepEqual(generateNotes1.args[1][1].nextRelease, nextRelease);
|
||||
t.deepEqual(generateNotes1.args[1][1].envCi, envCi);
|
||||
t.deepEqual(generateNotes1.args[1][1].envCi, envCiResults);
|
||||
|
||||
t.deepEqual(generateNotes2.args[1][0], config);
|
||||
t.deepEqual(generateNotes2.args[1][1].options, options);
|
||||
@@ -302,7 +301,7 @@ test('Plugins are called with expected values', async (t) => {
|
||||
t.deepEqual(generateNotes2.args[1][1].commits[0].hash, commits[0].hash);
|
||||
t.deepEqual(generateNotes2.args[1][1].commits[0].message, commits[0].message);
|
||||
t.deepEqual(generateNotes2.args[1][1].nextRelease, {...nextRelease, notes: notes1});
|
||||
t.deepEqual(generateNotes2.args[1][1].envCi, envCi);
|
||||
t.deepEqual(generateNotes2.args[1][1].envCi, envCiResults);
|
||||
|
||||
t.deepEqual(generateNotes3.args[1][0], config);
|
||||
t.deepEqual(generateNotes3.args[1][1].options, options);
|
||||
@@ -313,7 +312,7 @@ test('Plugins are called with expected values', async (t) => {
|
||||
t.deepEqual(generateNotes3.args[1][1].commits[0].hash, commits[0].hash);
|
||||
t.deepEqual(generateNotes3.args[1][1].commits[0].message, commits[0].message);
|
||||
t.deepEqual(generateNotes3.args[1][1].nextRelease, {...nextRelease, notes: `${notes1}\n\n${notes2}`});
|
||||
t.deepEqual(generateNotes3.args[1][1].envCi, envCi);
|
||||
t.deepEqual(generateNotes3.args[1][1].envCi, envCiResults);
|
||||
|
||||
t.is(prepare.callCount, 1);
|
||||
t.deepEqual(prepare.args[0][0], config);
|
||||
@@ -325,7 +324,7 @@ test('Plugins are called with expected values', async (t) => {
|
||||
t.deepEqual(prepare.args[0][1].commits[0].hash, commits[0].hash);
|
||||
t.deepEqual(prepare.args[0][1].commits[0].message, commits[0].message);
|
||||
t.deepEqual(prepare.args[0][1].nextRelease, {...nextRelease, notes: `${notes1}\n\n${notes2}\n\n${notes3}`});
|
||||
t.deepEqual(prepare.args[0][1].envCi, envCi);
|
||||
t.deepEqual(prepare.args[0][1].envCi, envCiResults);
|
||||
|
||||
t.is(publish.callCount, 1);
|
||||
t.deepEqual(publish.args[0][0], config);
|
||||
@@ -337,7 +336,7 @@ test('Plugins are called with expected values', async (t) => {
|
||||
t.deepEqual(publish.args[0][1].commits[0].hash, commits[0].hash);
|
||||
t.deepEqual(publish.args[0][1].commits[0].message, commits[0].message);
|
||||
t.deepEqual(publish.args[0][1].nextRelease, {...nextRelease, notes: `${notes1}\n\n${notes2}\n\n${notes3}`});
|
||||
t.deepEqual(publish.args[0][1].envCi, envCi);
|
||||
t.deepEqual(publish.args[0][1].envCi, envCiResults);
|
||||
|
||||
t.is(success.callCount, 2);
|
||||
t.deepEqual(success.args[0][0], config);
|
||||
@@ -358,7 +357,7 @@ test('Plugins are called with expected values', async (t) => {
|
||||
notes: `${notes1}\n\n${notes2}\n\n${notes3}`,
|
||||
});
|
||||
t.deepEqual(success.args[0][1].releases, [releases[0]]);
|
||||
t.deepEqual(success.args[0][1].envCi, envCi);
|
||||
t.deepEqual(success.args[0][1].envCi, envCiResults);
|
||||
|
||||
t.deepEqual(success.args[1][0], config);
|
||||
t.deepEqual(success.args[1][1].options, options);
|
||||
@@ -370,7 +369,7 @@ test('Plugins are called with expected values', async (t) => {
|
||||
t.deepEqual(success.args[1][1].commits[0].message, commits[0].message);
|
||||
t.deepEqual(success.args[1][1].nextRelease, {...nextRelease, notes: `${notes1}\n\n${notes2}\n\n${notes3}`});
|
||||
t.deepEqual(success.args[1][1].releases, [releases[1], releases[2]]);
|
||||
t.deepEqual(success.args[1][1].envCi, envCi);
|
||||
t.deepEqual(success.args[1][1].envCi, envCiResults);
|
||||
|
||||
t.deepEqual(result, {
|
||||
lastRelease,
|
||||
@@ -390,7 +389,7 @@ test('Plugins are called with expected values', async (t) => {
|
||||
t.is(env.GIT_COMMITTER_EMAIL, COMMIT_EMAIL);
|
||||
});
|
||||
|
||||
test('Use custom tag format', async (t) => {
|
||||
test.serial('Use custom tag format', async (t) => {
|
||||
const {cwd, repositoryUrl} = await gitRepo(true);
|
||||
await gitCommits(['First'], {cwd});
|
||||
await gitTagVersion('test-1.0.0', undefined, {cwd});
|
||||
@@ -419,10 +418,9 @@ test('Use custom tag format', async (t) => {
|
||||
fail: stub().resolves(),
|
||||
};
|
||||
|
||||
const semanticRelease = requireNoCache('..', {
|
||||
'./lib/get-logger': () => t.context.logger,
|
||||
'env-ci': () => ({isCi: true, branch: 'master', isPr: false}),
|
||||
});
|
||||
await td.replaceEsm('../lib/get-logger.js', null, () => t.context.logger);
|
||||
await td.replaceEsm('env-ci', null, () => ({isCi: true, branch: 'master', isPr: false}));
|
||||
const semanticRelease = (await import('../index.js')).default;
|
||||
t.truthy(
|
||||
await semanticRelease(options, {
|
||||
cwd,
|
||||
@@ -437,7 +435,7 @@ test('Use custom tag format', async (t) => {
|
||||
t.is(await gitRemoteTagHead(repositoryUrl, nextRelease.gitTag, {cwd}), nextRelease.gitHead);
|
||||
});
|
||||
|
||||
test('Use new gitHead, and recreate release notes if a prepare plugin create a commit', async (t) => {
|
||||
test.serial('Use new gitHead, and recreate release notes if a prepare plugin create a commit', 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
|
||||
@@ -478,10 +476,9 @@ test('Use new gitHead, and recreate release notes if a prepare plugin create a c
|
||||
fail: stub().resolves(),
|
||||
};
|
||||
|
||||
const semanticRelease = requireNoCache('..', {
|
||||
'./lib/get-logger': () => t.context.logger,
|
||||
'env-ci': () => ({isCi: true, branch: 'master', isPr: false}),
|
||||
});
|
||||
await td.replaceEsm('../lib/get-logger.js', null, () => t.context.logger);
|
||||
await td.replaceEsm('env-ci', null, () => ({isCi: true, branch: 'master', isPr: false}));
|
||||
const semanticRelease = (await import('../index.js')).default;
|
||||
|
||||
t.truthy(
|
||||
await semanticRelease(options, {
|
||||
@@ -511,7 +508,7 @@ test('Use new gitHead, and recreate release notes if a prepare plugin create a c
|
||||
t.is(await gitRemoteTagHead(repositoryUrl, nextRelease.gitTag, {cwd}), commits[0].hash);
|
||||
});
|
||||
|
||||
test('Make a new release when a commit is forward-ported to an upper branch', async (t) => {
|
||||
test.serial('Make a new release when a commit is forward-ported to an upper branch', async (t) => {
|
||||
const {cwd, repositoryUrl} = await gitRepo(true);
|
||||
await gitCommits(['feat: initial release'], {cwd});
|
||||
await gitTagVersion('v1.0.0', undefined, {cwd});
|
||||
@@ -545,10 +542,9 @@ test('Make a new release when a commit is forward-ported to an upper branch', as
|
||||
success,
|
||||
};
|
||||
|
||||
const semanticRelease = proxyquire('..', {
|
||||
'./lib/logger': t.context.logger,
|
||||
'env-ci': () => ({isCi: true, branch: 'master', isPr: false}),
|
||||
});
|
||||
await td.replaceEsm('../lib/get-logger.js', null, () => t.context.logger);
|
||||
await td.replaceEsm('env-ci', null, () => ({isCi: true, branch: 'master', isPr: false}));
|
||||
const semanticRelease = (await import('../index.js')).default;
|
||||
t.truthy(await semanticRelease(options, {cwd, env: {}, stdout: {write: () => {}}, stderr: {write: () => {}}}));
|
||||
|
||||
t.is(addChannel.callCount, 0);
|
||||
@@ -558,7 +554,7 @@ test('Make a new release when a commit is forward-ported to an upper branch', as
|
||||
t.is(success.callCount, 1);
|
||||
});
|
||||
|
||||
test('Publish a pre-release version', async (t) => {
|
||||
test.serial('Publish a pre-release version', async (t) => {
|
||||
const {cwd, repositoryUrl} = await gitRepo(true);
|
||||
await gitCommits(['feat: initial commit'], {cwd});
|
||||
await gitTagVersion('v1.0.0', undefined, {cwd});
|
||||
@@ -580,10 +576,11 @@ test('Publish a pre-release version', async (t) => {
|
||||
fail: stub().resolves(),
|
||||
};
|
||||
|
||||
const semanticRelease = requireNoCache('..', {
|
||||
'./lib/get-logger': () => t.context.logger,
|
||||
'env-ci': () => ({isCi: true, branch: 'beta', isPr: false}),
|
||||
});
|
||||
const env = {};
|
||||
await td.replaceEsm('../lib/get-logger.js', null, () => t.context.logger);
|
||||
const envCi = (await td.replaceEsm('env-ci')).default;
|
||||
td.when(envCi({env, cwd})).thenReturn({isCi: true, branch: 'beta', isPr: false});
|
||||
const semanticRelease = (await import('../index.js')).default;
|
||||
let {releases} = await semanticRelease(options, {cwd, env: {}, stdout: {write: () => {}}, stderr: {write: () => {}}});
|
||||
|
||||
t.is(releases.length, 1);
|
||||
@@ -594,7 +591,7 @@ test('Publish a pre-release version', async (t) => {
|
||||
await gitCommits(['fix: a fix'], {cwd});
|
||||
({releases} = await semanticRelease(options, {
|
||||
cwd,
|
||||
env: {},
|
||||
env,
|
||||
stdout: {write: () => {}},
|
||||
stderr: {write: () => {}},
|
||||
}));
|
||||
@@ -605,7 +602,7 @@ test('Publish a pre-release version', async (t) => {
|
||||
t.is(await gitGetNote('v1.1.0-beta.2', {cwd}), '{"channels":["beta"]}');
|
||||
});
|
||||
|
||||
test('Publish releases from different branch on the same channel', async (t) => {
|
||||
test.serial('Publish releases from different branch on the same channel', async (t) => {
|
||||
const {cwd, repositoryUrl} = await gitRepo(true);
|
||||
await gitCommits(['feat: initial commit'], {cwd});
|
||||
await gitTagVersion('v1.0.0', undefined, {cwd});
|
||||
@@ -633,11 +630,12 @@ test('Publish releases from different branch on the same channel', async (t) =>
|
||||
fail: stub().resolves(),
|
||||
};
|
||||
|
||||
let semanticRelease = requireNoCache('..', {
|
||||
'./lib/get-logger': () => t.context.logger,
|
||||
'env-ci': () => ({isCi: true, branch: 'next', isPr: false}),
|
||||
});
|
||||
let {releases} = await semanticRelease(options, {cwd, env: {}, stdout: {write: () => {}}, stderr: {write: () => {}}});
|
||||
const env = {};
|
||||
await td.replaceEsm('../lib/get-logger.js', null, () => t.context.logger);
|
||||
const envCi = (await td.replaceEsm('env-ci')).default;
|
||||
td.when(envCi({env, cwd})).thenReturn({isCi: true, branch: 'next', isPr: false});
|
||||
let semanticRelease = (await import('../index.js')).default;
|
||||
let {releases} = await semanticRelease(options, {cwd, env, stdout: {write: () => {}}, stderr: {write: () => {}}});
|
||||
|
||||
t.is(releases.length, 1);
|
||||
t.is(releases[0].version, '1.1.0');
|
||||
@@ -646,7 +644,7 @@ test('Publish releases from different branch on the same channel', async (t) =>
|
||||
await gitCommits(['fix: a fix'], {cwd});
|
||||
({releases} = await semanticRelease(options, {
|
||||
cwd,
|
||||
env: {},
|
||||
env,
|
||||
stdout: {write: () => {}},
|
||||
stderr: {write: () => {}},
|
||||
}));
|
||||
@@ -659,16 +657,15 @@ test('Publish releases from different branch on the same channel', async (t) =>
|
||||
await merge('next', {cwd});
|
||||
await gitPush('origin', 'master', {cwd});
|
||||
|
||||
semanticRelease = requireNoCache('..', {
|
||||
'./lib/get-logger': () => t.context.logger,
|
||||
'env-ci': () => ({isCi: true, branch: 'master', isPr: false}),
|
||||
});
|
||||
await td.replaceEsm('../lib/get-logger.js', null, () => t.context.logger);
|
||||
await td.replaceEsm('env-ci', null, () => ({isCi: true, branch: 'master', isPr: false}));
|
||||
semanticRelease = (await import('../index.js')).default;
|
||||
|
||||
t.falsy(await semanticRelease(options, {cwd, env: {}, stdout: {write: () => {}}, stderr: {write: () => {}}}));
|
||||
t.is(addChannel.callCount, 0);
|
||||
});
|
||||
|
||||
test('Publish pre-releases the same channel as regular releases', async (t) => {
|
||||
test.serial('Publish pre-releases the same channel as regular releases', async (t) => {
|
||||
const {cwd, repositoryUrl} = await gitRepo(true);
|
||||
await gitCommits(['feat: initial commit'], {cwd});
|
||||
await gitTagVersion('v1.0.0', undefined, {cwd});
|
||||
@@ -693,11 +690,12 @@ test('Publish pre-releases the same channel as regular releases', async (t) => {
|
||||
fail: stub().resolves(),
|
||||
};
|
||||
|
||||
const semanticRelease = requireNoCache('..', {
|
||||
'./lib/get-logger': () => t.context.logger,
|
||||
'env-ci': () => ({isCi: true, branch: 'beta', isPr: false}),
|
||||
});
|
||||
let {releases} = await semanticRelease(options, {cwd, env: {}, stdout: {write: () => {}}, stderr: {write: () => {}}});
|
||||
const env = {};
|
||||
await td.replaceEsm('../lib/get-logger.js', null, () => t.context.logger);
|
||||
const envCi = (await td.replaceEsm('env-ci')).default;
|
||||
td.when(envCi({cwd, env})).thenReturn({isCi: true, branch: 'beta', isPr: false});
|
||||
const semanticRelease = (await import('../index.js')).default;
|
||||
let {releases} = await semanticRelease(options, {cwd, env, stdout: {write: () => {}}, stderr: {write: () => {}}});
|
||||
|
||||
t.is(releases.length, 1);
|
||||
t.is(releases[0].version, '1.1.0-beta.1');
|
||||
@@ -706,7 +704,7 @@ test('Publish pre-releases the same channel as regular releases', async (t) => {
|
||||
await gitCommits(['fix: a fix'], {cwd});
|
||||
({releases} = await semanticRelease(options, {
|
||||
cwd,
|
||||
env: {},
|
||||
env,
|
||||
stdout: {write: () => {}},
|
||||
stderr: {write: () => {}},
|
||||
}));
|
||||
@@ -716,7 +714,7 @@ test('Publish pre-releases the same channel as regular releases', async (t) => {
|
||||
t.is(releases[0].gitTag, 'v1.1.0-beta.2');
|
||||
});
|
||||
|
||||
test('Do not add pre-releases to a different channel', async (t) => {
|
||||
test.serial('Do not add pre-releases to a different channel', async (t) => {
|
||||
const {cwd, repositoryUrl} = await gitRepo(true);
|
||||
await gitCommits(['feat: initial release'], {cwd});
|
||||
await gitTagVersion('v1.0.0', undefined, {cwd});
|
||||
@@ -759,11 +757,12 @@ test('Do not add pre-releases to a different channel', async (t) => {
|
||||
success,
|
||||
};
|
||||
|
||||
const semanticRelease = proxyquire('..', {
|
||||
'./lib/logger': t.context.logger,
|
||||
'env-ci': () => ({isCi: true, branch: 'master', isPr: false}),
|
||||
});
|
||||
t.truthy(await semanticRelease(options, {cwd, env: {}, stdout: {write: () => {}}, stderr: {write: () => {}}}));
|
||||
const env = {};
|
||||
await td.replaceEsm('../lib/get-logger.js', null, () => t.context.logger);
|
||||
const envCi = (await td.replaceEsm('env-ci')).default;
|
||||
td.when(envCi({cwd, env})).thenReturn({isCi: true, branch: 'master', isPr: false});
|
||||
const semanticRelease = (await import('../index.js')).default;
|
||||
t.truthy(await semanticRelease(options, {cwd, env, stdout: {write: () => {}}, stderr: {write: () => {}}}));
|
||||
|
||||
t.is(addChannel.callCount, 0);
|
||||
});
|
||||
@@ -828,11 +827,12 @@ async function addChannelMacro(t, mergeFunction) {
|
||||
gitHead: commits[2].hash,
|
||||
};
|
||||
|
||||
const semanticRelease = proxyquire('..', {
|
||||
'./lib/logger': t.context.logger,
|
||||
'env-ci': () => ({isCi: true, branch: 'master', isPr: false}),
|
||||
});
|
||||
const result = await semanticRelease(options, {cwd, env: {}, stdout: {write: () => {}}, stderr: {write: () => {}}});
|
||||
const env = {};
|
||||
await td.replaceEsm('../lib/get-logger.js', null, () => t.context.logger);
|
||||
const envCi = (await td.replaceEsm('env-ci')).default;
|
||||
td.when(envCi({env, cwd})).thenReturn({isCi: true, branch: 'master', isPr: false});
|
||||
const semanticRelease = (await import('../index.js')).default;
|
||||
const result = await semanticRelease(options, {cwd, env, stdout: {write: () => {}}, stderr: {write: () => {}}});
|
||||
|
||||
t.deepEqual(result.releases, [
|
||||
{...nextRelease, ...release1, notes, pluginName: '[Function: functionStub]'},
|
||||
@@ -846,11 +846,11 @@ async function addChannelMacro(t, mergeFunction) {
|
||||
|
||||
addChannelMacro.title = (providedTitle) => `Add version to a channel after a merge (${providedTitle})`;
|
||||
|
||||
test('fast-forward', addChannelMacro, mergeFf);
|
||||
test('non fast-forward', addChannelMacro, merge);
|
||||
test('rebase', addChannelMacro, rebase);
|
||||
test.serial('fast-forward', addChannelMacro, mergeFf);
|
||||
test.serial('non fast-forward', addChannelMacro, merge);
|
||||
test.serial('rebase', addChannelMacro, rebase);
|
||||
|
||||
test('Call all "success" plugins even if one errors out', async (t) => {
|
||||
test.serial('Call all "success" plugins even if one errors out', async (t) => {
|
||||
// Create a git repository, set the current working directory at the root of the repo
|
||||
const {cwd, repositoryUrl} = await gitRepo(true);
|
||||
// Add commits to the master branch
|
||||
@@ -895,13 +895,14 @@ test('Call all "success" plugins even if one errors out', async (t) => {
|
||||
success: [success1, success2],
|
||||
};
|
||||
|
||||
const semanticRelease = requireNoCache('..', {
|
||||
'./lib/get-logger': () => t.context.logger,
|
||||
'env-ci': () => ({isCi: true, branch: 'master', isPr: false}),
|
||||
});
|
||||
const env = {};
|
||||
await td.replaceEsm('../lib/get-logger.js', null, () => t.context.logger);
|
||||
const envCi = (await td.replaceEsm('env-ci')).default;
|
||||
td.when(envCi({cwd, env})).thenReturn({isCi: true, branch: 'master', isPr: false});
|
||||
const semanticRelease = (await import('../index.js')).default;
|
||||
|
||||
await t.throwsAsync(
|
||||
semanticRelease(options, {cwd, env: {}, stdout: new WritableStreamBuffer(), stderr: new WritableStreamBuffer()})
|
||||
semanticRelease(options, {cwd, env, stdout: new WritableStreamBuffer(), stderr: new WritableStreamBuffer()})
|
||||
);
|
||||
|
||||
t.is(success1.callCount, 1);
|
||||
@@ -916,7 +917,7 @@ test('Call all "success" plugins even if one errors out', async (t) => {
|
||||
]);
|
||||
});
|
||||
|
||||
test('Log all "verifyConditions" errors', async (t) => {
|
||||
test.serial('Log all "verifyConditions" errors', 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
|
||||
@@ -927,7 +928,12 @@ test('Log all "verifyConditions" errors', async (t) => {
|
||||
const error2 = new SemanticReleaseError('error 2', 'ERR2');
|
||||
const error3 = new SemanticReleaseError('error 3', 'ERR3');
|
||||
const fail = stub().resolves();
|
||||
const config = {branches: [{name: 'master'}], repositoryUrl, tagFormat: `v\${version}`};
|
||||
const config = {
|
||||
branches: [{name: 'master'}],
|
||||
repositoryUrl,
|
||||
originalRepositoryURL: repositoryUrl,
|
||||
tagFormat: `v\${version}`,
|
||||
};
|
||||
const options = {
|
||||
...config,
|
||||
plugins: false,
|
||||
@@ -935,14 +941,13 @@ test('Log all "verifyConditions" errors', async (t) => {
|
||||
fail,
|
||||
};
|
||||
|
||||
const semanticRelease = requireNoCache('..', {
|
||||
'./lib/get-logger': () => t.context.logger,
|
||||
'env-ci': () => ({isCi: true, branch: 'master', isPr: false}),
|
||||
});
|
||||
await td.replaceEsm('../lib/get-logger.js', null, () => t.context.logger);
|
||||
await td.replaceEsm('env-ci', null, () => ({isCi: true, branch: 'master', isPr: false}));
|
||||
const semanticRelease = (await import('../index.js')).default;
|
||||
const errors = [
|
||||
...(await t.throwsAsync(
|
||||
semanticRelease(options, {cwd, env: {}, stdout: new WritableStreamBuffer(), stderr: new WritableStreamBuffer()})
|
||||
)),
|
||||
)).errors,
|
||||
];
|
||||
|
||||
t.deepEqual(sortBy(errors, ['message']), sortBy([error1, error2, error3], ['message']));
|
||||
@@ -957,7 +962,7 @@ test('Log all "verifyConditions" errors', async (t) => {
|
||||
t.deepEqual(fail.args[0][1].errors, [error2, error3]);
|
||||
});
|
||||
|
||||
test('Log all "verifyRelease" errors', async (t) => {
|
||||
test.serial('Log all "verifyRelease" errors', 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
|
||||
@@ -980,14 +985,13 @@ test('Log all "verifyRelease" errors', async (t) => {
|
||||
fail,
|
||||
};
|
||||
|
||||
const semanticRelease = requireNoCache('..', {
|
||||
'./lib/get-logger': () => t.context.logger,
|
||||
'env-ci': () => ({isCi: true, branch: 'master', isPr: false}),
|
||||
});
|
||||
await td.replaceEsm('../lib/get-logger.js', null, () => t.context.logger);
|
||||
await td.replaceEsm('env-ci', null, () => ({isCi: true, branch: 'master', isPr: false}));
|
||||
const semanticRelease = (await import('../index.js')).default;
|
||||
const errors = [
|
||||
...(await t.throwsAsync(
|
||||
semanticRelease(options, {cwd, env: {}, stdout: new WritableStreamBuffer(), stderr: new WritableStreamBuffer()})
|
||||
)),
|
||||
)).errors,
|
||||
];
|
||||
|
||||
t.deepEqual(sortBy(errors, ['message']), sortBy([error1, error2], ['message']));
|
||||
@@ -998,7 +1002,7 @@ test('Log all "verifyRelease" errors', async (t) => {
|
||||
t.deepEqual(fail.args[0][1].errors, [error1, error2]);
|
||||
});
|
||||
|
||||
test('Dry-run skips addChannel, prepare, publish and success', async (t) => {
|
||||
test.serial('Dry-run skips addChannel, prepare, publish and success', async (t) => {
|
||||
const {cwd, repositoryUrl} = await gitRepo(true);
|
||||
await gitCommits(['First'], {cwd});
|
||||
await gitTagVersion('v1.0.0', undefined, {cwd});
|
||||
@@ -1034,10 +1038,9 @@ test('Dry-run skips addChannel, prepare, publish and success', async (t) => {
|
||||
success,
|
||||
};
|
||||
|
||||
const semanticRelease = requireNoCache('..', {
|
||||
'./lib/get-logger': () => t.context.logger,
|
||||
'env-ci': () => ({isCi: true, branch: 'master', isPr: false}),
|
||||
});
|
||||
await td.replaceEsm('../lib/get-logger.js', null, () => t.context.logger);
|
||||
await td.replaceEsm('env-ci', null, () => ({isCi: true, branch: 'master', isPr: false}));
|
||||
const semanticRelease = (await import('../index.js')).default;
|
||||
t.truthy(
|
||||
await semanticRelease(options, {
|
||||
cwd,
|
||||
@@ -1064,7 +1067,7 @@ test('Dry-run skips addChannel, prepare, publish and success', async (t) => {
|
||||
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) => {
|
||||
test.serial('Dry-run skips fail', 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
|
||||
@@ -1087,14 +1090,13 @@ test('Dry-run skips fail', async (t) => {
|
||||
fail,
|
||||
};
|
||||
|
||||
const semanticRelease = requireNoCache('..', {
|
||||
'./lib/get-logger': () => t.context.logger,
|
||||
'env-ci': () => ({isCi: true, branch: 'master', isPr: false}),
|
||||
});
|
||||
await td.replaceEsm('../lib/get-logger.js', null, () => t.context.logger);
|
||||
await td.replaceEsm('env-ci', null, () => ({isCi: true, branch: 'master', isPr: false}));
|
||||
const semanticRelease = (await import('../index.js')).default;
|
||||
const errors = [
|
||||
...(await t.throwsAsync(
|
||||
semanticRelease(options, {cwd, env: {}, stdout: new WritableStreamBuffer(), stderr: new WritableStreamBuffer()})
|
||||
)),
|
||||
)).errors,
|
||||
];
|
||||
|
||||
t.deepEqual(sortBy(errors, ['message']), sortBy([error1, error2], ['message']));
|
||||
@@ -1104,7 +1106,7 @@ test('Dry-run skips fail', async (t) => {
|
||||
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) => {
|
||||
test.serial('Force a dry-run if not on a CI and "noCi" is not explicitly set', 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
|
||||
@@ -1147,10 +1149,9 @@ test('Force a dry-run if not on a CI and "noCi" is not explicitly set', async (t
|
||||
fail: stub().resolves(),
|
||||
};
|
||||
|
||||
const semanticRelease = requireNoCache('..', {
|
||||
'./lib/get-logger': () => t.context.logger,
|
||||
'env-ci': () => ({isCi: false, branch: 'master'}),
|
||||
});
|
||||
await td.replaceEsm('../lib/get-logger.js', null, () => t.context.logger);
|
||||
await td.replaceEsm('env-ci', null, () => ({isCi: false, branch: 'master'}));
|
||||
const semanticRelease = (await import('../index.js')).default;
|
||||
t.truthy(
|
||||
await semanticRelease(options, {
|
||||
cwd,
|
||||
@@ -1169,7 +1170,7 @@ test('Force a dry-run if not on a CI and "noCi" is not explicitly set', async (t
|
||||
t.is(success.callCount, 0);
|
||||
});
|
||||
|
||||
test('Dry-run does not print changelog if "generateNotes" return "undefined"', async (t) => {
|
||||
test.serial('Dry-run does not print changelog if "generateNotes" return "undefined"', 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
|
||||
@@ -1197,10 +1198,9 @@ test('Dry-run does not print changelog if "generateNotes" return "undefined"', a
|
||||
success: false,
|
||||
};
|
||||
|
||||
const semanticRelease = requireNoCache('..', {
|
||||
'./lib/get-logger': () => t.context.logger,
|
||||
'env-ci': () => ({isCi: true, branch: 'master', isPr: false}),
|
||||
});
|
||||
await td.replaceEsm('../lib/get-logger.js', null, () => t.context.logger);
|
||||
await td.replaceEsm('env-ci', null, () => ({isCi: true, branch: 'master', isPr: false}));
|
||||
const semanticRelease = (await import('../index.js')).default;
|
||||
t.truthy(
|
||||
await semanticRelease(options, {
|
||||
cwd,
|
||||
@@ -1213,7 +1213,7 @@ test('Dry-run does not print changelog if "generateNotes" return "undefined"', a
|
||||
t.deepEqual(t.context.log.args[t.context.log.args.length - 1], ['Release note for version 2.0.0:']);
|
||||
});
|
||||
|
||||
test('Allow local releases with "noCi" option', async (t) => {
|
||||
test.serial('Allow local releases with "noCi" option', 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
|
||||
@@ -1256,10 +1256,9 @@ test('Allow local releases with "noCi" option', async (t) => {
|
||||
fail: stub().resolves(),
|
||||
};
|
||||
|
||||
const semanticRelease = requireNoCache('..', {
|
||||
'./lib/get-logger': () => t.context.logger,
|
||||
'env-ci': () => ({isCi: false, branch: 'master', isPr: false}),
|
||||
});
|
||||
await td.replaceEsm('../lib/get-logger.js', null, () => t.context.logger);
|
||||
await td.replaceEsm('env-ci', null, () => ({isCi: false, branch: 'master', isPr: false}));
|
||||
const semanticRelease = (await import('../index.js')).default;
|
||||
t.truthy(
|
||||
await semanticRelease(options, {
|
||||
cwd,
|
||||
@@ -1282,7 +1281,7 @@ test('Allow local releases with "noCi" option', async (t) => {
|
||||
t.is(success.callCount, 1);
|
||||
});
|
||||
|
||||
test('Accept "undefined" value returned by "generateNotes" and "false" by "publish" and "addChannel"', async (t) => {
|
||||
test.serial('Accept "undefined" value returned by "generateNotes" and "false" by "publish" and "addChannel"', async (t) => {
|
||||
const {cwd, repositoryUrl} = await gitRepo(true);
|
||||
await gitCommits(['First'], {cwd});
|
||||
await gitTagVersion('v1.0.0', undefined, {cwd});
|
||||
@@ -1326,10 +1325,9 @@ test('Accept "undefined" value returned by "generateNotes" and "false" by "publi
|
||||
fail: stub().resolves(),
|
||||
};
|
||||
|
||||
const semanticRelease = requireNoCache('..', {
|
||||
'./lib/get-logger': () => t.context.logger,
|
||||
'env-ci': () => ({isCi: true, branch: 'master', isPr: false}),
|
||||
});
|
||||
await td.replaceEsm('../lib/get-logger.js', null, () => t.context.logger);
|
||||
await td.replaceEsm('env-ci', null, () => ({isCi: true, branch: 'master', isPr: false}));
|
||||
const semanticRelease = (await import('../index.js')).default;
|
||||
t.truthy(
|
||||
await semanticRelease(options, {
|
||||
cwd,
|
||||
@@ -1351,14 +1349,13 @@ test('Accept "undefined" value returned by "generateNotes" and "false" by "publi
|
||||
t.deepEqual(success.args[1][1].releases, [{pluginName: '[Function: functionStub]'}]);
|
||||
});
|
||||
|
||||
test('Returns false if triggered by a PR', async (t) => {
|
||||
test.serial('Returns false if triggered by a PR', async (t) => {
|
||||
// Create a git repository, set the current working directory at the root of the repo
|
||||
const {cwd, repositoryUrl} = await gitRepo(true);
|
||||
|
||||
const semanticRelease = requireNoCache('..', {
|
||||
'./lib/get-logger': () => t.context.logger,
|
||||
'env-ci': () => ({isCi: true, branch: 'master', prBranch: 'patch-1', isPr: true}),
|
||||
});
|
||||
await td.replaceEsm('../lib/get-logger.js', null, () => t.context.logger);
|
||||
await td.replaceEsm('env-ci', null, () => ({isCi: true, branch: 'master', prBranch: 'patch-1', isPr: true}));
|
||||
const semanticRelease = (await import('../index.js')).default;
|
||||
|
||||
t.false(
|
||||
await semanticRelease(
|
||||
@@ -1372,7 +1369,7 @@ test('Returns false if triggered by a PR', async (t) => {
|
||||
);
|
||||
});
|
||||
|
||||
test('Throws "EINVALIDNEXTVERSION" if next release is out of range of the current maintenance branch', async (t) => {
|
||||
test.serial('Throws "EINVALIDNEXTVERSION" if next release is out of range of the current maintenance branch', async (t) => {
|
||||
const {cwd, repositoryUrl} = await gitRepo(true);
|
||||
await gitCommits(['feat: initial commit'], {cwd});
|
||||
await gitTagVersion('v1.0.0', undefined, {cwd});
|
||||
@@ -1408,13 +1405,14 @@ test('Throws "EINVALIDNEXTVERSION" if next release is out of range of the curren
|
||||
success,
|
||||
};
|
||||
|
||||
const semanticRelease = proxyquire('..', {
|
||||
'./lib/logger': t.context.logger,
|
||||
'env-ci': () => ({isCi: true, branch: '1.x', isPr: false}),
|
||||
});
|
||||
const env = {};
|
||||
await td.replaceEsm('../lib/get-logger.js', null, () => t.context.logger);
|
||||
const envCi = (await td.replaceEsm('env-ci')).default;
|
||||
td.when(envCi({cwd, env})).thenReturn({isCi: true, branch: '1.x', isPr: false});
|
||||
const semanticRelease = (await import('../index.js')).default;
|
||||
|
||||
const error = await t.throwsAsync(
|
||||
semanticRelease(options, {cwd, env: {}, stdout: {write: () => {}}, stderr: {write: () => {}}})
|
||||
semanticRelease(options, {cwd, env, stdout: {write: () => {}}, stderr: {write: () => {}}})
|
||||
);
|
||||
|
||||
t.is(error.code, 'EINVALIDNEXTVERSION');
|
||||
@@ -1423,7 +1421,7 @@ test('Throws "EINVALIDNEXTVERSION" if next release is out of range of the curren
|
||||
t.regex(error.details, /A valid branch could be `master`./);
|
||||
});
|
||||
|
||||
test('Throws "EINVALIDNEXTVERSION" if next release is out of range of the current release branch', async (t) => {
|
||||
test.serial('Throws "EINVALIDNEXTVERSION" if next release is out of range of the current release branch', async (t) => {
|
||||
const {cwd, repositoryUrl} = await gitRepo(true);
|
||||
await gitCommits(['feat: initial commit'], {cwd});
|
||||
await gitTagVersion('v1.0.0', undefined, {cwd});
|
||||
@@ -1460,10 +1458,9 @@ test('Throws "EINVALIDNEXTVERSION" if next release is out of range of the curren
|
||||
success,
|
||||
};
|
||||
|
||||
const semanticRelease = proxyquire('..', {
|
||||
'./lib/logger': t.context.logger,
|
||||
'env-ci': () => ({isCi: true, branch: 'master', isPr: false}),
|
||||
});
|
||||
await td.replaceEsm('../lib/get-logger.js', null, () => t.context.logger);
|
||||
await td.replaceEsm('env-ci', null, () => ({isCi: true, branch: 'master', isPr: false}));
|
||||
const semanticRelease = (await import('../index.js')).default;
|
||||
|
||||
const error = await t.throwsAsync(
|
||||
semanticRelease(options, {cwd, env: {}, stdout: {write: () => {}}, stderr: {write: () => {}}})
|
||||
@@ -1475,7 +1472,7 @@ test('Throws "EINVALIDNEXTVERSION" if next release is out of range of the curren
|
||||
t.regex(error.details, /A valid branch could be `next` or `next-major`./);
|
||||
});
|
||||
|
||||
test('Throws "EINVALIDMAINTENANCEMERGE" if merge an out of range release in a maintenance branch', async (t) => {
|
||||
test.serial('Throws "EINVALIDMAINTENANCEMERGE" if merge an out of range release in a maintenance branch', async (t) => {
|
||||
const {cwd, repositoryUrl} = await gitRepo(true);
|
||||
await gitCommits(['First'], {cwd});
|
||||
await gitTagVersion('v1.0.0', undefined, {cwd});
|
||||
@@ -1520,14 +1517,13 @@ test('Throws "EINVALIDMAINTENANCEMERGE" if merge an out of range release in a ma
|
||||
fail,
|
||||
};
|
||||
|
||||
const semanticRelease = proxyquire('..', {
|
||||
'./lib/logger': t.context.logger,
|
||||
'env-ci': () => ({isCi: true, branch: '1.1.x', isPr: false}),
|
||||
});
|
||||
await td.replaceEsm('../lib/get-logger.js', null, () => t.context.logger);
|
||||
await td.replaceEsm('env-ci', null, () => ({isCi: true, branch: '1.1.x', isPr: false}));
|
||||
const semanticRelease = (await import('../index.js')).default;
|
||||
const errors = [
|
||||
...(await t.throwsAsync(
|
||||
semanticRelease(options, {cwd, env: {}, stdout: {write: () => {}}, stderr: {write: () => {}}})
|
||||
)),
|
||||
)).errors,
|
||||
];
|
||||
|
||||
t.is(addChannel.callCount, 0);
|
||||
@@ -1545,7 +1541,7 @@ test('Throws "EINVALIDMAINTENANCEMERGE" if merge an out of range release in a ma
|
||||
t.truthy(errors[0].details);
|
||||
});
|
||||
|
||||
test('Returns false value if triggered on an outdated clone', async (t) => {
|
||||
test.serial('Returns false value if triggered on an outdated clone', async (t) => {
|
||||
// Create a git repository, set the current working directory at the root of the repo
|
||||
let {cwd, repositoryUrl} = await gitRepo(true);
|
||||
const repoDir = cwd;
|
||||
@@ -1557,10 +1553,9 @@ test('Returns false value if triggered on an outdated clone', async (t) => {
|
||||
await gitCommits(['Third'], {cwd});
|
||||
await gitPush(repositoryUrl, 'master', {cwd});
|
||||
|
||||
const semanticRelease = requireNoCache('..', {
|
||||
'./lib/get-logger': () => t.context.logger,
|
||||
'env-ci': () => ({isCi: true, branch: 'master', isPr: false}),
|
||||
});
|
||||
await td.replaceEsm('../lib/get-logger.js', null, () => t.context.logger);
|
||||
await td.replaceEsm('env-ci', null, () => ({isCi: true, branch: 'master', isPr: false}));
|
||||
const semanticRelease = (await import('../index.js')).default;
|
||||
|
||||
t.false(
|
||||
await semanticRelease(
|
||||
@@ -1573,7 +1568,7 @@ test('Returns false value if triggered on an outdated clone', async (t) => {
|
||||
]);
|
||||
});
|
||||
|
||||
test('Returns false if not running from the configured branch', async (t) => {
|
||||
test.serial('Returns false if not running from the configured branch', async (t) => {
|
||||
// Create a git repository, set the current working directory at the root of the repo
|
||||
const {cwd, repositoryUrl} = await gitRepo(true);
|
||||
const options = {
|
||||
@@ -1590,10 +1585,9 @@ test('Returns false if not running from the configured branch', async (t) => {
|
||||
fail: stub().resolves(),
|
||||
};
|
||||
|
||||
const semanticRelease = requireNoCache('..', {
|
||||
'./lib/get-logger': () => t.context.logger,
|
||||
'env-ci': () => ({isCi: true, branch: 'other-branch', isPr: false}),
|
||||
});
|
||||
await td.replaceEsm('../lib/get-logger.js', null, () => t.context.logger);
|
||||
await td.replaceEsm('env-ci', null, () => ({isCi: true, branch: 'other-branch', isPr: false}));
|
||||
const semanticRelease = (await import('../index.js')).default;
|
||||
|
||||
t.false(
|
||||
await semanticRelease(options, {
|
||||
@@ -1609,7 +1603,7 @@ test('Returns false if not running from the configured branch', async (t) => {
|
||||
);
|
||||
});
|
||||
|
||||
test('Returns false if there is no relevant changes', async (t) => {
|
||||
test.serial('Returns false if there is no relevant changes', 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
|
||||
@@ -1635,10 +1629,9 @@ test('Returns false if there is no relevant changes', async (t) => {
|
||||
fail: stub().resolves(),
|
||||
};
|
||||
|
||||
const semanticRelease = requireNoCache('..', {
|
||||
'./lib/get-logger': () => t.context.logger,
|
||||
'env-ci': () => ({isCi: true, branch: 'master', isPr: false}),
|
||||
});
|
||||
await td.replaceEsm('../lib/get-logger.js', null, () => t.context.logger);
|
||||
await td.replaceEsm('env-ci', null, () => ({isCi: true, branch: 'master', isPr: false}));
|
||||
const semanticRelease = (await import('../index.js')).default;
|
||||
|
||||
t.false(
|
||||
await semanticRelease(options, {
|
||||
@@ -1658,7 +1651,7 @@ test('Returns false if there is no relevant changes', async (t) => {
|
||||
);
|
||||
});
|
||||
|
||||
test('Exclude commits with [skip release] or [release skip] from analysis', async (t) => {
|
||||
test.serial('Exclude commits with [skip release] or [release skip] from analysis', 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
|
||||
@@ -1691,13 +1684,14 @@ test('Exclude commits with [skip release] or [release skip] from analysis', asyn
|
||||
fail: stub().resolves(),
|
||||
};
|
||||
|
||||
const semanticRelease = requireNoCache('..', {
|
||||
'./lib/get-logger': () => t.context.logger,
|
||||
'env-ci': () => ({isCi: true, branch: 'master', isPr: false}),
|
||||
});
|
||||
const env = {};
|
||||
await td.replaceEsm('../lib/get-logger.js', null, () => t.context.logger);
|
||||
const envCi = (await td.replaceEsm('env-ci')).default;
|
||||
td.when(envCi({env, cwd})).thenReturn({isCi: true, branch: 'master', isPr: false});
|
||||
const semanticRelease = (await import('../index.js')).default;
|
||||
await semanticRelease(options, {
|
||||
cwd,
|
||||
env: {},
|
||||
env,
|
||||
stdout: new WritableStreamBuffer(),
|
||||
stderr: new WritableStreamBuffer(),
|
||||
});
|
||||
@@ -1707,7 +1701,7 @@ test('Exclude commits with [skip release] or [release skip] from analysis', asyn
|
||||
t.deepEqual(analyzeCommits.args[0][1].commits[0], commits[commits.length - 1]);
|
||||
});
|
||||
|
||||
test('Log both plugins errors and errors thrown by "fail" plugin', async (t) => {
|
||||
test.serial('Log both plugins errors and errors thrown by "fail" plugin', async (t) => {
|
||||
const {cwd, repositoryUrl} = await gitRepo(true);
|
||||
const pluginError = new SemanticReleaseError('Plugin error', 'ERR');
|
||||
const failError1 = new Error('Fail error 1');
|
||||
@@ -1719,10 +1713,9 @@ test('Log both plugins errors and errors thrown by "fail" plugin', async (t) =>
|
||||
verifyConditions: stub().rejects(pluginError),
|
||||
fail: [stub().rejects(failError1), stub().rejects(failError2)],
|
||||
};
|
||||
const semanticRelease = requireNoCache('..', {
|
||||
'./lib/get-logger': () => t.context.logger,
|
||||
'env-ci': () => ({isCi: true, branch: 'master', isPr: false}),
|
||||
});
|
||||
await td.replaceEsm('../lib/get-logger.js', null, () => t.context.logger);
|
||||
await td.replaceEsm('env-ci', null, () => ({isCi: true, branch: 'master', isPr: false}));
|
||||
const semanticRelease = (await import('../index.js')).default;
|
||||
|
||||
await t.throwsAsync(
|
||||
semanticRelease(options, {cwd, env: {}, stdout: new WritableStreamBuffer(), stderr: new WritableStreamBuffer()})
|
||||
@@ -1733,7 +1726,7 @@ test('Log both plugins errors and errors thrown by "fail" plugin', async (t) =>
|
||||
t.is(t.context.error.args[t.context.error.args.length - 2][1], failError2);
|
||||
});
|
||||
|
||||
test('Call "fail" only if a plugin returns a SemanticReleaseError', async (t) => {
|
||||
test.serial('Call "fail" only if a plugin returns a SemanticReleaseError', async (t) => {
|
||||
const {cwd, repositoryUrl} = await gitRepo(true);
|
||||
const pluginError = new Error('Plugin error');
|
||||
const fail = stub().resolves();
|
||||
@@ -1744,10 +1737,9 @@ test('Call "fail" only if a plugin returns a SemanticReleaseError', async (t) =>
|
||||
verifyConditions: stub().rejects(pluginError),
|
||||
fail,
|
||||
};
|
||||
const semanticRelease = requireNoCache('..', {
|
||||
'./lib/get-logger': () => t.context.logger,
|
||||
'env-ci': () => ({isCi: true, branch: 'master', isPr: false}),
|
||||
});
|
||||
await td.replaceEsm('../lib/get-logger.js', null, () => t.context.logger);
|
||||
await td.replaceEsm('env-ci', null, () => ({isCi: true, branch: 'master', isPr: false}));
|
||||
const semanticRelease = (await import('../index.js')).default;
|
||||
|
||||
await t.throwsAsync(
|
||||
semanticRelease(options, {cwd, env: {}, stdout: new WritableStreamBuffer(), stderr: new WritableStreamBuffer()})
|
||||
@@ -1757,18 +1749,17 @@ test('Call "fail" only if a plugin returns a SemanticReleaseError', async (t) =>
|
||||
t.is(t.context.error.args[t.context.error.args.length - 1][1], pluginError);
|
||||
});
|
||||
|
||||
test('Throw SemanticReleaseError if repositoryUrl is not set and cannot be found from repo config', async (t) => {
|
||||
test.serial('Throw SemanticReleaseError if repositoryUrl is not set and cannot be found from repo config', async (t) => {
|
||||
// Create a git repository, set the current working directory at the root of the repo
|
||||
const {cwd} = await gitRepo();
|
||||
|
||||
const semanticRelease = requireNoCache('..', {
|
||||
'./lib/get-logger': () => t.context.logger,
|
||||
'env-ci': () => ({isCi: true, branch: 'master', isPr: false}),
|
||||
});
|
||||
await td.replaceEsm('../lib/get-logger.js', null, () => t.context.logger);
|
||||
await td.replaceEsm('env-ci', null, () => ({isCi: true, branch: 'master', isPr: false}));
|
||||
const semanticRelease = (await import('../index.js')).default;
|
||||
const errors = [
|
||||
...(await t.throwsAsync(
|
||||
semanticRelease({}, {cwd, env: {}, stdout: new WritableStreamBuffer(), stderr: new WritableStreamBuffer()})
|
||||
)),
|
||||
)).errors,
|
||||
];
|
||||
|
||||
// Verify error code and type
|
||||
@@ -1778,7 +1769,7 @@ test('Throw SemanticReleaseError if repositoryUrl is not set and cannot be found
|
||||
t.truthy(errors[0].details);
|
||||
});
|
||||
|
||||
test('Throw an Error if plugin returns an unexpected value', async (t) => {
|
||||
test.serial('Throw an Error if plugin returns an unexpected value', 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
|
||||
@@ -1801,10 +1792,9 @@ test('Throw an Error if plugin returns an unexpected value', async (t) => {
|
||||
fail: stub().resolves(),
|
||||
};
|
||||
|
||||
const semanticRelease = requireNoCache('..', {
|
||||
'./lib/get-logger': () => t.context.logger,
|
||||
'env-ci': () => ({isCi: true, branch: 'master', isPr: false}),
|
||||
});
|
||||
await td.replaceEsm('../lib/get-logger.js', null, () => t.context.logger);
|
||||
await td.replaceEsm('env-ci', null, () => ({isCi: true, branch: 'master', isPr: false}));
|
||||
const semanticRelease = (await import('../index.js')).default;
|
||||
const error = await t.throwsAsync(
|
||||
semanticRelease(options, {cwd, env: {}, stdout: new WritableStreamBuffer(), stderr: new WritableStreamBuffer()}),
|
||||
{instanceOf: SemanticReleaseError}
|
||||
@@ -1812,7 +1802,7 @@ test('Throw an Error if plugin returns an unexpected value', async (t) => {
|
||||
t.regex(error.details, /string/);
|
||||
});
|
||||
|
||||
test('Hide sensitive information passed to "fail" plugin', async (t) => {
|
||||
test.serial('Hide sensitive information passed to "fail" plugin', async (t) => {
|
||||
const {cwd, repositoryUrl} = await gitRepo(true);
|
||||
|
||||
const fail = stub().resolves();
|
||||
@@ -1831,10 +1821,9 @@ test('Hide sensitive information passed to "fail" plugin', async (t) => {
|
||||
fail,
|
||||
};
|
||||
|
||||
const semanticRelease = requireNoCache('..', {
|
||||
'./lib/get-logger': () => t.context.logger,
|
||||
'env-ci': () => ({isCi: true, branch: 'master', isPr: false}),
|
||||
});
|
||||
await td.replaceEsm('../lib/get-logger.js', null, () => t.context.logger);
|
||||
await td.replaceEsm('env-ci', null, () => ({isCi: true, branch: 'master', isPr: false}));
|
||||
const semanticRelease = (await import('../index.js')).default;
|
||||
await t.throwsAsync(
|
||||
semanticRelease(options, {cwd, env, stdout: new WritableStreamBuffer(), stderr: new WritableStreamBuffer()})
|
||||
);
|
||||
@@ -1851,7 +1840,7 @@ test('Hide sensitive information passed to "fail" plugin', async (t) => {
|
||||
});
|
||||
});
|
||||
|
||||
test('Hide sensitive information passed to "success" plugin', async (t) => {
|
||||
test.serial('Hide sensitive information passed to "success" plugin', async (t) => {
|
||||
const {cwd, repositoryUrl} = await gitRepo(true);
|
||||
await gitCommits(['feat: initial release'], {cwd});
|
||||
await gitTagVersion('v1.0.0', undefined, {cwd});
|
||||
@@ -1876,10 +1865,9 @@ test('Hide sensitive information passed to "success" plugin', async (t) => {
|
||||
fail: stub().resolves(),
|
||||
};
|
||||
|
||||
const semanticRelease = requireNoCache('..', {
|
||||
'./lib/get-logger': () => t.context.logger,
|
||||
'env-ci': () => ({isCi: true, branch: 'master', isPr: false}),
|
||||
});
|
||||
await td.replaceEsm('../lib/get-logger.js', null, () => t.context.logger);
|
||||
await td.replaceEsm('env-ci', null, () => ({isCi: true, branch: 'master', isPr: false}));
|
||||
const semanticRelease = (await import('../index.js')).default;
|
||||
await semanticRelease(options, {cwd, env, stdout: new WritableStreamBuffer(), stderr: new WritableStreamBuffer()});
|
||||
|
||||
const release = success.args[0][1].releases[0];
|
||||
@@ -1894,7 +1882,7 @@ test('Hide sensitive information passed to "success" plugin', async (t) => {
|
||||
});
|
||||
});
|
||||
|
||||
test('Get all commits including the ones not in the shallow clone', async (t) => {
|
||||
test.serial('Get all commits including the ones not in the shallow clone', async (t) => {
|
||||
let {cwd, repositoryUrl} = await gitRepo(true);
|
||||
await gitTagVersion('v1.0.0', undefined, {cwd});
|
||||
await gitCommits(['First', 'Second', 'Third'], {cwd});
|
||||
@@ -1926,10 +1914,9 @@ test('Get all commits including the ones not in the shallow clone', async (t) =>
|
||||
fail: stub().resolves(),
|
||||
};
|
||||
|
||||
const semanticRelease = requireNoCache('..', {
|
||||
'./lib/get-logger': () => t.context.logger,
|
||||
'env-ci': () => ({isCi: true, branch: 'master', isPr: false}),
|
||||
});
|
||||
await td.replaceEsm('../lib/get-logger.js', null, () => t.context.logger);
|
||||
await td.replaceEsm('env-ci', null, () => ({isCi: true, branch: 'master', isPr: false}));
|
||||
const semanticRelease = (await import('../index.js')).default;
|
||||
t.truthy(
|
||||
await semanticRelease(options, {
|
||||
cwd,
|
||||
|
||||
+33
-33
@@ -1,33 +1,34 @@
|
||||
const path = require('path');
|
||||
const test = require('ava');
|
||||
const proxyquire = require('proxyquire');
|
||||
const {escapeRegExp} = require('lodash');
|
||||
const {writeJson, readJson} = require('fs-extra');
|
||||
const execa = require('execa');
|
||||
const {WritableStreamBuffer} = require('stream-buffers');
|
||||
const delay = require('delay');
|
||||
const getAuthUrl = require('../lib/get-git-auth-url');
|
||||
const {SECRET_REPLACEMENT} = require('../lib/definitions/constants');
|
||||
const {
|
||||
gitHead,
|
||||
gitTagHead,
|
||||
gitRepo,
|
||||
gitCommits,
|
||||
gitRemoteTagHead,
|
||||
gitPush,
|
||||
import path from 'path';
|
||||
import test from 'ava';
|
||||
import * as td from 'testdouble';
|
||||
import {escapeRegExp} from 'lodash-es';
|
||||
import fsExtra from 'fs-extra';
|
||||
import {execa} from 'execa';
|
||||
import {WritableStreamBuffer} from 'stream-buffers';
|
||||
import delay from 'delay';
|
||||
|
||||
import getAuthUrl from '../lib/get-git-auth-url.js';
|
||||
import {SECRET_REPLACEMENT} from '../lib/definitions/constants.js';
|
||||
import {
|
||||
gitCheckout,
|
||||
merge,
|
||||
gitCommits,
|
||||
gitGetNote,
|
||||
} = require('./helpers/git-utils');
|
||||
const {npmView} = require('./helpers/npm-utils');
|
||||
const gitbox = require('./helpers/gitbox');
|
||||
const mockServer = require('./helpers/mockserver');
|
||||
const npmRegistry = require('./helpers/npm-registry');
|
||||
gitHead,
|
||||
gitPush,
|
||||
gitRemoteTagHead,
|
||||
gitRepo,
|
||||
gitTagHead,
|
||||
merge
|
||||
} from './helpers/git-utils.js';
|
||||
import {npmView} from './helpers/npm-utils.js';
|
||||
import * as gitbox from './helpers/gitbox.js';
|
||||
import * as mockServer from './helpers/mockserver.js';
|
||||
import * as npmRegistry from './helpers/npm-registry.js';
|
||||
|
||||
const {readJson, writeJson} = fsExtra;
|
||||
|
||||
/* eslint camelcase: ["error", {properties: "never"}] */
|
||||
|
||||
const requireNoCache = proxyquire.noPreserveCache();
|
||||
|
||||
// Environment variables used with semantic-release cli (similar to what a user would setup)
|
||||
const {GITHUB_ACTION, GITHUB_TOKEN, ...processEnvWithoutGitHubActionsVariables} = process.env;
|
||||
const env = {
|
||||
@@ -49,10 +50,10 @@ const npmTestEnv = {
|
||||
LEGACY_TOKEN: Buffer.from(`${env.NPM_USERNAME}:${env.NPM_PASSWORD}`, 'utf8').toString('base64'),
|
||||
};
|
||||
|
||||
const cli = require.resolve('../bin/semantic-release');
|
||||
const pluginError = require.resolve('./fixtures/plugin-error');
|
||||
const pluginInheritedError = require.resolve('./fixtures/plugin-error-inherited');
|
||||
const pluginLogEnv = require.resolve('./fixtures/plugin-log-env');
|
||||
const cli = path.resolve('./bin/semantic-release.js');
|
||||
const pluginError = path.resolve('./test/fixtures/plugin-error');
|
||||
const pluginInheritedError = path.resolve('./test/fixtures/plugin-error-inherited');
|
||||
const pluginLogEnv = path.resolve('./test/fixtures/plugin-log-env');
|
||||
|
||||
test.before(async () => {
|
||||
await Promise.all([gitbox.start(), npmRegistry.start(), mockServer.start()]);
|
||||
@@ -509,10 +510,9 @@ test('Pass options via CLI arguments', async (t) => {
|
||||
});
|
||||
|
||||
test('Run via JS API', async (t) => {
|
||||
const semanticRelease = requireNoCache('..', {
|
||||
'./lib/logger': {log: () => {}, error: () => {}, stdout: () => {}},
|
||||
'env-ci': () => ({isCi: true, branch: 'master', isPr: false}),
|
||||
});
|
||||
td.replace('../lib/logger', {log: () => {}, error: () => {}, stdout: () => {}});
|
||||
td.replace('env-ci', () => ({isCi: true, branch: 'master', isPr: false}));
|
||||
const semanticRelease = (await import('../index.js')).default;
|
||||
const packageName = 'test-js-api';
|
||||
const owner = 'git';
|
||||
// Create a git repository, set the current working directory at the root of the repo
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
const test = require('ava');
|
||||
const {noop} = require('lodash');
|
||||
const {stub} = require('sinon');
|
||||
const normalize = require('../../lib/plugins/normalize');
|
||||
import test from 'ava';
|
||||
import {noop} from 'lodash-es';
|
||||
import {stub} from 'sinon';
|
||||
import normalize from '../../lib/plugins/normalize.js';
|
||||
|
||||
const cwd = process.cwd();
|
||||
|
||||
@@ -19,46 +19,46 @@ test.beforeEach((t) => {
|
||||
};
|
||||
});
|
||||
|
||||
test('Normalize and load plugin from string', (t) => {
|
||||
const plugin = normalize(
|
||||
test('Normalize and load plugin from string', async (t) => {
|
||||
const plugin = await normalize(
|
||||
{cwd, options: {}, logger: t.context.logger},
|
||||
'verifyConditions',
|
||||
'./test/fixtures/plugin-noop',
|
||||
'./test/fixtures/plugin-noop.cjs',
|
||||
{}
|
||||
);
|
||||
|
||||
t.is(plugin.pluginName, './test/fixtures/plugin-noop');
|
||||
t.is(plugin.pluginName, './test/fixtures/plugin-noop.cjs');
|
||||
t.is(typeof plugin, 'function');
|
||||
t.deepEqual(t.context.success.args[0], ['Loaded plugin "verifyConditions" from "./test/fixtures/plugin-noop"']);
|
||||
t.deepEqual(t.context.success.args[0], ['Loaded plugin "verifyConditions" from "./test/fixtures/plugin-noop.cjs"']);
|
||||
});
|
||||
|
||||
test('Normalize and load plugin from object', (t) => {
|
||||
const plugin = normalize(
|
||||
test('Normalize and load plugin from object', async (t) => {
|
||||
const plugin = await normalize(
|
||||
{cwd, options: {}, logger: t.context.logger},
|
||||
'publish',
|
||||
{path: './test/fixtures/plugin-noop'},
|
||||
{path: './test/fixtures/plugin-noop.cjs'},
|
||||
{}
|
||||
);
|
||||
|
||||
t.is(plugin.pluginName, './test/fixtures/plugin-noop');
|
||||
t.is(plugin.pluginName, './test/fixtures/plugin-noop.cjs');
|
||||
t.is(typeof plugin, 'function');
|
||||
t.deepEqual(t.context.success.args[0], ['Loaded plugin "publish" from "./test/fixtures/plugin-noop"']);
|
||||
t.deepEqual(t.context.success.args[0], ['Loaded plugin "publish" from "./test/fixtures/plugin-noop.cjs"']);
|
||||
});
|
||||
|
||||
test('Normalize and load plugin from a base file path', (t) => {
|
||||
const plugin = normalize({cwd, options: {}, logger: t.context.logger}, 'verifyConditions', './plugin-noop', {
|
||||
'./plugin-noop': './test/fixtures',
|
||||
test('Normalize and load plugin from a base file path', async (t) => {
|
||||
const plugin = await normalize({cwd, options: {}, logger: t.context.logger}, 'verifyConditions', './plugin-noop.cjs', {
|
||||
'./plugin-noop.cjs': './test/fixtures',
|
||||
});
|
||||
|
||||
t.is(plugin.pluginName, './plugin-noop');
|
||||
t.is(plugin.pluginName, './plugin-noop.cjs');
|
||||
t.is(typeof plugin, 'function');
|
||||
t.deepEqual(t.context.success.args[0], [
|
||||
'Loaded plugin "verifyConditions" from "./plugin-noop" in shareable config "./test/fixtures"',
|
||||
'Loaded plugin "verifyConditions" from "./plugin-noop.cjs" in shareable config "./test/fixtures"',
|
||||
]);
|
||||
});
|
||||
|
||||
test('Wrap plugin in a function that add the "pluginName" to the error"', async (t) => {
|
||||
const plugin = normalize({cwd, options: {}, logger: t.context.logger}, 'verifyConditions', './plugin-error', {
|
||||
const plugin = await normalize({cwd, options: {}, logger: t.context.logger}, 'verifyConditions', './plugin-error', {
|
||||
'./plugin-error': './test/fixtures',
|
||||
});
|
||||
|
||||
@@ -68,39 +68,39 @@ test('Wrap plugin in a function that add the "pluginName" to the error"', async
|
||||
});
|
||||
|
||||
test('Wrap plugin in a function that add the "pluginName" to multiple errors"', async (t) => {
|
||||
const plugin = normalize({cwd, options: {}, logger: t.context.logger}, 'verifyConditions', './plugin-errors', {
|
||||
const plugin = await normalize({cwd, options: {}, logger: t.context.logger}, 'verifyConditions', './plugin-errors', {
|
||||
'./plugin-errors': './test/fixtures',
|
||||
});
|
||||
|
||||
const errors = [...(await t.throwsAsync(plugin({options: {}})))];
|
||||
const errors = [...(await t.throwsAsync(plugin({options: {}}))).errors];
|
||||
for (const error of errors) {
|
||||
t.is(error.pluginName, './plugin-errors');
|
||||
}
|
||||
});
|
||||
|
||||
test('Normalize and load plugin from function', (t) => {
|
||||
test('Normalize and load plugin from function', async (t) => {
|
||||
const pluginFunction = () => {};
|
||||
const plugin = normalize({cwd, options: {}, logger: t.context.logger}, '', pluginFunction, {});
|
||||
const plugin = await normalize({cwd, options: {}, logger: t.context.logger}, '', pluginFunction, {});
|
||||
|
||||
t.is(plugin.pluginName, '[Function: pluginFunction]');
|
||||
t.is(typeof plugin, 'function');
|
||||
});
|
||||
|
||||
test('Normalize and load plugin that retuns multiple functions', (t) => {
|
||||
const plugin = normalize(
|
||||
test('Normalize and load plugin that retuns multiple functions', async (t) => {
|
||||
const plugin = await normalize(
|
||||
{cwd, options: {}, logger: t.context.logger},
|
||||
'verifyConditions',
|
||||
'./test/fixtures/multi-plugin',
|
||||
'./test/fixtures/multi-plugin.cjs',
|
||||
{}
|
||||
);
|
||||
|
||||
t.is(typeof plugin, 'function');
|
||||
t.deepEqual(t.context.success.args[0], ['Loaded plugin "verifyConditions" from "./test/fixtures/multi-plugin"']);
|
||||
t.deepEqual(t.context.success.args[0], ['Loaded plugin "verifyConditions" from "./test/fixtures/multi-plugin.cjs"']);
|
||||
});
|
||||
|
||||
test('Wrap "analyzeCommits" plugin in a function that validate the output of the plugin', async (t) => {
|
||||
const analyzeCommits = stub().resolves(2);
|
||||
const plugin = normalize(
|
||||
const plugin = await normalize(
|
||||
{cwd, options: {}, stderr: t.context.stderr, logger: t.context.logger},
|
||||
'analyzeCommits',
|
||||
analyzeCommits,
|
||||
@@ -118,7 +118,7 @@ test('Wrap "analyzeCommits" plugin in a function that validate the output of the
|
||||
|
||||
test('Wrap "generateNotes" plugin in a function that validate the output of the plugin', async (t) => {
|
||||
const generateNotes = stub().resolves(2);
|
||||
const plugin = normalize(
|
||||
const plugin = await normalize(
|
||||
{cwd, options: {}, stderr: t.context.stderr, logger: t.context.logger},
|
||||
'generateNotes',
|
||||
generateNotes,
|
||||
@@ -136,7 +136,7 @@ test('Wrap "generateNotes" plugin in a function that validate the output of the
|
||||
|
||||
test('Wrap "publish" plugin in a function that validate the output of the plugin', async (t) => {
|
||||
const publish = stub().resolves(2);
|
||||
const plugin = normalize(
|
||||
const plugin = await normalize(
|
||||
{cwd, options: {}, stderr: t.context.stderr, logger: t.context.logger},
|
||||
'publish',
|
||||
publish,
|
||||
@@ -154,7 +154,7 @@ test('Wrap "publish" plugin in a function that validate the output of the plugin
|
||||
|
||||
test('Wrap "addChannel" plugin in a function that validate the output of the plugin', async (t) => {
|
||||
const addChannel = stub().resolves(2);
|
||||
const plugin = normalize(
|
||||
const plugin = await normalize(
|
||||
{cwd, options: {}, stderr: t.context.stderr, logger: t.context.logger},
|
||||
'addChannel',
|
||||
addChannel,
|
||||
@@ -174,7 +174,7 @@ test('Plugin is called with "pluginConfig" (with object definition) and input',
|
||||
const pluginFunction = stub().resolves();
|
||||
const pluginConf = {path: pluginFunction, conf: 'confValue'};
|
||||
const options = {global: 'globalValue'};
|
||||
const plugin = normalize({cwd, options, logger: t.context.logger}, '', pluginConf, {});
|
||||
const plugin = await normalize({cwd, options, logger: t.context.logger}, '', pluginConf, {});
|
||||
await plugin({options: {}, param: 'param'});
|
||||
|
||||
t.true(
|
||||
@@ -189,7 +189,7 @@ test('Plugin is called with "pluginConfig" (with array definition) and input', a
|
||||
const pluginFunction = stub().resolves();
|
||||
const pluginConf = [pluginFunction, {conf: 'confValue'}];
|
||||
const options = {global: 'globalValue'};
|
||||
const plugin = normalize({cwd, options, logger: t.context.logger}, '', pluginConf, {});
|
||||
const plugin = await normalize({cwd, options, logger: t.context.logger}, '', pluginConf, {});
|
||||
await plugin({options: {}, param: 'param'});
|
||||
|
||||
t.true(
|
||||
@@ -206,7 +206,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, {});
|
||||
const plugin = await normalize({cwd, options, logger: t.context.logger}, '', pluginConf, {});
|
||||
await plugin({options: {}});
|
||||
|
||||
t.is(pluginConf.conf.subConf, 'originalConf');
|
||||
@@ -218,21 +218,21 @@ test('Prevent plugins to modify its input', async (t) => {
|
||||
options.param.subParam = 'otherParam';
|
||||
});
|
||||
const input = {param: {subParam: 'originalSubParam'}, options: {}};
|
||||
const plugin = normalize({cwd, options: {}, logger: t.context.logger}, '', pluginFunction, {});
|
||||
const plugin = await normalize({cwd, options: {}, logger: t.context.logger}, '', pluginFunction, {});
|
||||
await plugin(input);
|
||||
|
||||
t.is(input.param.subParam, 'originalSubParam');
|
||||
});
|
||||
|
||||
test('Return noop if the plugin is not defined', (t) => {
|
||||
const plugin = normalize({cwd, options: {}, logger: t.context.logger});
|
||||
test('Return noop if the plugin is not defined', async (t) => {
|
||||
const plugin = await normalize({cwd, options: {}, logger: t.context.logger});
|
||||
|
||||
t.is(plugin, noop);
|
||||
});
|
||||
|
||||
test('Always pass a defined "pluginConfig" for plugin defined with string', async (t) => {
|
||||
// Call the normalize function with the path of a plugin that returns its config
|
||||
const plugin = normalize(
|
||||
const plugin = await normalize(
|
||||
{cwd, options: {}, logger: t.context.logger},
|
||||
'',
|
||||
'./test/fixtures/plugin-result-config',
|
||||
@@ -245,7 +245,7 @@ test('Always pass a defined "pluginConfig" for plugin defined with string', asyn
|
||||
|
||||
test('Always pass a defined "pluginConfig" for plugin defined with path', async (t) => {
|
||||
// Call the normalize function with the path of a plugin that returns its config
|
||||
const plugin = normalize(
|
||||
const plugin = await normalize(
|
||||
{cwd, options: {}, logger: t.context.logger},
|
||||
'',
|
||||
{path: './test/fixtures/plugin-result-config'},
|
||||
@@ -256,9 +256,9 @@ test('Always pass a defined "pluginConfig" for plugin defined with path', async
|
||||
t.deepEqual(pluginResult.pluginConfig, {});
|
||||
});
|
||||
|
||||
test('Throws an error if the plugin return an object without the expected plugin function', (t) => {
|
||||
const error = t.throws(() =>
|
||||
normalize({cwd, options: {}, logger: t.context.logger}, 'inexistantPlugin', './test/fixtures/multi-plugin', {})
|
||||
test('Throws an error if the plugin return an object without the expected plugin function', async (t) => {
|
||||
const error = await t.throwsAsync(() =>
|
||||
normalize({cwd, options: {}, logger: t.context.logger}, 'nonExistentPlugin', './test/fixtures/multi-plugin.cjs', {})
|
||||
);
|
||||
|
||||
t.is(error.code, 'EPLUGIN');
|
||||
@@ -267,10 +267,13 @@ test('Throws an error if the plugin return an object without the expected plugin
|
||||
t.truthy(error.details);
|
||||
});
|
||||
|
||||
test('Throws an error if the plugin is not found', (t) => {
|
||||
t.throws(() => normalize({cwd, options: {}, logger: t.context.logger}, 'inexistantPlugin', 'non-existing-path', {}), {
|
||||
message: /Cannot find module 'non-existing-path'/,
|
||||
code: 'MODULE_NOT_FOUND',
|
||||
instanceOf: Error,
|
||||
});
|
||||
test('Throws an error if the plugin is not found', async (t) => {
|
||||
await t.throwsAsync(
|
||||
() => normalize({cwd, options: {}, logger: t.context.logger}, 'nonExistentPlugin', 'non-existing-path', {}),
|
||||
{
|
||||
message: /Cannot find module 'non-existing-path'/,
|
||||
code: 'MODULE_NOT_FOUND',
|
||||
instanceOf: Error,
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
const test = require('ava');
|
||||
const {stub} = require('sinon');
|
||||
const AggregateError = require('aggregate-error');
|
||||
const pipeline = require('../../lib/plugins/pipeline');
|
||||
import test from 'ava';
|
||||
import {stub} from 'sinon';
|
||||
import AggregateError from 'aggregate-error';
|
||||
import pipeline from '../../lib/plugins/pipeline.js';
|
||||
|
||||
test('Execute each function in series passing the same input', async (t) => {
|
||||
const step1 = stub().resolves(1);
|
||||
@@ -116,9 +116,9 @@ 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.throwsAsync(pipeline([step1, step2, step3])(0));
|
||||
const error = await t.throwsAsync(pipeline([step1, step2, step3])(0));
|
||||
|
||||
t.deepEqual([...errors], [error1, error2]);
|
||||
t.deepEqual([...error.errors], [error1, error2]);
|
||||
t.true(step1.calledWith(0));
|
||||
t.true(step2.calledWith(0));
|
||||
t.true(step3.notCalled);
|
||||
@@ -131,9 +131,9 @@ test('Execute all even if a Promise rejects', async (t) => {
|
||||
const step2 = stub().rejects(error1);
|
||||
const step3 = stub().rejects(error2);
|
||||
|
||||
const errors = await t.throwsAsync(pipeline([step1, step2, step3], {settleAll: true})(0));
|
||||
const error = await t.throwsAsync(pipeline([step1, step2, step3], {settleAll: true})(0));
|
||||
|
||||
t.deepEqual([...errors], [error1, error2]);
|
||||
t.deepEqual([...error.errors], [error1, error2]);
|
||||
t.true(step1.calledWith(0));
|
||||
t.true(step2.calledWith(0));
|
||||
t.true(step3.calledWith(0));
|
||||
@@ -147,9 +147,9 @@ 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.throwsAsync(pipeline([step1, step2], {settleAll: true})(0));
|
||||
const error = await t.throwsAsync(pipeline([step1, step2], {settleAll: true})(0));
|
||||
|
||||
t.deepEqual([...errors], [error1, error2, error3, error4]);
|
||||
t.deepEqual([...error.errors], [error1, error2, error3, error4]);
|
||||
t.true(step1.calledWith(0));
|
||||
t.true(step2.calledWith(0));
|
||||
});
|
||||
@@ -163,9 +163,9 @@ test('Execute each function in series passing a transformed input even if a step
|
||||
const step4 = stub().resolves(4);
|
||||
const getNextInput = (previousResult, result) => previousResult + result;
|
||||
|
||||
const errors = await t.throwsAsync(pipeline([step1, step2, step3, step4], {settleAll: true, getNextInput})(0));
|
||||
const error = await t.throwsAsync(pipeline([step1, step2, step3, step4], {settleAll: true, getNextInput})(0));
|
||||
|
||||
t.deepEqual([...errors], [error2, error3]);
|
||||
t.deepEqual([...error.errors], [error2, error3]);
|
||||
t.true(step1.calledWith(0));
|
||||
t.true(step2.calledWith(0 + 1));
|
||||
t.true(step3.calledWith(0 + 1 + error2));
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
const path = require('path');
|
||||
const test = require('ava');
|
||||
const {copy, outputFile} = require('fs-extra');
|
||||
const {stub} = require('sinon');
|
||||
const tempy = require('tempy');
|
||||
const getPlugins = require('../../lib/plugins');
|
||||
import path from 'path';
|
||||
import test from 'ava';
|
||||
import {copy, outputFile} from 'fs-extra';
|
||||
import {stub} from 'sinon';
|
||||
import {temporaryDirectory} from 'tempy';
|
||||
import getPlugins from '../../lib/plugins/index.js';
|
||||
|
||||
// Save the current working diretory
|
||||
// Save the current working directory
|
||||
const cwd = process.cwd();
|
||||
|
||||
test.beforeEach((t) => {
|
||||
@@ -15,8 +15,8 @@ test.beforeEach((t) => {
|
||||
t.context.logger = {log: t.context.log, success: t.context.success, scope: () => t.context.logger};
|
||||
});
|
||||
|
||||
test('Export default plugins', (t) => {
|
||||
const plugins = getPlugins({cwd, options: {}, logger: t.context.logger}, {});
|
||||
test('Export default plugins', async (t) => {
|
||||
const plugins = await getPlugins({cwd, options: {}, logger: t.context.logger}, {});
|
||||
|
||||
// Verify the module returns a function for each plugin
|
||||
t.is(typeof plugins.verifyConditions, 'function');
|
||||
@@ -29,15 +29,15 @@ test('Export default plugins', (t) => {
|
||||
t.is(typeof plugins.fail, 'function');
|
||||
});
|
||||
|
||||
test('Export plugins based on steps config', (t) => {
|
||||
const plugins = getPlugins(
|
||||
test('Export plugins based on steps config', async (t) => {
|
||||
const plugins = await getPlugins(
|
||||
{
|
||||
cwd,
|
||||
logger: t.context.logger,
|
||||
options: {
|
||||
verifyConditions: ['./test/fixtures/plugin-noop', {path: './test/fixtures/plugin-noop'}],
|
||||
generateNotes: './test/fixtures/plugin-noop',
|
||||
analyzeCommits: {path: './test/fixtures/plugin-noop'},
|
||||
verifyConditions: ['./test/fixtures/plugin-noop.cjs', {path: './test/fixtures/plugin-noop.cjs'}],
|
||||
generateNotes: './test/fixtures/plugin-noop.cjs',
|
||||
analyzeCommits: {path: './test/fixtures/plugin-noop.cjs'},
|
||||
verifyRelease: () => {},
|
||||
},
|
||||
},
|
||||
@@ -58,11 +58,10 @@ test('Export plugins based on steps config', (t) => {
|
||||
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(
|
||||
const plugins = await 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);
|
||||
@@ -86,7 +85,7 @@ test('Export plugins based on "plugins" config (array)', async (t) => {
|
||||
|
||||
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}}, {});
|
||||
const plugins = await getPlugins({cwd, logger: t.context.logger, options: {plugins: plugin1}}, {});
|
||||
|
||||
await plugins.verifyConditions({options: {}});
|
||||
t.true(plugin1.verifyConditions.calledOnce);
|
||||
@@ -109,7 +108,7 @@ 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(
|
||||
const plugins = await getPlugins(
|
||||
{
|
||||
cwd,
|
||||
logger: t.context.logger,
|
||||
@@ -129,23 +128,23 @@ test('Merge global options, "plugins" options and step options', async (t) => {
|
||||
t.deepEqual(plugin3[0].args[0][0], {globalOpt: 'global', pluginOpt3: 'plugin3'});
|
||||
});
|
||||
|
||||
test('Unknown steps of plugins configured in "plugins" are ignored', (t) => {
|
||||
test('Unknown steps of plugins configured in "plugins" are ignored', async (t) => {
|
||||
const plugin1 = {verifyConditions: () => {}, unknown: () => {}};
|
||||
const plugins = getPlugins({cwd, logger: t.context.logger, options: {plugins: [plugin1]}}, {});
|
||||
const plugins = await 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();
|
||||
const cwd = temporaryDirectory();
|
||||
await copy(
|
||||
'./test/fixtures/plugin-noop.js',
|
||||
'./test/fixtures/plugin-noop.cjs',
|
||||
path.resolve(cwd, 'node_modules/shareable-config/node_modules/custom-plugin/index.js')
|
||||
);
|
||||
await outputFile(path.resolve(cwd, 'node_modules/shareable-config/index.js'), '');
|
||||
|
||||
const plugins = getPlugins(
|
||||
const plugins = await getPlugins(
|
||||
{
|
||||
cwd,
|
||||
logger: t.context.logger,
|
||||
@@ -171,18 +170,18 @@ test('Export plugins loaded from the dependency of a shareable config module', a
|
||||
});
|
||||
|
||||
test('Export plugins loaded from the dependency of a shareable config file', async (t) => {
|
||||
const cwd = tempy.directory();
|
||||
await copy('./test/fixtures/plugin-noop.js', path.resolve(cwd, 'plugin/plugin-noop.js'));
|
||||
const cwd = temporaryDirectory();
|
||||
await copy('./test/fixtures/plugin-noop.cjs', path.resolve(cwd, 'plugin/plugin-noop.cjs'));
|
||||
await outputFile(path.resolve(cwd, 'shareable-config.js'), '');
|
||||
|
||||
const plugins = getPlugins(
|
||||
const plugins = await getPlugins(
|
||||
{
|
||||
cwd,
|
||||
logger: t.context.logger,
|
||||
options: {
|
||||
verifyConditions: ['./plugin/plugin-noop', {path: './plugin/plugin-noop'}],
|
||||
generateNotes: './plugin/plugin-noop',
|
||||
analyzeCommits: {path: './plugin/plugin-noop'},
|
||||
verifyConditions: ['./plugin/plugin-noop.cjs', {path: './plugin/plugin-noop.cjs'}],
|
||||
generateNotes: './plugin/plugin-noop.cjs',
|
||||
analyzeCommits: {path: './plugin/plugin-noop.cjs'},
|
||||
verifyRelease: () => {},
|
||||
},
|
||||
},
|
||||
@@ -200,14 +199,14 @@ test('Export plugins loaded from the dependency of a shareable config file', asy
|
||||
t.is(typeof plugins.fail, 'function');
|
||||
});
|
||||
|
||||
test('Use default when only options are passed for a single plugin', (t) => {
|
||||
test('Use default when only options are passed for a single plugin', async (t) => {
|
||||
const analyzeCommits = {};
|
||||
const generateNotes = {};
|
||||
const publish = {};
|
||||
const success = () => {};
|
||||
const fail = [() => {}];
|
||||
|
||||
const plugins = getPlugins(
|
||||
const plugins = await getPlugins(
|
||||
{
|
||||
cwd,
|
||||
logger: t.context.logger,
|
||||
@@ -235,7 +234,7 @@ test('Use default when only options are passed for a single plugin', (t) => {
|
||||
});
|
||||
|
||||
test('Merge global options with plugin options', async (t) => {
|
||||
const plugins = getPlugins(
|
||||
const plugins = await getPlugins(
|
||||
{
|
||||
cwd,
|
||||
logger: t.context.logger,
|
||||
@@ -253,9 +252,9 @@ test('Merge global options with plugin options', async (t) => {
|
||||
t.deepEqual(result.pluginConfig, {localOpt: 'local', globalOpt: 'global', otherOpt: 'locally-defined'});
|
||||
});
|
||||
|
||||
test('Throw an error for each invalid plugin configuration', (t) => {
|
||||
test('Throw an error for each invalid plugin configuration', async (t) => {
|
||||
const errors = [
|
||||
...t.throws(() =>
|
||||
...(await t.throwsAsync(() =>
|
||||
getPlugins(
|
||||
{
|
||||
cwd,
|
||||
@@ -270,7 +269,7 @@ test('Throw an error for each invalid plugin configuration', (t) => {
|
||||
},
|
||||
{}
|
||||
)
|
||||
),
|
||||
)).errors,
|
||||
];
|
||||
|
||||
t.is(errors[0].name, 'SemanticReleaseError');
|
||||
@@ -283,18 +282,18 @@ test('Throw an error for each invalid plugin configuration', (t) => {
|
||||
t.is(errors[3].code, 'EPLUGINCONF');
|
||||
});
|
||||
|
||||
test('Throw EPLUGINSCONF error if the "plugins" option contains an old plugin definition (returns a function)', (t) => {
|
||||
test('Throw EPLUGINSCONF error if the "plugins" option contains an old plugin definition (returns a function)', async (t) => {
|
||||
const errors = [
|
||||
...t.throws(() =>
|
||||
...(await t.throwsAsync(() =>
|
||||
getPlugins(
|
||||
{
|
||||
cwd,
|
||||
logger: t.context.logger,
|
||||
options: {plugins: ['./test/fixtures/multi-plugin', './test/fixtures/plugin-noop', () => {}]},
|
||||
options: {plugins: ['./test/fixtures/multi-plugin.cjs', './test/fixtures/plugin-noop.cjs', () => {}]},
|
||||
},
|
||||
{}
|
||||
)
|
||||
),
|
||||
)).errors,
|
||||
];
|
||||
|
||||
t.is(errors[0].name, 'SemanticReleaseError');
|
||||
@@ -303,11 +302,11 @@ test('Throw EPLUGINSCONF error if the "plugins" option contains an old plugin de
|
||||
t.is(errors[1].code, 'EPLUGINSCONF');
|
||||
});
|
||||
|
||||
test('Throw EPLUGINSCONF error for each invalid definition if the "plugins" option', (t) => {
|
||||
test('Throw EPLUGINSCONF error for each invalid definition if the "plugins" option', async (t) => {
|
||||
const errors = [
|
||||
...t.throws(() =>
|
||||
...(await t.throwsAsync(() =>
|
||||
getPlugins({cwd, logger: t.context.logger, options: {plugins: [1, {path: 1}, [() => {}, {}, {}]]}}, {})
|
||||
),
|
||||
)).errors,
|
||||
];
|
||||
|
||||
t.is(errors[0].name, 'SemanticReleaseError');
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
const test = require('ava');
|
||||
const {validatePlugin, validateStep, loadPlugin, parseConfig} = require('../../lib/plugins/utils');
|
||||
import test from 'ava';
|
||||
import {loadPlugin, parseConfig, validatePlugin, validateStep} from '../../lib/plugins/utils.js';
|
||||
|
||||
test('validatePlugin', (t) => {
|
||||
const path = 'plugin-module';
|
||||
@@ -189,17 +189,17 @@ test('validateStep: required plugin configuration', (t) => {
|
||||
);
|
||||
});
|
||||
|
||||
test('loadPlugin', (t) => {
|
||||
test('loadPlugin', async (t) => {
|
||||
const cwd = process.cwd();
|
||||
const func = () => {};
|
||||
|
||||
t.is(require('../fixtures/plugin-noop'), loadPlugin({cwd: './test/fixtures'}, './plugin-noop', {}), 'From cwd');
|
||||
t.is((await import('../fixtures/plugin-noop.cjs')).default, await loadPlugin({cwd: './test/fixtures'}, './plugin-noop.cjs', {}), 'From cwd');
|
||||
t.is(
|
||||
require('../fixtures/plugin-noop'),
|
||||
loadPlugin({cwd}, './plugin-noop', {'./plugin-noop': './test/fixtures'}),
|
||||
(await import('../fixtures/plugin-noop.cjs')).default,
|
||||
await loadPlugin({cwd}, './plugin-noop.cjs', {'./plugin-noop.cjs': './test/fixtures'}),
|
||||
'From a shareable config context'
|
||||
);
|
||||
t.is(func, loadPlugin({cwd}, func, {}), 'Defined as a function');
|
||||
t.is(func, await loadPlugin({cwd}, func, {}), 'Defined as a function');
|
||||
});
|
||||
|
||||
test('parseConfig', (t) => {
|
||||
|
||||
+13
-13
@@ -1,21 +1,21 @@
|
||||
const test = require('ava');
|
||||
const AggregateError = require('aggregate-error');
|
||||
const {
|
||||
import test from 'ava';
|
||||
import AggregateError from 'aggregate-error';
|
||||
import {
|
||||
extractErrors,
|
||||
tagsToVersions,
|
||||
isMajorRange,
|
||||
isMaintenanceRange,
|
||||
getUpperBound,
|
||||
getLowerBound,
|
||||
highest,
|
||||
lowest,
|
||||
getLatestVersion,
|
||||
getEarliestVersion,
|
||||
getFirstVersion,
|
||||
getLatestVersion,
|
||||
getLowerBound,
|
||||
getRange,
|
||||
makeTag,
|
||||
getUpperBound,
|
||||
highest,
|
||||
isMaintenanceRange,
|
||||
isMajorRange,
|
||||
isSameChannel,
|
||||
} = require('../lib/utils');
|
||||
lowest,
|
||||
makeTag,
|
||||
tagsToVersions
|
||||
} from '../lib/utils.js';
|
||||
|
||||
test('extractErrors', (t) => {
|
||||
const errors = [new Error('Error 1'), new Error('Error 2')];
|
||||
|
||||
+11
-11
@@ -1,13 +1,13 @@
|
||||
const test = require('ava');
|
||||
const tempy = require('tempy');
|
||||
const verify = require('../lib/verify');
|
||||
const {gitRepo} = require('./helpers/git-utils');
|
||||
import test from 'ava';
|
||||
import {temporaryDirectory} from 'tempy';
|
||||
import verify from '../lib/verify.js';
|
||||
import {gitRepo} from './helpers/git-utils.js';
|
||||
|
||||
test('Throw a AggregateError', async (t) => {
|
||||
const {cwd} = await gitRepo();
|
||||
const options = {branches: [{name: 'master'}, {name: ''}]};
|
||||
|
||||
const errors = [...(await t.throwsAsync(verify({cwd, options})))];
|
||||
const errors = [...(await t.throwsAsync(verify({cwd, options}))).errors];
|
||||
|
||||
t.is(errors[0].name, 'SemanticReleaseError');
|
||||
t.is(errors[0].code, 'ENOREPOURL');
|
||||
@@ -28,10 +28,10 @@ test('Throw a AggregateError', async (t) => {
|
||||
});
|
||||
|
||||
test('Throw a SemanticReleaseError if does not run on a git repository', async (t) => {
|
||||
const cwd = tempy.directory();
|
||||
const cwd = temporaryDirectory();
|
||||
const options = {branches: []};
|
||||
|
||||
const errors = [...(await t.throwsAsync(verify({cwd, options})))];
|
||||
const errors = [...(await t.throwsAsync(verify({cwd, options}))).errors];
|
||||
|
||||
t.is(errors[0].name, 'SemanticReleaseError');
|
||||
t.is(errors[0].code, 'ENOGITREPO');
|
||||
@@ -43,7 +43,7 @@ test('Throw a SemanticReleaseError if the "tagFormat" is not valid', async (t) =
|
||||
const {cwd, repositoryUrl} = await gitRepo(true);
|
||||
const options = {repositoryUrl, tagFormat: `?\${version}`, branches: []};
|
||||
|
||||
const errors = [...(await t.throwsAsync(verify({cwd, options})))];
|
||||
const errors = [...(await t.throwsAsync(verify({cwd, options}))).errors];
|
||||
|
||||
t.is(errors[0].name, 'SemanticReleaseError');
|
||||
t.is(errors[0].code, 'EINVALIDTAGFORMAT');
|
||||
@@ -55,7 +55,7 @@ test('Throw a SemanticReleaseError if the "tagFormat" does not contains the "ver
|
||||
const {cwd, repositoryUrl} = await gitRepo(true);
|
||||
const options = {repositoryUrl, tagFormat: 'test', branches: []};
|
||||
|
||||
const errors = [...(await t.throwsAsync(verify({cwd, options})))];
|
||||
const errors = [...(await t.throwsAsync(verify({cwd, options}))).errors];
|
||||
|
||||
t.is(errors[0].name, 'SemanticReleaseError');
|
||||
t.is(errors[0].code, 'ETAGNOVERSION');
|
||||
@@ -67,7 +67,7 @@ test('Throw a SemanticReleaseError if the "tagFormat" contains multiple "version
|
||||
const {cwd, repositoryUrl} = await gitRepo(true);
|
||||
const options = {repositoryUrl, tagFormat: `\${version}v\${version}`, branches: []};
|
||||
|
||||
const errors = [...(await t.throwsAsync(verify({cwd, options})))];
|
||||
const errors = [...(await t.throwsAsync(verify({cwd, options}))).errors];
|
||||
|
||||
t.is(errors[0].name, 'SemanticReleaseError');
|
||||
t.is(errors[0].code, 'ETAGNOVERSION');
|
||||
@@ -83,7 +83,7 @@ test('Throw a SemanticReleaseError for each invalid branch', async (t) => {
|
||||
branches: [{name: ''}, {name: ' '}, {name: 1}, {}, {name: ''}, 1, 'master'],
|
||||
};
|
||||
|
||||
const errors = [...(await t.throwsAsync(verify({cwd, options})))];
|
||||
const errors = [...(await t.throwsAsync(verify({cwd, options}))).errors];
|
||||
|
||||
t.is(errors[0].name, 'SemanticReleaseError');
|
||||
t.is(errors[0].code, 'EINVALIDBRANCH');
|
||||
|
||||
Reference in New Issue
Block a user