Compare commits

..
56 Commits
Author SHA1 Message Date
Stephan Bönnemann db39c796a6 Merge pull request #38 from boennemann/feat-verify-version-placeholder
Not publishing placeholder versions
2015-06-09 20:11:17 +02:00
Stephan Bönnemann 1591608f83 fix(verify): not publishing placeholder versions closes #24 2015-06-09 20:01:14 +02:00
Stephan Bönnemann 3250b9a1af test(verify): not publishing placeholder versions 2015-06-09 19:59:23 +02:00
Stephan Bönnemann 96757ac645 docs(readme): add jsconfbp talk 2015-06-08 12:11:14 +02:00
Stephan Bönnemann 8244fe9f7d Merge pull request #33 from lewiscowper/patch-2
docs(readme): add travis-after-all note to example .travis.yml
2015-05-27 11:04:28 +02:00
Lewis Cowper 6c6562249b docs(readme): add travis-after-all note to example travis.yml 2015-05-27 09:37:55 +01:00
Stephan Bönnemann 0930a6e33d Merge pull request #27 from gr2m/patch-1
docs(readme): now also tested on io.js `^2`
2015-05-17 19:09:45 +02:00
Gregor Martynus 890255692f docs(readme): now also tested on io.js ^2 2015-05-17 13:11:44 +02:00
Christoph Witzko fd4c4d1c81 fix(pre): use path instead of name at verification hook object 2015-05-15 20:38:55 +02:00
Christoph Witzko 7ba1cb956f fix(pre): improved logging 2015-05-15 19:41:27 +02:00
Christoph Witzko 1f70215ffe test(pre): verification hook 2015-05-15 19:32:32 +02:00
Stephan BönnemannandChristoph Witzko 245f918201 fix(pre): exit script for failed validation 2015-05-15 19:08:27 +02:00
Christoph Witzko f0f53f207b fix(pre): correct type on initial release 2015-05-14 01:19:54 +02:00
Christoph Witzko 41c90124f6 feat(pre): pass more information to the verification hook 2015-05-12 15:52:47 +02:00
Christoph Witzko 44db677c4a chore: added cracks 2015-05-12 09:28:10 +02:00
Christoph Witzko 127cb673bd feat(pre): verification hook 2015-05-12 09:27:35 +02:00
Christoph Witzko a5dabed534 fix(pre): use raw body instead of subject 2015-05-12 08:53:38 +02:00
Christoph Witzko be9bb40dd2 refactor(pre): inline if 2015-05-12 08:53:38 +02:00
Stephan Bönnemann 4821aff69e fix(npm-info): correctly encode scoped package names
This adds support for releasing scoped packages that are public and and that have an initial version in the registry available.
More fixes needed to support yet unpublished/private scoped modules.
2015-05-12 00:06:03 +02:00
Stephan Bönnemann 773ecf693f docs(readme): document expected error closes #18 2015-05-11 23:34:35 +02:00
Stephan Bönnemann f2dd66f614 chore(travis): test on iojs-v2 2015-05-08 00:49:11 +02:00
Lewis CowperandChristoph Witzko 3b921a63c5 docs(ci server): typo fix 2015-05-04 14:41:03 +02:00
Christoph Witzko 785e7f7b3b fix(setup): add newline at the end of package.json 2015-05-04 09:18:08 +02:00
Lewis CowperandChristoph Witzko b38f1e0687 docs(intro): grammar fix 2015-05-04 09:06:51 +02:00
Stephan Bönnemann 323b5d5bf8 feat(post): custom release note generation 2015-04-24 15:52:54 +02:00
Stephan Bönnemann 3369f31a8d test(post): custom release note generation 2015-04-24 15:52:25 +02:00
Stephan Bönnemann 63096c50c4 docs(readme): add link to release note generation 2015-04-24 15:34:57 +02:00
Stephan Bönnemann 248c41a504 test(post): account for undeclared breaking change in github package 2015-04-24 00:24:21 +02:00
Stephan Bönnemann e0eee05a7e docs(readme): shorten, clarify, add custom commit analyzer section 2015-04-23 18:12:20 +02:00
Stephan Bönnemann 08ae05fb82 test(pre): custom commit message analyzer 2015-04-22 17:52:45 +02:00
Stephan Bönnemann e445effdcf feat(pre): add option to provide own commit message analyzer 2015-04-22 17:15:10 +02:00
Stephan Bönnemann 29469e0b8a perf(npm-info): remove duplicate status code check 2015-04-22 17:06:19 +02:00
Stephan Bönnemann 615d796f24 style(error): log stack if available 2015-04-21 15:04:12 +02:00
Stephan Bönnemann 49de103753 test(bin): remove legacy check 2015-04-21 15:03:35 +02:00
Stephan Bönnemann 749eb11e58 fix(pre): not running during npm pack 2015-04-21 14:21:57 +02:00
Stephan Bönnemann 36f5555d8e test(ignore): ignore pack and link commands as well 2015-04-21 14:16:44 +02:00
Stephan Bönnemann d4f6ee0d6a chore: make test command cleanup after itself and fail early for style errors 2015-04-04 15:34:31 +02:00
Stephan Bönnemann 6763a006d2 chore(package): update tape 2015-04-03 23:01:58 +02:00
Stephan Bönnemann 0307894914 fix(package): update dependencies and adapt to their internal changes
Released as a patch, because this includes security fixes.
2015-04-03 20:37:29 +02:00
Stephan Bönnemann 06c464f9d8 chore(package): update devDependencies 2015-04-03 20:03:07 +02:00
Stephan Bönnemann f74f764a80 fix(npm-info): registry unexpectedly returned no json formatted error
This only affected publishing of yet unreleased packages.
2015-04-03 19:37:39 +02:00
Stephan Bönnemann d5a8cb1935 style: adhere to standard style 2015-03-22 10:44:19 +01:00
Stephan Bönnemann f32a8e7d03 chore(package): update standard 2015-03-22 10:44:06 +01:00
Stephan Bönnemann 30fd1c19eb Merge pull request #16 from tlvince/15-oauth-scope
docs(readme): add GitHub token scope notes
2015-03-22 10:33:50 +01:00
Tom Vincent f192acc1ff docs(readme): add GitHub token scope notes
Closes #15.
2015-03-22 00:15:43 +00:00
Stephan Bönnemann 4ccda66a39 docs(readme): fix language and formatting 2015-03-01 17:18:37 +01:00
Stephan Bönnemann c2d963be70 Merge pull request #12 from davidpfahler/master
docs(readme): fix ignore scripts flag
2015-02-22 00:08:59 +01:00
David Pfahler f8c4e495fd docs(readme): fix ignore scripts flag 2015-02-22 00:07:53 +01:00
Stephan Bönnemann c3b59d6a06 Merge pull request #10 from boennemann/githead-registry
refactor(pre): use `gitHead` information from registry
2015-02-13 09:13:13 +01:00
Christoph Witzko 53c0adb365 refactor(pre): use gitHead information from registry 2015-02-12 22:07:04 +01:00
Christoph Witzko 045c913342 chore(pretest): automatically clean up 2015-02-11 15:28:46 +01:00
Stephan Bönnemann 5c12e718cb docs(readme): clarify npm abbrevs 2015-02-10 12:31:48 +01:00
Christoph Witzko 4e32c7dde0 chore: updated git-head 2015-02-09 14:32:46 +01:00
Stephan Bönnemann 6f891ed781 Merge pull request #6 from boennemann/fix-git-node
refactor(post): use git-head instead of exec
2015-02-09 00:11:50 +01:00
Christoph Witzko e43ff5573b refactor(post): use git-head instead of exec 2015-02-09 00:08:52 +01:00
Christoph Witzko 19af8b7ef2 test(postpublish): get commit hash in detached HEAD mode 2015-02-09 00:07:11 +01:00
31 changed files with 524 additions and 259 deletions
+1
View File
@@ -1,5 +1,6 @@
language: node_js
node_js:
- iojs-v2
- iojs-v1
- '0.10'
- '0.12'
+43 -66
View File
@@ -5,63 +5,31 @@
[![NPM](https://nodei.co/npm/semantic-release.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/semantic-release/)
## What is this thing even?
## What is `semantic-release` about?
`semantic-release` is a toolset to fully automate your package's releases. This will determine not only which version to release, but also when all without you having to care about it ever again.
It fully automates your package's releases. It will determine not only which version to release, but also when all without you wasting [cognitive resources](https://www.youtube.com/watch?v=FKTxC9pl-WM) on it.
This is fully integrated with the `npm` lifecycle, so all you have to do is to setup your CI to `npm publish`.
[![JSConfBP Talk](https://cloud.githubusercontent.com/assets/908178/8032541/e9bf6300-0dd6-11e5-92c9-8a39211368af.png)](https://www.youtube.com/watch?v=tc2UgG5L7WM&index=6&list=PLFZ5NyC0xHDaaTy6tY9p0C0jd_rRRl5Zm)
The goal of this package is to remove humans from version numbers and releases. The [SemVer](http://semver.org/) spec clearly and unambiguously defines when to increase the major, minor or patch part and still we tend to think we're clever when we ignore this, because marketing or something.
> This talk gives you a complete introduction to the underlying concepts plus a live demo at the end.
![https://twitter.com/trodrigues/status/509301317467373571](https://cloud.githubusercontent.com/assets/908178/6091690/cc86f58c-aeb8-11e4-94cb-15f15f486cde.png)
It is fully integrated into the `npm` lifecycle, so all you need to do is to configure your CI to regularly `npm publish` (i.e. for every commit).
## How does this work?
It removes human decisions and emotions from version numbers and releases suddenly, strictly following the [SemVer](http://semver.org/) spec isn't a problem anymore.
Conventions, conventions, conventions. Instead of dumping [funny lols](http://whatthecommit.com/) into our commit messages, we can take some time to think about what we changed in the codebase and write it down. Following formalized conventions it this then possible to not only generate a meaningful changelog, but to determine the next semantic version to release. Currently the only supported style is the [AngularJS Commit Message Convention](https://docs.google.com/document/d/1QrDFcIiPjSLDn3EL15IJygNPiHORgU1_OOAqWjiDU5Y/edit) style, but feel free to formalize your own style, write a parser for it, and send a PR to this package.
## How does it work?
```
<type>(<scope>): <subject>
<BLANK LINE>
<body>
```
Meaningful conventions. Instead of dumping [lols](http://whatthecommit.com/) into our commit messages, we can take some time to think about what we changed in the codebase and write it down. Following formalized conventions it this then possible to not only generate a helpful changelog, but to determine whether a new version should be released.
Examples:
```
feat(ruler): add inches as well as centimeters
```
```
fix(protractor): fix 90 degrees counting as 91 degrees
```
```
fix(pen): use blue ink instead of red ink
BREAKING CHANGE: Pen now uses blue ink instead of red.
To migrate, change your code from the following:
`pen.draw('blue')`
To:
`pen.draw('red')`
```
[Synopsis](https://github.com/ajoslin/conventional-changelog/blob/master/CONVENTIONS.md)
The preferred configuration is the "try to release on every push" mode. What it does is that everytime a build passes `npm publish` is executed.
This module ships with the [AngularJS Commit Message Conventions](https://docs.google.com/document/d/1QrDFcIiPjSLDn3EL15IJygNPiHORgU1_OOAqWjiDU5Y/edit), but you can [define your own](https://github.com/boennemann/semantic-release/wiki/commit-analysis).
### The `prepublish` step
Before `npm` actually gets to publish a new version `semantic-release`'s `prepublish` step does the following:
- Analyze the commits since the last version was published
- Decide on the release type (`major`|`minor`|`patch`) or abort if nothing changed
- Get the last published version from the registry
- Increase the last version with the determined type
- Write the new version to the package
- Extract all commits since the last version was published
- Determine the release type (`major`|`minor`|`patch`) or abort if nothing relevant changed
- Increase the version number accordingly
### The `publish` step
@@ -71,22 +39,24 @@ Before `npm` actually gets to publish a new version `semantic-release`'s `prepub
After `npm` published the new version the `postpublish` step does this:
- Generate a changelog
- Create a new [GitHub Release](https://help.github.com/articles/about-releases/) with the changelog as body
- Generate release notes
- Create a new [GitHub Release](https://help.github.com/articles/about-releases/) (including a git tag) with the release notes
Note: The GitHub Release automatically creates a tag, too.
Note: The default release notes are a [changelog](https://github.com/ajoslin/conventional-changelog) that is generated from git metadata, using the AngularJS commit conventions. You can [specify your own release note generator](https://github.com/boennemann/semantic-release/wiki/release-note-generation).
Note: This is tied to GitHub, feel free to send PRs for other services.
Note: `semantic-release` works around a limitation in `npm`'s `prepublish` step. Once a version is published it prints an error that you can *safely ignore* [npm/npm#7118](https://github.com/npm/npm/issues/7118).
Note: `semantic-release` works around a limitation in `npm`'s `prepublish` step. Once a version is published it prints a "Could not pack" error that you can *safely ignore* [npm/npm#7118](https://github.com/npm/npm/issues/7118).
## How do I set this up?
First of all you need to install `semantic-release` and save it as a `devDependency`.
## How you can set it up
### Installation
First of all you need to install `semantic-release` and save it as a `devDependency`.
```bash
npm install --save-dev semantic-release
# Btw, if you're feeling lazy you can just type this it's the same thing.
npm i -D semantic-release
```
@@ -109,7 +79,7 @@ The setup command configures `scripts` inside the `package.json`:
}
```
Note: If you have already configured `scripts` for `prepublish` or `postpublish` they're just executed one after another. For example: `"npm run 6to5 && semantic-release pre"`.
Note: If you have already configured `scripts` for `prepublish` or `postpublish` they're just executed one after another. For example: `"npm run babelify && semantic-release pre"`.
#### Version
@@ -117,27 +87,34 @@ It would be preferable not to have a version field in the `package.json` at all,
#### Repository
If you haven't defined your GitHub repository in the `package.json`s [repository field](https://docs.npmjs.com/files/package.json#repository) the remote `origin`'s repository is used.
If you haven't defined your GitHub repository in the `package.json`s [repository field](https://docs.npmjs.com/files/package.json#repository) the remote `origin`'s repository is used.
### CI Server
Inside your `.travis.yml`:
```yml
```yml
language: node_js
node_js:
- iojs-v1
# If you have a more sophisticated build with multiple jobs you should have a look at
# https://github.com/dmakhno/travis_after_all which is also configured for this
# package. (Check the .travis.yml)
sudo: false
cache:
directories:
- node_modules
notifications:
email: false
# See https://github.com/boennemann/semantic-release/issues/18
before_deploy:
- npm config set spin false --global
env:
# Get your token here: https://github.com/settings/tokens/new
# Grant the token repo/public_repo scope (all others can be deselected)
# You should encrypt this:
# `travis encrypt GH_TOKEN=<token> --add`
global: GH_TOKEN=<github-access-token-with-acceess-to-your-repo>
global: GH_TOKEN=<github-access-token-with-access-to-your-repo>
deploy:
provider: npm
email: <your-npm-mail@example.com>
@@ -153,15 +130,13 @@ deploy:
repo: <user>/<repo>
```
Note: For once this isn't tied to a specific service, but example configuration is shown for [Travis CI](https://travis-ci.org/). Feel free to contribute configuration of other servers or services.
Note: This isn't tied to a specific service, but example configuration is provided for [Travis CI](https://travis-ci.org/). Feel free to contribute configuration for other servers or services.
Note: You should [encrypt](http://docs.travis-ci.com/user/environment-variables/#sts=Secure Variables) your api keys and tokens.
Note: Your CI environment has to export `CI=true` in order for `semantic-release` not to automatically perform a dry run. Travis CI does this by default.
Note: Your CI environment has to export `CI=true` in order for `semantic-release` not to automatically perform a dry run. Travis CI does this by default.
Note: It is crucial that your CI server also fetches all tags when checking out your repository. Travis CI does this by default.
Note: If you have a more sophisticated build with multiple jobs you should have a look at [travis-after-all](https://github.com/dmakhno/travis_after_all), which is also configured for this [package](.travis.yml).
Note: It is crucial that your CI server also fetches all tags when checking out your repository. Travis CI does this by default.
## ITYM*FAQ*LT
> I think you might frequently ask questions like these
@@ -173,7 +148,7 @@ 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 when it _really_ is required.
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?
@@ -181,17 +156,17 @@ If you're running `npm publish` locally `semantic-release` automatically perform
### Can I run this on my own machine rather than on a CI server?
Of course you can, but this doesn't 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 GitHub tokens lying around and everything. That said, you can either set the environment variable `CI=true`, or run the scripts with `--debug=false` explicitly. Don't forget to export `GH_TOKEN=your_token` as well.
Of course you can, but this doesn't necessarly 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 GitHub tokens lying around and everything. That said, you can either set the environment variable `CI=true`, or run the scripts with `--debug=false` explicitly. Don't forget to export `GH_TOKEN=your_token` as well.
### Can I manually trigger the release of a specific version?
You can trigger a release by pushing to your repository. You deliberately can not trigger a _specific_ version release, because this is the whole point of `semantic-release`. Start your packages with `1.0.0` and semver on.
Note: pre-release flags are kind of an exeption here and a solution for them is being thought of. If you have one please open an issue. For the time being: Have a look at the next question.
Note: The default commit message conventions do not support pre-release flags, but you can build this in yourself using [custom analyzers](https://github.com/boennemann/semantic-release/wiki/commit-analysis).
### How do I get back to good ol' `npm publish`?
`npm` offers the `--no-scripts` flag. Doing `npm publish --no-scripts` doesn't execute the `prepublish` and `postpublish` scripts.
`npm` offers the `--ignore-scripts` flag. Doing `npm publish --ignore-scripts` doesn't execute the `prepublish` and `postpublish` scripts.
### Is it _really_ a good idea to release on every push?
@@ -199,9 +174,11 @@ 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? What if it breaks?
`semantic-release` has a full integration-test suite that tests _actual_ `npm` publishes and _actual_ GitHub Releases (with private registry/API) on node.js `^0.10`, `^0.12` and io.js `^1`. A new version won't get published if it doesn't pass on all these engines.
`semantic-release` has a full integration-test suite that tests _actual_ `npm` publishes and _actual_ GitHub Releases (with private registry/API) 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.
## License
MIT License
MIT License
2015 © Stephan Bönnemann and [contributors](https://github.com/boennemann/semantic-release/graphs/contributors)
![https://twitter.com/trodrigues/status/509301317467373571](https://cloud.githubusercontent.com/assets/908178/6091690/cc86f58c-aeb8-11e4-94cb-15f15f486cde.png)
-9
View File
@@ -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
+19 -4
View File
@@ -1,6 +1,8 @@
#!/usr/bin/env node
'use strict'
var readFile = require('fs').readFileSync
var abbrev = require('abbrev')
var minimist = require('minimist')
@@ -21,16 +23,29 @@ var argv = minimist(process.argv.slice(2), {
}
})
var plugins = JSON.parse(readFile('./package.json')).release || {}
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)
if (npmArgv['semantic-release-rerun']) {
if (!/semantically-released/.test(process.env.npm_package_version)) process.exit(0)
console.log('There is something wrong with your setup, as a placeholder version is about to be released.')
console.log('Please verify that your setup is correct.')
console.log('If you think this is a problem with semantic-release please open an issue.')
process.exit(1)
}
// 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') || isAbbrev(npmArgv, 'link')) process.exit(0)
if (
isAbbrev(npmArgv, 'install') ||
isAbbrev(npmArgv, 'link') ||
isAbbrev(npmArgv, 'pack')
) process.exit(0)
if (argv.debug) console.log('This is a dry run')
@@ -42,7 +57,7 @@ if (~argv._.indexOf('pre')) {
// require a correct setup during publish
if (publish && !argv.debug && !require('../src/verify')(argv)) process.exit(1)
require('../src/pre')(argv, efh(function (result) {
require('../src/pre')(argv, plugins, efh(function (result) {
if (!result) {
console.log('Nothing changed. Not publishing.')
process.exit(1)
@@ -60,7 +75,7 @@ if (~argv._.indexOf('pre')) {
}
if (~argv._.indexOf('post')) {
require('../src/post')(argv, efh(function () {
require('../src/post')(argv, plugins, 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.')
+19 -1
View File
@@ -1,7 +1,23 @@
#!/bin/sh
#!/bin/bash
set -e
npm run test:style
function cleanup {
set +e
cp .tmp/.npmrc ~/.npmrc
cat .tmp/sinopia.pid | xargs kill
cat .tmp/ghrs.pid | xargs kill
rm -rf .tmp
}
trap cleanup EXIT
mkdir -p .tmp/modules
export DEBUG=ghrs:cli
@@ -14,3 +30,5 @@ sleep 0.5
cp ~/.npmrc .tmp/.npmrc
cp tests/.npmrc ~/.npmrc
npm run test:integration
+32
View File
@@ -0,0 +1,32 @@
'use strict'
var parseRawCommit = require('conventional-changelog/lib/git').parseRawCommit
module.exports = function (commits) {
var type = null
commits
.map(function (commit) {
return parseRawCommit(commit.hash + '\n' + commit.message)
})
.filter(function (commit) {
return !!commit
})
.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
}
+27
View File
@@ -0,0 +1,27 @@
'use strict'
var exec = require('child_process').exec
var efh = require('./error').efh
module.exports = function (from, cb) {
var range = (from ? from + '..' : '') + 'HEAD'
exec(
'git log -E --format=%H==SPLIT==%B==END== ' + range,
efh(cb)(function (stdout) {
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]
}
}))
})
)
}
+2 -2
View File
@@ -4,10 +4,10 @@ var efh = require('error-first-handler')
module.exports = {
efh: efh,
standard: efh(function(err) {
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 instanceof Error) return console.log(err.message, err.stack)
if (err.message) return console.log(err.message)
console.log(err)
})
+28
View File
@@ -0,0 +1,28 @@
'use strict'
var request = require('request')
var efh = require('./error').efh
module.exports = function (pkgName, cb) {
var encodedPkgName = pkgName.replace(/\//g, '%2F')
request(process.env.npm_config_registry + encodedPkgName, efh(cb)(function (response, body) {
var res = {
version: null,
gitHead: null,
pkg: null
}
if (response.statusCode === 404 || !body) return cb(null, res)
var pkg = JSON.parse(body)
if (pkg.error) return cb(pkg.error)
res.version = pkg['dist-tags'].latest
res.gitHead = pkg.versions[res.version].gitHead
res.pkg = pkg
cb(null, res)
}))
}
+17
View File
@@ -0,0 +1,17 @@
'use strict'
var readFile = require('fs').readFileSync
var changelog = require('conventional-changelog')
var parseUrl = require('github-url-from-git')
module.exports = function (cb) {
var pkg = JSON.parse(readFile('./package.json'))
var repository = pkg.repository ? parseUrl(pkg.repository.url) : null
changelog({
version: pkg.version,
repository: repository,
file: false
}, cb)
}
-13
View File
@@ -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)
}))
}))
}
-11
View File
@@ -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))
}))
}
-17
View File
@@ -1,17 +0,0 @@
'use strict'
var request = require('request')
var efh = require('./error').efh
module.exports = function (pkg, cb) {
if (!pkg.name) return cb(new Error('Package must have a name'))
request(process.env.npm_config_registry + pkg.name, efh(cb)(function (response, body) {
var pkg = JSON.parse(body)
if (response.statusCode === 404 || pkg.error) return cb(null, null, true)
cb(null, pkg['dist-tags'].latest)
}))
}
+14 -9
View File
@@ -9,25 +9,27 @@
},
"dependencies": {
"abbrev": "^1.0.5",
"conventional-changelog": "0.0.11",
"conventional-changelog": "0.0.17",
"error-first-handler": "^1.0.1",
"github": "^0.2.3",
"git-head": "^1.2.1",
"github": "0.2.4",
"github-url-from-git": "^1.4.0",
"ini": "^1.3.2",
"minimist": "^1.1.0",
"parse-github-repo-url": "^1.0.0",
"request": "^2.53.0",
"semver": "^4.2.0"
"semver": "^4.3.3"
},
"devDependencies": {
"cracks": "^2.0.1",
"github-release-fake-server": "^1.3.0",
"lodash.defaults": "^3.0.0",
"nano-uid": "^0.2.0",
"nixt": "^0.4.1",
"sinopia": "^1.0.0",
"standard": "^2.3.1",
"tap-spec": "^2.2.0",
"tape": "^3.5.0"
"standard": "^3.2.1",
"tap-spec": "^3.0.0",
"tape": "^4.0.0"
},
"engines": {
"iojs": "^1",
@@ -54,9 +56,12 @@
},
"scripts": {
"postpublish": "./bin/semantic-release.js post",
"posttest": "./bin/post-test",
"prepublish": "./bin/semantic-release.js pre",
"pretest": "./bin/pre-test",
"test": "standard && node tests | tap-spec"
"test:style": "standard",
"test:integration": "node tests | tap-spec",
"test": "./bin/test"
},
"release": {
"verification": "cracks"
}
}
+6 -10
View File
@@ -1,22 +1,22 @@
'use strict'
var exec = require('child_process').exec
var readFile = require('fs').readFileSync
var url = require('url')
var changelog = require('conventional-changelog')
var gitHead = require('git-head')
var GitHubApi = require('github')
var parseSlug = require('parse-github-repo-url')
var parseUrl = require('github-url-from-git')
var efh = require('../lib/error').efh
module.exports = function (options, cb) {
module.exports = function (options, plugins, 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 notesGenerator = require(plugins.notes || '../lib/release-notes')
var config = options['github-url'] ? url.parse(options['github-url']) : {}
var github = new GitHubApi({
@@ -26,12 +26,8 @@ module.exports = function (options, cb) {
host: config.hostname
})
changelog({
version: pkg.version,
repository: parseUrl(repository),
file: false
}, efh(cb)(function (log) {
exec('git rev-parse HEAD', efh(cb)(function (hash) {
notesGenerator(efh(cb)(function (log) {
gitHead(efh(cb)(function (hash) {
var ghRepo = parseSlug(repository)
var release = {
owner: ghRepo[0],
+51 -11
View File
@@ -4,21 +4,61 @@ var fs = require('fs')
var semver = require('semver')
var type = require('../lib/type')
var version = require('../lib/version')
var getCommits = require('../lib/commits')
var npmInfo = require('../lib/npm-info')
var efh = require('../lib/error').efh
module.exports = function (options, cb) {
type(efh(cb)(function (type) {
if (!type) return cb(null, null)
module.exports = function (options, plugins, cb) {
var path = './package.json'
var pkg = JSON.parse(fs.readFileSync(path))
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))
if (!pkg.name) return cb(new Error('Package must have a name'))
cb(null, pkg.version)
npmInfo(pkg.name, efh(cb)(function (res) {
getCommits(res.gitHead, efh(cb)(function (commits) {
var analyzer = require(plugins.analyzer || '../lib/analyzer')
var type = analyzer(commits)
if (!type) return cb(null, null)
if (res.version) {
pkg.version = semver.inc(res.version, type)
} else {
type = 'major'
pkg.version = '1.0.0'
}
var writePkg = function () {
if (!options.debug) fs.writeFileSync(path, JSON.stringify(pkg, null, 2) + '\n')
cb(null, pkg.version)
}
if (!plugins.verification) return writePkg()
var opts = {}
if (typeof plugins.verification === 'string') {
opts.path = plugins.verification
}
if (typeof plugins.verification === 'object') {
opts = plugins.verification
opts.path = opts.path || opts.name
}
opts.type = type
opts.commits = commits
opts.version = res.version
opts.nextVersion = pkg.version
var verification = require(opts.path)
console.log('Running verification hook...')
verification(opts, function (error, ok) {
if (!error && ok) return writePkg()
console.log('Verification failed' + (error ? ': ' + error : ''))
process.exit(1)
})
}))
}))
}
+2 -5
View File
@@ -28,10 +28,7 @@ module.exports = function () {
var config = ini.decode(fs.readFileSync('./.git/config') + '')
var repo = config['remote "origin"'].url
if (repo) pkg.repository = {
type: 'git',
url: ghUrl(repo)
}
if (repo) pkg.repository = { type: 'git', url: ghUrl(repo) }
}
// set up devDependency
@@ -41,5 +38,5 @@ module.exports = function () {
pkg.devDependencies['semantic-release'] = '^' + require('../package.json').version
}
fs.writeFileSync('./package.json', JSON.stringify(pkg, null, 2))
fs.writeFileSync('./package.json', JSON.stringify(pkg, null, 2) + '\n')
}
+3 -1
View File
@@ -4,7 +4,9 @@ var test = require('tape')
var createModule = require('./lib/create-module')
require('./scenarios/install')(test, createModule)
require('./scenarios/custom-analyzer')(test, createModule)
require('./scenarios/custom-verification')(test, createModule)
require('./scenarios/ignore')(test, createModule)
require('./scenarios/prepublish')(test, createModule)
require('./scenarios/postpublish')(test, createModule)
require('./scenarios/publish')(test, createModule)
+37
View File
@@ -0,0 +1,37 @@
'use strict'
var fs = require('fs')
var exec = require('child_process').exec
var nixt = require('nixt')
module.exports = function (t, message, version, code, name, cwd) {
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)
})
})
})
}
@@ -4,14 +4,14 @@ module.exports = function (commits) {
var type = null
commits.every(function (commit) {
if (commit.breaks.length) {
if (/FOO/.test(commit.message)) {
type = 'major'
return false
}
if (commit.type === 'feat') type = 'minor'
if (/BAR/.test(commit.message)) type = 'minor'
if (!type && commit.type === 'fix') type = 'patch'
if (!type && /BAZ/.test(commit.message)) type = 'patch'
return true
})
+5
View File
@@ -0,0 +1,5 @@
'use strict'
module.exports = function (cb) {
cb(null, 'custom log')
}
+5
View File
@@ -0,0 +1,5 @@
'use strict'
module.exports = function (opts, cb) {
cb(null, !(opts.commits.length % 2))
}
+23
View File
@@ -0,0 +1,23 @@
'use strict'
var path = require('path')
var efh = require('error-first-handler')
var commitToVersionTest = require('../lib/commit-to-version-test')
module.exports = function (test, createModule) {
createModule({
release: {
analyzer: path.join(__dirname, '../lib/custom-analyzer')
}
}, efh()(function (name, cwd) {
test('custom-analyzer', function (t) {
commitToVersionTest(t, 'HO', '0.0.0', 1, 'abort publish w/o changes', cwd)
commitToVersionTest(t, 'BAZ', '1.0.0', 0, 'release 1.0.0 if unpublished', cwd)
commitToVersionTest(t, 'BAZ', '1.0.1', 0, 'bump patch for fix', cwd)
commitToVersionTest(t, 'BAR', '1.1.0', 0, 'bump minor for feature', cwd)
commitToVersionTest(t, 'FOO', '2.0.0', 0, 'bump major for breaking change', cwd)
})
}))
}
+45
View File
@@ -0,0 +1,45 @@
'use strict'
var path = require('path')
var efh = require('error-first-handler')
var nixt = require('nixt')
module.exports = function (test, createModule) {
createModule({
release: {
verification: path.join(__dirname, '../lib/custom-verification')
}
}, efh()(function (name, cwd) {
test('custom-verification', function (t) {
t.test('even commit count', function (t) {
t.plan(1)
nixt()
.cwd(cwd)
.env('CI', true)
.env('npm_config_registry', 'http://127.0.0.1:4873/')
.exec('git commit --allow-empty -m "feat: commit"')
.run('npm run prepublish')
.code(0)
.end(function (err) {
t.error(err, 'nixt')
})
})
t.test('odd commit count', function (t) {
t.plan(1)
nixt()
.cwd(cwd)
.env('CI', true)
.env('npm_config_registry', 'http://127.0.0.1:4873/')
.exec('git commit --allow-empty -m "feat: commit"')
.run('npm run prepublish')
.code(1)
.stdout(/Verification failed/)
.end(function (err) {
t.error(err, 'nixt')
})
})
})
}))
}
+37
View File
@@ -0,0 +1,37 @@
'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('ignore', function (t) {
ignoreTest(t, 'npm install', 'not doing anything when the module is installed')
ignoreTest(t, 'npm i', 'not doing anything when the module is installed with abbrevd command')
ignoreTest(t, 'npm link', 'not doing anything when the module is linked')
ignoreTest(t, 'npm lin', 'not doing anything when the module is linked with abbrevd command')
ignoreTest(t, 'npm pack', 'not doing anything when the module is packed')
ignoreTest(t, 'npm pa', 'not doing anything when the module is packed with abbrevd command')
})
function ignoreTest (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')
})
})
}
}))
}
-33
View File
@@ -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')
})
})
}
}))
}
+69 -11
View File
@@ -1,5 +1,7 @@
'use strict'
var path = require('path')
var efh = require('error-first-handler')
var GitHubApi = require('github')
var nixt = require('nixt')
@@ -25,19 +27,27 @@ module.exports = function (test, createModule) {
}
}, efh()(function (name, cwd) {
test('postpublish', function (t) {
var base = getBase(cwd)
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)
base.clone()
.stdout(/> semantic-release post\n\nGenerating changelog from.*\nParsed/m)
.end(function(err) {
.run('npm run postpublish')
.end(function (err) {
t.error(err, 'nixt')
})
})
t.test('publish new version (with detached HEAD) to github releases', function (t) {
t.plan(1)
base.clone()
.stdout(/> semantic-release post\n\nGenerating changelog from.*\nParsed/m)
.exec('git checkout `git rev-parse HEAD`')
.run('npm run postpublish')
.end(function (err) {
t.error(err, 'nixt')
})
})
@@ -45,13 +55,61 @@ module.exports = function (test, createModule) {
t.test('correct data published', function (t) {
t.plan(4)
github.releases.getRelease({ owner: 'user', repo: 'repo', id: 1}, function (err, res) {
github.releases.getRelease({ owner: 'user', repo: 'repo', id: 1}, function (err, raw) {
var res = JSON.parse(raw)
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')
t.ok(/\n\n\n#### Features\n\n\* \*\*cool:\*\*\n.*the next big thing/.test(res.body), 'body')
})
})
})
}))
createModule({
version: '2.0.0',
repository: {
type: 'git',
url: 'http://github.com/user/repo'
},
release: {
notes: path.join(__dirname, '../lib/custom-release-notes')
}
}, efh()(function (name, cwd) {
test('custom-release-notes', function (t) {
var base = getBase(cwd)
t.test('publish new version (with custom notes) to github releases', function (t) {
t.plan(1)
base.clone()
.run('npm run postpublish')
.end(function (err) {
t.error(err, 'nixt')
})
})
t.test('custom notes published', function (t) {
t.plan(4)
github.releases.getRelease({ owner: 'user', repo: 'repo', id: 3}, function (err, raw) {
var res = JSON.parse(raw)
t.error(err, 'github')
t.is(res.tag_name, 'v2.0.0', 'version')
t.is(res.author.login, 'user', 'user')
t.ok(/custom log/.test(res.body), 'body')
})
})
})
}))
}
function getBase (cwd) {
return 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"')
.code(0)
}
+7 -40
View File
@@ -1,50 +1,17 @@
'use strict'
var fs = require('fs')
var exec = require('child_process').exec
var efh = require('error-first-handler')
var nixt = require('nixt')
var commitToVersionTest = require('../lib/commit-to-version-test')
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')
commitToVersionTest(t, 'refactor: change', '0.0.0', 1, 'abort publish w/o changes', cwd)
commitToVersionTest(t, 'fix: change', '1.0.0', 0, 'release 1.0.0 if unpublished', cwd)
commitToVersionTest(t, 'fix: change', '1.0.1', 0, 'bump patch for fix', cwd)
commitToVersionTest(t, 'feat: change', '1.1.0', 0, 'bump minor for feature', cwd)
commitToVersionTest(t, 'fix: BREAKING CHANGE: change', '2.0.0', 0, 'bump major for breaking change', cwd)
})
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 -1
View File
@@ -27,7 +27,7 @@ module.exports = function (test, createModule) {
.run(command)
.code(1)
.stdout(/Everything is alright/)
.end(function(err) {
.end(function (err) {
t.error(err, 'nixt')
})
})
+1 -1
View File
@@ -22,7 +22,7 @@ module.exports = function (test, createModule) {
.exec('git remote add origin git@github.com:user/repo.git')
.run('./node_modules/.bin/semantic-release setup')
.code(0)
.end(function(err) {
.end(function (err) {
t.error(err, 'nixt')
var pkg = JSON.parse(readFile(join(cwd, 'package.json')))
+27 -11
View File
@@ -4,16 +4,15 @@ var efh = require('error-first-handler')
var nixt = require('nixt')
module.exports = function (test, createModule) {
createModule({
repository: {},
scripts: {
prepublish: 'semantic-release pre --no-token'
}
}, efh()(function (name, cwd) {
test('verify', function (t) {
test('verify', function (t) {
createModule({
repository: {},
scripts: {
prepublish: 'semantic-release pre --no-token'
}
}, efh()(function (name, cwd) {
t.test('verify package and options before publishing', function (t) {
t.plan(1)
nixt()
.cwd(cwd)
.env('CI', true)
@@ -25,10 +24,27 @@ module.exports = function (test, createModule) {
, 'm'
))
.code(1)
.end(function(err) {
.end(function (err) {
t.error(err, 'nixt')
})
})
})
}))
}))
createModule({
version: '1.0.0-semantically-released'
}, efh()(function (name, cwd) {
t.test('not publishing placeholder versions', function (t) {
t.plan(1)
nixt()
.cwd(cwd)
.env('CI', true)
.run('npm publish --semantic-release-rerun')
.code(1)
.end(function (err) {
t.error(err, 'nixt')
})
})
}))
})
}