Compare commits

...
25 Commits
Author SHA1 Message Date
Pierre Vanduynslager 5847514fcc fix: allow empty release notes in dry-run mode 2018-07-10 11:42:22 -04:00
Pierre Vanduynslager a39ccb8f6c docs: add missing link in GitBook summary 2018-07-08 01:16:21 -04:00
Pierre VanduynslagerandGitHub 0862480cf0 fix(package): update hosted-git-info to version 2.7.1 2018-07-06 21:47:50 -04:00
Pierre Vanduynslager 45eee4acdd fix: fetch all tags even if the repo is not shallow 2018-07-02 18:38:24 -04:00
Pierre Vanduynslager 2d3a5e53e9 test: harmonize git-utils functions name 2018-07-02 18:38:24 -04:00
Pierre Vanduynslager 4abda31f83 fix: add debug log for git fetch command 2018-07-02 16:50:41 -04:00
Pierre Vanduynslager 3602716c0b docs: update semantic-release and travis-deploy-once versions in examples 2018-07-02 11:23:37 -04:00
Pierre Vanduynslager d4f68a5680 fix(package): update yargs to version 12.0.0 2018-06-26 15:46:19 -04:00
Pierre Vanduynslager 4454d57e02 feat: allow to disable the publish plugin hook 2018-06-19 15:03:43 -04:00
greenkeeper[bot]andPierre Vanduynslager 9137f8537b fix(package): update read-pkg-up to version 4.0.0 2018-06-18 11:15:16 -04:00
Trevor RichardsonandPierre Vanduynslager 7615fdc9bc Fix documented explanation in plugins.md
`verifyConditions` explanation was wrong previously.
2018-06-18 10:52:27 -04:00
Pierre Vanduynslager 2b6378f26f fix: use git ls-remote to verify if the remote branch is ahead 2018-06-15 16:16:55 -04:00
Pierre Vanduynslager 24a8052038 refactor: simply EGITNOPERMISSION error parameters 2018-06-15 16:16:55 -04:00
greenkeeper[bot]andPierre Vanduynslager 0ab0426075 fix(package): update p-locate to version 3.0.0 2018-06-15 12:22:47 -04:00
Pierre Vanduynslager f9d9144e3d docs: Add a troubleshooting section about squashed commits 2018-06-11 11:52:23 -04:00
greenkeeper[bot]andPierre Vanduynslager 11cef46c48 chore(package): update sinon to version 6.0.0 2018-06-11 11:33:14 -04:00
greenkeeper[bot]andPierre Vanduynslager 29e7ebfe0b fix(package): update hook-std to version 1.0.0 2018-06-11 11:21:16 -04:00
Matt TraviandGregor Martynus 6a36832398 fix(plugin-load): clarify load message
added quotes around plugin name to set it apart from the message. without the quotes, some consumers
were missunderstanding the successful loading of the `fail` plugin as a load failure and assuming
something was broken

