Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fb1aa80f26 | ||
|
|
05490fe229 | ||
|
|
76d9e3d2be | ||
|
|
776ffd1256 | ||
|
|
494f851ee7 | ||
|
|
3bdeff3468 | ||
|
|
8dd79565d0 | ||
|
|
a344f32e36 | ||
|
|
e1c1b7419b | ||
|
|
3eb842c297 | ||
|
|
ddaec4f2bf | ||
|
|
22a283a027 | ||
|
|
d9eeb3fcae | ||
|
|
8892ec7f7a | ||
|
|
cf27cd16cc | ||
|
|
152d1f6874 | ||
|
|
626315e9fe | ||
|
|
f5573f7494 | ||
|
|
2d3506cda1 | ||
|
|
72f9f8ea7c | ||
|
|
59d852d6fb | ||
|
|
ed05101a61 | ||
|
|
431babb42e | ||
|
|
dbea5cc1b1 | ||
|
|
6cf1711151 | ||
|
|
ba5222af52 | ||
|
|
b1d9985ba3 | ||
|
|
13e2f5ce78 | ||
|
|
af15fb4c61 | ||
|
|
caf09c9be0 | ||
|
|
0316babf7a | ||
|
|
43c8df0bfe | ||
|
|
150273c8fe | ||
|
|
f247ed8741 | ||
|
|
2eff4a4467 | ||
|
|
e1d5da5864 | ||
|
|
a0190b7ad3 | ||
|
|
c6f95e4870 | ||
|
|
6d84b66c05 | ||
|
|
4d58af7145 | ||
|
|
9a3d9a9280 | ||
|
|
32c1dcf75b | ||
|
|
4093bb2dbe | ||
|
|
c59b5cac9c | ||
|
|
44a18fd5cf | ||
|
|
e24c7c3833 | ||
|
|
057e8e9759 | ||
|
|
da23c15ea5 | ||
|
|
b63a43fa53 | ||
|
|
c47ff97ab3 | ||
|
|
689f37ae2e | ||
|
|
a4fe18cade | ||
|
|
7412401d55 | ||
|
|
6df67828fe | ||
|
|
66bf8ff710 | ||
|
|
a405021d08 | ||
|
|
f79e26dcd6 | ||
|
|
861debb85e | ||
|
|
d6172b8767 | ||
|
|
f62525ad7e | ||
|
|
cce860ec03 | ||
|
|
56238887d3 | ||
|
|
ac7037d948 |
@@ -0,0 +1,11 @@
|
||||
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
|
||||
+11
@@ -1,3 +1,14 @@
|
||||
# common
|
||||
coverage
|
||||
node_modules
|
||||
test/registry/couch
|
||||
test/registry/data
|
||||
*.log
|
||||
*.dump
|
||||
.DS_Store
|
||||
.nyc_output
|
||||
.test
|
||||
.tmp
|
||||
|
||||
# build-artifacts
|
||||
dist
|
||||
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
# common
|
||||
coverage
|
||||
node_modules
|
||||
test/registry/couch
|
||||
test/registry/data
|
||||
*.log
|
||||
*.dump
|
||||
.DS_Store
|
||||
.nyc_output
|
||||
.test
|
||||
.tmp
|
||||
|
||||
# source/config
|
||||
src
|
||||
*.yml
|
||||
.gitignore
|
||||
.editorconfig
|
||||
.npmrc
|
||||
+15
-13
@@ -1,20 +1,22 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- '0.10'
|
||||
sudo: false
|
||||
language: node_js
|
||||
cache:
|
||||
directories:
|
||||
- node_modules
|
||||
notifications:
|
||||
email: false
|
||||
node_js:
|
||||
- iojs-v2
|
||||
- iojs-v1
|
||||
- '0.12'
|
||||
- '0.10'
|
||||
before_install:
|
||||
- npm i -g npm@^2.0.0
|
||||
deploy:
|
||||
provider: npm
|
||||
email: stephan@boennemann.me
|
||||
skip_cleanup: true
|
||||
api_key:
|
||||
secure: Lq1FZweaNr/Ah8M7h3oWQ59HTswzvcksTUfzWb/dpqNn5FECN9I+4gi79EQPD62ZbJDCuDHY0EEEDLdnaB1z8N7kOj1RtmvC1k0teTEXFsGBPS4evXakRj+AfoBAGsTaXHqBYBOvYBxJT2Md/UoOgPSQjtAdZSNsmoFb1xkngQ0=
|
||||
on:
|
||||
branch: master
|
||||
repo: boennemann/semantic-release
|
||||
- npm i -g npm@^2.0.0
|
||||
before_script:
|
||||
- npm prune
|
||||
- curl -Lo travis_after_all.py https://git.io/vLSON
|
||||
after_success:
|
||||
- python travis_after_all.py
|
||||
- export $(cat .to_export_back)
|
||||
- if [[ $BUILD_LEADER = YES ]]; then npm run coverage:upload; fi
|
||||
- npm run semantic-release
|
||||
|
||||
@@ -1,24 +1,184 @@
|
||||
# semantic-release
|
||||
[](https://travis-ci.org/boennemann/semantic-release)
|
||||
[](https://david-dm.org/boennemann/semantic-release)
|
||||
[](https://david-dm.org/boennemann/semantic-release#info=devDependencies)
|
||||
| [](https://travis-ci.org/semantic-release/semantic-release) | [](https://coveralls.io/github/semantic-release/semantic-release?branch=next) | [](https://david-dm.org/semantic-release/semantic-release/next) | [](https://david-dm.org/semantic-release/semantic-release/next#info=devDependencies) | [](https://github.com/feross/standard) |
|
||||
| --- | --- | --- | --- | --- |
|
||||
|
||||
`semantic-release` builds upon a set of conventions to give you **fully automated, semver-compliant package publishing**. It's mostly about _commit-messages_, but you can define more _heuristics_.
|
||||
|
||||
| Commands | Comment
|
||||
--- | --- | ---
|
||||
| **manual** | <pre><code><div>npm version major</div><div>git push origin master --tags</div><div>npm publish</div></code></pre> | You **manually decide** what the **next version** is. You have to remember what major, minor and patch means. You have to remember to push both commits and tags. You have to wait for the CI to pass. |
|
||||
| **semantic-release** | <pre><code><div>git commit -m "fix: <message>"</div><div>git push</div></code></pre> | You **think about and describe the changes** you've made. A new version is automatically published with the correct version number.
|
||||
|
||||
This removes the immediate connection between human emotions and version numbers, so strictly following the [SemVer](http://semver.org/) spec is not a problem anymore – and that’s ultimately `semantic-release`’s goal.
|
||||
|
||||
> ### “We fail to follow SemVer – and why it needn’t matter”
|
||||
> #### JSConf Budapest 2015
|
||||
|
||||
> [](https://www.youtube.com/watch?v=tc2UgG5L7WM&index=6&list=PLFZ5NyC0xHDaaTy6tY9p0C0jd_rRRl5Zm)
|
||||
|
||||
> This talk gives you a complete introduction to the underlying concepts of this module
|
||||
|
||||
## How does it work?
|
||||
|
||||
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 this then possible to generate a helpful changelog and to derive the next semantic version number from them.
|
||||
|
||||
_Note: This module ships with the [AngularJS Commit Message Conventions](https://docs.google.com/document/d/1QrDFcIiPjSLDn3EL15IJygNPiHORgU1_OOAqWjiDU5Y/edit) and changelog generator, but you can [define your own](#plugins) style_.
|
||||
|
||||
> ### Commit Message Format
|
||||
|
||||
> Each commit message consists of a **header**, a **body** and a **footer**. The header has a special
|
||||
format that includes a **type**, a **scope** and a **subject**:
|
||||
|
||||
> ```
|
||||
<type>(<scope>): <subject>
|
||||
<BLANK LINE>
|
||||
<body>
|
||||
<BLANK LINE>
|
||||
<footer>
|
||||
```
|
||||
|
||||
> [Full explanation](https://github.com/ajoslin/conventional-changelog/blob/master/conventions/angular.md)
|
||||
|
||||
When `semantic-release` got 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. That 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/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, for example with important security fixes.
|
||||
|
||||
This is what happens in series:
|
||||
|
||||
| 1. `git push` | 2. `semantic-release pre` | 3. `npm publish` | 4. `semantic-release post` |
|
||||
| :--- | :--- | :--- | :---- |
|
||||
| New code is pushed and triggers a CI build. | Based on all commits that happened since the last release, the new version number gets written to the `package.json`. | The new version gets published to `npm`. | A changelog gets generated and a [release](https://help.github.com/articles/about-releases/) (including a git tag) on GitHub gets created. |
|
||||
|
||||
_Note:_ The current release/tag implementation is tied to GitHub, but could be opened up to Bitbucket, GitLab, et al. Feel free to send PRs for these services.
|
||||
|
||||
## Setup
|
||||
|
||||
[](https://nodei.co/npm/semantic-release/)
|
||||
|
||||
```bash
|
||||
npm i semantic-release
|
||||
npm install -g semantic-release-cli
|
||||
|
||||
cd your-module
|
||||
semantic-release-cli setup
|
||||
```
|
||||
You *need* to set it up inside your `package.json`:
|
||||
|
||||

|
||||
|
||||
_[This is what happens under the hood.](https://github.com/semantic-release/cli#manual-setup)_
|
||||
|
||||
## Options
|
||||
|
||||
You can pass options either via command line (in [kebab-case](https://lodash.com/docs#kebabCase)) or in the `release` field of your `package.json` (in [camelCase](https://lodash.com/docs#camelCase)). The following two examples are the same, but CLI arguments take precedence.
|
||||
|
||||
| CLI | package.json |
|
||||
| --- | --- |
|
||||
| <pre><code>semantic-release pre --no-debug</code><pre> | <pre><code><div>//package.json</div><div>"release": {</div><div> "debug": false</div><div>}</div></code></pre><pre><code>semantic-release pre</code></pre> |
|
||||
|
||||
|
||||
These options are currently available:
|
||||
- `branch`: The branch on which releases should happen. Default: `'master'`
|
||||
- `debug`: If true doesn't actually publish to npm or write things to file. Default: `!process.env.CI`
|
||||
- `githubToken`: The token used to authenticate with GitHub. Default: `process.env.GH_TOKEN`
|
||||
- `githubUrl`: Optional. Pass your GitHub Enterprise endpoint.
|
||||
|
||||
_A few notes on `npm` config_:
|
||||
1. The `npm` token can only be defined in the environment as `NPM_TOKEN`, because that's where `npm` itself is going to read it from.
|
||||
|
||||
2. In order to publish to a different `npm` registry you can just configure that how you would usually do it and `semantic-release` will respect that setting.
|
||||
|
||||
3. If you want to use another dist-tag for your publishes than `'latest'` you can specify that inside the `package.json`'s [`publishConfig`](https://docs.npmjs.com/files/package.json#publishconfig) field.
|
||||
|
||||
4. `semantic-release` generally tries to orientate itself towards `npm` – it inherits the loglevel for example.
|
||||
|
||||
## Plugins
|
||||
|
||||
There are four steps where you can customize the `semantic-release` behavior using plugins. A plugin is a regular [option](#options), but inside the `package.json` you can pass additional config.
|
||||
|
||||
```json
|
||||
"scripts": {
|
||||
"prepublish": "semantic-release pre",
|
||||
"postpublish": "semantic-release post"
|
||||
{
|
||||
"release": {
|
||||
"analyzeCommits": "npm-module-name",
|
||||
"generateNotes": "./path/to/a/local/module",
|
||||
"verifyConditions": {
|
||||
"path": "./path/to/a/module",
|
||||
"additional": "config"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Note: `semantic-release` works around a limitation in npm's "prepublish" hook. Once a version is published it prints an error that you can *safely ignore*.
|
||||
See [npm/npm#7118](https://github.com/npm/npm/issues/7118).
|
||||
```
|
||||
semantic-release pre --analyze-commits="npm-module-name"
|
||||
```
|
||||
|
||||
A plugin itself is an async function that always receives three arguments.
|
||||
|
||||
```js
|
||||
module.exports = function (pluginConfig, config, callback) {}
|
||||
```
|
||||
|
||||
- `pluginConfig`: If the user of your plugin specifies additional plugin config in the `package.json` (see the `verifyConditions` example above) then it's this object.
|
||||
- `config`: A config object containing a lot of information to act upon.
|
||||
- `env`: All environment variables
|
||||
- `npm`: Select npm configuration bits like `registry`, `tag` and `auth`
|
||||
- `options`: `semantic-release` options like `debug`, or `branch`
|
||||
- `pkg`: Parsed `package.json`
|
||||
- For certain plugins the `config` object contains even more information. See below.
|
||||
- `callback`: If an error occurs pass it as first argument. Otherwise pass your result as second argument.
|
||||
|
||||
|
||||
### `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/).
|
||||
|
||||
### `generateNotes`
|
||||
|
||||
This plugin is responsible for generating release notes. Call the callback with the notes as a string. Have a look at the [default implementation](https://github.com/semantic-release/release-notes-generator/).
|
||||
|
||||
### `verifyConditions`
|
||||
|
||||
This plugins is responsible for verifying that a release should happen in the first place. For example, the [default implementation](https://github.com/semantic-release/condition-travis/) verifies that the publish is happening on Travis, that it's the right branch, and that all other build jobs succeeded. There are more use cases for this, e.g. verifying that test coverage is above a certain threshold or that there are no [vulnerabilities](https://nodesecurity.io/) in your dependencies. Be creative.
|
||||
|
||||
### `verifyRelease`
|
||||
|
||||
This plugin is responsible for verifying a release that was determined before and is about to be published. There is no default implementation. It additionally receives `nextRelease`, `lastRelease` and `commits` inside `config`. While `commits` is the same as with analyzeCommits, `nextRelease` contains a `type` (e.g. `'major'`) and the new version (e.g. `'1.0.0'`) and `lastRelease` contains the old `version`, the `gitHead` at the time of the release and the npm dist-`tag` (e.g. `'latest'`). Using this information you could [detect breaking changes](https://github.com/semantic-release/cracks) or hold back certain types of releases. Again: Be creative.
|
||||
|
||||
## ITYM*FAQ*LT
|
||||
> I think you might frequently ask questions like these
|
||||
|
||||
### Why is the `package.json`'s version not updated in my repository?
|
||||
|
||||
The `npm` docs even state:
|
||||
|
||||
> The most important things in your package.json are the name and version fields. Those are actually required, and your package won't install without them.
|
||||
> – [npm docs](https://docs.npmjs.com/files/package.json#version)
|
||||
|
||||
While this entirely true the version number doesn't have to be checked into source control. `semantic-release` takes care of the version field right before `npm publish` uses it – and this is the only point where it _really_ is required.
|
||||
|
||||
### Is there a way to preview which version would currently get published?
|
||||
|
||||
If you run `npm run semantic-release` locally a dry run gets performed, which logs the version that would currently get published.
|
||||
|
||||
### Can I run this on my own machine rather than on a CI server?
|
||||
|
||||
Of course you can, but this doesn't necessarily mean you should. Running your tests on an independent machine before releasing software is a crucial part of this workflow. Also it is a pain to set this up locally, with tokens lying around and everything. That said, you can run the scripts with `--debug=false` explicitly. You have to export `GH_TOKEN=<your_token>` and `NPM_TOKEN=<your_other_token>`.
|
||||
|
||||
### Can I manually trigger the release of a specific version?
|
||||
|
||||
You can trigger a release by pushing to your GitHub repository. You deliberately cannot trigger a _specific_ version release, because this is the whole point of `semantic-release`. Start your packages with `1.0.0` and semver on.
|
||||
|
||||
### Is it _really_ a good idea to release on every push?
|
||||
|
||||
It is indeed a great idea because it _forces_ you to follow best practices. If you don't feel comfortable making every passing feature or fix on your master branch addressable via `npm` you might not treat your master right. Have a look at [branch workflows](https://guides.github.com/introduction/flow/index.html). If you still think you should have control over the exact point in time of your release, e.g. because you are following a release schedule, you can release only on the `production`/`deploy`/`release` branch and push your code there in certain intervals, or better yet use [dist-tags](https://docs.npmjs.com/cli/dist-tag).
|
||||
|
||||
### 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 node.js `^0.10`, `^0.12` and io.js `^1`, `^2`. A new version won't get published if it doesn't pass on all these engines.
|
||||
|
||||
Note: Currently integration-tests don't run on Travis CI. If you know stuff about npm/Travis/Couch: Please help!
|
||||
|
||||
## License
|
||||
|
||||
MIT License
|
||||
2015 Stephan Bönnemann
|
||||
2015 © Stephan Bönnemann and [contributors](https://github.com/semantic-release/semantic-release/graphs/contributors)
|
||||
|
||||

|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
cat .tmp/sinopia.pid | xargs kill
|
||||
|
||||
cat .tmp/ghrs.pid | xargs kill
|
||||
|
||||
cp .tmp/.npmrc ~/.npmrc
|
||||
|
||||
rm -rf .tmp
|
||||
@@ -1,14 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -e
|
||||
|
||||
mkdir -p .tmp/modules
|
||||
|
||||
./node_modules/.bin/sinopia ./tests/config.yml & echo $! >> .tmp/sinopia.pid
|
||||
./node_modules/.bin/github-release-fake-server -p 4343 & echo $! >> .tmp/ghrs.pid
|
||||
|
||||
sleep 0.5
|
||||
|
||||
cp ~/.npmrc .tmp/.npmrc
|
||||
|
||||
cp tests/.npmrc ~/.npmrc
|
||||
@@ -1,78 +0,0 @@
|
||||
#!/usr/bin/env node
|
||||
'use strict'
|
||||
|
||||
var abbrev = require('abbrev')
|
||||
var confirm = require('confirm-simple')
|
||||
var minimist = require('minimist')
|
||||
|
||||
var efh = require('../lib/error').standard
|
||||
|
||||
var argv = minimist(process.argv.slice(2), {
|
||||
alias: {
|
||||
d: 'debug',
|
||||
dry: 'debug',
|
||||
t: 'token',
|
||||
g: 'github-url'
|
||||
},
|
||||
default: {
|
||||
token: process.env.GH_TOKEN || process.env.TOKEN || process.env.GITHUB_TOKEN,
|
||||
'github-url': process.env.GH_URL
|
||||
}
|
||||
})
|
||||
|
||||
var npmArgv = process.env.npm_config_argv ?
|
||||
minimist(JSON.parse(process.env.npm_config_argv).cooked) :
|
||||
{_: []}
|
||||
|
||||
if (~argv._.indexOf('pre')) {
|
||||
// see src/restart.js
|
||||
if (npmArgv['semantic-release-rerun']) process.exit(0)
|
||||
// the `prepublish` hook is also executed when the package is installed
|
||||
// in this case we abort the command and do nothing.
|
||||
if (isAbbrev(npmArgv, 'install')) process.exit(0)
|
||||
|
||||
return confirmCI(function () {
|
||||
console.log('Determining new version')
|
||||
|
||||
var publish = false
|
||||
if (isAbbrev(npmArgv, 'publish')) publish = true
|
||||
|
||||
require('../src/pre')(argv, efh(function (result) {
|
||||
if (!result) {
|
||||
console.log('Nothing changed. Not publishing.')
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
console.log('Publishing v' + result)
|
||||
if (!publish) process.exit(0)
|
||||
|
||||
require('../src/restart')(efh(function () {
|
||||
process.exit(1)
|
||||
}))
|
||||
}))
|
||||
})
|
||||
}
|
||||
|
||||
if (~argv._.indexOf('post')) {
|
||||
return confirmCI(function () {
|
||||
require('../src/post')(argv, efh(function () {
|
||||
// see src/restart.js
|
||||
if (npmArgv['semantic-release-rerun']) {
|
||||
console.log('Everything is alright :) npm will now print an error message that you can safely ignore.')
|
||||
}
|
||||
}))
|
||||
})
|
||||
}
|
||||
|
||||
function confirmCI (cb) {
|
||||
if (process.env.CI || argv.ci === false) return cb(null, true)
|
||||
|
||||
confirm('Not running in a CI enviroment. Are you sure you want to run this hook?', function (ok) {
|
||||
if (!ok) process.exit(1)
|
||||
cb(null, ok)
|
||||
})
|
||||
}
|
||||
|
||||
function isAbbrev (argv, command) {
|
||||
return argv._.some(Object.prototype.hasOwnProperty.bind(abbrev(command)))
|
||||
}
|
||||
Executable
+13
@@ -0,0 +1,13 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
/* istanbul ignore next */
|
||||
try {
|
||||
require('../dist')
|
||||
} catch (err) {
|
||||
if (err.code === 'MODULE_NOT_FOUND') {
|
||||
require('babel/register')
|
||||
require('../src')
|
||||
} else {
|
||||
console.log(err)
|
||||
}
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
'use strict'
|
||||
|
||||
var efh = require('error-first-handler')
|
||||
|
||||
module.exports = {
|
||||
efh: efh,
|
||||
standard: efh(function(err) {
|
||||
console.log('Something went wrong:')
|
||||
if (typeof err === 'string') return console.log(err)
|
||||
if (err instanceof Error) return console.log(err.message)
|
||||
if (err.message) return console.log(err.message)
|
||||
console.log(err)
|
||||
})
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
'use strict'
|
||||
|
||||
module.exports = function (commits) {
|
||||
var type = null
|
||||
|
||||
commits.every(function (commit) {
|
||||
if (commit.breaks.length) {
|
||||
type = 'major'
|
||||
return false
|
||||
}
|
||||
|
||||
if (commit.type === 'feat') type = 'minor'
|
||||
|
||||
if (!type && commit.type === 'fix') type = 'patch'
|
||||
|
||||
return true
|
||||
})
|
||||
|
||||
return type
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
'use strict'
|
||||
|
||||
var git = require('conventional-changelog/lib/git')
|
||||
|
||||
var efh = require('../error').efh
|
||||
|
||||
module.exports = function (cb) {
|
||||
git.latestTag(efh(cb)(function (from) {
|
||||
git.getCommits({from: from}, efh(cb)(function (commits) {
|
||||
cb(null, commits)
|
||||
}))
|
||||
}))
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
'use strict'
|
||||
|
||||
var analyze = require('./analyze')
|
||||
var commits = require('./commits')
|
||||
var efh = require('../error').efh
|
||||
|
||||
module.exports = function (cb) {
|
||||
commits(efh(cb)(function (commits) {
|
||||
cb(null, analyze(commits))
|
||||
}))
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
'use strict'
|
||||
|
||||
var exec = require('child_process').exec
|
||||
|
||||
var efh = require('./error').efh
|
||||
|
||||
module.exports = function (pkg, cb) {
|
||||
if (!pkg.name) return cb(new Error('Package must have a name'))
|
||||
|
||||
exec('curl -s "' + process.env.npm_config_registry + pkg.name + '"', efh(cb)(function(stdout) {
|
||||
var pkg = JSON.parse(stdout)
|
||||
|
||||
if (pkg.error) return cb(null, null, true)
|
||||
|
||||
cb(null, pkg['dist-tags'].latest)
|
||||
}))
|
||||
}
|
||||
+75
-36
@@ -1,58 +1,97 @@
|
||||
{
|
||||
"name": "semantic-release",
|
||||
"description": "semantic semver compliant package publishing",
|
||||
"version": "0.0.6",
|
||||
"author": "Stephan Bönnemann <stephan@boennemann.me>",
|
||||
"bin": "./bin/semantic-release",
|
||||
"description": "automated semver compliant package publishing",
|
||||
"author": "Stephan Bönnemann <stephan@boennemann.me> (http://boennemann.me)",
|
||||
"bin": {
|
||||
"semantic-release": "./bin/semantic-release.js"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/boennemann/semantic-release/issues"
|
||||
"url": "https://github.com/semantic-release/semantic-release/issues"
|
||||
},
|
||||
"bundleDependencies": [
|
||||
"@semantic-release/commit-analyzer",
|
||||
"@semantic-release/condition-travis",
|
||||
"@semantic-release/error",
|
||||
"@semantic-release/release-notes-generator"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=0.10",
|
||||
"npm": ">=2"
|
||||
},
|
||||
"config": {
|
||||
"nyc": {
|
||||
"exclude": [
|
||||
".test",
|
||||
"node_modules"
|
||||
]
|
||||
}
|
||||
},
|
||||
"dependencies": {
|
||||
"abbrev": "^1.0.5",
|
||||
"confirm-simple": "^1.0.3",
|
||||
"conventional-changelog": "0.0.11",
|
||||
"error-first-handler": "^1.0.1",
|
||||
"github": "^0.2.3",
|
||||
"github-url-from-git": "^1.4.0",
|
||||
"minimist": "^1.1.0",
|
||||
"@semantic-release/commit-analyzer": "^2.0.0",
|
||||
"@semantic-release/condition-travis": "^4.0.0",
|
||||
"@semantic-release/error": "^1.0.0",
|
||||
"@semantic-release/release-notes-generator": "^2.0.0",
|
||||
"git-head": "^1.2.1",
|
||||
"github": "^0.2.4",
|
||||
"lodash": "^3.9.3",
|
||||
"nopt": "^3.0.3",
|
||||
"npm-registry-client": "^6.4.0",
|
||||
"npmconf": "^2.1.2",
|
||||
"npmlog": "^1.2.1",
|
||||
"parse-github-repo-url": "^1.0.0",
|
||||
"semver": "^4.2.0"
|
||||
"require-relative": "^0.8.7",
|
||||
"run-auto": "^1.1.2",
|
||||
"semver": "^5.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"github-release-fake-server": "^1.1.1",
|
||||
"lodash.defaults": "^3.0.0",
|
||||
"nano-uid": "^0.2.0",
|
||||
"babel": "^5.5.8",
|
||||
"coveralls": "^2.11.2",
|
||||
"mkdirp": "^0.5.1",
|
||||
"nixt": "^0.4.1",
|
||||
"sinopia": "^1.0.0",
|
||||
"standard": "^2.3.1",
|
||||
"tap-spec": "^2.2.0",
|
||||
"tape": "^3.5.0"
|
||||
"nock": "^2.5.0",
|
||||
"npm-registry-couchapp": "^2.6.11",
|
||||
"nyc": "^3.0.0",
|
||||
"proxyquire": "^1.5.0",
|
||||
"rimraf": "^2.4.0",
|
||||
"standard": "^4.2.1",
|
||||
"tap": "^1.3.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^0.10.0",
|
||||
"npm": "^2.0.0"
|
||||
},
|
||||
"homepage": "https://github.com/boennemann/semantic-release",
|
||||
"homepage": "https://github.com/semantic-release/semantic-release/tree/next#readme",
|
||||
"keywords": [
|
||||
"release",
|
||||
"publish",
|
||||
"author",
|
||||
"automation",
|
||||
"changelog",
|
||||
"module",
|
||||
"package",
|
||||
"publish",
|
||||
"release",
|
||||
"semver",
|
||||
"version",
|
||||
"changelog"
|
||||
"version"
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "index.js",
|
||||
"main": "dist/index.js",
|
||||
"publishConfig": {
|
||||
"tag": "next"
|
||||
},
|
||||
"release": {
|
||||
"branch": "next"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/boennemann/semantic-release.git"
|
||||
"url": "git+https://github.com/semantic-release/semantic-release.git"
|
||||
},
|
||||
"scripts": {
|
||||
"postpublish": "./bin/semantic-release post",
|
||||
"posttest": "./bin/post-test",
|
||||
"prepublish": "./bin/semantic-release pre",
|
||||
"pretest": "./bin/pre-test",
|
||||
"test": "standard && node tests | tap-spec"
|
||||
"build": "rimraf dist && mkdirp dist && babel src --out-dir dist",
|
||||
"coverage": "nyc report",
|
||||
"coverage:upload": "npm run coverage -- --reporter=lcovonly && coveralls < coverage/lcov.info",
|
||||
"prepublish": "npm run build",
|
||||
"pretest:integration": "npm run build && npm run test:build",
|
||||
"pretest:unit": "npm run build && npm run test:build",
|
||||
"semantic-release": "./bin/semantic-release.js pre && npm dedupe && npm publish && ./bin/semantic-release.js post",
|
||||
"test": "npm run test:style && npm run test:unit",
|
||||
"test:build": "rimraf .test && mkdirp .test && babel test --out-dir .test",
|
||||
"test:integration": "tap --no-cov .test/scenarios/*.js",
|
||||
"test:style": "standard",
|
||||
"test:unit": "nyc tap --no-cov .test/specs/*.js"
|
||||
}
|
||||
}
|
||||
|
||||
+134
@@ -0,0 +1,134 @@
|
||||
const { readFileSync, writeFileSync } = require('fs')
|
||||
const path = require('path')
|
||||
|
||||
const _ = require('lodash')
|
||||
const log = require('npmlog')
|
||||
const nopt = require('nopt')
|
||||
const npmconf = require('npmconf')
|
||||
|
||||
const PREFIX = 'semantic-release'
|
||||
const env = process.env
|
||||
const pkg = JSON.parse(readFileSync('./package.json'))
|
||||
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) => _.camelCase(key)),
|
||||
pkg.release,
|
||||
{
|
||||
branch: 'master',
|
||||
debug: !env.CI,
|
||||
githubToken: env.GH_TOKEN || env.GITHUB_TOKEN,
|
||||
githubUrl: env.GH_URL
|
||||
}
|
||||
)
|
||||
const plugins = require('./lib/plugins')(options)
|
||||
|
||||
npmconf.load({}, (err, conf) => {
|
||||
if (err) {
|
||||
log.error(PREFIX, 'Failed to load npm config.', err)
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
let npm = {
|
||||
auth: {
|
||||
token: env.NPM_TOKEN
|
||||
},
|
||||
loglevel: conf.get('loglevel'),
|
||||
registry: conf.get('registry'),
|
||||
tag: (pkg.publishConfig || {}).tag || conf.get('tag') || 'latest'
|
||||
}
|
||||
|
||||
if (npm.registry[npm.registry.length - 1] !== '/') npm.registry += '/'
|
||||
|
||||
log.level = npm.loglevel
|
||||
|
||||
const config = {PREFIX, log, env, pkg, options, plugins, npm}
|
||||
|
||||
log.verbose(PREFIX, 'options:', _.assign({
|
||||
githubToken: options.githubToken ? '***' : undefined
|
||||
}), options)
|
||||
log.verbose(PREFIX, 'Verifying config.')
|
||||
|
||||
const errors = require('./lib/verify')(config)
|
||||
errors.forEach((err) => log.error(PREFIX, `${err.message} ${err.code}`))
|
||||
if (errors.length) process.exit(1)
|
||||
|
||||
if (options.argv.remain[0] === 'pre') {
|
||||
log.verbose(PREFIX, 'Running pre-script.')
|
||||
log.verbose(PREFIX, 'Veriying conditions.')
|
||||
|
||||
plugins.verifyConditions(config, (err) => {
|
||||
if (err) {
|
||||
log[options.debug ? 'warn' : 'error'](PREFIX, err.message)
|
||||
if (!options.debug) process.exit(1)
|
||||
}
|
||||
|
||||
const nerfDart = require('./lib/nerf-dart')(npm.registry)
|
||||
let wroteNpmRc = false
|
||||
|
||||
if (env.NPM_TOKEN) {
|
||||
conf.set(`${nerfDart}:_authToken`, '${NPM_TOKEN}', 'project')
|
||||
wroteNpmRc = true
|
||||
} else 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
|
||||
}
|
||||
|
||||
conf.save('project', (err) => {
|
||||
if (err) return log.error(PREFIX, 'Failed to save npm config.', err)
|
||||
|
||||
if (wroteNpmRc) log.verbose(PREFIX, 'Wrote authToken to .npmrc.')
|
||||
|
||||
require('./pre')(config, (err, release) => {
|
||||
if (err) {
|
||||
log.error(PREFIX, 'Failed to determine new version.')
|
||||
|
||||
const args = [PREFIX, (err.code ? `${err.code} ` : '') + err.message]
|
||||
if (err.stack) args.push(err.stack)
|
||||
log.error(...args)
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
const message = `Determined version ${release.version} as "${npm.tag}".`
|
||||
|
||||
log.verbose(PREFIX, message)
|
||||
|
||||
if (options.debug) {
|
||||
log.error(PREFIX, `${message} Not publishing in debug mode.`, release)
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
writeFileSync('./package.json', JSON.stringify(_.assign(pkg, {
|
||||
version: release.version
|
||||
}), null, 2))
|
||||
|
||||
log.verbose(PREFIX, `Wrote version ${release.version} to package.json.`)
|
||||
})
|
||||
})
|
||||
})
|
||||
} else if (options.argv.remain[0] === 'post') {
|
||||
log.verbose(PREFIX, 'Running post-script.')
|
||||
|
||||
require('./post')(config, (err, published, release) => {
|
||||
if (err) {
|
||||
log.error(PREFIX, 'Failed to publish release notes.', err)
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
log.verbose(PREFIX, `${published ? 'Published' : 'Generated'} release notes.`, release)
|
||||
})
|
||||
} else {
|
||||
log.error(PREFIX, `Command "${options.argv.remain[0]}" not recognized. User either "pre" or "post"`)
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,25 @@
|
||||
const { exec } = require('child_process')
|
||||
|
||||
module.exports = function ({lastRelease}, cb) {
|
||||
const from = lastRelease.gitHead
|
||||
const range = (from ? from + '..' : '') + 'HEAD'
|
||||
|
||||
exec(
|
||||
`git log -E --format=%H==SPLIT==%B==END== ${range}`,
|
||||
(err, stdout) => {
|
||||
if (err) return cb(err)
|
||||
|
||||
cb(null, String(stdout).split('==END==\n')
|
||||
|
||||
.filter((raw) => !!raw.trim())
|
||||
|
||||
.map((raw) => {
|
||||
const data = raw.split('==SPLIT==')
|
||||
return {
|
||||
hash: data[0],
|
||||
message: data[1]
|
||||
}
|
||||
}))
|
||||
}
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
const SemanticReleaseError = require('@semantic-release/error')
|
||||
|
||||
const npmlog = require('npmlog')
|
||||
const RegClient = require('npm-registry-client')
|
||||
|
||||
module.exports = function ({pkg, npm}, cb) {
|
||||
npmlog.level = npm.loglevel || 'error'
|
||||
const client = new RegClient({log: npmlog})
|
||||
|
||||
client.get(`${npm.registry}${pkg.name.replace('/', '%2F')}`, {
|
||||
auth: npm.auth
|
||||
}, (err, data) => {
|
||||
if (err && err.statusCode === 404) return cb(null, {})
|
||||
if (err) return cb(err)
|
||||
|
||||
const version = data['dist-tags'][npm.tag]
|
||||
|
||||
if (!version) return cb(new SemanticReleaseError(`There is no release with the dist-tag "${npm.tag}" yet. Tag a version first.`, 'ENODISTTAG'))
|
||||
|
||||
cb(null, {
|
||||
version,
|
||||
gitHead: data.versions[version].gitHead,
|
||||
tag: npm.tag
|
||||
})
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
// borrowed from https://github.com/npm/npm/blob/master/lib/config/nerf-dart.js
|
||||
const url = require('url')
|
||||
|
||||
/* istanbul ignore next */
|
||||
module.exports = function toNerfDart (uri) {
|
||||
let parsed = url.parse(uri)
|
||||
delete parsed.protocol
|
||||
delete parsed.auth
|
||||
delete parsed.query
|
||||
delete parsed.search
|
||||
delete parsed.hash
|
||||
|
||||
return url.resolve(url.format(parsed), '.')
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
/* istanbul ignore next */
|
||||
module.exports = function (config, options, cb) {
|
||||
cb(null)
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
const relative = require('require-relative')
|
||||
|
||||
let exports = module.exports = function (options) {
|
||||
return {
|
||||
analyzeCommits: exports.normalize(options.analyzeCommits, '@semantic-release/commit-analyzer'),
|
||||
generateNotes: exports.normalize(options.generateNotes, '@semantic-release/release-notes-generator'),
|
||||
verifyConditions: exports.normalize(options.verifyConditions, '@semantic-release/condition-travis'),
|
||||
verifyRelease: exports.normalize(options.verifyRelease, './plugin-noop')
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
return require(fallback).bind(null, pluginConfig)
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
const SemanticReleaseError = require('@semantic-release/error')
|
||||
|
||||
module.exports = function (config, cb) {
|
||||
const { plugins, lastRelease } = config
|
||||
|
||||
plugins.analyzeCommits(config, (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)
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
const parseSlug = require('parse-github-repo-url')
|
||||
|
||||
const SemanticReleaseError = require('@semantic-release/error')
|
||||
|
||||
module.exports = function ({pkg, options, env}) {
|
||||
let errors = []
|
||||
|
||||
if (!pkg.name) {
|
||||
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'
|
||||
))
|
||||
} else if (!parseSlug(pkg.repository.url)) {
|
||||
errors.push(new SemanticReleaseError(
|
||||
'The "repository" field in the package.json is malformed.',
|
||||
'EMALFORMEDPKGREPO'
|
||||
))
|
||||
}
|
||||
|
||||
if (options.debug) return errors
|
||||
|
||||
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'
|
||||
))
|
||||
}
|
||||
|
||||
return errors
|
||||
}
|
||||
+34
-38
@@ -1,55 +1,51 @@
|
||||
'use strict'
|
||||
const url = require('url')
|
||||
|
||||
var exec = require('child_process').exec
|
||||
var readFile = require('fs').readFileSync
|
||||
var url = require('url')
|
||||
const gitHead = require('git-head')
|
||||
const GitHubApi = require('github')
|
||||
const parseSlug = require('parse-github-repo-url')
|
||||
|
||||
var changelog = require('conventional-changelog')
|
||||
var GitHubApi = require('github')
|
||||
var parseSlug = require('parse-github-repo-url')
|
||||
var parseUrl = require('github-url-from-git')
|
||||
module.exports = function (config, cb) {
|
||||
const { pkg, options, plugins } = config
|
||||
const ghConfig = options.githubUrl ? url.parse(options.githubUrl) : {}
|
||||
|
||||
var efh = require('../lib/error').efh
|
||||
|
||||
module.exports = function (options, cb) {
|
||||
var pkg = JSON.parse(readFile('./package.json'))
|
||||
var repository = pkg.repository ? pkg.repository.url : null
|
||||
|
||||
if (!repository) return cb(new Error('Package must have a repository'))
|
||||
|
||||
var config = options['github-url'] ? url.parse(options['github-url']) : {}
|
||||
|
||||
var github = new GitHubApi({
|
||||
const github = new GitHubApi({
|
||||
version: '3.0.0',
|
||||
port: config.port,
|
||||
protocol: (config.protocol || '').split(':')[0] || null,
|
||||
host: config.hostname
|
||||
port: ghConfig.port,
|
||||
protocol: (ghConfig.protocol || '').split(':')[0] || null,
|
||||
host: ghConfig.hostname
|
||||
})
|
||||
|
||||
changelog({
|
||||
version: pkg.version,
|
||||
repository: parseUrl(repository),
|
||||
file: false
|
||||
}, efh(cb)(function (log) {
|
||||
exec('git rev-parse HEAD', efh(cb)(function (hash) {
|
||||
var ghRepo = parseSlug(repository)
|
||||
var release = {
|
||||
plugins.generateNotes(config, (err, log) => {
|
||||
if (err) return cb(err)
|
||||
|
||||
gitHead((err, hash) => {
|
||||
if (err) return cb(err)
|
||||
|
||||
const ghRepo = parseSlug(pkg.repository.url)
|
||||
const release = {
|
||||
owner: ghRepo[0],
|
||||
repo: ghRepo[1],
|
||||
tag_name: 'v' + pkg.version,
|
||||
name: `v${pkg.version}`,
|
||||
tag_name: `v${pkg.version}`,
|
||||
target_commitish: hash,
|
||||
draft: options.debug,
|
||||
draft: !!options.debug,
|
||||
body: log
|
||||
}
|
||||
|
||||
if (options.debug && !options.githubToken) {
|
||||
return cb(null, false, release)
|
||||
}
|
||||
|
||||
github.authenticate({
|
||||
type: 'oauth',
|
||||
token: options.token
|
||||
token: options.githubToken
|
||||
})
|
||||
|
||||
github.releases.createRelease(release, efh(cb)(function () {
|
||||
cb(null, true)
|
||||
}))
|
||||
}))
|
||||
}))
|
||||
github.releases.createRelease(release, (err) => {
|
||||
if (err) return cb(err)
|
||||
|
||||
cb(null, true, release)
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
+40
-19
@@ -1,24 +1,45 @@
|
||||
'use strict'
|
||||
const _ = require('lodash')
|
||||
const auto = require('run-auto')
|
||||
const semver = require('semver')
|
||||
|
||||
var fs = require('fs')
|
||||
const getLastRelease = require('./lib/last-release')
|
||||
const getCommits = require('./lib/commits')
|
||||
const getType = require('./lib/type')
|
||||
|
||||
var semver = require('semver')
|
||||
module.exports = function (config, cb) {
|
||||
const {plugins} = config
|
||||
auto({
|
||||
lastRelease: getLastRelease.bind(null, config),
|
||||
commits: ['lastRelease', (cb, results) => {
|
||||
getCommits(_.assign({
|
||||
lastRelease: results.lastRelease
|
||||
}, config),
|
||||
cb)
|
||||
}],
|
||||
type: ['commits', 'lastRelease', (cb, results) => {
|
||||
getType(_.assign({
|
||||
commits: results.commits,
|
||||
lastRelease: results.lastRelease
|
||||
}, config),
|
||||
cb)
|
||||
}]
|
||||
}, (err, results) => {
|
||||
if (err) return cb(err)
|
||||
|
||||
var type = require('../lib/type')
|
||||
var version = require('../lib/version')
|
||||
var efh = require('../lib/error').efh
|
||||
const nextRelease = {
|
||||
type: results.type,
|
||||
version: results.type === 'initial' ?
|
||||
'1.0.0' :
|
||||
semver.inc(results.lastRelease.version, results.type)
|
||||
}
|
||||
|
||||
module.exports = function (options, cb) {
|
||||
type(efh(cb)(function (type) {
|
||||
if (!type) return cb(null, null)
|
||||
|
||||
var path = './package.json'
|
||||
var pkg = JSON.parse(fs.readFileSync(path))
|
||||
version(pkg, efh(cb)(function (version, unpublished) {
|
||||
pkg.version = unpublished ? '1.0.0' : semver.inc(version, type)
|
||||
if (!options.debug) fs.writeFileSync(path, JSON.stringify(pkg, null, 2))
|
||||
|
||||
cb(null, pkg.version)
|
||||
}))
|
||||
}))
|
||||
plugins.verifyRelease(_.assign({
|
||||
commits: results.commits,
|
||||
lastRelease: results.lastRelease,
|
||||
nextRelease
|
||||
}, config), (err) => {
|
||||
if (err) return cb(err)
|
||||
cb(null, nextRelease)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
'use strict'
|
||||
|
||||
var spawn = require('child_process').spawn
|
||||
|
||||
var exports = module.exports = function (cb) {
|
||||
// npm loads package.json data before running the `prepublish` hook
|
||||
// changing the version on `prepublish` has no effect
|
||||
// see https://github.com/npm/npm/issues/7118
|
||||
// to circumvent this behavior we are calling `npm publish` inside `prepublish`
|
||||
// the package.json is then loaded again and the correct version will be published
|
||||
|
||||
var child = spawn('npm', ['publish', '--semantic-release-rerun'])
|
||||
var handler = exports.handleCloseAndExit.bind(null, cb)
|
||||
|
||||
child.stdout.pipe(process.stdout)
|
||||
child.stderr.pipe(process.stderr)
|
||||
|
||||
child.on('close', handler)
|
||||
child.on('exit', handler)
|
||||
child.on('error', cb)
|
||||
}
|
||||
|
||||
exports.handleCloseAndExit = function (cb, code, signal) {
|
||||
if (code === 0) return cb(null)
|
||||
cb({
|
||||
code: code,
|
||||
signal: signal,
|
||||
message: 'npm publish failed'
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
const 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('TRAVIS', 'true')
|
||||
.env('TRAVIS_BRANCH', 'master')
|
||||
.env('npm_config_registry', uri)
|
||||
.clone()
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
const { exec } = require('child_process')
|
||||
const { join } = require('path')
|
||||
const { writeFileSync } = require('fs')
|
||||
|
||||
const mkdirp = require('mkdirp')
|
||||
|
||||
module.exports = function (name, cb) {
|
||||
const cwd = join(__dirname, '../tmp', name)
|
||||
|
||||
mkdirp.sync(cwd)
|
||||
|
||||
writeFileSync(join(cwd, '.npmrc'), `
|
||||
//localhost:1337/registry/_design/app/_rewrite/:username=integration
|
||||
//localhost:1337/registry/_design/app/_rewrite/:email=integration@test.com`, null, 2)
|
||||
|
||||
writeFileSync(join(cwd, 'package.json'), JSON.stringify({
|
||||
name,
|
||||
repository: {
|
||||
url: 'git+https://github.com/semantic-release/test'
|
||||
},
|
||||
_npmUser: {
|
||||
name: 'integration',
|
||||
email: 'integration@test.com'
|
||||
},
|
||||
maintainers: [{
|
||||
name: 'integration',
|
||||
email: 'integration@test.com'
|
||||
}]
|
||||
}, 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}, (err, stdout, stderr) => {
|
||||
if (err) {
|
||||
console.log(stdout, stderr)
|
||||
return cb(err)
|
||||
}
|
||||
|
||||
cb(null, cwd)
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
const rawCommits = [
|
||||
'hash-one==SPLIT==commit-one==END==\n',
|
||||
'hash-two==SPLIT==commit-two==END==\n'
|
||||
]
|
||||
|
||||
module.exports = {
|
||||
exec: (command, cb) => {
|
||||
cb(
|
||||
null,
|
||||
/\.\.HEAD/.test(command) ?
|
||||
rawCommits[0] :
|
||||
rawCommits.join()
|
||||
)
|
||||
},
|
||||
'@noCallThru': true
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
module.exports = function (cb) {
|
||||
cb(null, 'bar')
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
module.exports = () => ({
|
||||
authenticate: () => true,
|
||||
releases: {
|
||||
createRelease: (release, cb) => cb(null)
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,28 @@
|
||||
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,12 @@
|
||||
const { exec } = require('child_process')
|
||||
const { join } = require('path')
|
||||
|
||||
const opts = {
|
||||
cwd: join(__dirname, '../../test/registry')
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
start: exec.bind(null, './start.sh', opts),
|
||||
stop: exec.bind(null, './stop.sh', opts),
|
||||
uri: 'http://localhost:15986/registry/_design/app/_rewrite/'
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
[couchdb]
|
||||
database_dir = data
|
||||
view_index_dir = data
|
||||
delayed_commits = false
|
||||
|
||||
[couch_httpd_auth]
|
||||
public_fields = appdotnet, avatar, avatarMedium, avatarLarge, date, email, fields, freenode, fullname, github, homepage, name, roles, twitter, type, _id, _rev
|
||||
users_db_public = true
|
||||
|
||||
[httpd]
|
||||
port = 15986
|
||||
bind_address = 127.0.0.1
|
||||
secure_rewrites = false
|
||||
|
||||
[log]
|
||||
file = couch/couch.log
|
||||
|
||||
[admins]
|
||||
admin = -pbkdf2-89582b49cd2e8443e29a841f5a76d367956a8e58,1afa2f1531a17ac97f2ac9e334293753,10
|
||||
Executable
+36
@@ -0,0 +1,36 @@
|
||||
#!/bin/bash
|
||||
|
||||
# exit if an error occurs
|
||||
set -e
|
||||
|
||||
cd $(dirname $0)
|
||||
|
||||
mkdir -p couch
|
||||
|
||||
# start couchdb as a background process, load local config, specify writable logfiles
|
||||
if [[ $TRAVIS = true ]]
|
||||
then
|
||||
echo 'starting couch with sudo'
|
||||
sudo couchdb -b -a local.ini -p couch/pid -o couch/stdout.log -e couch/stderr.log
|
||||
else
|
||||
couchdb -b -a local.ini -p couch/pid -o couch/stdout.log -e couch/stderr.log
|
||||
fi
|
||||
|
||||
# wait for couch to start
|
||||
sleep 5
|
||||
|
||||
COUCH=http://admin:password@127.0.0.1:15986
|
||||
|
||||
# create "registry" database
|
||||
curl -X PUT $COUCH/registry
|
||||
|
||||
# create sample npm user
|
||||
curl -X PUT $COUCH/_users/org.couchdb.user:integration -H Content-Type:application/json --data-binary '{"_id": "org.couchdb.user:integration","name": "integration","roles": [],"type": "user","password": "suchsecure","email": "integration@test.com"}'
|
||||
|
||||
# npm-registry-couchpp needs this variable set to run
|
||||
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
|
||||
Executable
+12
@@ -0,0 +1,12 @@
|
||||
#!/bin/bash
|
||||
|
||||
# close couchdb background process
|
||||
couchdb -d
|
||||
|
||||
# delete data and logs
|
||||
cd $(dirname $0)
|
||||
|
||||
cat couch/{couch,stdout,stderr}.log
|
||||
|
||||
rm -rf couch
|
||||
rm -rf data
|
||||
@@ -0,0 +1,98 @@
|
||||
const { join } = require('path')
|
||||
|
||||
const { test, tearDown } = require('tap')
|
||||
const rimraf = require('rimraf')
|
||||
|
||||
const registry = require('../registry')
|
||||
const testModule = require('../lib/test-module')
|
||||
const baseScenario = require('../lib/base-scenario')
|
||||
|
||||
test('change version', (t) => {
|
||||
t.plan(7)
|
||||
|
||||
registry.start((err) => {
|
||||
t.error(err, 'registry started')
|
||||
if (err) {
|
||||
t.end()
|
||||
t.bailout('registry not started')
|
||||
}
|
||||
|
||||
testModule('change-version', (err, cwd) => {
|
||||
t.error(err, 'test-module created')
|
||||
if (err) {
|
||||
t.end()
|
||||
t.bailout('test-module not created')
|
||||
}
|
||||
|
||||
t.test('no version', (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', (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', (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', (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', (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 cb (err, stdout, stderr) {
|
||||
if (err) console.log(err)
|
||||
if (stdout) console.log(stdout)
|
||||
if (stderr) console.log(stderr)
|
||||
}
|
||||
|
||||
rimraf(join(__dirname, '../tmp'), cb)
|
||||
registry.stop(cb)
|
||||
})
|
||||
@@ -0,0 +1,32 @@
|
||||
const test = require('tap').test
|
||||
const proxyquire = require('proxyquire')
|
||||
|
||||
const commits = proxyquire('../../dist/lib/commits', {
|
||||
'child_process': require('../mocks/child-process')
|
||||
})
|
||||
|
||||
test('commits since last release', (t) => {
|
||||
t.test('get all commits', (tt) => {
|
||||
commits({lastRelease: {}}, (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', (tt) => {
|
||||
commits({lastRelease: {gitHead: 'hash'}}, (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.end()
|
||||
})
|
||||
@@ -0,0 +1,79 @@
|
||||
const { defaults } = require('lodash')
|
||||
const test = require('tap').test
|
||||
|
||||
require('../mocks/registry')
|
||||
const lastRelease = require('../../dist/lib/last-release')
|
||||
|
||||
const npm = {
|
||||
registry: 'http://registry.npmjs.org/',
|
||||
tag: 'latest'
|
||||
}
|
||||
|
||||
test('last release from registry', (t) => {
|
||||
t.plan(5)
|
||||
|
||||
t.test('get release from package name', (tt) => {
|
||||
lastRelease({
|
||||
pkg: {name: 'available'},
|
||||
npm
|
||||
}, (err, release) => {
|
||||
tt.error(err)
|
||||
tt.is(release.version, '1.33.7', 'version')
|
||||
tt.is(release.gitHead, 'HEAD', 'gitHead')
|
||||
tt.is(release.tag, 'latest', 'dist-tag')
|
||||
|
||||
tt.end()
|
||||
})
|
||||
})
|
||||
|
||||
t.test('get release from a tagged package\'s name', (tt) => {
|
||||
lastRelease({
|
||||
pkg: {name: 'tagged'},
|
||||
npm: defaults({tag: 'foo'}, npm)
|
||||
}, (err, release) => {
|
||||
tt.error(err)
|
||||
tt.is(release.version, '0.8.15', 'version')
|
||||
tt.is(release.gitHead, 'bar', 'gitHead')
|
||||
tt.is(release.tag, 'foo', 'dist-tag')
|
||||
|
||||
tt.end()
|
||||
})
|
||||
})
|
||||
|
||||
t.test('get error from an untagged package\'s name', (tt) => {
|
||||
lastRelease({
|
||||
pkg: {name: 'untagged'},
|
||||
npm: defaults({tag: 'bar'}, npm)
|
||||
}, (err) => {
|
||||
tt.is(err.code, 'ENODISTTAG', 'error')
|
||||
|
||||
tt.end()
|
||||
})
|
||||
})
|
||||
|
||||
t.test('get release from scoped package name', (tt) => {
|
||||
lastRelease({
|
||||
pkg: {name: '@scoped/available'},
|
||||
npm
|
||||
}, (err, release) => {
|
||||
tt.error(err)
|
||||
tt.is(release.version, '1.33.7', 'version')
|
||||
tt.is(release.gitHead, 'HEAD', 'gitHead')
|
||||
tt.is(release.tag, 'latest', 'dist-tag')
|
||||
|
||||
tt.end()
|
||||
})
|
||||
})
|
||||
|
||||
t.test('get nothing from not yet published package name', (tt) => {
|
||||
lastRelease({
|
||||
pkg: {name: 'unavailable'},
|
||||
npm
|
||||
}, (err, release) => {
|
||||
tt.error(err)
|
||||
tt.is(release.version, undefined, 'no version')
|
||||
|
||||
tt.end()
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,43 @@
|
||||
const test = require('tap').test
|
||||
|
||||
const plugins = require('../../dist/lib/plugins')
|
||||
|
||||
test('export plugins', (t) => {
|
||||
t.plan(4)
|
||||
|
||||
const 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')
|
||||
})
|
||||
|
||||
test('normalize and load plugin', (t) => {
|
||||
|
||||
t.test('load from string', (tt) => {
|
||||
const plugin = plugins.normalize('./dist/lib/plugin-noop')
|
||||
|
||||
tt.is(typeof plugin, 'function')
|
||||
|
||||
tt.end()
|
||||
})
|
||||
|
||||
t.test('load from object', (tt) => {
|
||||
const plugin = plugins.normalize({
|
||||
path: './dist/lib/plugin-noop'
|
||||
})
|
||||
|
||||
tt.is(typeof plugin, 'function')
|
||||
|
||||
tt.end()
|
||||
})
|
||||
|
||||
t.test('load from object', (tt) => {
|
||||
const plugin = plugins.normalize(null, '../../dist/lib/plugin-noop')
|
||||
|
||||
tt.is(typeof plugin, 'function')
|
||||
|
||||
tt.end()
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,68 @@
|
||||
const { defaults } = require('lodash')
|
||||
const test = require('tap').test
|
||||
const proxyquire = require('proxyquire')
|
||||
|
||||
const post = proxyquire('../../dist/post', {
|
||||
'git-head': require('../mocks/git-head'),
|
||||
github: require('../mocks/github')
|
||||
})
|
||||
|
||||
const pkg = {
|
||||
version: '1.0.0',
|
||||
repository: {url: 'http://github.com/whats/up.git'}
|
||||
}
|
||||
|
||||
const plugins = {generateNotes: (pkg, cb) => cb(null, 'the log')}
|
||||
|
||||
const defaultRelease = {
|
||||
owner: 'whats',
|
||||
repo: 'up',
|
||||
name: 'v1.0.0',
|
||||
tag_name: 'v1.0.0',
|
||||
target_commitish: 'bar',
|
||||
body: 'the log'
|
||||
}
|
||||
|
||||
test('full post run', (t) => {
|
||||
t.test('in debug mode w/o token', (tt) => {
|
||||
post({
|
||||
options: {debug: true},
|
||||
pkg,
|
||||
plugins
|
||||
}, (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', (tt) => {
|
||||
post({
|
||||
options: {debug: true, githubToken: 'yo'},
|
||||
pkg,
|
||||
plugins
|
||||
}, (err, published, release) => {
|
||||
tt.error(err)
|
||||
tt.is(published, true)
|
||||
tt.match(release, defaults({draft: true}, defaultRelease))
|
||||
|
||||
tt.end()
|
||||
})
|
||||
})
|
||||
|
||||
t.test('production', (tt) => {
|
||||
post({
|
||||
options: {githubToken: 'yo'},
|
||||
pkg,
|
||||
plugins
|
||||
}, (err, published, release) => {
|
||||
tt.error(err)
|
||||
tt.is(published, true)
|
||||
tt.match(release, defaultRelease)
|
||||
|
||||
tt.end()
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,50 @@
|
||||
const test = require('tap').test
|
||||
const proxyquire = require('proxyquire')
|
||||
|
||||
require('../mocks/registry')
|
||||
const pre = proxyquire('../../dist/pre', {
|
||||
'child_process': require('../mocks/child-process')
|
||||
})
|
||||
|
||||
const plugins = {
|
||||
verifyRelease: (release, cb) => cb(null, release),
|
||||
analyzeCommits: (commits, cb) => cb(null, 'major')
|
||||
}
|
||||
|
||||
const npm = {
|
||||
registry: 'http://registry.npmjs.org/',
|
||||
tag: 'latest'
|
||||
|
||||
}
|
||||
|
||||
test('full pre run', (t) => {
|
||||
t.test('increase version', (tt) => {
|
||||
tt.plan(3)
|
||||
|
||||
pre({
|
||||
npm,
|
||||
pkg: {name: 'available'},
|
||||
plugins
|
||||
}, (err, release) => {
|
||||
tt.error(err)
|
||||
tt.is(release.type, 'major')
|
||||
tt.is(release.version, '2.0.0')
|
||||
})
|
||||
})
|
||||
|
||||
t.test('increase version', (tt) => {
|
||||
tt.plan(3)
|
||||
|
||||
pre({
|
||||
npm,
|
||||
pkg: {name: 'unavailable'},
|
||||
plugins
|
||||
}, (err, release) => {
|
||||
tt.error(err)
|
||||
tt.is(release.type, 'initial')
|
||||
tt.is(release.version, '1.0.0')
|
||||
})
|
||||
})
|
||||
|
||||
t.end()
|
||||
})
|
||||
@@ -0,0 +1,48 @@
|
||||
const test = require('tap').test
|
||||
|
||||
const type = require('../../dist/lib/type')
|
||||
|
||||
test('get type from commits', (t) => {
|
||||
t.test('get type from plugin', (tt) => {
|
||||
tt.plan(2)
|
||||
|
||||
type({
|
||||
commits: [{
|
||||
hash: '0',
|
||||
message: 'a'
|
||||
}],
|
||||
lastRelease: {version: '1.0.0'},
|
||||
plugins: {analyzeCommits: (config, cb) => cb(null, 'major')}
|
||||
}, (err, type) => {
|
||||
tt.error(err)
|
||||
tt.is(type, 'major')
|
||||
})
|
||||
})
|
||||
|
||||
t.test('error when no changes', (tt) => {
|
||||
tt.plan(1)
|
||||
|
||||
type({
|
||||
commits: [],
|
||||
lastRelease: {},
|
||||
plugins: {analyzeCommits: (config, cb) => cb(null, null)}
|
||||
}, (err) => {
|
||||
tt.is(err.code, 'ENOCHANGE')
|
||||
})
|
||||
})
|
||||
|
||||
t.test('initial version', (tt) => {
|
||||
tt.plan(2)
|
||||
|
||||
type({
|
||||
commits: [],
|
||||
lastRelease: {},
|
||||
plugins: {analyzeCommits: (config, cb) => cb(null, 'major')}
|
||||
}, (err, type) => {
|
||||
tt.error(err)
|
||||
tt.is(type, 'initial')
|
||||
})
|
||||
})
|
||||
|
||||
t.end()
|
||||
})
|
||||
@@ -0,0 +1,68 @@
|
||||
const test = require('tap').test
|
||||
|
||||
const verify = require('../../dist/lib/verify')
|
||||
|
||||
test('verify pkg, options and env', (t) => {
|
||||
t.test('dry run verification', (tt) => {
|
||||
const noErrors = verify({
|
||||
options: {debug: true},
|
||||
pkg: {
|
||||
name: 'package',
|
||||
repository: {
|
||||
url: 'http://github.com/whats/up.git'
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
tt.is(noErrors.length, 0)
|
||||
|
||||
const errors = verify({
|
||||
options: {debug: true},
|
||||
pkg: {}
|
||||
})
|
||||
|
||||
tt.is(errors.length, 2)
|
||||
tt.is(errors[0].code, 'ENOPKGNAME')
|
||||
tt.is(errors[1].code, 'ENOPKGREPO')
|
||||
|
||||
const errors2 = verify({
|
||||
options: {debug: true},
|
||||
pkg: {
|
||||
name: 'package',
|
||||
repository: {
|
||||
url: 'lol'
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
tt.is(errors2.length, 1)
|
||||
tt.is(errors2[0].code, 'EMALFORMEDPKGREPO')
|
||||
|
||||
tt.end()
|
||||
})
|
||||
|
||||
t.test('publish verification', (tt) => {
|
||||
const 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)
|
||||
|
||||
const 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()
|
||||
})
|
||||
})
|
||||
@@ -1 +0,0 @@
|
||||
test:{SHA}C+7Hteo/D9vJXQ3UfzxbwnXaijM=
|
||||
@@ -1,3 +0,0 @@
|
||||
_auth=dGVzdDpmb28=
|
||||
email=test@example.com
|
||||
registry=http://127.0.0.1:4873/
|
||||
@@ -1,17 +0,0 @@
|
||||
storage: ../.tmp/.storage
|
||||
|
||||
auth:
|
||||
htpasswd:
|
||||
file: ./.htpasswd
|
||||
|
||||
uplinks:
|
||||
npmjs:
|
||||
url: https://registry.npmjs.org/
|
||||
|
||||
logs:
|
||||
- {type: stdout, format: pretty, level: silent}
|
||||
|
||||
packages:
|
||||
'*':
|
||||
allow_access: all
|
||||
allow_publish: all
|
||||
@@ -1,10 +0,0 @@
|
||||
'use strict'
|
||||
|
||||
var test = require('tape')
|
||||
|
||||
var createModule = require('./lib/create-module')
|
||||
|
||||
require('./scenarios/install')(test, createModule)
|
||||
require('./scenarios/prepublish')(test, createModule)
|
||||
require('./scenarios/postpublish')(test, createModule)
|
||||
require('./scenarios/publish')(test, createModule)
|
||||
@@ -1,45 +0,0 @@
|
||||
'use strict'
|
||||
|
||||
var exec = require('child_process').exec
|
||||
var join = require('path').join
|
||||
|
||||
var efh = require('error-first-handler')
|
||||
var defaults = require('lodash.defaults')
|
||||
var uid = require('nano-uid')()
|
||||
|
||||
module.exports = function (input) {
|
||||
var cb = Array.prototype.pop.call(arguments)
|
||||
uid.generate(5, efh(cb)(function (id) {
|
||||
var pkg = defaults((typeof input === 'object' ? input : {}), {
|
||||
name: id,
|
||||
version: '0.0.0',
|
||||
devDependencies: {
|
||||
'semantic-release': 'file:../../../'
|
||||
},
|
||||
scripts: {
|
||||
prepublish: 'semantic-release pre',
|
||||
postpublish: 'semantic-release post'
|
||||
},
|
||||
publishConfig: {
|
||||
registry: 'http://localhost:4873/'
|
||||
}
|
||||
})
|
||||
|
||||
id = pkg.name
|
||||
var cwd = join(__dirname, '../../.tmp/modules', id)
|
||||
|
||||
exec(
|
||||
'mkdir ' + cwd + ' && ' +
|
||||
'cd ' + cwd + ' && ' +
|
||||
'git init && ' +
|
||||
'echo \'' + JSON.stringify(pkg, null, 2) + '\' >> package.json && ' +
|
||||
'git add . && ' +
|
||||
'git config user.email "integration@test" && ' +
|
||||
'git config user.name "Integration Test" && ' +
|
||||
'git commit -m "initial" && ' +
|
||||
'npm install'
|
||||
, efh(cb)(function (stdout) {
|
||||
cb(null, id, cwd)
|
||||
}))
|
||||
}))
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
'use strict'
|
||||
|
||||
var fs = require('fs')
|
||||
|
||||
var efh = require('error-first-handler')
|
||||
var nixt = require('nixt')
|
||||
|
||||
module.exports = function (test, createModule) {
|
||||
createModule(efh()(function (name, cwd) {
|
||||
test('install', function (t) {
|
||||
installTest(t, 'npm install', 'not doing anything when the module is installed')
|
||||
installTest(t, 'npm i', 'not doing anything when the module is installed with abbrevd command')
|
||||
})
|
||||
|
||||
function installTest (t, command, name, last) {
|
||||
t.test(name, function (t) {
|
||||
t.plan(2)
|
||||
|
||||
var pkg = fs.readFileSync(cwd + '/package.json')
|
||||
|
||||
nixt()
|
||||
.cwd(cwd)
|
||||
.run(command)
|
||||
.code(0)
|
||||
.stdout(/> semantic-release pre\n$/m)
|
||||
.end(function(err) {
|
||||
t.is(pkg + '', fs.readFileSync(cwd + '/package.json') + '', 'package')
|
||||
t.error(err, 'nixt')
|
||||
})
|
||||
})
|
||||
}
|
||||
}))
|
||||
}
|
||||
@@ -1,57 +0,0 @@
|
||||
'use strict'
|
||||
|
||||
var efh = require('error-first-handler')
|
||||
var GitHubApi = require('github')
|
||||
var nixt = require('nixt')
|
||||
|
||||
var github = new GitHubApi({
|
||||
version: '3.0.0',
|
||||
port: 4343,
|
||||
protocol: 'http',
|
||||
host: '127.0.0.1'
|
||||
})
|
||||
|
||||
github.authenticate({
|
||||
type: 'oauth',
|
||||
token: '***'
|
||||
})
|
||||
|
||||
module.exports = function (test, createModule) {
|
||||
createModule({
|
||||
version: '2.0.0',
|
||||
repository: {
|
||||
type: 'git',
|
||||
url: 'http://github.com/user/repo'
|
||||
}
|
||||
}, efh()(function (name, cwd) {
|
||||
test('postpublish', function (t) {
|
||||
t.test('publish new version to github releases', function (t) {
|
||||
t.plan(1)
|
||||
|
||||
nixt()
|
||||
.cwd(cwd)
|
||||
.env('CI', true)
|
||||
.env('GH_URL', 'http://127.0.0.1:4343/')
|
||||
.env('GH_TOKEN', '***')
|
||||
.exec('git commit --allow-empty -m "feat(cool): the next big thing"')
|
||||
.run('npm run postpublish')
|
||||
.code(0)
|
||||
.stdout(/> semantic-release post\n\nGenerating changelog from.*\nParsed/m)
|
||||
.end(function(err) {
|
||||
t.error(err, 'nixt')
|
||||
})
|
||||
})
|
||||
|
||||
t.test('correct data published', function (t) {
|
||||
t.plan(4)
|
||||
|
||||
github.releases.getRelease({ owner: 'user', repo: 'repo', id: 1}, function (err, res) {
|
||||
t.error(err, 'github')
|
||||
t.is(res.tag_name, 'v2.0.0', 'version')
|
||||
t.is(res.author.login, 'user', 'user')
|
||||
t.ok(/\n\n\n#### Features\n\n\* \*\*cool:\*\* the next big thing/.test(res.body), 'body')
|
||||
})
|
||||
})
|
||||
})
|
||||
}))
|
||||
}
|
||||
@@ -1,50 +0,0 @@
|
||||
'use strict'
|
||||
|
||||
var fs = require('fs')
|
||||
var exec = require('child_process').exec
|
||||
|
||||
var efh = require('error-first-handler')
|
||||
var nixt = require('nixt')
|
||||
|
||||
module.exports = function (test, createModule) {
|
||||
createModule(efh()(function (name, cwd) {
|
||||
test('prepublish', function (t) {
|
||||
prepublishTest(t, 'refactor: change', '0.0.0', 1, 'abort publish w/o changes')
|
||||
prepublishTest(t, 'fix: change', '1.0.0', 0, 'release 1.0.0 if unpublished')
|
||||
prepublishTest(t, 'fix: change', '1.0.1', 0, 'bump patch for fix')
|
||||
prepublishTest(t, 'feat: change', '1.1.0', 0, 'bump minor for feature')
|
||||
prepublishTest(t, 'fix: BREAKING CHANGE: change', '2.0.0', 0, 'bump major for breaking change')
|
||||
})
|
||||
|
||||
function prepublishTest (t, message, version, code, name) {
|
||||
t.test(name, function (t) {
|
||||
t.plan(3)
|
||||
|
||||
nixt()
|
||||
.cwd(cwd)
|
||||
.env('CI', true)
|
||||
.env('npm_config_registry', 'http://127.0.0.1:4873/')
|
||||
.exec('git commit --allow-empty -m "' + message + '"')
|
||||
.run('npm run prepublish')
|
||||
.code(code)
|
||||
.stdout(/> semantic-release pre\n\nDetermining new version\n/m)
|
||||
.end(function(err) {
|
||||
t.error(err, 'nixt')
|
||||
|
||||
var pkg = JSON.parse(fs.readFileSync(cwd + '/package.json'))
|
||||
t.is(pkg.version, version, 'version')
|
||||
|
||||
if (code === 1) {
|
||||
return t.error(null, 'no publish')
|
||||
}
|
||||
|
||||
exec('npm publish --ignore-scripts', {cwd: cwd}, function(err) {
|
||||
setTimeout(function() {
|
||||
t.error(err, 'publish')
|
||||
}, 300)
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
}))
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
'use strict'
|
||||
|
||||
var efh = require('error-first-handler')
|
||||
var nixt = require('nixt')
|
||||
|
||||
module.exports = function (test, createModule) {
|
||||
test('publish', function (t) {
|
||||
publishTest(t, 'npm publish', 'pre and post hooks work as a part of publish')
|
||||
publishTest(t, 'npm pub', 'pre and post hooks work as a part of publish with abbrevd command')
|
||||
|
||||
function publishTest (t, command, testname, last) {
|
||||
createModule({
|
||||
repository: {
|
||||
type: 'git',
|
||||
url: 'http://github.com/user/repo'
|
||||
}
|
||||
}, efh()(function (name, cwd) {
|
||||
t.test(testname, function (t) {
|
||||
t.plan(1)
|
||||
|
||||
nixt()
|
||||
.cwd(cwd)
|
||||
.env('CI', true)
|
||||
.env('GH_URL', 'http://127.0.0.1:4343/')
|
||||
.env('GH_TOKEN', '***')
|
||||
.exec('git commit --allow-empty -m "feat: super"')
|
||||
.run(command)
|
||||
.code(1)
|
||||
.stdout(/Everything is alright/)
|
||||
.end(function(err) {
|
||||
t.error(err, 'nixt')
|
||||
})
|
||||
})
|
||||
}))
|
||||
}
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user