Compare commits

...
6 Commits
7 changed files with 87 additions and 23 deletions
+7 -5
View File
@@ -11,7 +11,7 @@ It fully automates your package's releases. It will determine not only which ver
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).
Removing human descisions and emotions from version numbers and releases strictly following the [SemVer](http://semver.org/) spec suddenly isn't a problem anymore.
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.
![https://twitter.com/trodrigues/status/509301317467373571](https://cloud.githubusercontent.com/assets/908178/6091690/cc86f58c-aeb8-11e4-94cb-15f15f486cde.png)
@@ -19,7 +19,7 @@ Removing human descisions and emotions from version numbers and releases str
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.
This module ships with the [AngularJS Commit Message Conventions](https://docs.google.com/document/d/1QrDFcIiPjSLDn3EL15IJygNPiHORgU1_OOAqWjiDU5Y/edit), but you can [easily define your own](https://github.com/boennemann/semantic-release/wiki/commit-analysis).
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
@@ -37,8 +37,10 @@ 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/) and tag 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 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.
@@ -104,7 +106,7 @@ env:
# 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>
+1 -1
View File
@@ -68,7 +68,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.')
+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)
}
+4 -8
View File
@@ -3,20 +3,20 @@
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,11 +26,7 @@ module.exports = function (options, cb) {
host: config.hostname
})
changelog({
version: pkg.version,
repository: parseUrl(repository),
file: false
}, efh(cb)(function (log) {
notesGenerator(efh(cb)(function (log) {
gitHead(efh(cb)(function (hash) {
var ghRepo = parseSlug(repository)
var release = {
+1 -1
View File
@@ -38,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')
}
+5
View File
@@ -0,0 +1,5 @@
'use strict'
module.exports = function (cb) {
cb(null, 'custom log')
}
+52 -8
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,13 @@ module.exports = function (test, createModule) {
}
}, efh()(function (name, cwd) {
test('postpublish', function (t) {
var base = 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)
.stdout(/> semantic-release post\n\nGenerating changelog from.*\nParsed/m)
var base = getBase(cwd)
t.test('publish new version to github releases', function (t) {
t.plan(1)
base.clone()
.stdout(/> semantic-release post\n\nGenerating changelog from.*\nParsed/m)
.run('npm run postpublish')
.end(function (err) {
t.error(err, 'nixt')
@@ -48,6 +44,7 @@ module.exports = function (test, createModule) {
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) {
@@ -68,4 +65,51 @@ module.exports = function (test, createModule) {
})
})
}))
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)
}