Compare commits

..
40 Commits
Author SHA1 Message Date
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
29 changed files with 385 additions and 238 deletions
+1
View File
@@ -1,5 +1,6 @@
language: node_js
node_js:
- iojs-v2
- iojs-v1
- '0.10'
- '0.12'
+30 -58
View File
@@ -5,63 +5,29 @@
[![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`.
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).
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.
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)
## How does this work?
## How does it work?
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.
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.
```
<type>(<scope>): <subject>
<BLANK LINE>
<body>
```
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 +37,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 +77,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
@@ -133,11 +101,15 @@ cache:
- 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,7 +125,7 @@ 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.
@@ -173,7 +145,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 +153,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?
-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
+11 -3
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,6 +23,8 @@ 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) :
{_: []}
@@ -30,7 +34,11 @@ if (~argv._.indexOf('pre')) {
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') || 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 +50,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 +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.')
+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)
}))
}
+10 -9
View File
@@ -9,15 +9,16 @@
},
"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": {
"github-release-fake-server": "^1.3.0",
@@ -25,9 +26,9 @@
"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 +55,9 @@
},
"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"
}
}
+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],
+14 -9
View File
@@ -4,18 +4,23 @@ 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 (!pkg.name) return cb(new Error('Package must have a name'))
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)
pkg.version = res.version ? semver.inc(res.version, type) : '1.0.0'
if (!options.debug) fs.writeFileSync(path, JSON.stringify(pkg, null, 2))
cb(null, pkg.version)
+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')
}
+2 -1
View File
@@ -4,7 +4,8 @@ var test = require('tape')
var createModule = require('./lib/create-module')
require('./scenarios/install')(test, createModule)
require('./scenarios/custom-analyzer')(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')
}
+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)
})
}))
}
+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')))
+1 -1
View File
@@ -25,7 +25,7 @@ module.exports = function (test, createModule) {
, 'm'
))
.code(1)
.end(function(err) {
.end(function (err) {
t.error(err, 'nixt')
})
})