resolves #811
2018-06-05 22:27:05 -07:00
Pierre Vanduynslager 4d47b20831 docs: clarify config file format 2018-06-04 15:12:46 -04:00
greenkeeper[bot]andGregor Martynus ddcf29acf7 chore(package): update nyc to version 12.0.1 2018-06-02 10:24:04 -07:00
Felix BeckerandGregor Martynus 4c157f3bfd docs(plugins): add semantic-release-vsce 2018-05-30 16:35:46 -07:00
Felix BeckerandGregor Martynus c6636abfd2 docs(plugins): remove warning
semantic-release-docker is compatible with latest semantic-release now,
see peerDependency: https://david-dm.org/felixfbecker/semantic-release-docker?type=peer
2018-05-30 16:34:59 -07:00
greenkeeper[bot]andPierre Vanduynslager 44fd7fe3f6 chore(package): update delay to version 3.0.0 2018-05-25 14:38:20 -04:00
Pierre Vanduynslager db1cc60c41 feat: verify minimum required git version is installed 2018-05-21 17:52:52 -04:00
Pierre Vanduynslager 47c73eb672 feat: add support for git version 2.0.0 2018-05-21 17:52:52 -04:00
24 changed files with 221 additions and 109 deletions
+2
View File
@@ -21,6 +21,8 @@
- [Travis CI](docs/recipes/travis.md)
- [Travis CI with build stages](docs/recipes/travis-build-stages.md)
- [GitLab CI](docs/recipes/gitlab-ci.md)
- [Git hosted services](docs/recipes/README.md)
- [Git authentication with SSH keys](docs/recipes/git-auth-ssh-keys.md)
- [Package managers and languages](docs/recipes/README.md)
## Developer guide
+20 -1
View File
@@ -3,11 +3,15 @@
// 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 */
/* eslint-disable no-var, promise/prefer-await-to-then, prefer-destructuring */
var semver = require('semver');
var execa = require('execa');
var findVersions = require('find-versions');
var pkg = require('../package.json');
var MIN_GIT_VERSION = '2.0.0';
if (!semver.satisfies(process.version, pkg.engines.node)) {
console.error(
`[semantic-release]: node version ${pkg.engines.node} is required. Found ${process.version}.
@@ -17,6 +21,21 @@ See https://github.com/semantic-release/semantic-release/blob/caribou/docs/suppo
process.exit(1);
}
execa
.stdout('git', ['--version'])
.then(stdout => {
var gitVersion = findVersions(stdout)[0];
if (semver.lt(gitVersion, MIN_GIT_VERSION)) {
console.error(`[semantic-release]: Git version ${MIN_GIT_VERSION} is required. Found ${gitVersion}.`);
process.exit(1);
}
})
.catch(err => {
console.error(`[semantic-release]: Git version ${MIN_GIT_VERSION} is required. No git binary found.`);
console.error(err);
process.exit(1);
});
// Node 8+ from this point on
require('../cli')().catch(() => {
process.exitCode = 1;
+7 -9
View File
@@ -1,5 +1,3 @@
const {pickBy, isUndefined} = require('lodash');
const stringList = {
type: 'string',
array: true,
@@ -13,6 +11,7 @@ module.exports = async () => {
const cli = require('yargs')
.command('$0', 'Run automated package publishing', yargs => {
yargs.demandCommand(0, 0).usage(`Run automated package publishing
Usage:
semantic-release [options] [plugins]`);
})
@@ -20,7 +19,7 @@ Usage:
.option('r', {alias: 'repository-url', describe: 'Git repository URL', type: 'string', group: 'Options'})
.option('t', {alias: 'tag-format', describe: 'Git tag format', type: 'string', group: 'Options'})
.option('e', {alias: 'extends', describe: 'Shareable configurations', ...stringList, group: 'Options'})
.option('ci', {describe: 'Toggle CI verifications', default: undefined, type: 'boolean', group: 'Options'})
.option('ci', {describe: 'Toggle CI verifications', type: 'boolean', group: 'Options'})
.option('verify-conditions', {...stringList, group: 'Plugins'})
.option('analyze-commits', {type: 'string', group: 'Plugins'})
.option('verify-release', {...stringList, group: 'Plugins'})
@@ -29,16 +28,15 @@ Usage:
.option('publish', {...stringList, group: 'Plugins'})
.option('success', {...stringList, group: 'Plugins'})
.option('fail', {...stringList, group: 'Plugins'})
.option('debug', {describe: 'Output debugging information', default: undefined, type: 'boolean', group: 'Options'})
.option('d', {alias: 'dry-run', describe: 'Skip publishing', default: undefined, type: 'boolean', group: 'Options'})
.option('h', {alias: 'help', default: undefined, group: 'Options'})
.option('v', {alias: 'version', default: undefined, group: 'Options'})
.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 {
// Remove option with undefined values, as yargs sets non defined options as `undefined`
const {help, version, ...opts} = pickBy(cli.argv, value => !isUndefined(value));
const {help, version, ...opts} = cli.argv;
if (Boolean(help) || Boolean(version)) {
process.exitCode = 0;
+5 -1
View File
@@ -37,9 +37,13 @@
[Open a Pull Request](https://github.com/semantic-release/semantic-release/blob/caribou/CONTRIBUTING.md#submitting-a-pull-request) to add your plugin to the list.
- [semantic-release-docker](https://github.com/felixfbecker/semantic-release-docker) Set of semantic-release plugins for publishing a docker image to Docker Hub (tested on semantic-release **^11.0.0**)
- [semantic-release-docker](https://github.com/felixfbecker/semantic-release-docker) Set of semantic-release plugins for publishing a docker image to Docker Hub
- [verifyConditions](https://github.com/felixfbecker/semantic-release-docker#verifyconditions) Verify that all needed configuration is present and login to the Docker registry.
- [publish](https://github.com/felixfbecker/semantic-release-docker#publish) Tag the image specified by `name` with the new version, push it to Docker Hub and update the latest tag.
- [semantic-release-vsce](https://github.com/raix/semantic-release-vsce) Set of semantic-release plugins for publishing Visual Studio Code extensions to the marketplace
- **verifyConditions** Verify the presence and the validity of the vsce authentication and release configuration
- **prepare** Create a `.vsix` for distribution
- **publish** Publish the package to the Visual Studio Code marketplace
- [semantic-release-verify-deps](https://github.com/piercus/semantic-release-verify-deps)
- [verifyConditions](https://github.com/piercus/semantic-release-verify-deps) Check the dependencies format against a regexp before a release
- [semantic-release-chrome](https://github.com/GabrielDuarteM/semantic-release-chrome) Set of semantic-release plugins for publishing a Chrome extension release.
+1 -1
View File
@@ -59,7 +59,7 @@ A `package.json` is required only for [local](../usage/installation.md#local-ins
```json
{
"devDependencies": {
"semantic-release": "^12.0.0"
"semantic-release": "^15.0.0"
}
}
```
+1 -1
View File
@@ -51,7 +51,7 @@ A `package.json` is required only for [local](../usage/installation.md#local-ins
```json
{
"devDependencies": {
"semantic-release": "^12.0.0"
"semantic-release": "^15.0.0"
}
}
```
+1 -1
View File
@@ -48,7 +48,7 @@ A `package.json` is required only for [local](../usage/installation.md#local-ins
```json
{
"devDependencies": {
"semantic-release": "^12.0.0"
"semantic-release": "^15.0.0"
}
}
```
+2 -2
View File
@@ -83,8 +83,8 @@ A `package.json` is required only for [local](../usage/installation.md#local-ins
```json
{
"devDependencies": {
"semantic-release": "^12.0.0",
"travis-deploy-once": "^4.0.0"
"semantic-release": "^15.0.0",
"travis-deploy-once": "^5.0.0"
}
}
```
+10
View File
@@ -44,3 +44,13 @@ npm ERR! You do not have permission to publish "<package-name>". Are you logged
This message is a little unclear, and might not have anything to with your `NPM_TOKEN` or authentication method. It might instead be related to the package name itself. If there is already a package with the same name as yours or, there is a very close match, it could trigger this error.
Best way to be sure, is to search [npmjs.org](https://www.npmjs.com/)) using your package name. If there is a name conflict, rename your package in your `package.json`
## Squashed commits are ignored by **semantic-release**
**semantic-release** parses commits according to a [commit message convention](https://github.com/semantic-release/semantic-release#commit-message-format) to figure out how they affect the codebase. Commits that doesn't follow the project's commit message convention are simply ignored.
When [squashing commits](https://git-scm.com/book/en/v2/Git-Tools-Rewriting-History#_squashing) most Git tools will by default generate a new commit message with a summary of the squashed commits. This commit message will most likely not be compliant with the project's commit message convention and therefore will be ignored by **semantic-release**.
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).
+17 -2
View File
@@ -6,7 +6,7 @@ In order to customize **semantic-release**’s behavior, [options](#options) and
- A `release` key in the project's `package.json` file
- CLI arguments
The following two examples are the same.
The following three examples are the same.
Via CLI argument:
@@ -17,7 +17,20 @@ $ semantic-release --branch next
Via `release` key in the project's `package.json` file:
```json
"release": {
{
"release": {
"branch": "next"
}
}
```
```bash
$ semantic-release
```
Via `.releaserc` file:
```json
{
"branch": "next"
}
```
@@ -29,6 +42,8 @@ $ semantic-release
**Note**: Plugin options cannot be defined via CLI arguments and must be defined in the configuration file.
**Note**: When configuring via `package.json`, the configuration must be under the `release` property. However, when using a `.releaserc` or a `release.config.js` file, the configuration must be set without a `release` property.
## Environment variables
| Variable | Description | Default |
+2 -2
View File
@@ -24,6 +24,6 @@ For other type of projects we recommend installing **semantic-release** directly
$ npx semantic-release
```
**Note:** For a global installation, it's recommended to specify the major **semantic-release** version to install (for example with with `npx semantic-release@12`, or `npm install -g semantic-release@12`). This way your build will not automatically use the next major **semantic-release** release that could possibly break your build. You will have to upgrade manually when a new major version is released.
**Note:** For a global installation, it's recommended to specify the major **semantic-release** version to install (for example with with `npx semantic-release@15`, or `npm install -g semantic-release@15`). This way your build will not automatically use the next major **semantic-release** release that could possibly break your build. You will have to upgrade manually when a new major version is released.
**Note:** `npx` is a tool bundled with `npm@>=5.2.0`. It is used to conveniently install the semantic-release binary and to execute it. See [What is npx](../support/FAQ.md#what-is-npx) for more details.
**Note:** `npx` is a tool bundled with `npm@>=5.2.0`. It is used to conveniently install the semantic-release binary and to execute it. See [What is npx](../support/FAQ.md#what-is-npx) for more details.
+1 -1
View File
@@ -91,7 +91,7 @@ For example:
With this configuration:
- the `custom-plugin` npm module will be used to [analyze commits](#analyzecommits-plugin)
- the `./build/my-plugin.js` script will be used to [generate release notes](#generatenotes-plugin)
- the [`@semantic-release/exec`](https://github.com/semantic-release/exec), [`@semantic-release/npm`](https://github.com/semantic-release/npm) and [`@semantic-release/exec`](https://github.com/semantic-release/exec) plugins will be used to [verify conditions](#verifyconditions-plugin)
- the [`@semantic-release/exec`](https://github.com/semantic-release/exec), [`@semantic-release/npm`](https://github.com/semantic-release/npm) and [`@semantic-release/github`](https://github.com/semantic-release/github) plugins will be used to [verify conditions](#verifyconditions-plugin)
- the [`@semantic-release/exec`](https://github.com/semantic-release/exec) plugin will be used to [verify the release](#verifyrelease-plugin)
- the `cmd` option will be set to `verify-conditions.sh` only for the [`@semantic-release/exec`](https://github.com/semantic-release/exec) plugin used to [verify conditions](#verifyconditions-plugin)
- the `cmd` option will be set to `verify-release.sh` only for the [`@semantic-release/exec`](https://github.com/semantic-release/exec) plugin used to [verify the release](#verifyrelease-plugin)
+14 -15
View File
@@ -13,7 +13,7 @@ const getLastRelease = require('./lib/get-last-release');
const {extractErrors} = require('./lib/utils');
const getGitAuthUrl = require('./lib/get-git-auth-url');
const logger = require('./lib/logger');
const {unshallow, verifyAuth, isBranchUpToDate, gitHead: getGitHead, tag, push} = require('./lib/git');
const {fetch, verifyAuth, isBranchUpToDate, gitHead: getGitHead, tag, push} = require('./lib/git');
const getError = require('./lib/get-error');
const {COMMIT_NAME, COMMIT_EMAIL} = require('./lib/definitions/constants');
@@ -54,22 +54,20 @@ async function run(options, plugins) {
await verify(options);
const {repositoryUrl} = options;
options.repositoryUrl = await getGitAuthUrl(options);
if (!(await isBranchUpToDate(options.branch))) {
logger.log(
"The local branch %s is behind the remote one, therefore a new version won't be published.",
options.branch
);
return false;
}
try {
await verifyAuth(options.repositoryUrl, options.branch);
} catch (err) {
if (!(await isBranchUpToDate(options.repositoryUrl, options.branch))) {
logger.log(
"The local branch %s is behind the remote one, therefore a new version won't be published.",
options.branch
);
return false;
}
logger.error(`The command "${err.cmd}" failed with the error message %s.`, err.stderr);
throw getError('EGITNOPERMISSION', {options, repositoryUrl});
throw getError('EGITNOPERMISSION', {options});
}
logger.log('Run automated release from branch %s', options.branch);
@@ -77,8 +75,7 @@ async function run(options, plugins) {
logger.log('Call plugin %s', 'verify-conditions');
await plugins.verifyConditions({options, logger}, {settleAll: true});
// Unshallow the repo in order to get all the tags
await unshallow(options.repositoryUrl);
await fetch(options.repositoryUrl);
const lastRelease = await getLastRelease(options.tagFormat, logger);
const commits = await getCommits(lastRelease.gitHead, options.branch, logger);
@@ -106,7 +103,9 @@ async function run(options, plugins) {
logger.log('Call plugin %s', 'generate-notes');
const notes = await plugins.generateNotes(generateNotesParam);
logger.log('Release note for version %s:\n', nextRelease.version);
process.stdout.write(`${marked(notes)}\n`);
if (notes) {
process.stdout.write(`${marked(notes)}\n`);
}
} else {
logger.log('Call plugin %s', 'generateNotes');
nextRelease.notes = await plugins.generateNotes(generateNotesParam);
@@ -179,7 +178,7 @@ async function callFail(plugins, options, error) {
module.exports = async opts => {
logger.log(`Running %s version %s`, pkg.name, pkg.version);
const unhook = hookStd({silent: false}, hideSensitive);
const {unhook} = hookStd({silent: false}, hideSensitive);
try {
const config = await getConfig(opts, logger);
const {plugins, options} = config;
+2 -2
View File
@@ -27,11 +27,11 @@ Please make sure to add the \`repositoryUrl\` to the [semantic-release configura
'docs/usage/configuration.md'
)}).`,
}),
EGITNOPERMISSION: ({options, repositoryUrl}) => ({
EGITNOPERMISSION: ({options}) => ({
message: 'The push permission to the Git repository is required.',
details: `**semantic-release** cannot push the version tag to the branch \`${
options.branch
}\` on remote Git repository with URL \`${repositoryUrl}\`.
}\` on remote Git repository with URL \`${options.repositoryUrl}\`.
Please refer to the [authentication configuration documentation](${linkify(
'docs/usage/ci-configuration.md#authentication'
+1 -1
View File
@@ -45,7 +45,7 @@ module.exports = {
publish: {
default: ['@semantic-release/npm', '@semantic-release/github'],
config: {
validator: conf => Boolean(conf) && (isArray(conf) ? conf : [conf]).every(conf => validatePluginConfig(conf)),
validator: conf => !conf || (isArray(conf) ? conf : [conf]).every(conf => validatePluginConfig(conf)),
},
output: {
validator: output => !output || isPlainObject(output),
+18 -7
View File
@@ -49,12 +49,16 @@ async function isRefInHistory(ref) {
}
/**
* Unshallow the git repository (retriving every commits and tags).
* Unshallow the git repository if necessary and fetch all the tags.
*
* @param {String} repositoryUrl The remote repository URL.
*/
async function unshallow(repositoryUrl) {
await execa('git', ['fetch', '--unshallow', '--tags', repositoryUrl], {reject: false});
async function fetch(repositoryUrl) {
try {
await execa('git', ['fetch', '--unshallow', '--tags', repositoryUrl]);
} catch (err) {
await execa('git', ['fetch', '--tags', repositoryUrl]);
}
}
/**
@@ -69,7 +73,7 @@ async function gitHead() {
*/
async function repoUrl() {
try {
return await execa.stdout('git', ['remote', 'get-url', 'origin']);
return await execa.stdout('git', ['config', '--get', 'remote.origin.url']);
} catch (err) {
debug(err);
}
@@ -141,19 +145,26 @@ async function verifyTagName(tagName) {
/**
* Verify the local branch is up to date with the remote one.
*
* @param {String} repositoryUrl The remote repository URL.
* @param {String} branch The repository branch for which to verify status.
*
* @return {Boolean} `true` is the HEAD of the current local branch is the same as the HEAD of the remote branch, falsy otherwise.
*/
async function isBranchUpToDate(branch) {
return isRefInHistory(await execa.stdout('git', ['rev-parse', `origin/${branch}`]));
async function isBranchUpToDate(repositoryUrl, branch) {
try {
return await isRefInHistory(
(await execa.stdout('git', ['ls-remote', '--heads', repositoryUrl, branch])).match(/^(\w+)?/)[1]
);
} catch (err) {
debug(err);
}
}
module.exports = {
gitTagHead,
gitTags,
isRefInHistory,
unshallow,
fetch,
gitHead,
repoUrl,
isGitRepo,
+2 -2
View File
@@ -15,9 +15,9 @@ module.exports = (pluginType, pluginsPath, globalOpts, pluginOpts, logger) => {
if (!isFunction(pluginOpts)) {
if (pluginsPath[path]) {
logger.log('Load plugin %s from %s in shareable config %s', pluginType, path, pluginsPath[path]);
logger.log('Load plugin "%s" from %s in shareable config %s', pluginType, path, pluginsPath[path]);
} else {
logger.log('Load plugin %s from %s', pluginType, path);
logger.log('Load plugin "%s" from %s', pluginType, path);
}
}
+9 -8
View File
@@ -30,20 +30,21 @@
"debug": "^3.1.0",
"env-ci": "^2.0.0",
"execa": "^0.10.0",
"find-versions": "^2.0.0",
"get-stream": "^3.0.0",
"git-log-parser": "^1.2.0",
"git-url-parse": "^9.0.0",
"hook-std": "^0.4.0",
"hosted-git-info": "^2.6.0",
"hook-std": "^1.0.1",
"hosted-git-info": "^2.7.1",
"lodash": "^4.17.4",
"marked": "^0.4.0",
"marked-terminal": "^3.0.0",
"p-locate": "^2.0.0",
"p-locate": "^3.0.0",
"p-reduce": "^1.0.0",
"read-pkg-up": "^3.0.0",
"read-pkg-up": "^4.0.0",
"resolve-from": "^4.0.0",
"semver": "^5.4.1",
"yargs": "^11.0.0"
"yargs": "^12.0.0"
},
"devDependencies": {
"ava": "^0.25.0",
@@ -51,7 +52,7 @@
"codecov": "^3.0.0",
"commitizen": "^2.9.6",
"cz-conventional-changelog": "^2.0.0",
"delay": "^2.0.0",
"delay": "^3.0.0",
"dockerode": "^2.5.2",
"file-url": "^2.0.2",
"fs-extra": "^6.0.0",
@@ -59,10 +60,10 @@
"js-yaml": "^3.10.0",
"mockserver-client": "^5.1.1",
"nock": "^9.0.2",
"nyc": "^11.2.1",
"nyc": "^12.0.1",
"p-retry": "^2.0.0",
"proxyquire": "^2.0.0",
"sinon": "^5.0.1",
"sinon": "^6.0.0",
"tempy": "^0.2.1",
"xo": "^0.21.0"
},
+1 -1
View File
@@ -60,9 +60,9 @@ test('The "prepare" plugin, if defined, must be a single or an array of plugins
test('The "publish" plugin is mandatory, and must be a single or an array of plugins definition', t => {
t.false(plugins.publish.config.validator({}));
t.false(plugins.publish.config.validator({path: null}));
t.false(plugins.publish.config.validator());
t.true(plugins.publish.config.validator({path: 'plugin-path.js'}));
t.true(plugins.publish.config.validator());
t.true(plugins.publish.config.validator('plugin-path.js'));
t.true(plugins.publish.config.validator(() => {}));
t.true(plugins.publish.config.validator([{path: 'plugin-path.js'}, 'plugin-path.js', () => {}]));
+38 -17
View File
@@ -3,7 +3,7 @@ import tempy from 'tempy';
import {
gitTagHead,
isRefInHistory,
unshallow,
fetch,
gitHead,
repoUrl,
tag,
@@ -23,8 +23,8 @@ import {
gitAddConfig,
gitCommitTag,
gitRemoteTagHead,
push as pushUtil,
reset,
gitPush,
gitDetachedHead,
} from './helpers/git-utils';
// Save the current working diretory
@@ -53,7 +53,7 @@ test.serial('Throw error if the last commit sha cannot be found', async t => {
await t.throws(gitHead(), Error);
});
test.serial('Unshallow repository', async t => {
test.serial('Unshallow and fetch repository', async t => {
// Create a git repository, set the current working directory at the root of the repo
const repo = await gitRepo();
// Add commits to the master branch
@@ -64,7 +64,7 @@ test.serial('Unshallow repository', async t => {
// Verify the shallow clone contains only one commit
t.is((await gitGetCommits()).length, 1);
await unshallow(repo);
await fetch(repo);
// Verify the shallow clone contains all the commits
t.is((await gitGetCommits()).length, 2);
@@ -75,7 +75,24 @@ test.serial('Do not throw error when unshallow a complete repository', async t =
const repo = await gitRepo();
// Add commits to the master branch
await gitCommits(['First']);
await t.notThrows(unshallow(repo));
await t.notThrows(fetch(repo));
});
test.serial('Fetch all tags on a detached head repository', async t => {
const repo = await gitRepo(true);
await gitCommits(['First']);
await gitTagVersion('v1.0.0');
await gitCommits(['Second']);
await gitTagVersion('v1.0.1');
const [commit] = await gitCommits(['Third']);
await gitTagVersion('v1.1.0');
await gitPush();
await gitDetachedHead(repo, commit.hash);
await fetch(repo);
t.deepEqual((await gitTags()).sort(), ['v1.0.0', 'v1.0.1', 'v1.1.0'].sort());
});
test.serial('Verify if the commit `sha` is in the direct history of the current branch', async t => {
@@ -189,31 +206,35 @@ test.serial('Throws error if obtaining the tags fails', async t => {
});
test.serial('Return "true" if repository is up to date', async t => {
await gitRepo(true);
const repositoryUrl = await gitRepo(true);
await gitCommits(['First']);
await pushUtil();
await gitPush();
t.true(await isBranchUpToDate('master'));
t.true(await isBranchUpToDate(repositoryUrl, 'master'));
});
test.serial('Return falsy if repository is not up to date', async t => {
await gitRepo(true);
const repositoryUrl = await gitRepo(true);
const repoDir = process.cwd();
await gitCommits(['First']);
await gitCommits(['Second']);
await pushUtil();
await gitPush();
t.true(await isBranchUpToDate('master'));
t.true(await isBranchUpToDate(repositoryUrl, 'master'));
await reset();
await gitShallowClone(repositoryUrl);
await gitCommits(['Third']);
await gitPush();
process.chdir(repoDir);
t.falsy(await isBranchUpToDate('master'));
t.falsy(await isBranchUpToDate(repositoryUrl, 'master'));
});
test.serial('Return "true" if local repository is ahead', async t => {
await gitRepo(true);
const repositoryUrl = await gitRepo(true);
await gitCommits(['First']);
await pushUtil();
await gitPush();
await gitCommits(['Second']);
t.true(await isBranchUpToDate('master'));
t.true(await isBranchUpToDate(repositoryUrl, 'master'));
});
+2 -11
View File
@@ -151,7 +151,7 @@ export async function gitDetachedHead(repositoryUrl, head) {
process.chdir(dir);
await execa('git', ['init']);
await execa('git', ['remote', 'add', 'origin', repositoryUrl]);
await execa('git', ['fetch']);
await execa('git', ['fetch', repositoryUrl]);
await execa('git', ['checkout', head]);
return dir;
}
@@ -209,15 +209,6 @@ export async function gitCommitTag(gitHead) {
* @param {String} branch The branch to push.
* @throws {Error} if the push failed.
*/
export async function push(repositoryUrl = 'origin', branch = 'master') {
export async function gitPush(repositoryUrl = 'origin', branch = 'master') {
await execa('git', ['push', '--tags', repositoryUrl, `HEAD:${branch}`]);
}
/**
* Reset repository to a commit.
*
* @param {String} [commit='HEAD~1'] Commit reference to reset the repo to.
*/
export async function reset(commit = 'HEAD~1') {
await execa('git', ['reset', commit]);
}
+59 -19
View File
@@ -13,9 +13,8 @@ import {
gitCommits,
gitTagVersion,
gitRemoteTagHead,
push,
gitPush,
gitShallowClone,
reset,
} from './helpers/git-utils';
// Save the current process.env
@@ -59,7 +58,7 @@ test.serial('Plugins are called with expected values', async t => {
await gitTagVersion('v1.0.0');
// Add new commits to the master branch
commits = (await gitCommits(['Second'])).concat(commits);
await push();
await gitPush();
const lastRelease = {version: '1.0.0', gitHead: commits[commits.length - 1].hash, gitTag: 'v1.0.0'};
const nextRelease = {type: 'major', version: '2.0.0', gitHead: await getGitHead(), gitTag: 'v2.0.0'};
@@ -171,7 +170,7 @@ test.serial('Use custom tag format', async t => {
await gitCommits(['First']);
await gitTagVersion('test-1.0.0');
await gitCommits(['Second']);
await push();
await gitPush();
const nextRelease = {type: 'major', version: '2.0.0', gitHead: await getGitHead(), gitTag: 'test-2.0.0'};
const notes = 'Release notes';
@@ -208,7 +207,7 @@ test.serial('Use new gitHead, and recreate release notes if a prepare plugin cre
await gitTagVersion('v1.0.0');
// Add new commits to the master branch
commits = (await gitCommits(['Second'])).concat(commits);
await push();
await gitPush();
const nextRelease = {type: 'major', version: '2.0.0', gitHead: await getGitHead(), gitTag: 'v2.0.0'};
const notes = 'Release notes';
@@ -268,7 +267,7 @@ test.serial('Call all "success" plugins even if one errors out', async t => {
await gitTagVersion('v1.0.0');
// Add new commits to the master branch
await gitCommits(['Second']);
await push();
await gitPush();
const nextRelease = {type: 'major', version: '2.0.0', gitHead: await getGitHead(), gitTag: 'v2.0.0'};
const notes = 'Release notes';
@@ -316,7 +315,7 @@ test.serial('Log all "verifyConditions" errors', async t => {
const repositoryUrl = await gitRepo(true);
// Add commits to the master branch
await gitCommits(['First']);
await push();
await gitPush();
const error1 = new Error('error 1');
const error2 = new SemanticReleaseError('error 2', 'ERR2');
@@ -359,7 +358,7 @@ test.serial('Log all "verifyRelease" errors', async t => {
await gitTagVersion('v1.0.0');
// Add new commits to the master branch
await gitCommits(['Second']);
await push();
await gitPush();
const error1 = new SemanticReleaseError('error 1', 'ERR1');
const error2 = new SemanticReleaseError('error 2', 'ERR2');
@@ -396,7 +395,7 @@ test.serial('Dry-run skips publish and success', async t => {
await gitTagVersion('v1.0.0');
// Add new commits to the master branch
await gitCommits(['Second']);
await push();
await gitPush();
const nextRelease = {type: 'major', version: '2.0.0', gitHead: await getGitHead(), gitTag: 'v2.0.0'};
const notes = 'Release notes';
@@ -445,7 +444,7 @@ test.serial('Dry-run skips fail', async t => {
await gitTagVersion('v1.0.0');
// Add new commits to the master branch
await gitCommits(['Second']);
await push();
await gitPush();
const error1 = new SemanticReleaseError('error 1', 'ERR1');
const error2 = new SemanticReleaseError('error 2', 'ERR2');
@@ -480,7 +479,7 @@ test.serial('Force a dry-run if not on a CI and "noCi" is not explicitly set', a
await gitTagVersion('v1.0.0');
// Add new commits to the master branch
await gitCommits(['Second']);
await push();
await gitPush();
const nextRelease = {type: 'major', version: '2.0.0', gitHead: await getGitHead(), gitTag: 'v2.0.0'};
const notes = 'Release notes';
@@ -521,6 +520,43 @@ test.serial('Force a dry-run if not on a CI and "noCi" is not explicitly set', a
t.is(success.callCount, 0);
});
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 repositoryUrl = await gitRepo(true);
// Add commits to the master branch
await gitCommits(['First']);
// Create the tag corresponding to version 1.0.0
await gitTagVersion('v1.0.0');
// Add new commits to the master branch
await gitCommits(['Second']);
await gitPush();
const nextRelease = {type: 'major', version: '2.0.0', gitHead: await getGitHead(), gitTag: 'v2.0.0'};
const analyzeCommits = stub().resolves(nextRelease.type);
const generateNotes = stub().resolves();
const options = {
dryRun: true,
branch: 'master',
repositoryUrl,
verifyConditions: false,
analyzeCommits,
verifyRelease: false,
generateNotes,
prepare: false,
publish: false,
success: false,
};
const semanticRelease = proxyquire('..', {
'./lib/logger': t.context.logger,
'env-ci': () => ({isCi: true, branch: 'master', isPr: false}),
});
t.truthy(await semanticRelease(options));
t.deepEqual(t.context.log.args[t.context.log.args.length - 1], ['Release note for version %s:\n', '2.0.0']);
});
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 repositoryUrl = await gitRepo(true);
@@ -530,7 +566,7 @@ test.serial('Allow local releases with "noCi" option', async t => {
await gitTagVersion('v1.0.0');
// Add new commits to the master branch
await gitCommits(['Second']);
await push();
await gitPush();
const nextRelease = {type: 'major', version: '2.0.0', gitHead: await getGitHead(), gitTag: 'v2.0.0'};
const notes = 'Release notes';
@@ -584,7 +620,7 @@ test.serial('Accept "undefined" value returned by the "generateNotes" plugins',
await gitTagVersion('v1.0.0');
// Add new commits to the master branch
commits = (await gitCommits(['Second'])).concat(commits);
await push();
await gitPush();
const lastRelease = {version: '1.0.0', gitHead: commits[commits.length - 1].hash, gitTag: 'v1.0.0'};
const nextRelease = {type: 'major', version: '2.0.0', gitHead: await getGitHead(), gitTag: 'v2.0.0'};
@@ -645,11 +681,15 @@ test.serial('Returns falsy value if triggered by a PR', async t => {
test.serial('Returns falsy value if triggered on an outdated clone', async t => {
// Create a git repository, set the current working directory at the root of the repo
const repositoryUrl = await gitRepo(true);
const repoDir = process.cwd();
// Add commits to the master branch
await gitCommits(['First']);
await gitCommits(['Second']);
await push();
await reset();
await gitPush();
await gitShallowClone(repositoryUrl);
await gitCommits(['Third']);
await gitPush();
process.chdir(repoDir);
const semanticRelease = proxyquire('..', {
'./lib/logger': t.context.logger,
@@ -696,7 +736,7 @@ test.serial('Returns falsy value if there is no relevant changes', async t => {
const repositoryUrl = await gitRepo(true);
// Add commits to the master branch
await gitCommits(['First']);
await push();
await gitPush();
const analyzeCommits = stub().resolves();
const verifyRelease = stub().resolves();
@@ -746,7 +786,7 @@ test.serial('Exclude commits with [skip release] or [release skip] from analysis
'Test commit\n\n commit body\n[skip release]',
'Test commit\n\n commit body\n[release skip]',
]);
await push();
await gitPush();
const analyzeCommits = stub().resolves();
const config = {branch: 'master', repositoryUrl, globalOpt: 'global'};
const options = {
@@ -871,7 +911,7 @@ test.serial('Throw an Error if plugin returns an unexpected value', async t => {
await gitTagVersion('v1.0.0');
// Add new commits to the master branch
await gitCommits(['Second']);
await push();
await gitPush();
const verifyConditions = stub().resolves();
const analyzeCommits = stub().resolves('string');
@@ -900,7 +940,7 @@ test.serial('Get all commits including the ones not in the shallow clone', async
const repositoryUrl = await gitRepo(true);
await gitTagVersion('v1.0.0');
await gitCommits(['First', 'Second', 'Third']);
await push(repositoryUrl, 'master');
await gitPush(repositoryUrl, 'master');
await gitShallowClone(repositoryUrl);
+2 -1
View File
@@ -2,7 +2,7 @@ import test from 'ava';
import {writeJson, readJson} from 'fs-extra';
import {stub} from 'sinon';
import execa from 'execa';
import {gitHead as getGitHead, gitTagHead, gitRepo, gitCommits, gitRemoteTagHead} from './helpers/git-utils';
import {gitHead as getGitHead, gitTagHead, gitRepo, gitCommits, gitRemoteTagHead, gitPush} from './helpers/git-utils';
import gitbox from './helpers/gitbox';
import mockServer from './helpers/mockserver';
import npmRegistry from './helpers/npm-registry';
@@ -609,6 +609,7 @@ test.serial('Exit with 1 if missing permission to push to the remote repository'
/* Initial release */
t.log('Commit a feature');
await gitCommits(['feat: Initial commit']);
await gitPush();
t.log('$ semantic-release');
const {stdout, code} = await execa(
cli,
+4 -4
View File
@@ -14,7 +14,7 @@ test('Normalize and load plugin from string', t => {
t.is(plugin.pluginName, './test/fixtures/plugin-noop');
t.is(typeof plugin, 'function');
t.deepEqual(t.context.log.args[0], ['Load plugin %s from %s', 'verifyConditions', './test/fixtures/plugin-noop']);
t.deepEqual(t.context.log.args[0], ['Load plugin "%s" from %s', 'verifyConditions', './test/fixtures/plugin-noop']);
});
test('Normalize and load plugin from object', t => {
@@ -22,7 +22,7 @@ test('Normalize and load plugin from object', t => {
t.is(plugin.pluginName, './test/fixtures/plugin-noop');
t.is(typeof plugin, 'function');
t.deepEqual(t.context.log.args[0], ['Load plugin %s from %s', 'publish', './test/fixtures/plugin-noop']);
t.deepEqual(t.context.log.args[0], ['Load plugin "%s" from %s', 'publish', './test/fixtures/plugin-noop']);
});
test('Normalize and load plugin from a base file path', t => {
@@ -37,7 +37,7 @@ test('Normalize and load plugin from a base file path', t => {
t.is(plugin.pluginName, './plugin-noop');
t.is(typeof plugin, 'function');
t.deepEqual(t.context.log.args[0], [
'Load plugin %s from %s in shareable config %s',
'Load plugin "%s" from %s in shareable config %s',
'verifyConditions',
'./plugin-noop',
'./test/fixtures',
@@ -85,7 +85,7 @@ test('Normalize and load plugin that retuns multiple functions', t => {
const plugin = normalize('verifyConditions', {}, {}, './test/fixtures/multi-plugin', t.context.logger);
t.is(typeof plugin, 'function');
t.deepEqual(t.context.log.args[0], ['Load plugin %s from %s', 'verifyConditions', './test/fixtures/multi-plugin']);
t.deepEqual(t.context.log.args[0], ['Load plugin "%s" from %s', 'verifyConditions', './test/fixtures/multi-plugin']);
});
test('Wrap "analyzeCommits" plugin in a function that validate the output of the plugin', async t => {