Compare commits
@@ -1,11 +0,0 @@
|
||||
root = true
|
||||
|
||||
[*]
|
||||
end_of_line = lf
|
||||
insert_final_newline = true
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
trim_trailing_whitespace = true
|
||||
|
||||
[*.md]
|
||||
trim_trailing_whitespace = false
|
||||
+135
-7
@@ -1,9 +1,137 @@
|
||||
coverage
|
||||
node_modules
|
||||
test/registry/couch
|
||||
test/registry/data
|
||||
test/tmp
|
||||
|
||||
# Created by https://www.gitignore.io/api/macos,windows,linux,node
|
||||
|
||||
### Linux ###
|
||||
*~
|
||||
|
||||
# temporary files which can be created if a process still has a handle open of a deleted file
|
||||
.fuse_hidden*
|
||||
|
||||
# KDE directory preferences
|
||||
.directory
|
||||
|
||||
# Linux trash folder which might appear on any partition or disk
|
||||
.Trash-*
|
||||
|
||||
# .nfs files are created when an open file is removed but is still being accessed
|
||||
.nfs*
|
||||
|
||||
### macOS ###
|
||||
*.DS_Store
|
||||
.AppleDouble
|
||||
.LSOverride
|
||||
|
||||
# Icon must end with two \r
|
||||
Icon
|
||||
|
||||
# Thumbnails
|
||||
._*
|
||||
|
||||
# Files that might appear in the root of a volume
|
||||
.DocumentRevisions-V100
|
||||
.fseventsd
|
||||
.Spotlight-V100
|
||||
.TemporaryItems
|
||||
.Trashes
|
||||
.VolumeIcon.icns
|
||||
.com.apple.timemachine.donotpresent
|
||||
|
||||
# Directories potentially created on remote AFP share
|
||||
.AppleDB
|
||||
.AppleDesktop
|
||||
Network Trash Folder
|
||||
Temporary Items
|
||||
.apdisk
|
||||
|
||||
### Node ###
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
*.dump
|
||||
.DS_Store
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
|
||||
# Runtime data
|
||||
pids
|
||||
*.pid
|
||||
*.seed
|
||||
*.pid.lock
|
||||
|
||||
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||
lib-cov
|
||||
|
||||
# Coverage directory used by tools like istanbul
|
||||
coverage
|
||||
|
||||
# nyc test coverage
|
||||
.nyc_output
|
||||
|
||||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
|
||||
.grunt
|
||||
|
||||
# Bower dependency directory (https://bower.io/)
|
||||
bower_components
|
||||
|
||||
# node-waf configuration
|
||||
.lock-wscript
|
||||
|
||||
# Compiled binary addons (http://nodejs.org/api/addons.html)
|
||||
build/Release
|
||||
|
||||
# Dependency directories
|
||||
node_modules/
|
||||
jspm_packages/
|
||||
|
||||
# Typescript v1 declaration files
|
||||
typings/
|
||||
|
||||
# Optional npm cache directory
|
||||
.npm
|
||||
|
||||
# Optional eslint cache
|
||||
.eslintcache
|
||||
|
||||
# Optional REPL history
|
||||
.node_repl_history
|
||||
|
||||
# Output of 'npm pack'
|
||||
*.tgz
|
||||
|
||||
# Yarn Integrity file
|
||||
.yarn-integrity
|
||||
|
||||
# dotenv environment variables file
|
||||
.env
|
||||
|
||||
|
||||
### Windows ###
|
||||
# Windows thumbnail cache files
|
||||
Thumbs.db
|
||||
ehthumbs.db
|
||||
ehthumbs_vista.db
|
||||
|
||||
# Folder config file
|
||||
Desktop.ini
|
||||
|
||||
# Recycle Bin used on file shares
|
||||
$RECYCLE.BIN/
|
||||
|
||||
# Windows Installer files
|
||||
*.cab
|
||||
*.msi
|
||||
*.msm
|
||||
*.msp
|
||||
|
||||
# Windows shortcuts
|
||||
*.lnk
|
||||
|
||||
# End of https://www.gitignore.io/api/macos,windows,linux,node
|
||||
|
||||
package-lock.json
|
||||
yarn.lock
|
||||
|
||||
# Registry tests
|
||||
|
||||
test/helpers/registry/couch
|
||||
test/helpers/registry/data
|
||||
test/helpers/tmp
|
||||
+20
-17
@@ -1,22 +1,25 @@
|
||||
sudo: false
|
||||
language: node_js
|
||||
cache:
|
||||
directories:
|
||||
- node_modules
|
||||
services:
|
||||
- couchdb
|
||||
notifications:
|
||||
email: false
|
||||
node_js:
|
||||
- 5
|
||||
- 4
|
||||
- iojs
|
||||
- '0.12'
|
||||
- '0.10'
|
||||
before_install:
|
||||
- npm i -g npm@^2.0.0
|
||||
before_script:
|
||||
- npm prune
|
||||
- 8
|
||||
|
||||
# Trigger a push build on caribou and greenkeeper branches + PRs build on every branches
|
||||
# Avoid double build on PRs (See https://github.com/travis-ci/travis-ci/issues/1147)
|
||||
branches:
|
||||
only:
|
||||
- caribou
|
||||
- /^greenkeeper.*$/
|
||||
|
||||
# Retry install on fail to avoid failing a build on network/disk/external errors
|
||||
install:
|
||||
- travis_retry npm install
|
||||
|
||||
script:
|
||||
- npm run test
|
||||
|
||||
after_success:
|
||||
- npm run coverage:upload
|
||||
- npm run semantic-release
|
||||
services:
|
||||
- couchdb
|
||||
- npm run codecov
|
||||
- npm run semantic-release
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2017 Contributors
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
@@ -7,15 +7,15 @@
|
||||
> – [egghead.io](https://egghead.io/lessons/javascript-how-to-write-a-javascript-library-automating-releases-with-semantic-release)
|
||||
|
||||
[](https://gitter.im/semantic-release/semantic-release?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
||||
[](https://www.npmjs.com/package/semantic-release)
|
||||
[](https://greenkeeper.io/)
|
||||
[](https://github.com/semantic-release/semantic-release/blob/master/LICENSE)
|
||||
[](https://github.com/prettier/prettier)
|
||||
[](https://github.com/semantic-release/semantic-release)
|
||||
[](https://github.com/feross/standard)
|
||||
[](http://commitizen.github.io/cz-cli/)
|
||||
|
||||
[](https://david-dm.org/semantic-release/semantic-release/caribou)
|
||||
[](https://david-dm.org/semantic-release/semantic-release/caribou#info=devDependencies)
|
||||
|
||||
[](https://travis-ci.org/semantic-release/semantic-release)
|
||||
[](https://coveralls.io/github/semantic-release/semantic-release?branch=caribou)
|
||||
[](https://travis-ci.org/semantic-release/semantic-release)
|
||||
[](https://codecov.io/gh/semantic-release/semantic-release)
|
||||
|
||||
Out of the box this is just about _commit-messages_, but you can do so much more.
|
||||
|
||||
@@ -79,7 +79,7 @@ This removes the immediate connection between human emotions and version numbers
|
||||
|
||||
Instead of writing [meaningless commit messages](http://whatthecommit.com/), we can take our time to think about the changes in the codebase and write them down. Following formalized conventions it is then possible to generate a helpful changelog and to derive the next semantic version number from them.
|
||||
|
||||
When `semantic-release` is setup it will do that after every successful continuous integration build of your master branch (or any other branch you specify) and publish the new version for you. This way no human is directly involved in the release process and your releases are guaranteed to be [unromantic and unsentimental](http://sentimentalversioning.org/).
|
||||
When `semantic-release` is set up it will do that after every successful continuous integration build of your master branch (or any other branch you specify) and publish the new version for you. This way no human is directly involved in the release process and your releases are guaranteed to be [unromantic and unsentimental](http://sentimentalversioning.org/).
|
||||
|
||||
If you fear the loss of control over timing and marketing implications of software releases you should know that `semantic-release` supports [release channels](https://github.com/npm/npm/issues/2718) using `npm`’s [dist-tags](https://docs.npmjs.com/cli/dist-tag). This way you can keep control over what your users end up using by default, you can decide when to promote an automatically released version to the stable channel, and you can choose which versions to write blogposts and tweets about. You can use the same mechanism to [support older versions of your software](https://gist.github.com/boennemann/54042374e49c7ade8910), for example with important security fixes.
|
||||
|
||||
@@ -106,7 +106,7 @@ format that includes a **type**, a **scope** and a **subject** ([full explanatio
|
||||
<footer>
|
||||
```
|
||||
|
||||
You can simplify using this convention for yourself and contributors by using [commitizen](https://github.com/commitizen/cz-cli) and [validate-commit-msg](https://github.com/kentcdodds/validate-commit-msg).
|
||||
You can simplify using this convention for yourself and contributors by using [commitizen](https://github.com/commitizen/cz-cli) and [commitlint](https://github.com/marionebl/commitlint) or [semantic-git-commit-cli](https://github.com/JPeer264/node-semantic-git-commit-cli).
|
||||
|
||||
### Patch Release
|
||||
|
||||
@@ -125,7 +125,7 @@ feat(pencil): add 'graphiteWidth' option
|
||||
```
|
||||
perf(pencil): remove graphiteWidth option
|
||||
|
||||
BREAKING CHANGE: The graphiteWidth option has been removed. The default graphite width of 10mm is always used for performance reason.
|
||||
BREAKING CHANGE: The graphiteWidth option has been removed. The default graphite width of 10mm is always used for performance reasons.
|
||||
```
|
||||
|
||||
## Setup
|
||||
@@ -141,7 +141,7 @@ semantic-release-cli setup
|
||||
|
||||

|
||||
|
||||
_[This is what happens under the hood.](https://github.com/semantic-release/cli#manual-setup)_
|
||||
_[This is what happens under the hood.](https://github.com/semantic-release/cli#what-it-does)_
|
||||
|
||||
## Options
|
||||
|
||||
@@ -206,7 +206,11 @@ module.exports = function (pluginConfig, config, callback) {}
|
||||
|
||||
### `analyzeCommits`
|
||||
|
||||
This plugin is responsible for determining the type of the next release. It additionally receives a `commits` array inside `config`. One commit is an object with a `message` and `hash` property. Call the callback with `'major'`, `'premajor'`, `'minor'`, `'preminor'`, `'patch'`, `'prepatch'`, `'prerelease'`, or `null` if nothing changed. Have a look at the [default implementation](https://github.com/semantic-release/commit-analyzer/).
|
||||
This plugin is responsible for determining the type of the next release. It additionally receives a `commits` array inside `config`. One commit is an object with a `message` and `hash` property. Call the callback with `'major'`, `'premajor'`, `'minor'`, `'preminor'`, `'patch'`, `'prepatch'`, `'prerelease'`, or `null` if nothing changed.
|
||||
|
||||
While it may be tempting to use `'prepatch'`, `'preminor'` & `'prerelease'` as part of a release process, this is strongly discouraged. A better approach is to use [dist-tags](https://docs.npmjs.com/cli/dist-tag) to create release channels (such as 'latest', 'next', 'stable') and to return only `'major'`, `'premajor'` and `'minor'` from the commit analyzer.
|
||||
|
||||
Have a look at the [default implementation](https://github.com/semantic-release/commit-analyzer/).
|
||||
|
||||
### `generateNotes`
|
||||
|
||||
@@ -258,7 +262,13 @@ It is indeed a great idea because it _forces_ you to follow best practices. If y
|
||||
|
||||
### Why should I trust `semantic-release` with my releases?
|
||||
|
||||
`semantic-release` has a full unit- and integration-test-suite that tests _actual_ `npm` publishes against the [npm-registry-couchapp](https://github.com/npm/npm-registry-couchapp/) on all major node.js versions from `^0.10` on. A new version won’t get published if it doesn’t pass on all these engines.
|
||||
`semantic-release` has a full unit- and integration-test-suite that tests _actual_ `npm` publishes against the [npm-registry-couchapp](https://github.com/npm/npm-registry-couchapp/). A new version won’t get published if it doesn’t pass on all these engines.
|
||||
|
||||
### Why does `semantic-release` require node version >= 8
|
||||
|
||||
Being able to write code for just the most recent node versions greatly simplifies development. More language features are available, no transpilation is required, less test builds are to be run, awaited and debugged.
|
||||
|
||||
For a special purpose tool like `semantic-release`, that's only meant to be used in controlled CI environments, we think it's okay to have such a high version requirement. As `semantic-release` handles package publishing we expect almost every project to have at least one build job running node 8 already – and that's all it takes. Even if that's not that case `semantic-release` can still be executed with the help of [npx](https://www.npmjs.com/package/npx) (`npx -p node@8 npm run semantic-release`).
|
||||
|
||||
## Badge
|
||||
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
# Troubleshooting semantic-release
|
||||
|
||||
### ENOTINHISTORY Commit not in history
|
||||
|
||||
```
|
||||
semantic-release ERR! commits The commit the last release of this package was derived from is not in the direct history of the "master" branch.
|
||||
semantic-release ERR! commits This means semantic-release can not extract the commits between now and then.
|
||||
semantic-release ERR! commits This is usually caused by force pushing, releasing from an unrelated branch, or using an already existing package name.
|
||||
semantic-release ERR! commits You can recover from this error by publishing manually or restoring the commit "123".
|
||||
semantic-release ERR! pre Failed to determine new version.
|
||||
semantic-release ERR! pre ENOTINHISTORY Commit not in history
|
||||
```
|
||||
|
||||
To restore semantic-release, follow these steps:
|
||||
|
||||
```
|
||||
git pull
|
||||
git reset --hard origin/master
|
||||
npm version x.y.z # check your current version and set this based on semver rules manually
|
||||
|
||||
# if you have a PR workflow, create a new branch, otherwise commit to master
|
||||
|
||||
git checkout -B chore/release
|
||||
git commit -am 'chore: release'
|
||||
git push
|
||||
|
||||
# merge (not squash-merge) on github (this is important before running git push). This is only required when you work with branches
|
||||
git checkout master
|
||||
|
||||
# definitely required
|
||||
git pull
|
||||
git push --tags
|
||||
npm publish
|
||||
```
|
||||
+24
-159
@@ -1,165 +1,30 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
var fs = require('fs')
|
||||
var path = require('path')
|
||||
var url = require('url')
|
||||
// Bad news: We have to write plain ES5 in this file
|
||||
// Good news: It's the only file of the entire project
|
||||
|
||||
var _ = require('lodash')
|
||||
var log = require('npmlog')
|
||||
var nopt = require('nopt')
|
||||
var npmconf = require('npmconf')
|
||||
var normalizeData = require('normalize-package-data')
|
||||
var semver = require('semver');
|
||||
|
||||
log.heading = 'semantic-release'
|
||||
var env = process.env
|
||||
var pkg = JSON.parse(fs.readFileSync('./package.json'))
|
||||
var originalPkg = _.cloneDeep(pkg)
|
||||
normalizeData(pkg)
|
||||
var knownOptions = {
|
||||
branch: String,
|
||||
debug: Boolean,
|
||||
'github-token': String,
|
||||
'github-url': String,
|
||||
'analyze-commits': [path, String],
|
||||
'generate-notes': [path, String],
|
||||
'verify-conditions': [path, String],
|
||||
'verify-release': [path, String]
|
||||
if (semver.lt(process.version, '8.0.0')) {
|
||||
console.error(
|
||||
`semantic-release: node version >= 8 is required. Found ${process.version}.
|
||||
|
||||
If there is another job running on node version >= 8, it will be picked as
|
||||
the build leader and you can safely ignore this message.
|
||||
|
||||
If you don't have node 8 in your build matrix you can use "npx" to restore
|
||||
compatibility with minimal overhead:
|
||||
|
||||
$ npx -p node@8 npm run semantic-release
|
||||
|
||||
npx is bundled with npm >= 5.4, or available via npm. More info: npm.im/npx`
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
var options = _.defaults(
|
||||
_.mapKeys(nopt(knownOptions), function (value, key) {
|
||||
return _.camelCase(key)
|
||||
}),
|
||||
pkg.release,
|
||||
{
|
||||
branch: 'master',
|
||||
fallbackTags: {
|
||||
next: 'latest'
|
||||
},
|
||||
debug: !env.CI,
|
||||
githubToken: env.GH_TOKEN || env.GITHUB_TOKEN,
|
||||
githubUrl: env.GH_URL
|
||||
}
|
||||
)
|
||||
var plugins = require('../src/lib/plugins')(options)
|
||||
|
||||
npmconf.load({}, function (err, conf) {
|
||||
if (err) {
|
||||
log.error('init', 'Failed to load npm config.', err)
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
var npm = {
|
||||
auth: {
|
||||
token: env.NPM_TOKEN
|
||||
},
|
||||
cafile: conf.get('cafile'),
|
||||
loglevel: conf.get('loglevel'),
|
||||
registry: require('../src/lib/get-registry')(pkg, conf),
|
||||
tag: (pkg.publishConfig || {}).tag || conf.get('tag') || 'latest'
|
||||
}
|
||||
|
||||
// normalize trailing slash
|
||||
npm.registry = url.format(url.parse(npm.registry))
|
||||
|
||||
log.level = npm.loglevel
|
||||
|
||||
var config = {
|
||||
env: env,
|
||||
pkg: pkg,
|
||||
options: options,
|
||||
plugins: plugins,
|
||||
npm: npm
|
||||
}
|
||||
|
||||
var hide = {}
|
||||
if (options.githubToken) hide.githubToken = '***'
|
||||
|
||||
log.verbose('init', 'options:', _.assign({}, options, hide))
|
||||
log.verbose('init', 'Verifying config.')
|
||||
|
||||
var errors = require('../src/lib/verify')(config)
|
||||
errors.forEach(function (err) {
|
||||
log.error('init', err.message + ' ' + err.code)
|
||||
})
|
||||
if (errors.length) process.exit(1)
|
||||
|
||||
if (options.argv.remain[0] === 'pre') {
|
||||
log.verbose('pre', 'Running pre-script.')
|
||||
log.verbose('pre', 'Veriying conditions.')
|
||||
|
||||
plugins.verifyConditions(config, function (err) {
|
||||
if (err) {
|
||||
log[options.debug ? 'warn' : 'error']('pre', err.message)
|
||||
if (!options.debug) process.exit(1)
|
||||
}
|
||||
|
||||
var nerfDart = require('nerf-dart')(npm.registry)
|
||||
var wroteNpmRc = false
|
||||
|
||||
if (env.NPM_OLD_TOKEN && env.NPM_EMAIL) {
|
||||
// Using the old auth token format is not considered part of the public API
|
||||
// This might go away anytime (i.e. once we have a better testing strategy)
|
||||
conf.set('_auth', '${NPM_OLD_TOKEN}', 'project')
|
||||
conf.set('email', '${NPM_EMAIL}', 'project')
|
||||
wroteNpmRc = true
|
||||
} else if (env.NPM_TOKEN) {
|
||||
conf.set(nerfDart + ':_authToken', '${NPM_TOKEN}', 'project')
|
||||
wroteNpmRc = true
|
||||
}
|
||||
|
||||
conf.save('project', function (err) {
|
||||
if (err) return log.error('pre', 'Failed to save npm config.', err)
|
||||
|
||||
if (wroteNpmRc) log.verbose('pre', 'Wrote authToken to .npmrc.')
|
||||
|
||||
require('../src/pre')(config, function (err, release) {
|
||||
if (err) {
|
||||
log.error('pre', 'Failed to determine new version.')
|
||||
|
||||
var args = ['pre', (err.code ? err.code + ' ' : '') + err.message]
|
||||
if (err.stack) args.push(err.stack)
|
||||
log.error.apply(log, args)
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
var message = 'Determined version ' + release.version + ' as "' + npm.tag + '".'
|
||||
|
||||
log.verbose('pre', message)
|
||||
|
||||
if (options.debug) {
|
||||
log.error('pre', message + ' Not publishing in debug mode.', release)
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
try {
|
||||
var shrinkwrap = JSON.parse(fs.readFileSync('./npm-shrinkwrap.json'))
|
||||
shrinkwrap.version = release.version
|
||||
fs.writeFileSync('./npm-shrinkwrap.json', JSON.stringify(shrinkwrap, null, 2))
|
||||
log.verbose('pre', 'Wrote version ' + release.version + 'to npm-shrinkwrap.json.')
|
||||
} catch (e) {
|
||||
log.silly('pre', 'Couldn\'t find npm-shrinkwrap.json.')
|
||||
}
|
||||
|
||||
fs.writeFileSync('./package.json', JSON.stringify(_.assign(originalPkg, {
|
||||
version: release.version
|
||||
}), null, 2))
|
||||
|
||||
log.verbose('pre', 'Wrote version ' + release.version + ' to package.json.')
|
||||
})
|
||||
})
|
||||
})
|
||||
} else if (options.argv.remain[0] === 'post') {
|
||||
log.verbose('post', 'Running post-script.')
|
||||
|
||||
require('../src/post')(config, function (err, published, release) {
|
||||
if (err) {
|
||||
log.error('post', 'Failed to publish release notes.', err)
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
log.verbose('post', (published ? 'Published' : 'Generated') + ' release notes.', release)
|
||||
})
|
||||
} else {
|
||||
log.error('post', 'Command "' + options.argv.remain[0] + '" not recognized. Use either "pre" or "post"')
|
||||
}
|
||||
})
|
||||
// node 8+ from this point on
|
||||
require('../src')().catch(err => {
|
||||
console.error('An error occurred while running semantic-release');
|
||||
console.error(err);
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
codecov:
|
||||
branch: caribou
|
||||
+77
-35
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "semantic-release",
|
||||
"description": "automated semver compliant package publishing",
|
||||
"description": "Automated semver compliant package publishing",
|
||||
"version": "0.0.0-placeholder",
|
||||
"author": "Stephan Bönnemann <stephan@boennemann.me> (http://boennemann.me)",
|
||||
"bin": {
|
||||
@@ -9,47 +9,76 @@
|
||||
"bugs": {
|
||||
"url": "https://github.com/semantic-release/semantic-release/issues"
|
||||
},
|
||||
"czConfig": {
|
||||
"path": "node_modules/cz-conventional-changelog/"
|
||||
"config": {
|
||||
"commitizen": {
|
||||
"path": "cz-conventional-changelog"
|
||||
}
|
||||
},
|
||||
"dependencies": {
|
||||
"@bahmutov/parse-github-repo-url": "^0.1.0",
|
||||
"@semantic-release/commit-analyzer": "^2.0.0",
|
||||
"@semantic-release/condition-travis": "^5.0.2",
|
||||
"@semantic-release/error": "^1.0.0",
|
||||
"@semantic-release/last-release-npm": "^1.2.1",
|
||||
"@semantic-release/release-notes-generator": "^2.0.0",
|
||||
"@semantic-release/commit-analyzer": "^3.0.1",
|
||||
"@semantic-release/condition-travis": "^6.0.0",
|
||||
"@semantic-release/error": "^2.0.0",
|
||||
"@semantic-release/last-release-npm": "^2.0.0",
|
||||
"@semantic-release/release-notes-generator": "^4.0.0",
|
||||
"execa": "^0.8.0",
|
||||
"fs-extra": "^4.0.2",
|
||||
"git-head": "^1.2.1",
|
||||
"github": "^0.2.4",
|
||||
"github": "^12.0.0",
|
||||
"lodash": "^4.0.0",
|
||||
"nerf-dart": "^1.0.0",
|
||||
"nopt": "^3.0.3",
|
||||
"nopt": "^4.0.0",
|
||||
"normalize-package-data": "^2.3.4",
|
||||
"npmconf": "^2.1.2",
|
||||
"npmlog": "^4.0.0",
|
||||
"p-series": "^1.0.0",
|
||||
"parse-github-repo-url": "^1.3.0",
|
||||
"require-relative": "^0.8.7",
|
||||
"run-auto": "^2.0.0",
|
||||
"run-series": "^1.1.3",
|
||||
"semver": "^5.0.3"
|
||||
"semver": "^5.4.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"coveralls": "^2.11.4",
|
||||
"cz-conventional-changelog": "^1.1.4",
|
||||
"mkdirp": "^0.5.1",
|
||||
"nixt": "^0.5.0",
|
||||
"nock": "^8.0.0",
|
||||
"npm-registry-couchapp": "^2.6.11",
|
||||
"nyc": "^7.0.0",
|
||||
"ava": "^0.23.0",
|
||||
"codecov": "^3.0.0",
|
||||
"commitizen": "^2.9.6",
|
||||
"cz-conventional-changelog": "^2.0.0",
|
||||
"eslint": "^4.7.0",
|
||||
"eslint-config-prettier": "^2.5.0",
|
||||
"eslint-config-standard": "^10.2.1",
|
||||
"eslint-plugin-import": "^2.7.0",
|
||||
"eslint-plugin-node": "^5.2.0",
|
||||
"eslint-plugin-prettier": "^2.3.0",
|
||||
"eslint-plugin-promise": "^3.5.0",
|
||||
"eslint-plugin-standard": "^3.0.1",
|
||||
"nock": "^9.0.2",
|
||||
"npm-registry-couchapp": "^2.6.12",
|
||||
"nyc": "^11.2.1",
|
||||
"p-map-series": "^1.0.0",
|
||||
"prettier": "^1.7.0",
|
||||
"proxyquire": "^1.7.3",
|
||||
"rimraf": "^2.5.0",
|
||||
"standard": "^7.0.1",
|
||||
"tap": "^6.2.0"
|
||||
"sinon": "^4.0.0",
|
||||
"tempy": "^0.2.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=0.10",
|
||||
"node": ">=4",
|
||||
"npm": ">=2"
|
||||
},
|
||||
"homepage": "https://github.com/semantic-release/semantic-release/tree/next#readme",
|
||||
"eslintConfig": {
|
||||
"extends": [
|
||||
"standard",
|
||||
"prettier"
|
||||
],
|
||||
"plugins": [
|
||||
"prettier"
|
||||
],
|
||||
"rules": {
|
||||
"prettier/prettier": 2
|
||||
}
|
||||
},
|
||||
"files": [
|
||||
"bin",
|
||||
"src"
|
||||
],
|
||||
"homepage": "https://github.com/semantic-release/semantic-release#readme",
|
||||
"keywords": [
|
||||
"author",
|
||||
"automation",
|
||||
@@ -63,10 +92,23 @@
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "bin/semantic-release.js",
|
||||
"files": [
|
||||
"bin",
|
||||
"src"
|
||||
],
|
||||
"nyc": {
|
||||
"include": [
|
||||
"src/**/*.js"
|
||||
],
|
||||
"reporter": [
|
||||
"json",
|
||||
"text",
|
||||
"html"
|
||||
],
|
||||
"all": true
|
||||
},
|
||||
"prettier": {
|
||||
"printWidth": 120,
|
||||
"singleQuote": true,
|
||||
"bracketSpacing": false,
|
||||
"trailingComma": "es5"
|
||||
},
|
||||
"publishConfig": {
|
||||
"tag": "next"
|
||||
},
|
||||
@@ -78,12 +120,12 @@
|
||||
"url": "git+https://github.com/semantic-release/semantic-release.git"
|
||||
},
|
||||
"scripts": {
|
||||
"coverage": "nyc report",
|
||||
"coverage:upload": "npm run coverage -s -- --reporter=text-lcov | coveralls",
|
||||
"pretest": "standard",
|
||||
"clean": "rimraf coverage && rimraf .nyc_output",
|
||||
"cm": "git-cz",
|
||||
"codecov": "codecov -f coverage/coverage-final.json",
|
||||
"lint": "eslint .",
|
||||
"pretest": "npm run clean && npm run lint",
|
||||
"semantic-release": "./bin/semantic-release.js pre && npm publish && ./bin/semantic-release.js post",
|
||||
"test": "npm run test:unit && npm run test:integration",
|
||||
"test:integration": "tap --no-cov test/scenarios/*.js",
|
||||
"test:unit": "nyc tap --no-cov test/specs/*.js"
|
||||
"test": "nyc ava -v"
|
||||
}
|
||||
}
|
||||
|
||||
+153
@@ -0,0 +1,153 @@
|
||||
const path = require('path');
|
||||
const {promisify} = require('util');
|
||||
const url = require('url');
|
||||
const {readJson, writeJson} = require('fs-extra');
|
||||
const {cloneDeep, defaults, mapKeys, camelCase, assign} = require('lodash');
|
||||
const log = require('npmlog');
|
||||
const nopt = require('nopt');
|
||||
const npmconf = require('npmconf');
|
||||
const normalizeData = require('normalize-package-data');
|
||||
|
||||
module.exports = async () => {
|
||||
log.heading = 'semantic-release';
|
||||
const env = process.env;
|
||||
const pkg = await readJson('./package.json');
|
||||
const originalPkg = cloneDeep(pkg);
|
||||
normalizeData(pkg);
|
||||
const knownOptions = {
|
||||
branch: String,
|
||||
debug: Boolean,
|
||||
'github-token': String,
|
||||
'github-url': String,
|
||||
'analyze-commits': [path, String],
|
||||
'generate-notes': [path, String],
|
||||
'verify-conditions': [path, String],
|
||||
'verify-release': [path, String],
|
||||
};
|
||||
const options = defaults(
|
||||
mapKeys(nopt(knownOptions), (value, key) => {
|
||||
return camelCase(key);
|
||||
}),
|
||||
pkg.release,
|
||||
{
|
||||
branch: 'master',
|
||||
fallbackTags: {next: 'latest'},
|
||||
debug: !env.CI,
|
||||
githubToken: env.GH_TOKEN || env.GITHUB_TOKEN,
|
||||
githubUrl: env.GH_URL,
|
||||
}
|
||||
);
|
||||
const plugins = require('../src/lib/plugins')(options);
|
||||
let conf;
|
||||
try {
|
||||
conf = await promisify(npmconf.load)({});
|
||||
} catch (err) {
|
||||
log.error('init', 'Failed to load npm config.', err);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const npm = {
|
||||
auth: {token: env.NPM_TOKEN},
|
||||
cafile: conf.get('cafile'),
|
||||
loglevel: conf.get('loglevel'),
|
||||
registry: require('../src/lib/get-registry')(pkg, conf),
|
||||
tag: (pkg.publishConfig || {}).tag || conf.get('tag') || 'latest',
|
||||
};
|
||||
|
||||
// normalize trailing slash
|
||||
npm.registry = url.format(url.parse(npm.registry));
|
||||
log.level = npm.loglevel;
|
||||
|
||||
const config = {env: env, pkg: pkg, options: options, plugins: plugins, npm: npm};
|
||||
const hide = {};
|
||||
if (options.githubToken) hide.githubToken = '***';
|
||||
|
||||
log.verbose('init', 'options:', assign({}, options, hide));
|
||||
log.verbose('init', 'Verifying config.');
|
||||
|
||||
const errors = require('../src/lib/verify')(config);
|
||||
errors.forEach(err => {
|
||||
log.error('init', err.message + ' ' + err.code);
|
||||
});
|
||||
if (errors.length) process.exit(1);
|
||||
|
||||
if (options.argv.remain[0] === 'pre') {
|
||||
log.verbose('pre', 'Running pre-script.');
|
||||
log.verbose('pre', 'Veriying conditions.');
|
||||
try {
|
||||
await plugins.verifyConditions(config);
|
||||
} catch (err) {
|
||||
log[options.debug ? 'warn' : 'error']('pre', err.message);
|
||||
if (!options.debug) process.exit(1);
|
||||
}
|
||||
|
||||
const nerfDart = require('nerf-dart')(npm.registry);
|
||||
let wroteNpmRc = false;
|
||||
|
||||
if (env.NPM_OLD_TOKEN && env.NPM_EMAIL) {
|
||||
// Using the old auth token format is not considered part of the public API
|
||||
// This might go away anytime (i.e. once we have a better testing strategy)
|
||||
conf.set('_auth', '${NPM_OLD_TOKEN}', 'project'); // eslint-disable-line no-template-curly-in-string
|
||||
conf.set('email', '${NPM_EMAIL}', 'project'); // eslint-disable-line no-template-curly-in-string
|
||||
wroteNpmRc = true;
|
||||
} else if (env.NPM_TOKEN) {
|
||||
conf.set(nerfDart + ':_authToken', '${NPM_TOKEN}', 'project'); // eslint-disable-line no-template-curly-in-string
|
||||
wroteNpmRc = true;
|
||||
}
|
||||
|
||||
try {
|
||||
await promisify(conf.save.bind(conf))('project');
|
||||
} catch (err) {
|
||||
return log.error('pre', 'Failed to save npm config.', err);
|
||||
}
|
||||
|
||||
if (wroteNpmRc) log.verbose('pre', 'Wrote authToken to .npmrc.');
|
||||
|
||||
let release;
|
||||
try {
|
||||
release = await require('../src/pre')(config);
|
||||
} catch (err) {
|
||||
log.error('pre', 'Failed to determine new version.');
|
||||
|
||||
const args = ['pre', (err.code ? err.code + ' ' : '') + err.message];
|
||||
if (err.stack) args.push(err.stack);
|
||||
log.error.apply(log, args);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const message = 'Determined version ' + release.version + ' as "' + npm.tag + '".';
|
||||
|
||||
log.verbose('pre', message);
|
||||
|
||||
if (options.debug) {
|
||||
log.error('pre', message + ' Not publishing in debug mode.', release);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
try {
|
||||
const shrinkwrap = await readJson('./npm-shrinkwrap.json');
|
||||
shrinkwrap.version = release.version;
|
||||
await writeJson('./npm-shrinkwrap.json', shrinkwrap);
|
||||
log.verbose('pre', 'Wrote version ' + release.version + 'to npm-shrinkwrap.json.');
|
||||
} catch (e) {
|
||||
log.silly('pre', "Couldn't find npm-shrinkwrap.json.");
|
||||
}
|
||||
|
||||
await writeJson('./package.json', assign(originalPkg, {version: release.version}));
|
||||
|
||||
log.verbose('pre', 'Wrote version ' + release.version + ' to package.json.');
|
||||
} else if (options.argv.remain[0] === 'post') {
|
||||
log.verbose('post', 'Running post-script.');
|
||||
|
||||
let published, release;
|
||||
try {
|
||||
({published, release} = await require('../src/post')(config));
|
||||
log.verbose('post', (published ? 'Published' : 'Generated') + ' release notes.', release);
|
||||
} catch (err) {
|
||||
log.error('post', 'Failed to publish release notes.', err);
|
||||
process.exit(1);
|
||||
}
|
||||
} else {
|
||||
log.error('post', 'Command "' + options.argv.remain[0] + '" not recognized. Use either "pre" or "post"');
|
||||
}
|
||||
};
|
||||
@@ -1,74 +0,0 @@
|
||||
var exec = require('child_process').exec
|
||||
|
||||
var log = require('npmlog')
|
||||
|
||||
var SemanticReleaseError = require('@semantic-release/error')
|
||||
|
||||
module.exports = function (config, cb) {
|
||||
var lastRelease = config.lastRelease
|
||||
var options = config.options
|
||||
var branch = options.branch
|
||||
var from = lastRelease.gitHead
|
||||
var range = (from ? from + '..' : '') + 'HEAD'
|
||||
|
||||
if (!from) return extract()
|
||||
|
||||
exec('git branch --contains ' + from, function (err, stdout) {
|
||||
var inHistory = false
|
||||
var branches
|
||||
|
||||
if (!err && stdout) {
|
||||
branches = stdout.split('\n')
|
||||
.map(function (result) {
|
||||
if (branch === result.replace('*', '').trim()) {
|
||||
inHistory = true
|
||||
return null
|
||||
}
|
||||
return result.trim()
|
||||
})
|
||||
.filter(function (branch) {
|
||||
return !!branch
|
||||
})
|
||||
}
|
||||
|
||||
if (!inHistory) {
|
||||
log.error('commits',
|
||||
'The commit the last release of this package was derived from is not in the direct history of the "' + branch + '" branch.\n' +
|
||||
'This means semantic-release can not extract the commits between now and then.\n' +
|
||||
'This is usually caused by force pushing, releasing from an unrelated branch, or using an already existing package name.\n' +
|
||||
'You can recover from this error by publishing manually or restoring the commit "' + from + '".' + (branches && branches.length
|
||||
? '\nHere is a list of branches that still contain the commit in question: \n * ' + branches.join('\n * ')
|
||||
: ''
|
||||
))
|
||||
return cb(new SemanticReleaseError('Commit not in history', 'ENOTINHISTORY'))
|
||||
}
|
||||
|
||||
extract()
|
||||
})
|
||||
|
||||
function extract () {
|
||||
exec(
|
||||
'git log -E --format=%H==SPLIT==%B==END== ' + range,
|
||||
{
|
||||
maxBuffer: 1024 * 1024 // 1MB instead of 220KB (issue #286)
|
||||
},
|
||||
function (err, stdout) {
|
||||
if (err) return cb(err)
|
||||
|
||||
cb(null, String(stdout).split('==END==\n')
|
||||
|
||||
.filter(function (raw) {
|
||||
return !!raw.trim()
|
||||
})
|
||||
|
||||
.map(function (raw) {
|
||||
var data = raw.split('==SPLIT==')
|
||||
return {
|
||||
hash: data[0],
|
||||
message: data[1]
|
||||
}
|
||||
}))
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
const execa = require('execa');
|
||||
const log = require('npmlog');
|
||||
const getVersionHead = require('./get-version-head');
|
||||
|
||||
/**
|
||||
* Commit message.
|
||||
*
|
||||
* @typedef {Object} Commit
|
||||
* @property {string} hash The commit hash.
|
||||
* @property {string} message The commit message.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Retrieve the list of commits on the current branch since the last released version, or all the commits of the current branch if there is no last released version.
|
||||
*
|
||||
* The commit correspoding to the last released version is determined as follow:
|
||||
* - Use `lastRelease.gitHead` if defined and present in `config.options.branch` history.
|
||||
* - If `lastRelease.gitHead` is not in the `config.options.branch` history, unshallow the repository and try again.
|
||||
* - If `lastRelease.gitHead` is still not in the `config.options.branch` history, search for a tag named `v<version>` or `<version>` and verify if it's associated commit sha is present in `config.options.branch` history.
|
||||
*
|
||||
* @param {Object} config
|
||||
* @param {Object} config.lastRelease The lastRelease object obtained from the getLastRelease plugin.
|
||||
* @param {string} [config.lastRelease.version] The version number of the last release.
|
||||
* @param {string} [config.lastRelease.gitHead] The commit sha used to make the last release.
|
||||
* @param {Object} config.options The semantic-relese options.
|
||||
* @param {string} config.options.branch The branch to release from.
|
||||
*
|
||||
* @return {Promise<Array<Commit>>} The list of commits on the branch `config.options.branch` since the last release.
|
||||
*
|
||||
* @throws {SemanticReleaseError} with code `ENOTINHISTORY` if `config.lastRelease.gitHead` or the commit sha derived from `config.lastRelease.version` is not in the direct history of `config.options.branch`.
|
||||
* @throws {SemanticReleaseError} with code `ENOGITHEAD` if `config.lastRelease.gitHead` is undefined and no commit sha can be found for the `config.lastRelease.version`.
|
||||
*/
|
||||
module.exports = async ({lastRelease: {version, gitHead}, options: {branch}}) => {
|
||||
if (gitHead || version) {
|
||||
try {
|
||||
gitHead = await getVersionHead(gitHead, version, branch);
|
||||
} catch (err) {
|
||||
if (err.code === 'ENOTINHISTORY') {
|
||||
log.error('commits', notInHistoryMessage(err.gitHead, branch, version));
|
||||
} else {
|
||||
log.error('commits', noGitHeadMessage(branch, version));
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
} else {
|
||||
// If there is no gitHead nor a version, there is no previous release. Unshallow the repo in order to retrieve all commits
|
||||
await execa('git', ['fetch', '--unshallow', '--tags'], {reject: false});
|
||||
}
|
||||
|
||||
try {
|
||||
return (await execa('git', [
|
||||
'log',
|
||||
'--format=format:%H==SPLIT==%B==END==',
|
||||
`${gitHead ? gitHead + '..' : ''}HEAD`,
|
||||
])).stdout
|
||||
.split('==END==')
|
||||
.filter(raw => !!raw.trim())
|
||||
.map(raw => {
|
||||
const [hash, message] = raw.trim().split('==SPLIT==');
|
||||
return {hash, message};
|
||||
});
|
||||
} catch (err) {
|
||||
return [];
|
||||
}
|
||||
};
|
||||
|
||||
function noGitHeadMessage(branch, version) {
|
||||
return `The commit the last release of this package was derived from cannot be determined from the release metadata not from the repository tags.
|
||||
This means semantic-release can not extract the commits between now and then.
|
||||
This is usually caused by releasing from outside the repository directory or with innaccessible git metadata.
|
||||
|
||||
You can recover from this error by creating a tag for the version "${version}" on the commit corresponding to this release:
|
||||
$ git tag -f v${version} <commit sha1 corresponding to last release>
|
||||
$ git push -f --tags origin ${branch}
|
||||
`;
|
||||
}
|
||||
|
||||
function notInHistoryMessage(gitHead, branch, version) {
|
||||
return `The commit the last release of this package was derived from is not in the direct history of the "${branch}" branch.
|
||||
This means semantic-release can not extract the commits between now and then.
|
||||
This is usually caused by force pushing, releasing from an unrelated branch, or using an already existing package name.
|
||||
|
||||
You can recover from this error by restoring the commit "${gitHead}" or by creating a tag for the version "${version}" on the commit corresponding to this release:
|
||||
$ git tag -f v${version || '<version>'} <commit sha1 corresponding to last release>
|
||||
$ git push -f --tags origin ${branch}
|
||||
`;
|
||||
}
|
||||
+9
-10
@@ -1,12 +1,11 @@
|
||||
module.exports = function (pkg, conf) {
|
||||
if (pkg.publishConfig && pkg.publishConfig.registry) return pkg.publishConfig.registry
|
||||
module.exports = ({publishConfig, name}, conf) => {
|
||||
if (publishConfig && publishConfig.registry) {
|
||||
return publishConfig.registry;
|
||||
}
|
||||
|
||||
if (pkg.name[0] !== '@') return conf.get('registry') || 'https://registry.npmjs.org/'
|
||||
if (name[0] !== '@') {
|
||||
return conf.get('registry') || 'https://registry.npmjs.org/';
|
||||
}
|
||||
|
||||
var scope = pkg.name.split('/')[0]
|
||||
var scopedRegistry = conf.get(scope + '/registry')
|
||||
|
||||
if (scopedRegistry) return scopedRegistry
|
||||
|
||||
return conf.get('registry') || 'https://registry.npmjs.org/'
|
||||
}
|
||||
return conf.get(`${name.split('/')[0]}/registry`) || conf.get('registry') || 'https://registry.npmjs.org/';
|
||||
};
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
const {promisify} = require('util');
|
||||
const SemanticReleaseError = require('@semantic-release/error');
|
||||
|
||||
module.exports = async config => {
|
||||
const {plugins, lastRelease} = config;
|
||||
const type = await promisify(plugins.analyzeCommits)(config);
|
||||
|
||||
if (!type) {
|
||||
throw new SemanticReleaseError('There are no relevant changes, so no new version is released.', 'ENOCHANGE');
|
||||
}
|
||||
if (!lastRelease.version) return 'initial';
|
||||
|
||||
return type;
|
||||
};
|
||||
@@ -0,0 +1,75 @@
|
||||
const SemanticReleaseError = require('@semantic-release/error');
|
||||
const execa = require('execa');
|
||||
|
||||
/**
|
||||
* Get the commit sha for a given tag.
|
||||
*
|
||||
* @param {string} tagName Tag name for which to retrieve the commit sha.
|
||||
*
|
||||
* @return {string} The commit sha of the tag in parameter or `null`.
|
||||
*/
|
||||
async function gitTagHead(tagName) {
|
||||
try {
|
||||
return (await execa('git', ['rev-list', '-1', '--tags', tagName])).stdout;
|
||||
} catch (err) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify if the commist `sha` is in the direct history of the current branch.
|
||||
*
|
||||
* @param {string} sha The sha of the commit to look for.
|
||||
*
|
||||
* @return {boolean} `true` if the commit `sha` is in the history of the current branch, `false` otherwise.
|
||||
*/
|
||||
async function isCommitInHistory(sha) {
|
||||
return (await execa('git', ['merge-base', '--is-ancestor', sha, 'HEAD'], {reject: false})).code === 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the commit sha for a given version, if it's contained in the given branch.
|
||||
*
|
||||
* @param {string} gitHead The commit sha to look for.
|
||||
* @param {string} version The version corresponding to the commit sha to look for. Used to search in git tags.
|
||||
*
|
||||
* @return {Promise<string>} A Promise that resolves to the commit sha of the version, either `gitHead` of the commit associated with the `version` tag.
|
||||
*
|
||||
* @throws {SemanticReleaseError} with code `ENOTINHISTORY` if `gitHead` or the commit sha dereived from `version` is not in the direct history of `branch`.
|
||||
* @throws {SemanticReleaseError} with code `ENOGITHEAD` if `gitHead` is undefined and no commit sha can be found for the `version`.
|
||||
*/
|
||||
module.exports = async (gitHead, version) => {
|
||||
// Check if gitHead is defined and exists in release branch
|
||||
if (gitHead && (await isCommitInHistory(gitHead))) {
|
||||
return gitHead;
|
||||
}
|
||||
|
||||
// Ushallow the repository
|
||||
await execa('git', ['fetch', '--unshallow', '--tags'], {reject: false});
|
||||
|
||||
// Check if gitHead is defined and exists in release branch again
|
||||
if (gitHead && (await isCommitInHistory(gitHead))) {
|
||||
return gitHead;
|
||||
}
|
||||
|
||||
let tagHead;
|
||||
if (version) {
|
||||
// If a version is defined search a corresponding tag
|
||||
tagHead = (await gitTagHead(`v${version}`)) || (await gitTagHead(version));
|
||||
|
||||
// Check if tagHead is found and exists in release branch again
|
||||
if (tagHead && (await isCommitInHistory(tagHead))) {
|
||||
return tagHead;
|
||||
}
|
||||
}
|
||||
|
||||
// Either gitHead is defined or a tagHead has been found but none is in the branch history
|
||||
if (gitHead || tagHead) {
|
||||
const error = new SemanticReleaseError('Commit not in history', 'ENOTINHISTORY');
|
||||
error.gitHead = gitHead || tagHead;
|
||||
throw error;
|
||||
}
|
||||
|
||||
// There is no gitHead in the last release and there is no tags correponsing to the last release version
|
||||
throw new SemanticReleaseError('There is no commit associated with last release', 'ENOGITHEAD');
|
||||
};
|
||||
@@ -1,4 +1,3 @@
|
||||
/* istanbul ignore next */
|
||||
module.exports = function (config, options, cb) {
|
||||
cb(null)
|
||||
}
|
||||
module.exports = (config, options, cb) => {
|
||||
cb(null);
|
||||
};
|
||||
|
||||
+35
-34
@@ -1,42 +1,43 @@
|
||||
var relative = require('require-relative')
|
||||
var series = require('run-series')
|
||||
const {promisify} = require('util');
|
||||
const relative = require('require-relative');
|
||||
const pSeries = require('p-series');
|
||||
|
||||
var exports = module.exports = function (options) {
|
||||
var plugins = {
|
||||
analyzeCommits: exports.normalize(options.analyzeCommits, '@semantic-release/commit-analyzer'),
|
||||
generateNotes: exports.normalize(options.generateNotes, '@semantic-release/release-notes-generator'),
|
||||
getLastRelease: exports.normalize(options.getLastRelease, '@semantic-release/last-release-npm')
|
||||
}
|
||||
|
||||
;['verifyConditions', 'verifyRelease'].forEach(function (plugin) {
|
||||
module.exports = options => {
|
||||
const plugins = {
|
||||
analyzeCommits: normalize(options.analyzeCommits, '@semantic-release/commit-analyzer'),
|
||||
generateNotes: normalize(options.generateNotes, '@semantic-release/release-notes-generator'),
|
||||
getLastRelease: normalize(options.getLastRelease, '@semantic-release/last-release-npm'),
|
||||
};
|
||||
['verifyConditions', 'verifyRelease'].forEach(plugin => {
|
||||
if (!Array.isArray(options[plugin])) {
|
||||
plugins[plugin] = exports.normalize(
|
||||
options[plugin],
|
||||
plugin === 'verifyConditions'
|
||||
? '@semantic-release/condition-travis'
|
||||
: './plugin-noop'
|
||||
)
|
||||
return
|
||||
plugins[plugin] = promisify(
|
||||
normalize(
|
||||
options[plugin],
|
||||
plugin === 'verifyConditions' ? '@semantic-release/condition-travis' : './plugin-noop'
|
||||
)
|
||||
);
|
||||
} else {
|
||||
plugins[plugin] = async pluginOptions => {
|
||||
return pSeries(
|
||||
options[plugin].map(step => {
|
||||
return () => promisify(normalize(step, './plugin-noop'))(pluginOptions);
|
||||
})
|
||||
);
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
plugins[plugin] = function (pluginOptions, cb) {
|
||||
var tasks = options[plugin].map(function (step) {
|
||||
return exports.normalize(step, './plugin-noop').bind(null, pluginOptions)
|
||||
})
|
||||
return plugins;
|
||||
};
|
||||
|
||||
series(tasks, cb)
|
||||
}
|
||||
})
|
||||
const normalize = (pluginConfig, fallback) => {
|
||||
if (typeof pluginConfig === 'string') return relative(pluginConfig).bind(null, {});
|
||||
|
||||
return plugins
|
||||
}
|
||||
|
||||
exports.normalize = function (pluginConfig, fallback) {
|
||||
if (typeof pluginConfig === 'string') return relative(pluginConfig).bind(null, {})
|
||||
|
||||
if (pluginConfig && (typeof pluginConfig.path === 'string')) {
|
||||
return relative(pluginConfig.path).bind(null, pluginConfig)
|
||||
if (pluginConfig && typeof pluginConfig.path === 'string') {
|
||||
return relative(pluginConfig.path).bind(null, pluginConfig);
|
||||
}
|
||||
|
||||
return require(fallback).bind(null, pluginConfig)
|
||||
}
|
||||
return require(fallback).bind(null, pluginConfig || {});
|
||||
};
|
||||
|
||||
module.exports.normalize = normalize;
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
var SemanticReleaseError = require('@semantic-release/error')
|
||||
|
||||
module.exports = function (config, cb) {
|
||||
var plugins = config.plugins
|
||||
var lastRelease = config.lastRelease
|
||||
|
||||
plugins.analyzeCommits(config, function (err, type) {
|
||||
if (err) return cb(err)
|
||||
|
||||
if (!type) {
|
||||
return cb(new SemanticReleaseError(
|
||||
'There are no relevant changes, so no new version is released.',
|
||||
'ENOCHANGE'
|
||||
))
|
||||
}
|
||||
|
||||
if (!lastRelease.version) return cb(null, 'initial')
|
||||
|
||||
cb(null, type)
|
||||
})
|
||||
}
|
||||
+14
-29
@@ -1,40 +1,25 @@
|
||||
var SemanticReleaseError = require('@semantic-release/error')
|
||||
const SemanticReleaseError = require('@semantic-release/error');
|
||||
|
||||
module.exports = function (config) {
|
||||
var pkg = config.pkg
|
||||
var options = config.options
|
||||
var env = config.env
|
||||
var errors = []
|
||||
module.exports = ({pkg, options, env}) => {
|
||||
const errors = [];
|
||||
|
||||
if (!pkg.name) {
|
||||
errors.push(new SemanticReleaseError(
|
||||
'No "name" found in package.json.',
|
||||
'ENOPKGNAME'
|
||||
))
|
||||
errors.push(new SemanticReleaseError('No "name" found in package.json.', 'ENOPKGNAME'));
|
||||
}
|
||||
|
||||
if (!pkg.repository || !pkg.repository.url) {
|
||||
errors.push(new SemanticReleaseError(
|
||||
'No "repository" found in package.json.',
|
||||
'ENOPKGREPO'
|
||||
))
|
||||
errors.push(new SemanticReleaseError('No "repository" found in package.json.', 'ENOPKGREPO'));
|
||||
}
|
||||
|
||||
if (options.debug) return errors
|
||||
if (!options.debug) {
|
||||
if (!options.githubToken) {
|
||||
errors.push(new SemanticReleaseError('No github token specified.', 'ENOGHTOKEN'));
|
||||
}
|
||||
|
||||
if (!options.githubToken) {
|
||||
errors.push(new SemanticReleaseError(
|
||||
'No github token specified.',
|
||||
'ENOGHTOKEN'
|
||||
))
|
||||
if (!(env.NPM_TOKEN || (env.NPM_OLD_TOKEN && env.NPM_EMAIL))) {
|
||||
errors.push(new SemanticReleaseError('No npm token specified.', 'ENONPMTOKEN'));
|
||||
}
|
||||
}
|
||||
|
||||
if (!(env.NPM_TOKEN || (env.NPM_OLD_TOKEN && env.NPM_EMAIL))) {
|
||||
errors.push(new SemanticReleaseError(
|
||||
'No npm token specified.',
|
||||
'ENONPMTOKEN'
|
||||
))
|
||||
}
|
||||
|
||||
return errors
|
||||
}
|
||||
return errors;
|
||||
};
|
||||
|
||||
+31
-47
@@ -1,54 +1,38 @@
|
||||
var url = require('url')
|
||||
const {promisify} = require('util');
|
||||
const url = require('url');
|
||||
const gitHead = require('git-head');
|
||||
const GitHubApi = require('github');
|
||||
const parseSlug = require('parse-github-repo-url');
|
||||
|
||||
var gitHead = require('git-head')
|
||||
var GitHubApi = require('github')
|
||||
var parseSlug = require('@bahmutov/parse-github-repo-url')
|
||||
module.exports = async config => {
|
||||
const {pkg, options: {branch, debug, githubUrl, githubToken, githubApiPathPrefix}, plugins} = config;
|
||||
const [owner, repo] = parseSlug(pkg.repository.url);
|
||||
const name = `v${pkg.version}`;
|
||||
const tag = {owner, repo, ref: `refs/tags/${name}`, sha: await promisify(gitHead)()};
|
||||
const body = await promisify(plugins.generateNotes)(config);
|
||||
const release = {owner, repo, tag_name: name, name, target_commitish: branch, draft: !!debug, body};
|
||||
|
||||
module.exports = function (config, cb) {
|
||||
var pkg = config.pkg
|
||||
var options = config.options
|
||||
var plugins = config.plugins
|
||||
var ghConfig = options.githubUrl ? url.parse(options.githubUrl) : {}
|
||||
if (debug && !githubToken) {
|
||||
return {published: false, release};
|
||||
}
|
||||
|
||||
var github = new GitHubApi({
|
||||
version: '3.0.0',
|
||||
port: ghConfig.port,
|
||||
protocol: (ghConfig.protocol || '').split(':')[0] || null,
|
||||
host: ghConfig.hostname,
|
||||
pathPrefix: options.githubApiPathPrefix || null
|
||||
})
|
||||
const {port, protocol, hostname} = githubUrl ? url.parse(githubUrl) : {};
|
||||
const github = new GitHubApi({
|
||||
port,
|
||||
protocol: (protocol || '').split(':')[0] || null,
|
||||
host: hostname,
|
||||
pathPrefix: githubApiPathPrefix || null,
|
||||
});
|
||||
|
||||
plugins.generateNotes(config, function (err, log) {
|
||||
if (err) return cb(err)
|
||||
github.authenticate({type: 'token', token: githubToken});
|
||||
|
||||
gitHead(function (err, hash) {
|
||||
if (err) return cb(err)
|
||||
if (debug) {
|
||||
await github.repos.createRelease(release);
|
||||
return {published: true, release};
|
||||
}
|
||||
|
||||
var ghRepo = parseSlug(pkg.repository.url)
|
||||
var release = {
|
||||
owner: ghRepo[0],
|
||||
repo: ghRepo[1],
|
||||
name: 'v' + pkg.version,
|
||||
tag_name: 'v' + pkg.version,
|
||||
target_commitish: hash,
|
||||
draft: !!options.debug,
|
||||
body: log
|
||||
}
|
||||
await github.gitdata.createReference(tag);
|
||||
await github.repos.createRelease(release);
|
||||
|
||||
if (options.debug && !options.githubToken) {
|
||||
return cb(null, false, release)
|
||||
}
|
||||
|
||||
github.authenticate({
|
||||
type: 'oauth',
|
||||
token: options.githubToken
|
||||
})
|
||||
|
||||
github.releases.createRelease(release, function (err) {
|
||||
if (err) return cb(err)
|
||||
|
||||
cb(null, true, release)
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
return {published: true, release};
|
||||
};
|
||||
|
||||
+18
-40
@@ -1,45 +1,23 @@
|
||||
var _ = require('lodash')
|
||||
var auto = require('run-auto')
|
||||
var semver = require('semver')
|
||||
const {promisify} = require('util');
|
||||
const {assign} = require('lodash');
|
||||
const semver = require('semver');
|
||||
|
||||
var getCommits = require('./lib/commits')
|
||||
var getType = require('./lib/type')
|
||||
const getCommits = require('./lib/get-commits');
|
||||
const getReleaseType = require('./lib/get-release-type');
|
||||
|
||||
module.exports = function (config, cb) {
|
||||
var plugins = config.plugins
|
||||
module.exports = async config => {
|
||||
const {getLastRelease, verifyRelease} = config.plugins;
|
||||
|
||||
auto({
|
||||
lastRelease: plugins.getLastRelease.bind(null, config),
|
||||
commits: ['lastRelease', function (results, cb) {
|
||||
getCommits(_.assign({
|
||||
lastRelease: results.lastRelease
|
||||
}, config),
|
||||
cb)
|
||||
}],
|
||||
type: ['commits', 'lastRelease', function (results, cb) {
|
||||
getType(_.assign({
|
||||
commits: results.commits,
|
||||
lastRelease: results.lastRelease
|
||||
}, config),
|
||||
cb)
|
||||
}]
|
||||
}, function (err, results) {
|
||||
if (err) return cb(err)
|
||||
const lastRelease = await promisify(getLastRelease)(config);
|
||||
const commits = await getCommits(assign({lastRelease}, config));
|
||||
const type = await getReleaseType(assign({commits, lastRelease}, config));
|
||||
|
||||
var nextRelease = {
|
||||
type: results.type,
|
||||
version: results.type === 'initial'
|
||||
? '1.0.0'
|
||||
: semver.inc(results.lastRelease.version, results.type)
|
||||
}
|
||||
const nextRelease = {
|
||||
type: type,
|
||||
version: type === 'initial' ? '1.0.0' : semver.inc(lastRelease.version, type),
|
||||
};
|
||||
|
||||
plugins.verifyRelease(_.assign({
|
||||
commits: results.commits,
|
||||
lastRelease: results.lastRelease,
|
||||
nextRelease: nextRelease
|
||||
}, config), function (err) {
|
||||
if (err) return cb(err)
|
||||
cb(null, nextRelease)
|
||||
})
|
||||
})
|
||||
}
|
||||
await verifyRelease(assign({commits, lastRelease, nextRelease}, config));
|
||||
|
||||
return nextRelease;
|
||||
};
|
||||
|
||||
Vendored
+3
@@ -0,0 +1,3 @@
|
||||
module.exports = function(config, options, cb) {
|
||||
cb(new Error('a'));
|
||||
};
|
||||
Vendored
+3
@@ -0,0 +1,3 @@
|
||||
module.exports = function(config, options, cb) {
|
||||
cb(new Error('b'));
|
||||
};
|
||||
Vendored
+3
@@ -0,0 +1,3 @@
|
||||
module.exports = function(config, options, cb) {
|
||||
cb(null, 'a');
|
||||
};
|
||||
Vendored
+3
@@ -0,0 +1,3 @@
|
||||
module.exports = function(config, options, cb) {
|
||||
cb(null, 'b');
|
||||
};
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
module.exports = function(pluginConfig, options, cb) {
|
||||
cb(null, {pluginConfig, options});
|
||||
};
|
||||
@@ -0,0 +1,383 @@
|
||||
import test from 'ava';
|
||||
import {
|
||||
gitRepo,
|
||||
gitCommits,
|
||||
gitCheckout,
|
||||
gitTagVersion,
|
||||
gitShallowClone,
|
||||
gitTags,
|
||||
gitLog,
|
||||
gitDetachedHead,
|
||||
} from './helpers/git-utils';
|
||||
import proxyquire from 'proxyquire';
|
||||
import {stub} from 'sinon';
|
||||
import SemanticReleaseError from '@semantic-release/error';
|
||||
|
||||
// Stub to capture the log messages
|
||||
const errorLog = stub();
|
||||
// Module to test
|
||||
const getCommits = proxyquire('../src/lib/get-commits', {npmlog: {error: errorLog}});
|
||||
|
||||
test.beforeEach(t => {
|
||||
// Save the current working diretory
|
||||
t.context.cwd = process.cwd();
|
||||
// Reset the stub call history
|
||||
errorLog.resetHistory();
|
||||
});
|
||||
|
||||
test.afterEach.always(t => {
|
||||
// Restore the current working directory
|
||||
process.chdir(t.context.cwd);
|
||||
});
|
||||
|
||||
test.serial('Get all commits when there is no last release', async t => {
|
||||
// Create a git repository, set the current working directory at the root of the repo
|
||||
await gitRepo();
|
||||
// Add commits to the master branch
|
||||
const commits = await gitCommits(['First', 'Second']);
|
||||
|
||||
// Retrieve the commits with the commits module
|
||||
const result = await getCommits({lastRelease: {}, options: {branch: 'master'}});
|
||||
|
||||
// Verify the commits created and retrieved by the module are identical
|
||||
t.is(result.length, 2);
|
||||
t.is(result[0].hash.substring(0, 7), commits[0].hash);
|
||||
t.is(result[0].message, commits[0].message);
|
||||
t.is(result[1].hash.substring(0, 7), commits[1].hash);
|
||||
t.is(result[1].message, commits[1].message);
|
||||
});
|
||||
|
||||
test.serial('Get all commits when there is no last release, including the ones not in the shallow clone', 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
|
||||
const commits = await gitCommits(['First', 'Second']);
|
||||
// Create a shallow clone with only 1 commit
|
||||
await gitShallowClone(repo);
|
||||
|
||||
// Verify the shallow clone contains only one commit
|
||||
t.is((await gitLog()).length, 1);
|
||||
|
||||
// Retrieve the commits with the commits module
|
||||
const result = await getCommits({lastRelease: {}, options: {branch: 'master'}});
|
||||
|
||||
// Verify the commits created and retrieved by the module are identical
|
||||
t.is(result.length, 2);
|
||||
t.is(result[0].hash.substring(0, 7), commits[0].hash);
|
||||
t.is(result[0].message, commits[0].message);
|
||||
t.is(result[1].hash.substring(0, 7), commits[1].hash);
|
||||
t.is(result[1].message, commits[1].message);
|
||||
});
|
||||
|
||||
test.serial('Get all commits since gitHead (from lastRelease)', async t => {
|
||||
// Create a git repository, set the current working directory at the root of the repo
|
||||
await gitRepo();
|
||||
// Add commits to the master branch
|
||||
const commits = await gitCommits(['First', 'Second', 'Third']);
|
||||
|
||||
// Retrieve the commits with the commits module, since commit 'First'
|
||||
const result = await getCommits({
|
||||
lastRelease: {gitHead: commits[commits.length - 1].hash},
|
||||
options: {branch: 'master'},
|
||||
});
|
||||
|
||||
// Verify the commits created and retrieved by the module are identical
|
||||
t.is(result.length, 2);
|
||||
t.is(result[0].hash.substring(0, 7), commits[0].hash);
|
||||
t.is(result[0].message, commits[0].message);
|
||||
t.is(result[1].hash.substring(0, 7), commits[1].hash);
|
||||
t.is(result[1].message, commits[1].message);
|
||||
});
|
||||
|
||||
test.serial('Get all commits since gitHead (from lastRelease) on a detached head repo', 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
|
||||
const commits = await gitCommits(['First', 'Second', 'Third']);
|
||||
// Create a detached head repo at commit 'feat: Second'
|
||||
await gitDetachedHead(repo, commits[1].hash);
|
||||
|
||||
// Retrieve the commits with the commits module, since commit 'First'
|
||||
const result = await getCommits({
|
||||
lastRelease: {gitHead: commits[commits.length - 1].hash},
|
||||
options: {branch: 'master'},
|
||||
});
|
||||
|
||||
// Verify the module retrieved only the commit 'feat: Second' (included in the detached and after 'fix: First')
|
||||
t.is(result.length, 1);
|
||||
t.is(result[0].hash.substring(0, 7), commits[1].hash);
|
||||
t.is(result[0].message, commits[1].message);
|
||||
});
|
||||
|
||||
test.serial('Get all commits since gitHead (from tag) ', async t => {
|
||||
// Create a git repository, set the current working directory at the root of the repo
|
||||
await gitRepo();
|
||||
// Add commits to the master branch
|
||||
let commits = await gitCommits(['First']);
|
||||
// Create the tag corresponding to version 1.0.0
|
||||
await gitTagVersion('1.0.0');
|
||||
// Add new commits to the master branch
|
||||
commits = (await gitCommits(['Second', 'Third'])).concat(commits);
|
||||
|
||||
// Retrieve the commits with the commits module, since commit 'First' (associated with tag v1.0.0)
|
||||
const result = await getCommits({lastRelease: {version: '1.0.0'}, options: {branch: 'master'}});
|
||||
|
||||
// Verify the commits created and retrieved by the module are identical
|
||||
t.is(result.length, 2);
|
||||
t.is(result[0].hash.substring(0, 7), commits[0].hash);
|
||||
t.is(result[0].message, commits[0].message);
|
||||
t.is(result[1].hash.substring(0, 7), commits[1].hash);
|
||||
t.is(result[1].message, commits[1].message);
|
||||
});
|
||||
|
||||
test.serial('Get all commits since gitHead (from tag) on a detached head repo', 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
|
||||
let commits = await gitCommits(['First']);
|
||||
// Create the tag corresponding to version 1.0.0
|
||||
await gitTagVersion('1.0.0');
|
||||
// Add new commits to the master branch
|
||||
commits = (await gitCommits(['Second', 'Third'])).concat(commits);
|
||||
// Create a detached head repo at commit 'feat: Second'
|
||||
await gitDetachedHead(repo, commits[1].hash);
|
||||
|
||||
// Retrieve the commits with the commits module, since commit 'First' (associated with tag 1.0.0)
|
||||
const result = await getCommits({lastRelease: {version: '1.0.0'}, options: {branch: 'master'}});
|
||||
|
||||
// Verify the module retrieved only the commit 'feat: Second' (included in the detached and after 'fix: First')
|
||||
t.is(result.length, 1);
|
||||
t.is(result[0].hash.substring(0, 7), commits[1].hash);
|
||||
t.is(result[0].message, commits[1].message);
|
||||
});
|
||||
|
||||
test.serial('Get all commits since gitHead (from tag formatted like v<version>) ', async t => {
|
||||
// Create a git repository, set the current working directory at the root of the repo
|
||||
await gitRepo();
|
||||
// Add commits to the master branch
|
||||
let commits = await gitCommits(['First']);
|
||||
// Create the tag corresponding to version 1.0.0
|
||||
await gitTagVersion('v1.0.0');
|
||||
// Add new commits to the master branch
|
||||
commits = (await gitCommits(['Second', 'Third'])).concat(commits);
|
||||
|
||||
// Retrieve the commits with the commits module, since commit 'First' (associated with tag v1.0.0)
|
||||
const result = await getCommits({lastRelease: {version: '1.0.0'}, options: {branch: 'master'}});
|
||||
|
||||
// Verify the commits created and retrieved by the module are identical
|
||||
t.is(result.length, 2);
|
||||
t.is(result[0].hash.substring(0, 7), commits[0].hash);
|
||||
t.is(result[0].message, commits[0].message);
|
||||
t.is(result[1].hash.substring(0, 7), commits[1].hash);
|
||||
t.is(result[1].message, commits[1].message);
|
||||
});
|
||||
|
||||
test.serial('Get commits when last release gitHead is missing but a tag match the version', async t => {
|
||||
// Create a git repository, set the current working directory at the root of the repo
|
||||
await gitRepo();
|
||||
// Add commits to the master branch
|
||||
let commits = await gitCommits(['First']);
|
||||
// Create the tag corresponding to version 1.0.0
|
||||
await gitTagVersion('v1.0.0');
|
||||
// Add new commits to the master branch
|
||||
commits = (await gitCommits(['Second', 'Third'])).concat(commits);
|
||||
|
||||
// Retrieve the commits with the commits module, since commit 'First' (associated with tag v1.0.0)
|
||||
const result = await getCommits({lastRelease: {version: '1.0.0', gitHead: 'missing'}, options: {branch: 'master'}});
|
||||
|
||||
// Verify the commits created and retrieved by the module are identical
|
||||
t.is(result.length, 2);
|
||||
t.is(result[0].hash.substring(0, 7), commits[0].hash);
|
||||
t.is(result[0].message, commits[0].message);
|
||||
t.is(result[1].hash.substring(0, 7), commits[1].hash);
|
||||
t.is(result[1].message, commits[1].message);
|
||||
});
|
||||
|
||||
test.serial('Get all commits since gitHead, when gitHead are mising from the shallow clone', 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
|
||||
const commits = await gitCommits(['First', 'Second', 'Third']);
|
||||
// Create a shallow clone with only 1 commit and no tags
|
||||
await gitShallowClone(repo);
|
||||
|
||||
// Retrieve the commits with the commits module, since commit 'First'
|
||||
const result = await getCommits({
|
||||
lastRelease: {version: '1.0.0', gitHead: commits[commits.length - 1].hash},
|
||||
options: {branch: 'master'},
|
||||
});
|
||||
|
||||
// Verify the commits created and retrieved by the module are identical
|
||||
t.is(result.length, 2);
|
||||
t.is(result[0].hash.substring(0, 7), commits[0].hash);
|
||||
t.is(result[0].message, commits[0].message);
|
||||
t.is(result[1].hash.substring(0, 7), commits[1].hash);
|
||||
t.is(result[1].message, commits[1].message);
|
||||
});
|
||||
|
||||
test.serial('Get all commits since gitHead from tag, when tags are mising from the shallow clone', 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
|
||||
let commits = await gitCommits(['First']);
|
||||
// Create the tag corresponding to version 1.0.0
|
||||
await gitTagVersion('v1.0.0');
|
||||
// Add new commits to the master branch
|
||||
commits = (await gitCommits(['Second', 'Third'])).concat(commits);
|
||||
// Create a shallow clone with only 1 commit and no tags
|
||||
await gitShallowClone(repo);
|
||||
|
||||
// Verify the shallow clone does not contains any tags
|
||||
t.is((await gitTags()).length, 0);
|
||||
|
||||
// Retrieve the commits with the commits module, since commit 'First' (associated with tag v1.0.0)
|
||||
const result = await getCommits({lastRelease: {version: '1.0.0'}, options: {branch: 'master'}});
|
||||
|
||||
// Verify the commits created and retrieved by the module are identical
|
||||
t.is(result.length, 2);
|
||||
t.is(result[0].hash.substring(0, 7), commits[0].hash);
|
||||
t.is(result[0].message, commits[0].message);
|
||||
t.is(result[1].hash.substring(0, 7), commits[1].hash);
|
||||
t.is(result[1].message, commits[1].message);
|
||||
});
|
||||
|
||||
test.serial('Return empty array if lastRelease.gitHead is the last commit', async t => {
|
||||
// Create a git repository, set the current working directory at the root of the repo
|
||||
await gitRepo();
|
||||
// Add commits to the master branch
|
||||
const commits = await gitCommits(['First', 'Second']);
|
||||
|
||||
// Retrieve the commits with the commits module, since commit 'Second' (therefore none)
|
||||
const result = await getCommits({lastRelease: {gitHead: commits[0].hash}, options: {branch: 'master'}});
|
||||
|
||||
// Verify no commit is retrieved
|
||||
t.deepEqual(result, []);
|
||||
});
|
||||
|
||||
test.serial('Return empty array if there is no commits', async t => {
|
||||
// Create a git repository, set the current working directory at the root of the repo
|
||||
await gitRepo();
|
||||
|
||||
// Retrieve the commits with the commits module
|
||||
const result = await getCommits({lastRelease: {}, options: {branch: 'master'}});
|
||||
|
||||
// Verify no commit is retrieved
|
||||
t.deepEqual(result, []);
|
||||
});
|
||||
|
||||
test.serial('Throws ENOGITHEAD error if the gitHead of the last release cannot be found', async t => {
|
||||
// Create a git repository, set the current working directory at the root of the repo
|
||||
await gitRepo();
|
||||
// Add commits to the master branch
|
||||
await gitCommits(['First', 'Second']);
|
||||
|
||||
// Retrieve the commits with the commits module
|
||||
const error = await t.throws(getCommits({lastRelease: {version: '1.0.0'}, options: {branch: 'master'}}));
|
||||
|
||||
// Verify error code and message
|
||||
t.is(error.code, 'ENOGITHEAD');
|
||||
t.true(error instanceof SemanticReleaseError);
|
||||
// Verify the log function has been called with a message explaining the error
|
||||
t.regex(
|
||||
errorLog.firstCall.args[1],
|
||||
/The commit the last release of this package was derived from cannot be determined from the release metadata not from the repository tags/
|
||||
);
|
||||
});
|
||||
|
||||
test.serial('Throws ENOTINHISTORY error if gitHead is not in history', async t => {
|
||||
// Create a git repository, set the current working directory at the root of the repo
|
||||
await gitRepo();
|
||||
// Add commits to the master branch
|
||||
await gitCommits(['First', 'Second']);
|
||||
|
||||
// Retrieve the commits with the commits module
|
||||
const error = await t.throws(getCommits({lastRelease: {gitHead: 'notinhistory'}, options: {branch: 'master'}}));
|
||||
|
||||
// Verify error code and message
|
||||
t.is(error.code, 'ENOTINHISTORY');
|
||||
t.true(error instanceof SemanticReleaseError);
|
||||
// Verify the log function has been called with a message mentionning the branch
|
||||
t.regex(errorLog.firstCall.args[1], /history of the "master" branch/);
|
||||
// Verify the log function has been called with a message mentionning the missing gitHead
|
||||
t.regex(errorLog.firstCall.args[1], /restoring the commit "notinhistory"/);
|
||||
});
|
||||
|
||||
test.serial('Throws ENOTINHISTORY error if gitHead is not in branch history but present in others', async t => {
|
||||
// Create a git repository, set the current working directory at the root of the repo
|
||||
await gitRepo();
|
||||
// Add commits to the master branch
|
||||
await gitCommits(['First', 'Second']);
|
||||
// Create the new branch 'other-branch' from master
|
||||
await gitCheckout('other-branch');
|
||||
// Add commits to the 'other-branch' branch
|
||||
const commitsBranch = await gitCommits(['Third', 'Fourth']);
|
||||
await gitCheckout('master', false);
|
||||
|
||||
// Retrieve the commits with the commits module
|
||||
const error = await t.throws(
|
||||
getCommits({lastRelease: {version: '1.0.1', gitHead: commitsBranch[0].hash}, options: {branch: 'master'}})
|
||||
);
|
||||
|
||||
// Verify error code and message
|
||||
t.is(error.code, 'ENOTINHISTORY');
|
||||
t.true(error instanceof SemanticReleaseError);
|
||||
// Verify the log function has been called with a message mentionning the branch
|
||||
t.regex(errorLog.firstCall.args[1], /history of the "master" branch/);
|
||||
// Verify the log function has been called with a message mentionning the missing gitHead
|
||||
t.regex(errorLog.firstCall.args[1], new RegExp(`restoring the commit "${commitsBranch[0].hash}"`));
|
||||
});
|
||||
|
||||
test.serial('Throws ENOTINHISTORY error if gitHead is not in detached head but present in other branch', async t => {
|
||||
// Create a git repository, set the current working directory at the root of the repo
|
||||
const repo = await gitRepo();
|
||||
// Add commit to the master branch
|
||||
await gitCommits(['First']);
|
||||
// Create the new branch 'other-branch' from master
|
||||
await gitCheckout('other-branch');
|
||||
// Add commits to the 'other-branch' branch
|
||||
const commitsBranch = await gitCommits(['Second', 'Third']);
|
||||
await gitCheckout('master', false);
|
||||
// Add new commit to master branch
|
||||
const commitsMaster = await gitCommits(['Fourth']);
|
||||
// Create a detached head repo at commit 'Fourth'
|
||||
await gitDetachedHead(repo, commitsMaster[0].hash);
|
||||
|
||||
// Retrieve the commits with the commits module, since commit 'Second'
|
||||
const error = await t.throws(
|
||||
getCommits({lastRelease: {version: '1.0.1', gitHead: commitsBranch[0].hash}, options: {branch: 'master'}})
|
||||
);
|
||||
|
||||
// Verify error code and message
|
||||
t.is(error.code, 'ENOTINHISTORY');
|
||||
t.true(error instanceof SemanticReleaseError);
|
||||
// Verify the log function has been called with a message mentionning the branch
|
||||
t.regex(errorLog.firstCall.args[1], /history of the "master" branch/);
|
||||
// Verify the log function has been called with a message mentionning the missing gitHead
|
||||
t.regex(errorLog.firstCall.args[1], new RegExp(`restoring the commit "${commitsBranch[0].hash}"`));
|
||||
});
|
||||
|
||||
test.serial('Throws ENOTINHISTORY error when a tag is not in branch history but present in others', async t => {
|
||||
// Create a git repository, set the current working directory at the root of the repo
|
||||
await gitRepo();
|
||||
// Add commits to the master branch
|
||||
await gitCommits(['First', 'Second']);
|
||||
// Create the new branch 'other-branch' from master
|
||||
await gitCheckout('other-branch');
|
||||
// Add commits to the 'other-branch' branch
|
||||
await gitCommits(['Third']);
|
||||
// Create the tag corresponding to version 1.0.0
|
||||
const shaTag = await gitTagVersion('v1.0.0');
|
||||
await gitCheckout('master', false);
|
||||
// Add new commit to the master branch
|
||||
await gitCommits(['Forth']);
|
||||
|
||||
// Retrieve the commits with the commits module
|
||||
const error = await t.throws(getCommits({lastRelease: {version: '1.0.0'}, options: {branch: 'master'}}));
|
||||
// Verify error code and message
|
||||
t.is(error.code, 'ENOTINHISTORY');
|
||||
t.true(error instanceof SemanticReleaseError);
|
||||
// Verify the log function has been called with a message mentionning the branch
|
||||
t.regex(errorLog.firstCall.args[1], /history of the "master" branch/);
|
||||
// Verify the log function has been called with a message mentionning the missing gitHead
|
||||
t.regex(errorLog.firstCall.args[1], new RegExp(`restoring the commit "${shaTag}"`));
|
||||
});
|
||||
@@ -0,0 +1,82 @@
|
||||
import test from 'ava';
|
||||
import {stub} from 'sinon';
|
||||
const getRegistry = require('../src/lib/get-registry');
|
||||
|
||||
test('Get registry from package.json', t => {
|
||||
// Retrieve the registry with the get-registry module and verify it returns the one from the package.json in parameter
|
||||
t.is(getRegistry({name: 'publish-config', publishConfig: {registry: 'a'}}, {}), 'a');
|
||||
});
|
||||
|
||||
test('Prioritize the package.json registry config', t => {
|
||||
// Stub the npmconf object
|
||||
const get = stub();
|
||||
|
||||
// Retrieve the registry with the get-registry module and verify it returns the one from the package.json in parameter
|
||||
t.is(getRegistry({name: 'publish-config', publishConfig: {registry: 'b'}}, {get}), 'b');
|
||||
|
||||
// Verify the registry has been retrieved from the package.json without trying the stubbed npmconf
|
||||
t.true(get.notCalled);
|
||||
});
|
||||
|
||||
test('Get registry for regular package name', t => {
|
||||
// Stub the npmconf object returns 'b' for 'registry' property
|
||||
const get = stub()
|
||||
.withArgs('registry')
|
||||
.returns('b');
|
||||
|
||||
// Retrieve the registry with the get-registry module and verify it returns the one configured in the stubbed npmconf
|
||||
t.is(getRegistry({name: 'normal'}, {get}), 'b');
|
||||
|
||||
// Verify the registry has been retrieved by calling the stubbed npmconf
|
||||
t.true(get.calledWithExactly('registry'));
|
||||
});
|
||||
|
||||
test('Get default registry', t => {
|
||||
// Stub the npmconf object, returns 'null'
|
||||
const get = stub().returns(null);
|
||||
|
||||
// Retrieve the registry with the get-registry module and verify it returns default one
|
||||
t.is(getRegistry({name: 'normal'}, {get}), 'https://registry.npmjs.org/');
|
||||
|
||||
// Verify the module tried first to retrieve the registry by calling the stubbed npmconf
|
||||
t.true(get.calledWithExactly('registry'));
|
||||
});
|
||||
|
||||
test('Get registry for scoped package name', t => {
|
||||
// Stub the npmconf object, returns 'c' for '@scoped/registry' property
|
||||
const get = stub()
|
||||
.withArgs('@scoped/registry')
|
||||
.returns('c');
|
||||
|
||||
// Retrieve the registry with the get-registry module and verify it returns the one configured in the stubbed npmconf
|
||||
t.is(getRegistry({name: '@scoped/foo'}, {get}), 'c');
|
||||
|
||||
// Verify the registry for the scope '@scoped' has been retrieved by calling the stubbed npmconf
|
||||
t.true(get.calledWithExactly('@scoped/registry'));
|
||||
});
|
||||
|
||||
test('Get regular registry for scoped package name', t => {
|
||||
// Stub the npmconf object, returns 'd' for 'registry' property
|
||||
const get = stub()
|
||||
.withArgs('registry')
|
||||
.returns('d');
|
||||
|
||||
// Retrieve the registry with the get-registry module and verify it returns the regular default one for `@scoped` packages
|
||||
t.is(getRegistry({name: '@scoped/baz'}, {get}), 'd');
|
||||
|
||||
// Verify the module tried to retrieve the @scoped registry by calling the stubbed npmconf
|
||||
t.true(get.calledWithExactly('@scoped/registry'));
|
||||
});
|
||||
|
||||
test('Get default registry for scoped package name', t => {
|
||||
// Stub the npmconf object, returns 'd' for 'registry' property
|
||||
const get = stub().returns(null);
|
||||
|
||||
// Retrieve the registry with the get-registry module and verify it returns default one for `@scoped` packages
|
||||
t.is(getRegistry({name: '@scoped/baz'}, {get}), 'https://registry.npmjs.org/');
|
||||
|
||||
// Verify the module tried to retrieve the @scoped registry by calling the stubbed npmconf
|
||||
t.true(get.calledWithExactly('@scoped/registry'));
|
||||
// Verify the module tried to retrieve the regular registry by calling the stubbed npmconf
|
||||
t.true(get.calledWithExactly('registry'));
|
||||
});
|
||||
@@ -0,0 +1,87 @@
|
||||
import {callbackify} from 'util';
|
||||
import test from 'ava';
|
||||
import {stub} from 'sinon';
|
||||
import SemanticReleaseError from '@semantic-release/error';
|
||||
import getReleaseType from '../src/lib/get-release-type';
|
||||
|
||||
test('Get commit types from commits', async t => {
|
||||
// Stub the commitAnalyzer plugin, returns 'major' release type
|
||||
const analyzeCommits = stub().resolves('major');
|
||||
const commits = [{hash: '0', message: 'a'}];
|
||||
|
||||
// Call the get-release-type module
|
||||
const releaseType = await getReleaseType({
|
||||
commits,
|
||||
lastRelease: {version: '1.0.0'},
|
||||
plugins: {analyzeCommits: callbackify(analyzeCommits)},
|
||||
});
|
||||
|
||||
// Verify the module return the release type obtain from the commitAnalyzer plugin
|
||||
t.is(releaseType, 'major');
|
||||
|
||||
// Verify the commitAnalyzer plugin was called with the commits
|
||||
t.true(analyzeCommits.calledOnce);
|
||||
t.deepEqual(analyzeCommits.firstCall.args[0].commits, commits);
|
||||
});
|
||||
|
||||
test('Throws error when no changes', async t => {
|
||||
// Stub the commitAnalyzer plugin, returns 'null' release type
|
||||
const analyzeCommits = stub().resolves(null);
|
||||
const commits = [{hash: '0', message: 'a'}];
|
||||
|
||||
// Call the get-release-type module and verify it returns an error
|
||||
const error = await t.throws(
|
||||
getReleaseType({
|
||||
commits,
|
||||
lastRelease: {version: '1.0.0'},
|
||||
plugins: {analyzeCommits: callbackify(analyzeCommits)},
|
||||
})
|
||||
);
|
||||
|
||||
// Verify the error code adn type
|
||||
t.is(error.code, 'ENOCHANGE');
|
||||
t.true(error instanceof SemanticReleaseError);
|
||||
|
||||
// Verify the commitAnalyzer plugin was called with the commits
|
||||
t.true(analyzeCommits.calledOnce);
|
||||
t.deepEqual(analyzeCommits.firstCall.args[0].commits, commits);
|
||||
});
|
||||
|
||||
test('Return initial if there is no lastRelease', async t => {
|
||||
// Stub the commitAnalyzer plugin, returns 'major' release type
|
||||
const analyzeCommits = stub().resolves('major');
|
||||
const commits = [{hash: '0', message: 'a'}];
|
||||
|
||||
// Call the get-release-type module
|
||||
const releaseType = await getReleaseType({
|
||||
commits,
|
||||
lastRelease: {},
|
||||
plugins: {analyzeCommits: callbackify(analyzeCommits)},
|
||||
});
|
||||
|
||||
// Verify the module return an initial release type
|
||||
t.is(releaseType, 'initial');
|
||||
|
||||
// Verify the commitAnalyzer plugin was called with the commits
|
||||
t.true(analyzeCommits.calledOnce);
|
||||
t.deepEqual(analyzeCommits.firstCall.args[0].commits, commits);
|
||||
});
|
||||
|
||||
test('Throws error when no changes even if there is no lastRelease', async t => {
|
||||
// Stub the commitAnalyzer plugin, returns 'null' release type
|
||||
const analyzeCommits = stub().resolves(null);
|
||||
const commits = [{hash: '0', message: 'a'}];
|
||||
|
||||
// Call the get-release-type module and verify it returns an error
|
||||
const error = await t.throws(
|
||||
getReleaseType({commits, lastRelease: {}, plugins: {analyzeCommits: callbackify(analyzeCommits)}})
|
||||
);
|
||||
|
||||
// Verify the error code adn type
|
||||
t.is(error.code, 'ENOCHANGE');
|
||||
t.true(error instanceof SemanticReleaseError);
|
||||
|
||||
// Verify the commitAnalyzer plugin was called with the commits
|
||||
t.true(analyzeCommits.calledOnce);
|
||||
t.deepEqual(analyzeCommits.firstCall.args[0].commits, commits);
|
||||
});
|
||||
@@ -0,0 +1,144 @@
|
||||
import {mkdir} from 'fs-extra';
|
||||
import tempy from 'tempy';
|
||||
import execa from 'execa';
|
||||
import pMapSeries from 'p-map-series';
|
||||
|
||||
/**
|
||||
* Commit message informations.
|
||||
*
|
||||
* @typedef {Object} Commit
|
||||
* @property {string} branch The commit branch.
|
||||
* @property {string} hash The commit hash.
|
||||
* @property {string} message The commit message.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Create a temporary git repository and change the current working directory to the repository root.
|
||||
*
|
||||
* @method gitCommits
|
||||
* @param {Array<Commit>} commits the created commits.
|
||||
*
|
||||
* @return {string} The path of the repository.
|
||||
*/
|
||||
export async function gitRepo() {
|
||||
const dir = tempy.directory();
|
||||
|
||||
process.chdir(dir);
|
||||
await mkdir('git-templates');
|
||||
await execa('git', ['init', '--template=./git-templates']);
|
||||
await gitCheckout('master');
|
||||
return dir;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create commits on the current git repository.
|
||||
*
|
||||
* @param {Array<string>} messages commit messages.
|
||||
*
|
||||
* @returns {Array<Commit>} The created commits, in reverse order (to match `git log` order).
|
||||
*/
|
||||
export async function gitCommits(messages) {
|
||||
return (await pMapSeries(messages, async msg => {
|
||||
const {stdout} = await execa('git', ['commit', '-m', msg, '--allow-empty', '--no-gpg-sign']);
|
||||
const [, branch, hash, message] = /^\[(\w+)\(?.*?\)?(\w+)\] (.+)$/.exec(stdout);
|
||||
return {branch, hash, message};
|
||||
})).reverse();
|
||||
}
|
||||
|
||||
/**
|
||||
* Amend a commit (rewriting the sha) on the current git repository.
|
||||
*
|
||||
* @param {string} messages commit message.
|
||||
*
|
||||
* @returns {Array<Commit>} the created commits.
|
||||
*/
|
||||
export async function gitAmmendCommit(msg) {
|
||||
const {stdout} = await execa('git', ['commit', '--amend', '-m', msg, '--allow-empty']);
|
||||
const [, branch, hash, message] = /^\[(\w+)\(?.*?\)?(\w+)\] (.+)(.|\s)+$/.exec(stdout);
|
||||
return {branch, hash, message};
|
||||
}
|
||||
|
||||
/**
|
||||
* Checkout a branch on the current git repository.
|
||||
*
|
||||
* @param {string} branch Branch name.
|
||||
* @param {boolean} create `true` to create the branche ans switch, `false` to only switch.
|
||||
*/
|
||||
export async function gitCheckout(branch, create = true) {
|
||||
await execa('git', create ? ['checkout', '-b', branch] : ['checkout', branch]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {string} The sha of the head commit in the current git repository.
|
||||
*/
|
||||
export async function gitHead() {
|
||||
return (await execa('git', ['rev-parse', 'HEAD'])).stdout;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a tag on the head commit in the current git repository.
|
||||
*
|
||||
* @param {string} tagName The tag name to create.
|
||||
* @param {string} [sha] The commit on which to create the tag. If undefined the tag is created on the last commit.
|
||||
*
|
||||
* @return {string} The commit sha of the created tag.
|
||||
*/
|
||||
export async function gitTagVersion(tagName, sha) {
|
||||
await execa('git', sha ? ['tag', '-f', tagName, sha] : ['tag', tagName]);
|
||||
return (await execa('git', ['rev-list', '-1', '--tags', tagName])).stdout;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {Array<string>} The list of tags from the current git repository.
|
||||
*/
|
||||
export async function gitTags() {
|
||||
return (await execa('git', ['tag'])).stdout.split('\n').filter(tag => !!tag);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {Array<string>} The list of commit sha from the current git repository.
|
||||
*/
|
||||
export async function gitLog() {
|
||||
return (await execa('git', ['log', '--format=format:%H'])).stdout.split('\n').filter(sha => !!sha);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a shallow clone of a git repository and change the current working directory to the cloned repository root.
|
||||
* The shallow will contain a limited number of commit and no tags.
|
||||
*
|
||||
* @param {string} origin The path of the repository to clone.
|
||||
* @param {number} [depth=1] The number of commit to clone.
|
||||
* @return {string} The path of the cloned repository.
|
||||
*/
|
||||
export async function gitShallowClone(origin, branch = 'master', depth = 1) {
|
||||
const dir = tempy.directory();
|
||||
|
||||
process.chdir(dir);
|
||||
await execa('git', ['clone', '--no-hardlinks', '--no-tags', '-b', branch, '--depth', depth, `file://${origin}`, dir]);
|
||||
return dir;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a git repo with a detached head from another git repository and change the current working directory to the new repository root.
|
||||
*
|
||||
* @param {string} origin The path of the repository to clone.
|
||||
* @param {number} head A commit sha of the origin repo that will become the detached head of the new one.
|
||||
* @return {string} The path of the new repository.
|
||||
*/
|
||||
export async function gitDetachedHead(origin, head) {
|
||||
const dir = tempy.directory();
|
||||
|
||||
process.chdir(dir);
|
||||
await execa('git', ['init']);
|
||||
await execa('git', ['remote', 'add', 'origin', origin]);
|
||||
await execa('git', ['fetch']);
|
||||
await execa('git', ['checkout', head]);
|
||||
return dir;
|
||||
}
|
||||
|
||||
/**
|
||||
* Pack heads and tags of the current git repository.
|
||||
*/
|
||||
export async function gitPackRefs() {
|
||||
await execa('git', ['pack-refs', '--all']);
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
import nock from 'nock';
|
||||
|
||||
export function authenticate(
|
||||
{githubToken = 'GH_TOKEN', githubUrl = 'https://api.github.com', githubApiPathPrefix = ''} = {}
|
||||
) {
|
||||
return nock(`${githubUrl}/${githubApiPathPrefix}`, {reqheaders: {Authorization: `token ${githubToken}`}});
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import execa from 'execa';
|
||||
|
||||
const opts = {cwd: __dirname};
|
||||
|
||||
export const uri =
|
||||
'http://localhost:' + (process.env.TRAVIS === 'true' ? 5984 : 15986) + '/registry/_design/app/_rewrite/';
|
||||
|
||||
export function start() {
|
||||
return execa('./start.sh', opts);
|
||||
}
|
||||
|
||||
export function stop() {
|
||||
return execa('./stop.sh', opts);
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
database_dir = data
|
||||
view_index_dir = data
|
||||
delayed_commits = false
|
||||
uuid = bf4ecd84a7c89d60b5b2540fdf8c322c
|
||||
|
||||
[couch_httpd_auth]
|
||||
public_fields = appdotnet, avatar, avatarMedium, avatarLarge, date, email, fields, freenode, fullname, github, homepage, name, roles, twitter, type, _id, _rev
|
||||
@@ -37,4 +37,5 @@ export DEPLOY_VERSION=nope
|
||||
# setup npm-registry-couchapp
|
||||
npm explore npm-registry-couchapp -- npm start --npm-registry-couchapp:couch=$COUCH/registry
|
||||
npm explore npm-registry-couchapp -- npm run load --npm-registry-couchapp:couch=$COUCH/registry
|
||||
npm explore npm-registry-couchapp -- NO_PROMPT=yes npm run copy --npm-registry-couchapp:couch=$COUCH/registry
|
||||
export NO_PROMPT=yes
|
||||
npm explore npm-registry-couchapp -- npm run copy --npm-registry-couchapp:couch=$COUCH/registry
|
||||
@@ -0,0 +1,304 @@
|
||||
import test from 'ava';
|
||||
import {writeJson, readJson} from 'fs-extra';
|
||||
import {start, stop, uri} from './helpers/registry';
|
||||
import {gitRepo, gitCommits, gitHead, gitTagVersion, gitPackRefs, gitAmmendCommit} from './helpers/git-utils';
|
||||
import execa from 'execa';
|
||||
|
||||
// Environment variables used with cli
|
||||
const env = {
|
||||
CI: true,
|
||||
npm_config_registry: uri,
|
||||
GH_TOKEN: 'github_token',
|
||||
NPM_OLD_TOKEN: 'aW50ZWdyYXRpb246c3VjaHNlY3VyZQ==',
|
||||
NPM_EMAIL: 'integration@test.com',
|
||||
};
|
||||
|
||||
test.before(async t => {
|
||||
// Start the local NPM registry
|
||||
await start();
|
||||
});
|
||||
|
||||
test.beforeEach(async t => {
|
||||
// Save the current working diretory
|
||||
t.context.cwd = process.cwd();
|
||||
});
|
||||
|
||||
test.afterEach.always(async t => {
|
||||
// Restore the current working directory
|
||||
process.chdir(t.context.cwd);
|
||||
});
|
||||
|
||||
test.after.always(async t => {
|
||||
// Stop the local NPM registry
|
||||
await stop();
|
||||
});
|
||||
|
||||
test.serial('Release patch, minor and major versions', async t => {
|
||||
// Create a git repository, set the current working directory at the root of the repo
|
||||
t.log('Create git repository');
|
||||
await gitRepo();
|
||||
|
||||
// Create package.json in repository root
|
||||
await writeJson('./package.json', {
|
||||
name: 'test-module',
|
||||
version: '0.0.0-dev',
|
||||
repository: {url: 'git+https://github.com/semantic-release/test-module'},
|
||||
release: {verifyConditions: require.resolve('../src/lib/plugin-noop')},
|
||||
});
|
||||
// Create a npm-shrinkwrap.json file
|
||||
await execa('npm', ['shrinkwrap'], {env});
|
||||
|
||||
/** No release **/
|
||||
|
||||
t.log('Commit a chore');
|
||||
await gitCommits(['chore: Init repository']);
|
||||
t.log('$ semantic-release pre');
|
||||
let {stdout, stderr, code} = await t.throws(execa(require.resolve('../bin/semantic-release'), ['pre'], {env}));
|
||||
t.regex(stderr, /ENOCHANGE There are no relevant changes, so no new version is released/);
|
||||
t.is(code, 1);
|
||||
|
||||
/** Minor release **/
|
||||
|
||||
t.log('Commit a feature');
|
||||
await gitCommits(['feat: Initial commit']);
|
||||
t.log('$ semantic-release pre');
|
||||
({stdout, stderr, code} = await execa(require.resolve('../bin/semantic-release'), ['pre'], {env}));
|
||||
// Verify package.json and npm-shrinkwrap.json have been updated
|
||||
t.is((await readJson('./package.json')).version, '1.0.0');
|
||||
t.is((await readJson('./npm-shrinkwrap.json')).version, '1.0.0');
|
||||
t.log('$ npm publish');
|
||||
({stdout, stderr, code} = await execa('npm', ['publish'], {env}));
|
||||
// Verify output of npm publish
|
||||
t.regex(stdout, /test-module@1.0.0/);
|
||||
t.is(code, 0);
|
||||
// Retrieve the published package from the registry and check version and gitHead
|
||||
let [, version, releaseGitHead] = /^version = '(.+)'\s+gitHead = '(.+)'$/.exec(
|
||||
(await execa('npm', ['show', 'test-module', 'version', 'gitHead'], {env})).stdout
|
||||
);
|
||||
t.is(version, '1.0.0');
|
||||
t.is(releaseGitHead, await gitHead());
|
||||
t.log(`+ released ${version} with gitHead ${releaseGitHead}`);
|
||||
|
||||
/** Patch release **/
|
||||
|
||||
t.log('Commit a fix');
|
||||
await gitCommits(['fix: bar']);
|
||||
t.log('$ semantic-release pre');
|
||||
({stdout, stderr, code} = await execa(require.resolve('../bin/semantic-release'), ['pre'], {env}));
|
||||
// Verify package.json and npm-shrinkwrap.json have been updated
|
||||
t.is((await readJson('./package.json')).version, '1.0.1');
|
||||
t.is((await readJson('./npm-shrinkwrap.json')).version, '1.0.1');
|
||||
t.log('$ npm publish');
|
||||
({stdout, stderr, code} = await execa('npm', ['publish'], {env}));
|
||||
// Verify output of npm publish
|
||||
t.regex(stdout, /test-module@1.0.1/);
|
||||
t.is(code, 0);
|
||||
// Retrieve the published package from the registry and check version and gitHead
|
||||
[, version, releaseGitHead] = /^version = '(.+)'\s+gitHead = '(.+)'$/.exec(
|
||||
(await execa('npm', ['show', 'test-module', 'version', 'gitHead'], {env})).stdout
|
||||
);
|
||||
t.is(version, '1.0.1');
|
||||
t.is(releaseGitHead, await gitHead());
|
||||
t.log(`+ released ${version} with gitHead ${releaseGitHead}`);
|
||||
|
||||
/** Minor release **/
|
||||
|
||||
t.log('Commit a feature');
|
||||
await gitCommits(['feat: baz']);
|
||||
t.log('$ semantic-release pre');
|
||||
({stdout, stderr, code} = await execa(require.resolve('../bin/semantic-release'), ['pre'], {env}));
|
||||
// Verify package.json and npm-shrinkwrap.json have been updated
|
||||
t.is((await readJson('./package.json')).version, '1.1.0');
|
||||
t.is((await readJson('./npm-shrinkwrap.json')).version, '1.1.0');
|
||||
t.log('$ npm publish');
|
||||
({stdout, stderr, code} = await execa('npm', ['publish'], {env}));
|
||||
// Verify output of npm publish
|
||||
t.regex(stdout, /test-module@1.1.0/);
|
||||
t.is(code, 0);
|
||||
// Retrieve the published package from the registry and check version and gitHead
|
||||
[, version, releaseGitHead] = /^version = '(.+)'\s+gitHead = '(.+)'$/.exec(
|
||||
(await execa('npm', ['show', 'test-module', 'version', 'gitHead'], {env})).stdout
|
||||
);
|
||||
t.is(version, '1.1.0');
|
||||
t.is(releaseGitHead, await gitHead());
|
||||
t.log(`+ released ${version} with gitHead ${releaseGitHead}`);
|
||||
|
||||
/** Major release **/
|
||||
|
||||
t.log('Commit a breaking change');
|
||||
await gitCommits(['feat: foo\n\n BREAKING CHANGE: bar']);
|
||||
t.log('$ semantic-release pre');
|
||||
({stdout, stderr, code} = await execa(require.resolve('../bin/semantic-release'), ['pre'], {env}));
|
||||
// Verify package.json and npm-shrinkwrap.json have been updated
|
||||
t.is((await readJson('./package.json')).version, '2.0.0');
|
||||
t.is((await readJson('./npm-shrinkwrap.json')).version, '2.0.0');
|
||||
t.log('$ npm publish');
|
||||
({stdout, stderr, code} = await execa('npm', ['publish'], {env}));
|
||||
// Verify output of npm publish
|
||||
t.regex(stdout, /test-module@2.0.0/);
|
||||
t.is(code, 0);
|
||||
// Retrieve the published package from the registry and check version and gitHead
|
||||
[, version, releaseGitHead] = /^version = '(.+)'\s+gitHead = '(.+)'$/.exec(
|
||||
(await execa('npm', ['show', 'test-module', 'version', 'gitHead'], {env})).stdout
|
||||
);
|
||||
t.is(version, '2.0.0');
|
||||
t.is(releaseGitHead, await gitHead());
|
||||
t.log(`+ released ${version} with gitHead ${releaseGitHead}`);
|
||||
});
|
||||
|
||||
test.serial('Release versions from a packed git repository, using tags to determine last release gitHead', async t => {
|
||||
// Create a git repository, set the current working directory at the root of the repo
|
||||
t.log('Create git repository');
|
||||
await gitRepo();
|
||||
|
||||
// Create package.json in repository root
|
||||
await writeJson('./package.json', {
|
||||
name: 'test-module-2',
|
||||
version: '0.0.0-dev',
|
||||
repository: {url: 'git+https://github.com/semantic-release/test-module-2'},
|
||||
release: {verifyConditions: require.resolve('../src/lib/plugin-noop')},
|
||||
});
|
||||
|
||||
/** Minor release **/
|
||||
|
||||
t.log('Commit a feature');
|
||||
await gitCommits(['feat: Initial commit']);
|
||||
t.log('$ git pack-refs --all');
|
||||
await gitPackRefs();
|
||||
t.log('$ semantic-release pre');
|
||||
let {stdout, code} = await execa(require.resolve('../bin/semantic-release'), ['pre'], {env});
|
||||
// Verify package.json has been updated
|
||||
t.is((await readJson('./package.json')).version, '1.0.0');
|
||||
t.log('$ npm publish');
|
||||
({stdout, code} = await execa('npm', ['publish'], {env}));
|
||||
// Verify output of npm publish
|
||||
t.regex(stdout, /test-module-2@1.0.0/);
|
||||
t.is(code, 0);
|
||||
// Retrieve the published package from the registry and check version and gitHead
|
||||
let version = (await execa('npm', ['show', 'test-module-2', 'version'], {env})).stdout;
|
||||
t.is(version, '1.0.0');
|
||||
t.log(`+ released ${version}`);
|
||||
// Create a tag version so the tag can be used later to determine the commit associated with the version
|
||||
await gitTagVersion('v1.0.0');
|
||||
t.log('Create git tag v1.0.0');
|
||||
|
||||
/** Patch release **/
|
||||
|
||||
t.log('Commit a fix');
|
||||
await gitCommits(['fix: bar']);
|
||||
t.log('$ semantic-release pre');
|
||||
({stdout, code} = await execa(require.resolve('../bin/semantic-release'), ['pre'], {env}));
|
||||
// Verify package.json has been updated
|
||||
t.is((await readJson('./package.json')).version, '1.0.1');
|
||||
t.log('$ npm publish');
|
||||
({stdout, code} = await execa('npm', ['publish'], {env}));
|
||||
// Verify output of npm publish
|
||||
t.regex(stdout, /test-module-2@1.0.1/);
|
||||
t.is(code, 0);
|
||||
// Retrieve the published package from the registry and check version and gitHead
|
||||
version = (await execa('npm', ['show', 'test-module-2', 'version'], {env})).stdout;
|
||||
t.is(version, '1.0.1');
|
||||
t.log(`+ released ${version}`);
|
||||
});
|
||||
|
||||
test.serial('Exit with 1 in a plugin is not found', async t => {
|
||||
// Environment variables used with cli
|
||||
const env = {
|
||||
CI: true,
|
||||
npm_config_registry: uri,
|
||||
GH_TOKEN: 'github_token',
|
||||
NPM_OLD_TOKEN: 'aW50ZWdyYXRpb246c3VjaHNlY3VyZQ==',
|
||||
NPM_EMAIL: 'integration@test.com',
|
||||
};
|
||||
// Create a git repository, set the current working directory at the root of the repo
|
||||
t.log('Create git repository');
|
||||
await gitRepo();
|
||||
await writeJson('./package.json', {
|
||||
name: 'test-module-3',
|
||||
version: '0.0.0-dev',
|
||||
repository: {url: 'git+https://github.com/semantic-release/test-module-4'},
|
||||
release: {analyzeCommits: 'non-existing-path'},
|
||||
});
|
||||
|
||||
const {code} = await t.throws(execa(require.resolve('../bin/semantic-release'), ['pre'], {env}));
|
||||
t.is(code, 1);
|
||||
});
|
||||
|
||||
test.serial('Create a tag as a recovery solution for "ENOTINHISTORY" error', async t => {
|
||||
// Create a git repository, set the current working directory at the root of the repo
|
||||
t.log('Create git repository');
|
||||
await gitRepo();
|
||||
|
||||
// Create package.json in repository root
|
||||
await writeJson('./package.json', {
|
||||
name: 'test-module-4',
|
||||
version: '0.0.0-dev',
|
||||
repository: {url: 'git+https://github.com/semantic-release/test-module-2'},
|
||||
release: {verifyConditions: require.resolve('../src/lib/plugin-noop')},
|
||||
});
|
||||
|
||||
/** Minor release **/
|
||||
|
||||
t.log('Commit a feature');
|
||||
await gitCommits(['feat: Initial commit']);
|
||||
t.log('$ semantic-release pre');
|
||||
let {stdout, stderr, code} = await execa(require.resolve('../bin/semantic-release'), ['pre'], {env});
|
||||
// Verify package.json has been updated
|
||||
t.is((await readJson('./package.json')).version, '1.0.0');
|
||||
t.log('$ npm publish');
|
||||
({stdout, code} = await execa('npm', ['publish'], {env}));
|
||||
// Verify output of npm publish
|
||||
t.regex(stdout, /test-module-4@1.0.0/);
|
||||
t.is(code, 0);
|
||||
// Retrieve the published package from the registry and check version and gitHead
|
||||
let [, version, releaseGitHead] = /^version = '(.+)'\s+gitHead = '(.+)'$/.exec(
|
||||
(await execa('npm', ['show', 'test-module-4', 'version', 'gitHead'], {env})).stdout
|
||||
);
|
||||
const head = await gitHead();
|
||||
t.is(releaseGitHead, head);
|
||||
t.log(`+ released ${version}`);
|
||||
t.is(version, '1.0.0');
|
||||
// Create a tag version so the tag can be used later to determine the commit associated with the version
|
||||
await gitTagVersion('v1.0.0');
|
||||
t.log('Create git tag v1.0.0');
|
||||
|
||||
/** Rewrite sha of commit used for release **/
|
||||
|
||||
t.log('Amend release commit');
|
||||
const {hash} = await gitAmmendCommit('feat: Initial commit');
|
||||
|
||||
/** Patch release **/
|
||||
|
||||
t.log('Commit a fix');
|
||||
await gitCommits(['fix: bar']);
|
||||
t.log('$ semantic-release pre');
|
||||
({stderr, stdout, code} = await execa(require.resolve('../bin/semantic-release'), ['pre'], {env, reject: false}));
|
||||
|
||||
t.log('Fail with "ENOTINHISTORY" error');
|
||||
t.is(code, 1);
|
||||
t.regex(
|
||||
stderr,
|
||||
new RegExp(
|
||||
`You can recover from this error by restoring the commit "${head}" or by creating a tag for the version "1.0.0" on the commit corresponding to this release`
|
||||
)
|
||||
);
|
||||
|
||||
/** Create a tag to recover and redo release **/
|
||||
|
||||
t.log('Create git tag v1.0.0 to recover');
|
||||
await gitTagVersion('v1.0.0', hash);
|
||||
|
||||
t.log('$ semantic-release pre');
|
||||
({stderr, stdout, code} = await execa(require.resolve('../bin/semantic-release'), ['pre'], {env}));
|
||||
// Verify package.json has been updated
|
||||
t.is((await readJson('./package.json')).version, '1.0.1');
|
||||
t.log('$ npm publish');
|
||||
({stdout, code} = await execa('npm', ['publish'], {env}));
|
||||
// Verify output of npm publish
|
||||
t.regex(stdout, /test-module-4@1.0.1/);
|
||||
t.is(code, 0);
|
||||
// Retrieve the published package from the registry and check version and gitHead
|
||||
version = (await execa('npm', ['show', 'test-module-4', 'version'], {env})).stdout;
|
||||
t.is(version, '1.0.1');
|
||||
t.log(`+ released ${version}`);
|
||||
});
|
||||
@@ -1,12 +0,0 @@
|
||||
var nixt = require('nixt')
|
||||
|
||||
module.exports = function (cwd, uri) {
|
||||
return nixt()
|
||||
.cwd(cwd)
|
||||
.env('NPM_OLD_TOKEN', 'aW50ZWdyYXRpb246c3VjaHNlY3VyZQ==')
|
||||
.env('NPM_EMAIL', 'integration@test.com')
|
||||
.env('GH_TOKEN', 'ghtoken')
|
||||
.env('CI', 'true')
|
||||
.env('npm_config_registry', uri)
|
||||
.clone()
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
var exec = require('child_process').exec
|
||||
var join = require('path').join
|
||||
var writeFileSync = require('fs').writeFileSync
|
||||
|
||||
var mkdirp = require('mkdirp')
|
||||
|
||||
module.exports = function (name, registry, cb) {
|
||||
var cwd = join(__dirname, '../tmp', name)
|
||||
|
||||
mkdirp.sync(cwd)
|
||||
|
||||
writeFileSync(join(cwd, 'package.json'), JSON.stringify({
|
||||
name: name,
|
||||
repository: {
|
||||
url: 'git+https://github.com/semantic-release/test'
|
||||
},
|
||||
release: {
|
||||
verifyConditions: '../../../src/lib/plugin-noop'
|
||||
}
|
||||
}, null, 2))
|
||||
|
||||
exec(
|
||||
'git init && ' +
|
||||
'git config user.email "integration@test" && ' +
|
||||
'git config user.name "Integration Test" && ' +
|
||||
'git add . && ' +
|
||||
'git commit -m "chore: root"'
|
||||
, {cwd: cwd}, function (err, stdout, stderr) {
|
||||
if (err) {
|
||||
console.log(stdout, stderr)
|
||||
return cb(err)
|
||||
}
|
||||
|
||||
cb(null, cwd)
|
||||
})
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
const rawCommits = [
|
||||
'hash-one==SPLIT==commit-one==END==\n',
|
||||
'hash-two==SPLIT==commit-two==END==\n'
|
||||
]
|
||||
|
||||
module.exports = {
|
||||
exec: function (command, options, cb) {
|
||||
if (typeof cb === 'undefined' && typeof options === 'function') {
|
||||
cb = options
|
||||
}
|
||||
if (/contains/.test(command)) {
|
||||
if (/notinhistory/.test(command)) return cb(new Error())
|
||||
return cb(null, 'whatever\nmaster\n')
|
||||
}
|
||||
|
||||
cb(
|
||||
null,
|
||||
/\.\.HEAD/.test(command)
|
||||
? rawCommits[0]
|
||||
: rawCommits.join()
|
||||
)
|
||||
},
|
||||
'@noCallThru': true
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
module.exports = function (cb) {
|
||||
cb(null, 'bar')
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
module.exports = function () {
|
||||
return {
|
||||
authenticate: function () {
|
||||
return true
|
||||
},
|
||||
releases: {
|
||||
createRelease: function (release, cb) {
|
||||
cb(null)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
module.exports = function (config, options, cb) {
|
||||
cb(new Error('a'))
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
module.exports = function (config, options, cb) {
|
||||
cb(new Error('b'))
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
module.exports = function (config, options, cb) {
|
||||
cb(null, 'a')
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
module.exports = function (config, options, cb) {
|
||||
cb(null, 'b')
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
const nock = require('nock')
|
||||
|
||||
const availableModule = {
|
||||
'dist-tags': {
|
||||
latest: '1.33.7',
|
||||
foo: '0.8.15'
|
||||
},
|
||||
versions: {
|
||||
'0.8.15': {
|
||||
gitHead: 'bar'
|
||||
},
|
||||
'1.33.7': {
|
||||
gitHead: 'HEAD'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = nock('http://registry.npmjs.org')
|
||||
.get('/available')
|
||||
.reply(200, availableModule)
|
||||
.get('/tagged')
|
||||
.reply(200, availableModule)
|
||||
.get('/untagged')
|
||||
.reply(200, availableModule)
|
||||
.get('/@scoped%2Favailable')
|
||||
.reply(200, availableModule)
|
||||
.get('/unavailable')
|
||||
.reply(404, {})
|
||||
@@ -0,0 +1,103 @@
|
||||
import {promisify} from 'util';
|
||||
import test from 'ava';
|
||||
import plugins from '../src/lib/plugins';
|
||||
|
||||
test('Export plugins', t => {
|
||||
// Call the plugin module
|
||||
const defaultPlugins = plugins({});
|
||||
|
||||
// Verify the module returns a function for each plugin
|
||||
t.is(typeof defaultPlugins.analyzeCommits, 'function');
|
||||
t.is(typeof defaultPlugins.generateNotes, 'function');
|
||||
t.is(typeof defaultPlugins.verifyConditions, 'function');
|
||||
t.is(typeof defaultPlugins.verifyRelease, 'function');
|
||||
t.is(typeof defaultPlugins.getLastRelease, 'function');
|
||||
});
|
||||
|
||||
test('Pipeline - Get all results', async t => {
|
||||
// Call the plugin module with a verifyRelease plugin pipeline
|
||||
const pipelinePlugins = plugins({
|
||||
verifyRelease: ['./src/lib/plugin-noop', './test/fixtures/plugin-result-a', './test/fixtures/plugin-result-b'],
|
||||
});
|
||||
|
||||
// Call the verifyRelease pipeline
|
||||
const results = await pipelinePlugins.verifyRelease({});
|
||||
|
||||
// Verify the pipeline return the expected result for each plugin, in order
|
||||
t.deepEqual(results, [undefined, 'a', 'b']);
|
||||
});
|
||||
|
||||
test('Pipeline - Pass pluginConfig and options to each plugins', async t => {
|
||||
// Plugin configuration with options (plugin-result-config is a mock plugin returning its pluginConfig and options parameters)
|
||||
const pluginConfig = {path: './test/fixtures/plugin-result-config', pluginParam: 'param1'};
|
||||
// Semantic-release global options
|
||||
const options = {semanticReleaseParam: 'param2'};
|
||||
// Call the plugin module with a verifyRelease plugin pipeline
|
||||
const pipelinePlugins = plugins({
|
||||
verifyRelease: [pluginConfig, './test/fixtures/plugin-result-config'],
|
||||
});
|
||||
|
||||
// Call the verifyRelease pipeline
|
||||
const results = await pipelinePlugins.verifyRelease(options);
|
||||
|
||||
// Verify the pipeline first result is the pluginConfig and options parameters (to verify the plugin was called with the defined pluginConfig and options parameters)
|
||||
t.deepEqual(results, [{pluginConfig, options}, {pluginConfig: {}, options}]);
|
||||
});
|
||||
|
||||
test('Pipeline - Get first error', async t => {
|
||||
// Call the plugin module with a verifyRelease plugin pipeline
|
||||
const pipelinePlugins = plugins({
|
||||
verifyRelease: ['./src/lib/plugin-noop', './test/fixtures/plugin-error-a', './test/fixtures/plugin-error-b'],
|
||||
});
|
||||
|
||||
// Call the verifyRelease pipeline and verify it returns the error thrown by './test/fixtures/plugin-error-a'
|
||||
await t.throws(pipelinePlugins.verifyRelease({}), 'a');
|
||||
});
|
||||
|
||||
test('Normalize and load plugin from string', t => {
|
||||
// Call the normalize function with a path
|
||||
const plugin = plugins.normalize('./src/lib/plugin-noop');
|
||||
|
||||
// Verify the plugin is loaded
|
||||
t.is(typeof plugin, 'function');
|
||||
});
|
||||
|
||||
test('Normalize and load plugin from object', t => {
|
||||
// Call the normalize function with an object (with path property)
|
||||
const plugin = plugins.normalize({path: './src/lib/plugin-noop'});
|
||||
|
||||
// Verify the plugin is loaded
|
||||
t.is(typeof plugin, 'function');
|
||||
});
|
||||
|
||||
test('Load from fallback', t => {
|
||||
// Call the normalize function with a fallback
|
||||
const plugin = plugins.normalize(null, '../lib/plugin-noop');
|
||||
|
||||
// Verify the fallback plugin is loaded
|
||||
t.is(typeof plugin, 'function');
|
||||
});
|
||||
|
||||
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 = plugins.normalize('./test/fixtures/plugin-result-config');
|
||||
const pluginResult = await promisify(plugin)({});
|
||||
|
||||
t.deepEqual(pluginResult.pluginConfig, {});
|
||||
});
|
||||
|
||||
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 = plugins.normalize({path: './test/fixtures/plugin-result-config'});
|
||||
const pluginResult = await promisify(plugin)({});
|
||||
|
||||
t.deepEqual(pluginResult.pluginConfig, {path: './test/fixtures/plugin-result-config'});
|
||||
});
|
||||
|
||||
test('Always pass a defined "pluginConfig" for fallback plugin', async t => {
|
||||
// Call the normalize function with the path of a plugin that returns its config
|
||||
const plugin = plugins.normalize(null, '../../test/fixtures/plugin-result-config');
|
||||
const pluginResult = await promisify(plugin)({});
|
||||
|
||||
t.deepEqual(pluginResult.pluginConfig, {});
|
||||
});
|
||||
@@ -0,0 +1,151 @@
|
||||
import {callbackify} from 'util';
|
||||
import test from 'ava';
|
||||
import {gitRepo, gitCommits, gitHead} from './helpers/git-utils';
|
||||
import {stub} from 'sinon';
|
||||
import nock from 'nock';
|
||||
import {authenticate} from './helpers/mock-github';
|
||||
import post from '../src/post';
|
||||
|
||||
test.beforeEach(t => {
|
||||
// Save the current working diretory
|
||||
t.context.cwd = process.cwd();
|
||||
});
|
||||
|
||||
test.afterEach.always(t => {
|
||||
// Restore the current working directory
|
||||
process.chdir(t.context.cwd);
|
||||
// Reset nock
|
||||
nock.cleanAll();
|
||||
});
|
||||
|
||||
test.serial('Post run with github token', async t => {
|
||||
// Create a git repository, set the current working directory at the root of the repo
|
||||
await gitRepo();
|
||||
// Add commits to the master branch
|
||||
await gitCommits(['fix: First fix', 'feat: Second feature']);
|
||||
|
||||
const sha = await gitHead();
|
||||
const owner = 'test_user';
|
||||
const repo = 'test_repo';
|
||||
const githubUrl = 'https://testurl.com:443';
|
||||
const githubToken = 'github_token';
|
||||
const githubApiPathPrefix = 'prefix';
|
||||
const releaseLog = 'Test release note body';
|
||||
// Stub the generateNotes plugin
|
||||
const generateNotes = stub().resolves(releaseLog);
|
||||
const version = '1.0.0';
|
||||
const branch = 'master';
|
||||
const debug = false;
|
||||
const tagName = `v${version}`;
|
||||
const options = {branch, debug, githubUrl, githubToken, githubApiPathPrefix};
|
||||
const pkg = {version, repository: {url: `git+https://othertesturl.com/${owner}/${repo}.git`}};
|
||||
|
||||
// Mock github API for releases and git/refs endpoints
|
||||
const github = authenticate({githubUrl, githubToken, githubApiPathPrefix})
|
||||
.post(`/repos/${owner}/${repo}/releases`, {
|
||||
tag_name: tagName,
|
||||
target_commitish: branch,
|
||||
name: tagName,
|
||||
body: releaseLog,
|
||||
draft: debug,
|
||||
})
|
||||
.reply({})
|
||||
.post(`/repos/${owner}/${repo}/git/refs`, {ref: `refs/tags/${tagName}`, sha})
|
||||
.reply({});
|
||||
|
||||
// Call the post module
|
||||
const result = await post({pkg, options, plugins: {generateNotes: callbackify(generateNotes)}});
|
||||
|
||||
// Verify the getLastRelease plugin has been called with 'options' and 'pkg'
|
||||
t.true(generateNotes.calledOnce);
|
||||
t.deepEqual(generateNotes.firstCall.args[0].options, options);
|
||||
t.deepEqual(generateNotes.firstCall.args[0].pkg, pkg);
|
||||
|
||||
// Verify the published release note
|
||||
t.deepEqual(result, {
|
||||
published: true,
|
||||
release: {owner, repo, tag_name: tagName, name: tagName, target_commitish: branch, draft: debug, body: releaseLog},
|
||||
});
|
||||
// Verify the releases and git/refs endpoint have been call with expected requests
|
||||
t.true(github.isDone());
|
||||
});
|
||||
|
||||
test.serial('Post dry run with github token', async t => {
|
||||
// Create a git repository, set the current working directory at the root of the repo
|
||||
await gitRepo();
|
||||
// Add commits to the master branch
|
||||
await gitCommits(['fix: First fix', 'feat: Second feature']);
|
||||
|
||||
const owner = 'test_user';
|
||||
const repo = 'test_repo';
|
||||
const githubToken = 'github_token';
|
||||
const releaseLog = 'Test release note body';
|
||||
// Stub the generateNotes plugin
|
||||
const generateNotes = stub().resolves(releaseLog);
|
||||
const version = '1.0.0';
|
||||
const branch = 'master';
|
||||
const debug = true;
|
||||
const tagName = `v${version}`;
|
||||
const options = {branch, debug, githubToken};
|
||||
const pkg = {version, repository: {url: `git+https://othertesturl.com/${owner}/${repo}.git`}};
|
||||
|
||||
// Mock github API for releases endpoint
|
||||
const github = authenticate({githubToken})
|
||||
.post(`/repos/${owner}/${repo}/releases`, {
|
||||
tag_name: tagName,
|
||||
target_commitish: branch,
|
||||
name: tagName,
|
||||
body: releaseLog,
|
||||
draft: debug,
|
||||
})
|
||||
.reply({});
|
||||
|
||||
// Call the post module
|
||||
const result = await post({pkg, options, plugins: {generateNotes: callbackify(generateNotes)}});
|
||||
|
||||
// Verify the getLastRelease plugin has been called with 'options' and 'pkg'
|
||||
t.true(generateNotes.calledOnce);
|
||||
t.deepEqual(generateNotes.firstCall.args[0].options, options);
|
||||
t.deepEqual(generateNotes.firstCall.args[0].pkg, pkg);
|
||||
|
||||
// Verify the published release note
|
||||
t.deepEqual(result, {
|
||||
published: true,
|
||||
release: {owner, repo, tag_name: tagName, name: tagName, target_commitish: branch, draft: debug, body: releaseLog},
|
||||
});
|
||||
// Verify the releases and git/refs endpoint have been call with expected requests
|
||||
t.true(github.isDone());
|
||||
});
|
||||
|
||||
test.serial('Post dry run without github token', async t => {
|
||||
// Create a git repository, set the current working directory at the root of the repo
|
||||
await gitRepo();
|
||||
// Add commits to the master branch
|
||||
await gitCommits(['fix: First fix', 'feat: Second feature']);
|
||||
|
||||
const owner = 'test_user';
|
||||
const repo = 'test_repo';
|
||||
const releaseLog = 'Test release note body';
|
||||
// Stub the generateNotes plugin
|
||||
const generateNotes = stub().resolves(releaseLog);
|
||||
const version = '1.0.0';
|
||||
const branch = 'master';
|
||||
const debug = true;
|
||||
const tagName = `v${version}`;
|
||||
const options = {branch, debug};
|
||||
const pkg = {version, repository: {url: `git+https://othertesturl.com/${owner}/${repo}.git`}};
|
||||
|
||||
// Call the post module
|
||||
const result = await post({pkg, options, plugins: {generateNotes: callbackify(generateNotes)}});
|
||||
|
||||
// Verify the getLastRelease plugin has been called with 'options' and 'pkg'
|
||||
t.true(generateNotes.calledOnce);
|
||||
t.deepEqual(generateNotes.firstCall.args[0].options, options);
|
||||
t.deepEqual(generateNotes.firstCall.args[0].pkg, pkg);
|
||||
|
||||
// Verify the release note
|
||||
t.deepEqual(result, {
|
||||
published: false,
|
||||
release: {owner, repo, tag_name: tagName, name: tagName, target_commitish: branch, draft: debug, body: releaseLog},
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,163 @@
|
||||
import {callbackify} from 'util';
|
||||
import test from 'ava';
|
||||
import {gitRepo, gitCommits} from './helpers/git-utils';
|
||||
import proxyquire from 'proxyquire';
|
||||
import {stub} from 'sinon';
|
||||
|
||||
// Stub to capture the log messages
|
||||
const errorLog = stub();
|
||||
// Module to test
|
||||
const pre = proxyquire('../src/pre', {
|
||||
'./lib/get-commits': proxyquire('../src/lib/get-commits', {npmlog: {error: errorLog}}),
|
||||
});
|
||||
|
||||
test.beforeEach(t => {
|
||||
// Save the current working diretory
|
||||
t.context.cwd = process.cwd();
|
||||
// Reset the stub call history
|
||||
errorLog.resetHistory();
|
||||
});
|
||||
|
||||
test.afterEach.always(t => {
|
||||
// Restore the current working directory
|
||||
process.chdir(t.context.cwd);
|
||||
});
|
||||
|
||||
test.serial('Increase version', async t => {
|
||||
// Create a git repository, set the current working directory at the root of the repo
|
||||
await gitRepo();
|
||||
// Add commits to the master branch
|
||||
const cmts = await gitCommits(['fix: First fix', 'feat: Second feature']);
|
||||
|
||||
const options = {branch: 'master'};
|
||||
const pkg = {name: 'available'};
|
||||
const lastRelease = {version: '1.0.0', gitHead: cmts[cmts.length - 1].hash};
|
||||
// Stub the getLastRelease, analyzeCommits and verifyRelease plugins
|
||||
const getLastRelease = stub().resolves(lastRelease);
|
||||
const analyzeCommits = stub().resolves('major');
|
||||
const verifyRelease = stub().resolves();
|
||||
|
||||
// Call the pre module
|
||||
const nextRelease = await pre({
|
||||
options,
|
||||
pkg,
|
||||
plugins: {
|
||||
getLastRelease: callbackify(getLastRelease),
|
||||
analyzeCommits: callbackify(analyzeCommits),
|
||||
verifyRelease: verifyRelease,
|
||||
},
|
||||
});
|
||||
|
||||
// Verify the pre module returns the 'type' returned by analyzeCommits and the 'version' returned by getLastRelease increamented with the 'type' (current version 1.0.0 => major release = version 2.0.0)
|
||||
t.deepEqual(nextRelease, {type: 'major', version: '2.0.0'});
|
||||
|
||||
// Verify the getLastRelease plugin has been called with 'options' and 'pkg'
|
||||
t.true(getLastRelease.calledOnce);
|
||||
t.deepEqual(getLastRelease.firstCall.args[0].options, options);
|
||||
t.deepEqual(getLastRelease.firstCall.args[0].pkg, pkg);
|
||||
|
||||
// Verify the analyzeCommits plugin has been called with the repo 'commits' since lastVersion githead
|
||||
t.true(analyzeCommits.calledOnce);
|
||||
t.is(analyzeCommits.firstCall.args[0].commits.length, 1);
|
||||
t.is(analyzeCommits.firstCall.args[0].commits[0].hash.substring(0, 7), cmts[0].hash);
|
||||
t.is(analyzeCommits.firstCall.args[0].commits[0].message, cmts[0].message);
|
||||
|
||||
// Verify the verifyRelease plugin has been called with 'lastRelease' and 'nextRelease'
|
||||
t.true(verifyRelease.calledOnce);
|
||||
t.deepEqual(verifyRelease.firstCall.args[0].lastRelease, lastRelease);
|
||||
t.deepEqual(verifyRelease.firstCall.args[0].nextRelease, nextRelease);
|
||||
});
|
||||
|
||||
test.serial('Initial version', async t => {
|
||||
// Create a git repository, set the current working directory at the root of the repo
|
||||
await gitRepo();
|
||||
// Add commits to the master branch
|
||||
const cmts = await gitCommits(['fix(scope1): First fix', 'feat(scope2): Second feature']);
|
||||
|
||||
const options = {branch: 'master'};
|
||||
const pkg = {name: 'available'};
|
||||
const lastRelease = {version: null, gitHead: undefined};
|
||||
// Stub the getLastRelease, analyzeCommits and verifyRelease plugins
|
||||
const getLastRelease = stub().resolves({version: null, gitHead: undefined});
|
||||
const analyzeCommits = stub().resolves('major');
|
||||
const verifyRelease = stub().resolves();
|
||||
|
||||
// Call the pre module
|
||||
const nextRelease = await pre({
|
||||
options,
|
||||
pkg,
|
||||
plugins: {
|
||||
getLastRelease: callbackify(getLastRelease),
|
||||
analyzeCommits: callbackify(analyzeCommits),
|
||||
verifyRelease: verifyRelease,
|
||||
},
|
||||
});
|
||||
|
||||
// Verify the pre module returns the 'type' returned by analyzeCommits and the 'version' returned by getLastRelease increamented with the 'type' (no current version => initial release = version 1.0.0)
|
||||
t.deepEqual(nextRelease, {type: 'initial', version: '1.0.0'});
|
||||
|
||||
// Verify the getLastRelease plugin has been called with 'options' and 'pkg'
|
||||
t.true(getLastRelease.calledOnce);
|
||||
t.deepEqual(getLastRelease.firstCall.args[0].options, options);
|
||||
t.deepEqual(getLastRelease.firstCall.args[0].pkg, pkg);
|
||||
|
||||
// Verify the analyzeCommits plugin has been called with all the repo 'commits'
|
||||
t.true(analyzeCommits.calledOnce);
|
||||
t.is(analyzeCommits.firstCall.args[0].commits.length, 2);
|
||||
t.is(analyzeCommits.firstCall.args[0].commits[0].hash.substring(0, 7), cmts[0].hash);
|
||||
t.is(analyzeCommits.firstCall.args[0].commits[0].message, cmts[0].message);
|
||||
t.is(analyzeCommits.firstCall.args[0].commits[1].hash.substring(0, 7), cmts[1].hash);
|
||||
t.is(analyzeCommits.firstCall.args[0].commits[1].message, cmts[1].message);
|
||||
|
||||
// Verify the verifyRelease plugin has been called with 'lastRelease' and 'nextRelease'
|
||||
t.true(verifyRelease.calledOnce);
|
||||
t.deepEqual(verifyRelease.firstCall.args[0].lastRelease, lastRelease);
|
||||
t.deepEqual(verifyRelease.firstCall.args[0].nextRelease, nextRelease);
|
||||
});
|
||||
|
||||
test.serial('Throws error if verifyRelease fails', async t => {
|
||||
// Create a git repository, set the current working directory at the root of the repo
|
||||
await gitRepo();
|
||||
// Add commits to the master branch
|
||||
const cmts = await gitCommits(['fix: First fix', 'feat: Second feature']);
|
||||
|
||||
const options = {branch: 'master'};
|
||||
const pkg = {name: 'available'};
|
||||
const lastRelease = {version: '1.0.0', gitHead: cmts[cmts.length - 1].hash};
|
||||
// Stub the getLastRelease, analyzeCommits and verifyRelease plugins
|
||||
const getLastRelease = stub().resolves(lastRelease);
|
||||
const analyzeCommits = stub().resolves('major');
|
||||
const verifyRelease = stub().rejects(new Error('verifyRelease failed'));
|
||||
|
||||
// Call the pre module and verify it returns the Error returned by verifyRelease
|
||||
const error = await t.throws(
|
||||
pre({
|
||||
options,
|
||||
pkg,
|
||||
plugins: {
|
||||
getLastRelease: callbackify(getLastRelease),
|
||||
analyzeCommits: callbackify(analyzeCommits),
|
||||
verifyRelease: verifyRelease,
|
||||
},
|
||||
})
|
||||
);
|
||||
|
||||
// Verify the error message is the one returned by verifyRelease
|
||||
t.is(error.message, 'verifyRelease failed');
|
||||
|
||||
// Verify the getLastRelease plugin has been called with 'options' and 'pkg'
|
||||
t.true(getLastRelease.calledOnce);
|
||||
t.deepEqual(getLastRelease.firstCall.args[0].options, options);
|
||||
t.deepEqual(getLastRelease.firstCall.args[0].pkg, pkg);
|
||||
|
||||
// Verify the analyzeCommits plugin has been called with all the repo 'commits'
|
||||
t.true(analyzeCommits.calledOnce);
|
||||
t.is(analyzeCommits.firstCall.args[0].commits.length, 1);
|
||||
t.is(analyzeCommits.firstCall.args[0].commits[0].hash.substring(0, 7), cmts[0].hash);
|
||||
t.is(analyzeCommits.firstCall.args[0].commits[0].message, cmts[0].message);
|
||||
|
||||
// Verify the verifyRelease plugin has been called with 'lastRelease' and 'nextRelease'
|
||||
t.true(verifyRelease.calledOnce);
|
||||
t.deepEqual(verifyRelease.firstCall.args[0].lastRelease, lastRelease);
|
||||
t.deepEqual(verifyRelease.firstCall.args[0].nextRelease, {type: 'major', version: '2.0.0'});
|
||||
});
|
||||
@@ -1,11 +0,0 @@
|
||||
var exec = require('child_process').exec
|
||||
|
||||
var opts = {
|
||||
cwd: __dirname
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
start: exec.bind(null, './start.sh', opts),
|
||||
stop: exec.bind(null, './stop.sh', opts),
|
||||
uri: 'http://localhost:' + (process.env.TRAVIS === 'true' ? 5984 : 15986) + '/registry/_design/app/_rewrite/'
|
||||
}
|
||||
@@ -1,96 +0,0 @@
|
||||
var join = require('path').join
|
||||
|
||||
var tap = require('tap')
|
||||
var rimraf = require('rimraf')
|
||||
|
||||
var registry = require('../registry')
|
||||
var testModule = require('../lib/test-module')
|
||||
var baseScenario = require('../lib/base-scenario')
|
||||
|
||||
var tearDown = tap.tearDown
|
||||
var test = tap.test
|
||||
|
||||
test('change version', {bail: process.env.TRAVIS === 'true'}, function (t) {
|
||||
t.plan(7)
|
||||
|
||||
registry.start(function (err, stdout, stderr) {
|
||||
t.error(err, 'registry started')
|
||||
if (err) return t.end()
|
||||
|
||||
testModule('change-version', registry.uri, function (err, cwd) {
|
||||
t.error(err, 'test-module created')
|
||||
if (err) return t.end()
|
||||
|
||||
t.test('no version', function (tt) {
|
||||
tt.plan(1)
|
||||
|
||||
baseScenario(cwd, registry.uri)
|
||||
.env('npm_config_loglevel', 'info')
|
||||
.run('node ../../../bin/semantic-release.js pre')
|
||||
.stderr(/ENOCHANGE/)
|
||||
.code(1)
|
||||
.end(tt.error)
|
||||
})
|
||||
|
||||
t.test('initial version', function (tt) {
|
||||
tt.plan(1)
|
||||
|
||||
baseScenario(cwd, registry.uri)
|
||||
.exec('git commit -m "feat: initial" --allow-empty')
|
||||
.exec('node ../../../bin/semantic-release.js pre')
|
||||
.run('npm publish')
|
||||
.stdout(/1\.0\.0/)
|
||||
.code(0)
|
||||
.end(tt.error)
|
||||
})
|
||||
|
||||
t.test('patch version', function (tt) {
|
||||
tt.plan(1)
|
||||
|
||||
baseScenario(cwd, registry.uri)
|
||||
.exec('git commit -m "fix: foo" --allow-empty')
|
||||
.exec('node ../../../bin/semantic-release.js pre')
|
||||
.run('npm publish')
|
||||
.stdout(/1\.0\.1/)
|
||||
.code(0)
|
||||
.end(tt.error)
|
||||
})
|
||||
|
||||
t.test('feature version', function (tt) {
|
||||
tt.plan(1)
|
||||
|
||||
baseScenario(cwd, registry.uri)
|
||||
.exec('git commit -m "feat: foo" --allow-empty')
|
||||
.exec('node ../../../bin/semantic-release.js pre')
|
||||
.run('npm publish')
|
||||
.code(0)
|
||||
.stdout(/1\.1\.0/)
|
||||
.end(tt.error)
|
||||
})
|
||||
|
||||
t.test('breaking version', function (tt) {
|
||||
tt.plan(1)
|
||||
|
||||
baseScenario(cwd, registry.uri)
|
||||
.exec('git commit -m "feat: foo\n\n BREAKING CHANGE: bar" --allow-empty')
|
||||
.exec('node ../../../bin/semantic-release.js pre')
|
||||
.run('npm publish')
|
||||
.code(0)
|
||||
.stdout(/2\.0\.0/)
|
||||
.end(tt.error)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
tearDown(function () {
|
||||
if (process.env.TRAVIS === 'true') return
|
||||
|
||||
function cb (err, stdout, stderr) {
|
||||
if (err) console.log(err)
|
||||
if (stderr) console.log(stderr)
|
||||
}
|
||||
|
||||
rimraf(join(__dirname, '../tmp'), cb)
|
||||
registry.stop(cb)
|
||||
})
|
||||
@@ -1,43 +0,0 @@
|
||||
var test = require('tap').test
|
||||
var proxyquire = require('proxyquire')
|
||||
|
||||
var commits = proxyquire('../../src/lib/commits', {
|
||||
'npmlog': {
|
||||
error: function () {}
|
||||
},
|
||||
'child_process': require('../mocks/child-process')
|
||||
})
|
||||
|
||||
test('commits since last release', function (t) {
|
||||
t.test('get all commits', function (tt) {
|
||||
commits({lastRelease: {}, options: {branch: 'master'}}, function (err, commits) {
|
||||
tt.error(err)
|
||||
tt.is(commits.length, 2, 'all commits')
|
||||
tt.is(commits[0].hash, 'hash-one', 'parsed hash')
|
||||
tt.is(commits[1].message, 'commit-two', 'parsed message')
|
||||
|
||||
tt.end()
|
||||
})
|
||||
})
|
||||
|
||||
t.test('get commits since hash', function (tt) {
|
||||
commits({lastRelease: {gitHead: 'hash'}, options: {branch: 'master'}}, function (err, commits) {
|
||||
tt.error(err)
|
||||
tt.is(commits.length, 1, 'specified commits')
|
||||
tt.is(commits[0].hash, 'hash-one', 'parsed hash')
|
||||
tt.is(commits[0].message, 'commit-one', 'parsed message')
|
||||
|
||||
tt.end()
|
||||
})
|
||||
})
|
||||
|
||||
t.test('get commits since hash', function (tt) {
|
||||
commits({lastRelease: {gitHead: 'notinhistory'}, options: {branch: 'notmaster'}}, function (err, commits) {
|
||||
tt.ok(err)
|
||||
tt.is(err.code, 'ENOTINHISTORY')
|
||||
tt.end()
|
||||
})
|
||||
})
|
||||
|
||||
t.end()
|
||||
})
|
||||
@@ -1,44 +0,0 @@
|
||||
const test = require('tap').test
|
||||
|
||||
const getRegistry = require('../../src/lib/get-registry')
|
||||
|
||||
test('get correct registry', function (t) {
|
||||
t.is(getRegistry({
|
||||
name: 'publish-config',
|
||||
publishConfig: {
|
||||
registry: 'a'
|
||||
}},
|
||||
{}), 'a')
|
||||
|
||||
t.is(getRegistry({name: 'normal'}, {
|
||||
get: function () {
|
||||
return 'b'
|
||||
}
|
||||
}), 'b')
|
||||
|
||||
t.is(getRegistry({name: 'normal'}, {
|
||||
get: function () {
|
||||
return null
|
||||
}
|
||||
}), 'https://registry.npmjs.org/')
|
||||
|
||||
t.is(getRegistry({name: '@scoped/foo'}, {
|
||||
get: function (input) {
|
||||
return input === '@scoped/registry' ? 'c' : 'd'
|
||||
}
|
||||
}), 'c')
|
||||
|
||||
t.is(getRegistry({name: '@scoped/bar'}, {
|
||||
get: function () {
|
||||
return 'e'
|
||||
}
|
||||
}), 'e')
|
||||
|
||||
t.is(getRegistry({name: '@scoped/baz'}, {
|
||||
get: function () {
|
||||
return null
|
||||
}
|
||||
}), 'https://registry.npmjs.org/')
|
||||
|
||||
t.end()
|
||||
})
|
||||
@@ -1,97 +0,0 @@
|
||||
var test = require('tap').test
|
||||
|
||||
var plugins = require('../../src/lib/plugins')
|
||||
|
||||
test('export plugins', function (t) {
|
||||
t.plan(5)
|
||||
|
||||
var defaultPlugins = plugins({})
|
||||
|
||||
t.is(typeof defaultPlugins.analyzeCommits, 'function')
|
||||
t.is(typeof defaultPlugins.generateNotes, 'function')
|
||||
t.is(typeof defaultPlugins.verifyConditions, 'function')
|
||||
t.is(typeof defaultPlugins.verifyRelease, 'function')
|
||||
t.is(typeof defaultPlugins.getLastRelease, 'function')
|
||||
})
|
||||
|
||||
test('plugin pipelines', function (t) {
|
||||
t.plan(3)
|
||||
|
||||
t.test('get all results', function (tt) {
|
||||
var pipelinePlugins = plugins({
|
||||
verifyRelease: [
|
||||
'./src/lib/plugin-noop',
|
||||
'./test/mocks/plugin-result-a',
|
||||
'./test/mocks/plugin-result-b'
|
||||
]
|
||||
})
|
||||
|
||||
pipelinePlugins.verifyRelease({}, function (err, results) {
|
||||
tt.error(err)
|
||||
tt.same(results, [undefined, 'a', 'b'])
|
||||
tt.end()
|
||||
})
|
||||
})
|
||||
|
||||
t.test('get first error', function (tt) {
|
||||
var pipelinePlugins = plugins({
|
||||
verifyConditions: [
|
||||
'./src/lib/plugin-noop',
|
||||
'./test/mocks/plugin-error-a',
|
||||
'./test/mocks/plugin-error-b'
|
||||
]
|
||||
})
|
||||
|
||||
pipelinePlugins.verifyConditions({}, function (err) {
|
||||
tt.is(err.message, 'a')
|
||||
tt.end()
|
||||
})
|
||||
})
|
||||
|
||||
t.test('get error and only results before', function (tt) {
|
||||
var pipelinePlugins = plugins({
|
||||
verifyRelease: [
|
||||
'./src/lib/plugin-noop',
|
||||
'./test/mocks/plugin-result-a',
|
||||
'./test/mocks/plugin-error-b',
|
||||
'./test/mocks/plugin-result-b'
|
||||
]
|
||||
})
|
||||
|
||||
pipelinePlugins.verifyRelease({}, function (err, results) {
|
||||
tt.is(err.message, 'b')
|
||||
tt.same(results, [undefined, 'a', undefined])
|
||||
tt.end()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
test('normalize and load plugin', function (t) {
|
||||
t.test('load from string', function (tt) {
|
||||
var plugin = plugins.normalize('./src/lib/plugin-noop')
|
||||
|
||||
tt.is(typeof plugin, 'function')
|
||||
|
||||
tt.end()
|
||||
})
|
||||
|
||||
t.test('load from object', function (tt) {
|
||||
var plugin = plugins.normalize({
|
||||
path: './src/lib/plugin-noop'
|
||||
})
|
||||
|
||||
tt.is(typeof plugin, 'function')
|
||||
|
||||
tt.end()
|
||||
})
|
||||
|
||||
t.test('load from fallback', function (tt) {
|
||||
var plugin = plugins.normalize(null, '../../src/lib/plugin-noop')
|
||||
|
||||
tt.is(typeof plugin, 'function')
|
||||
|
||||
tt.end()
|
||||
})
|
||||
|
||||
t.end()
|
||||
})
|
||||
@@ -1,74 +0,0 @@
|
||||
var defaults = require('lodash').defaults
|
||||
var test = require('tap').test
|
||||
var proxyquire = require('proxyquire')
|
||||
|
||||
var post = proxyquire('../../src/post', {
|
||||
'git-head': require('../mocks/git-head'),
|
||||
github: require('../mocks/github')
|
||||
})
|
||||
|
||||
var pkg = {
|
||||
version: '1.0.0',
|
||||
repository: {url: 'http://github.com/whats/up.git'}
|
||||
}
|
||||
|
||||
var plugins = {
|
||||
generateNotes: function (pkg, cb) {
|
||||
cb(null, 'the log')
|
||||
}
|
||||
}
|
||||
|
||||
var defaultRelease = {
|
||||
owner: 'whats',
|
||||
repo: 'up',
|
||||
name: 'v1.0.0',
|
||||
tag_name: 'v1.0.0',
|
||||
target_commitish: 'bar',
|
||||
body: 'the log'
|
||||
}
|
||||
|
||||
test('full post run', function (t) {
|
||||
t.test('in debug mode w/o token', function (tt) {
|
||||
post({
|
||||
options: {debug: true},
|
||||
pkg: pkg,
|
||||
plugins: plugins
|
||||
}, function (err, published, release) {
|
||||
tt.error(err)
|
||||
tt.is(published, false)
|
||||
tt.match(release, defaults({draft: true}, defaultRelease))
|
||||
|
||||
tt.end()
|
||||
})
|
||||
})
|
||||
|
||||
t.test('in debug mode w/token', function (tt) {
|
||||
post({
|
||||
options: {debug: true, githubToken: 'yo'},
|
||||
pkg: pkg,
|
||||
plugins: plugins
|
||||
}, function (err, published, release) {
|
||||
tt.error(err)
|
||||
tt.is(published, true)
|
||||
tt.match(release, defaults({draft: true}, defaultRelease))
|
||||
|
||||
tt.end()
|
||||
})
|
||||
})
|
||||
|
||||
t.test('production', function (tt) {
|
||||
post({
|
||||
options: {githubToken: 'yo'},
|
||||
pkg: pkg,
|
||||
plugins: plugins
|
||||
}, function (err, published, release) {
|
||||
tt.error(err)
|
||||
tt.is(published, true)
|
||||
tt.match(release, defaultRelease)
|
||||
|
||||
tt.end()
|
||||
})
|
||||
})
|
||||
|
||||
t.end()
|
||||
})
|
||||
@@ -1,64 +0,0 @@
|
||||
var test = require('tap').test
|
||||
var proxyquire = require('proxyquire')
|
||||
|
||||
require('../mocks/registry')
|
||||
var pre = proxyquire('../../src/pre', {
|
||||
'./lib/commits': proxyquire('../../src/lib/commits', {
|
||||
'child_process': require('../mocks/child-process')
|
||||
})
|
||||
})
|
||||
|
||||
var versions = {
|
||||
available: '1.0.0'
|
||||
}
|
||||
|
||||
var plugins = {
|
||||
verifyRelease: function (release, cb) {
|
||||
cb(null, release)
|
||||
},
|
||||
analyzeCommits: function (commits, cb) {
|
||||
cb(null, 'major')
|
||||
},
|
||||
getLastRelease: function (config, cb) {
|
||||
cb(null, {version: versions[config.pkg.name] || null, gitHead: 'HEAD'})
|
||||
}
|
||||
}
|
||||
|
||||
var npm = {
|
||||
registry: 'http://registry.npmjs.org/',
|
||||
tag: 'latest'
|
||||
}
|
||||
|
||||
test('full pre run', function (t) {
|
||||
t.test('increase version', function (tt) {
|
||||
tt.plan(3)
|
||||
|
||||
pre({
|
||||
options: {branch: 'master'},
|
||||
npm: npm,
|
||||
pkg: {name: 'available'},
|
||||
plugins: plugins
|
||||
}, function (err, release) {
|
||||
tt.error(err)
|
||||
tt.is(release.type, 'major')
|
||||
tt.is(release.version, '2.0.0')
|
||||
})
|
||||
})
|
||||
|
||||
t.test('increase version', function (tt) {
|
||||
tt.plan(3)
|
||||
|
||||
pre({
|
||||
options: {branch: 'master'},
|
||||
npm: npm,
|
||||
pkg: {name: 'unavailable'},
|
||||
plugins: plugins
|
||||
}, function (err, release) {
|
||||
tt.error(err)
|
||||
tt.is(release.type, 'initial')
|
||||
tt.is(release.version, '1.0.0')
|
||||
})
|
||||
})
|
||||
|
||||
t.end()
|
||||
})
|
||||
@@ -1,60 +0,0 @@
|
||||
var test = require('tap').test
|
||||
|
||||
var type = require('../../src/lib/type')
|
||||
|
||||
test('get type from commits', function (t) {
|
||||
t.test('get type from plugin', function (tt) {
|
||||
tt.plan(2)
|
||||
|
||||
type({
|
||||
commits: [{
|
||||
hash: '0',
|
||||
message: 'a'
|
||||
}],
|
||||
lastRelease: {version: '1.0.0'},
|
||||
plugins: {
|
||||
analyzeCommits: function (config, cb) {
|
||||
cb(null, 'major')
|
||||
}
|
||||
}
|
||||
}, function (err, type) {
|
||||
tt.error(err)
|
||||
tt.is(type, 'major')
|
||||
})
|
||||
})
|
||||
|
||||
t.test('error when no changes', function (tt) {
|
||||
tt.plan(1)
|
||||
|
||||
type({
|
||||
commits: [],
|
||||
lastRelease: {},
|
||||
plugins: {
|
||||
analyzeCommits: function (config, cb) {
|
||||
cb(null, null)
|
||||
}
|
||||
}
|
||||
}, function (err) {
|
||||
tt.is(err.code, 'ENOCHANGE')
|
||||
})
|
||||
})
|
||||
|
||||
t.test('initial version', function (tt) {
|
||||
tt.plan(2)
|
||||
|
||||
type({
|
||||
commits: [],
|
||||
lastRelease: {},
|
||||
plugins: {
|
||||
analyzeCommits: function (config, cb) {
|
||||
cb(null, 'major')
|
||||
}
|
||||
}
|
||||
}, function (err, type) {
|
||||
tt.error(err)
|
||||
tt.is(type, 'initial')
|
||||
})
|
||||
})
|
||||
|
||||
t.end()
|
||||
})
|
||||
@@ -1,73 +0,0 @@
|
||||
var test = require('tap').test
|
||||
|
||||
var verify = require('../../src/lib/verify')
|
||||
|
||||
test('verify pkg, options and env', function (t) {
|
||||
t.test('dry run verification', function (tt) {
|
||||
var noErrors = verify({
|
||||
options: {debug: true},
|
||||
pkg: {
|
||||
name: 'package',
|
||||
repository: {
|
||||
url: 'http://github.com/whats/up.git'
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
tt.is(noErrors.length, 0)
|
||||
|
||||
var errors = verify({
|
||||
options: {debug: true},
|
||||
pkg: {}
|
||||
})
|
||||
|
||||
tt.is(errors.length, 2)
|
||||
tt.is(errors[0].code, 'ENOPKGNAME')
|
||||
tt.is(errors[1].code, 'ENOPKGREPO')
|
||||
|
||||
tt.end()
|
||||
})
|
||||
|
||||
t.test('dry run verification for gitlab repo', function (tt) {
|
||||
var noErrors = verify({
|
||||
options: {debug: true},
|
||||
pkg: {
|
||||
name: 'package',
|
||||
repository: {
|
||||
url: 'http://gitlab.corp.com/whats/up.git'
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
console.log(noErrors)
|
||||
tt.is(noErrors.length, 0)
|
||||
tt.end()
|
||||
})
|
||||
|
||||
t.test('publish verification', function (tt) {
|
||||
var noErrors = verify({
|
||||
env: {NPM_TOKEN: 'yo'},
|
||||
options: {githubToken: 'sup'},
|
||||
pkg: {
|
||||
name: 'package',
|
||||
repository: {
|
||||
url: 'http://github.com/whats/up.git'
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
tt.is(noErrors.length, 0)
|
||||
|
||||
var errors = verify({env: {}, options: {}, pkg: {}})
|
||||
|
||||
tt.is(errors.length, 4)
|
||||
tt.is(errors[0].code, 'ENOPKGNAME')
|
||||
tt.is(errors[1].code, 'ENOPKGREPO')
|
||||
tt.is(errors[2].code, 'ENOGHTOKEN')
|
||||
tt.is(errors[3].code, 'ENONPMTOKEN')
|
||||
|
||||
tt.end()
|
||||
})
|
||||
|
||||
t.end()
|
||||
})
|
||||
@@ -0,0 +1,71 @@
|
||||
import test from 'ava';
|
||||
import verify from '../src/lib/verify';
|
||||
|
||||
test('Dry run - Verify pkg, options and env', t => {
|
||||
// Call the verify module with debug (Dry run), package name and repo URL
|
||||
const errors = verify({
|
||||
options: {debug: true},
|
||||
pkg: {name: 'package', repository: {url: 'http://github.com/whats/up.git'}},
|
||||
});
|
||||
|
||||
// Verify no error has been returned
|
||||
t.is(errors.length, 0);
|
||||
});
|
||||
|
||||
test('Dry run - Returns errors for missing package name and repo', t => {
|
||||
// Call the verify module with debug (Dry run), no package name and no repo URL
|
||||
const errors = verify({options: {debug: true}, pkg: {}});
|
||||
|
||||
// Verify the module return an error for each missing configuration
|
||||
t.is(errors.length, 2);
|
||||
t.is(errors[0].code, 'ENOPKGNAME');
|
||||
t.is(errors[1].code, 'ENOPKGREPO');
|
||||
});
|
||||
|
||||
test('Dry run - Verify pkg, options and env for gitlab repo', t => {
|
||||
// Call the verify module with debug (Dry run), no package name and no repo URL
|
||||
const errors = verify({
|
||||
options: {debug: true},
|
||||
pkg: {name: 'package', repository: {url: 'http://gitlab.corp.com/whats/up.git'}},
|
||||
});
|
||||
|
||||
// Verify no error has been returned
|
||||
t.is(errors.length, 0);
|
||||
});
|
||||
|
||||
test('Publish - Verify pkg, options and env', t => {
|
||||
// Call the verify module with package name, repo URL, npm token and github token
|
||||
const errors = verify({
|
||||
env: {NPM_TOKEN: 'yo'},
|
||||
options: {githubToken: 'sup'},
|
||||
pkg: {name: 'package', repository: {url: 'http://github.com/whats/up.git'}},
|
||||
});
|
||||
|
||||
// Verify no error has been returned
|
||||
t.is(errors.length, 0);
|
||||
});
|
||||
|
||||
test('Publish - Returns errors for missing package name, repo github token and npm token', t => {
|
||||
// Call the verify module with no package name, no repo URL, no NPM token and no github token
|
||||
const errors = verify({env: {}, options: {}, pkg: {}});
|
||||
|
||||
// Verify the module return an error for each missing configuration
|
||||
t.is(errors.length, 4);
|
||||
t.is(errors[0].code, 'ENOPKGNAME');
|
||||
t.is(errors[1].code, 'ENOPKGREPO');
|
||||
t.is(errors[2].code, 'ENOGHTOKEN');
|
||||
t.is(errors[3].code, 'ENONPMTOKEN');
|
||||
});
|
||||
|
||||
test('Publish - Returns errors for missing email when using legacy npm token', t => {
|
||||
// Call the verify module with package name, repo URL, old NPM token and github token and no npm email
|
||||
const errors = verify({
|
||||
env: {NPM_OLD_TOKEN: 'yo'},
|
||||
options: {githubToken: 'sup'},
|
||||
pkg: {name: 'package', repository: {url: 'http://github.com/whats/up.git'}},
|
||||
});
|
||||
|
||||
// Verify the module return an error for each missing configuration
|
||||
t.is(errors.length, 1);
|
||||
t.is(errors[0].code, 'ENONPMTOKEN');
|
||||
});
|
||||
Reference in New Issue
Block a user