Compare commits

...
16 Commits
Author SHA1 Message Date
Stephan Bönnemann 875bb038a1 chore(package): change version to yet unpublished version
one last time hopefully >:(
2015-02-05 01:35:53 +01:00
Stephan Bönnemann 89f1928769 test(publish): initial scenario 2015-02-05 01:33:50 +01:00
Christoph Witzko 3799ad0cb6 test(postpublish): initial scenario 2015-02-05 01:04:52 +01:00
Christoph Witzko 7380d586ee feat(release): configure github api endpoint via environment variables 2015-02-05 01:00:42 +01:00
Christoph Witzko eb470712d7 test: added github-release-fake-server 2015-02-05 01:00:42 +01:00
Christoph Witzko f2484b8e42 test: set npm registry inside .npmrc 2015-02-04 20:18:19 +01:00
Stephan Bönnemann 73b888fdc3 docs(readme): remove usage outside of npm scripts 2015-02-04 19:02:37 +01:00
Stephan Bönnemann f44cedbaa7 text: expose correct registry to environment 2015-02-04 18:58:37 +01:00
Stephan Bönnemann a540c402a9 fix(version): use $npm_config_registry variable to ensure the right registry
BREAKING CHANGE: This breaks the usage of the `semantic-release` CLI outside of npm scripts.
2015-02-04 18:56:31 +01:00
Stephan Bönnemann ffbd39e78a test(prepublish): initial scenario 2015-02-04 15:39:05 +01:00
Stephan Bönnemann 81df21b924 test(install): initial scenario 2015-02-04 15:23:30 +01:00
Stephan Bönnemann d22b98a4ee test(create-module): helper to create fresh repo/module 2015-02-04 15:23:21 +01:00
Stephan Bönnemann c936e8be4b test: setup private npm registry w/sinopia 2015-02-04 15:23:16 +01:00
Stephan Bönnemann 019aeeabe1 refator: use error-first-handler 2015-02-03 20:45:03 +01:00
Stephan Bönnemann 19fd15c1dc refactor(cli): parse npmArgv w/minimist 2015-02-03 14:21:42 +01:00
Christoph WitzkoandStephan Bönnemann 16cf9aee9b fix(cli): hooks work correctly w/abbrevd npm commands 2015-02-03 14:09:02 +01:00
22 changed files with 383 additions and 85 deletions
+1
View File
@@ -1,2 +1,3 @@
node_modules
*.log
.tmp
+2
View File
@@ -7,6 +7,8 @@ cache:
- node_modules
notifications:
email: false
before_install:
- npm i -g npm@^2.0.0
deploy:
provider: npm
email: stephan@boennemann.me
+2 -7
View File
@@ -8,12 +8,7 @@
```bash
npm i semantic-release
```
`semantic-release` provides "prepublish" and "postpublish" hooks so you automatically release the correct version.
Run `semantic-release pre` right before `npm publish` and `semantic-release post` right after.
For maximum comfort you can automate this inside your `package.json`:
You *need* to set it up inside your `package.json`:
```json
"scripts": {
@@ -22,7 +17,7 @@ For maximum comfort you can automate this inside your `package.json`:
}
```
Note: Even though `semantic-release` works around a limitation in npm's "prepublish" hook using it prints an error that you can *safely ignore*.
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).
MIT License
Executable
+9
View File
@@ -0,0 +1,9 @@
#!/bin/sh
cat .tmp/sinopia.pid | xargs kill
cat .tmp/ghrs.pid | xargs kill
cp .tmp/.npmrc ~/.npmrc
rm -rf .tmp
Executable
+14
View File
@@ -0,0 +1,14 @@
#!/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
+28 -31
View File
@@ -1,73 +1,66 @@
#!/usr/bin/env node
'use strict'
var abbrev = require('abbrev')
var confirm = require('confirm-simple')
var minimist = require('minimist')
var argv = require('minimist')(process.argv.slice(2), {
var efh = require('../lib/error').standard
var argv = minimist(process.argv.slice(2), {
alias: {
d: 'debug',
dry: 'debug',
t: 'token'
t: 'token',
g: 'github-url'
},
default: {
token: process.env.GH_TOKEN || process.env.TOKEN || process.env.GITHUB_TOKEN
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
npmArgv = npmArgv ? JSON.parse(npmArgv).cooked : []
var npmArgv = process.env.npm_config_argv ?
minimist(JSON.parse(process.env.npm_config_argv).cooked) :
{_: []}
if (~argv._.indexOf('pre')) {
var publish = false
// see src/restart.js
if (~npmArgv.indexOf('--semantic-release-rerun')) process.exit(0)
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 (~npmArgv.indexOf('install')) process.exit(0)
if (isAbbrev(npmArgv, 'install')) process.exit(0)
return confirmCI(function () {
if (~npmArgv.indexOf('publish')) publish = true
console.log('Determining new version')
require('../src/pre')(argv, function (err, result) {
if (err) {
console.log('Something went wrong.')
throw err
}
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) require('../src/restart')(function (err) {
if (err) {
console.log('Something went wrong.')
throw err
}
if (!publish) process.exit(0)
require('../src/restart')(efh(function () {
process.exit(1)
})
})
}))
}))
})
}
if (~argv._.indexOf('post')) {
return confirmCI(function () {
require('../src/post')(argv, function (err) {
if (err) {
console.log('Something went wrong.')
throw err
}
require('../src/post')(argv, efh(function () {
// see src/restart.js
if (~npmArgv.indexOf('--semantic-release-rerun')) {
if (npmArgv['semantic-release-rerun']) {
console.log('Everything is alright :) npm will now print an error message that you can safely ignore.')
}
})
}))
})
}
@@ -79,3 +72,7 @@ function confirmCI (cb) {
cb(null, ok)
})
}
function isAbbrev (argv, command) {
return argv._.some(Object.prototype.hasOwnProperty.bind(abbrev(command)))
}
+14
View File
@@ -0,0 +1,14 @@
'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)
})
}
+6 -7
View File
@@ -2,13 +2,12 @@
var git = require('conventional-changelog/lib/git')
module.exports = function (cb) {
git.latestTag(function (err, from) {
if (err) return cb(err)
var efh = require('../error').efh
git.getCommits({from: from}, function (err, commits) {
if (err) return cb(err)
module.exports = function (cb) {
git.latestTag(efh(cb)(function (from) {
git.getCommits({from: from}, efh(cb)(function (commits) {
cb(null, commits)
})
})
}))
}))
}
+4 -5
View File
@@ -1,12 +1,11 @@
'use strict'
var commits = require('./commits')
var analyze = require('./analyze')
var commits = require('./commits')
var efh = require('../error').efh
module.exports = function (cb) {
commits(function (err, commits) {
if (err) return cb(err)
commits(efh(cb)(function (commits) {
cb(null, analyze(commits))
})
}))
}
+8 -9
View File
@@ -1,18 +1,17 @@
'use strict'
var exec = require('child_process').exec
var unlink = require('fs').unlinkSync
var efh = require('./error').efh
module.exports = function (pkg, cb) {
if (!pkg.name) return cb('Package must have a name')
if (!pkg.name) return cb(new Error('Package must have a name'))
exec('npm show ' + pkg.name + ' version', function(err, stdout, stderr) {
if (err) unlink('./npm-debug.log')
exec('curl -s "' + process.env.npm_config_registry + pkg.name + '"', efh(cb)(function(stdout) {
var pkg = JSON.parse(stdout)
if (err && /is not in the npm registry/m.test(stderr)) return cb(null, null, true)
if (pkg.error) return cb(null, null, true)
if (err) return cb(err)
cb(null, stdout.trim())
})
cb(null, pkg['dist-tags'].latest)
}))
}
+19 -4
View File
@@ -1,15 +1,17 @@
{
"name": "semantic-release",
"description": "semantic semver compliant package publishing",
"version": "0.0.5",
"version": "0.0.6",
"author": "Stephan Bönnemann <stephan@boennemann.me>",
"bin": "./bin/semantic-release",
"bugs": {
"url": "https://github.com/boennemann/semantic-release/issues"
},
"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",
@@ -17,7 +19,18 @@
"semver": "^4.2.0"
},
"devDependencies": {
"standard": "^2.3.1"
"github-release-fake-server": "^1.1.1",
"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"
},
"engines": {
"node": "^0.10.0",
"npm": "^2.0.0"
},
"homepage": "https://github.com/boennemann/semantic-release",
"keywords": [
@@ -36,8 +49,10 @@
"url": "https://github.com/boennemann/semantic-release.git"
},
"scripts": {
"prepublish": "./bin/semantic-release pre",
"postpublish": "./bin/semantic-release post",
"test": "standard"
"posttest": "./bin/post-test",
"prepublish": "./bin/semantic-release pre",
"pretest": "./bin/pre-test",
"test": "standard && node tests | tap-spec"
}
}
+18 -15
View File
@@ -2,32 +2,36 @@
var exec = require('child_process').exec
var readFile = require('fs').readFileSync
var url = require('url')
var changelog = require('conventional-changelog')
var GitHubApi = require('github')
var parseSlug = require('parse-github-repo-url')
var parseUrl = require('github-url-from-git')
var github = new GitHubApi({
version: '3.0.0'
})
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('Package must have a repository')
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({
version: '3.0.0',
port: config.port,
protocol: (config.protocol || '').split(':')[0] || null,
host: config.hostname
})
changelog({
version: pkg.version,
repository: parseUrl(repository),
file: false
}, function(err, log) {
if (err) return cb(err)
exec('git rev-parse HEAD', function(err, hash) {
if (err) return cb(err)
}, efh(cb)(function (log) {
exec('git rev-parse HEAD', efh(cb)(function (hash) {
var ghRepo = parseSlug(repository)
var release = {
owner: ghRepo[0],
@@ -43,10 +47,9 @@ module.exports = function (options, cb) {
token: options.token
})
github.releases.createRelease(release, function(err) {
if (err) return cb(err)
github.releases.createRelease(release, efh(cb)(function () {
cb(null, true)
})
})
})
}))
}))
}))
}
+5 -7
View File
@@ -6,21 +6,19 @@ var semver = require('semver')
var type = require('../lib/type')
var version = require('../lib/version')
var efh = require('../lib/error').efh
module.exports = function (options, cb) {
type(function (err, type) {
if (err) return cb(err)
type(efh(cb)(function (type) {
if (!type) return cb(null, null)
var path = './package.json'
var pkg = JSON.parse(fs.readFileSync(path))
version(pkg, function (err, version, unpublished) {
if (err) return cb(err)
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)
})
})
}))
}))
}
+1
View File
@@ -0,0 +1 @@
test:{SHA}C+7Hteo/D9vJXQ3UfzxbwnXaijM=
+3
View File
@@ -0,0 +1,3 @@
_auth=dGVzdDpmb28=
email=test@example.com
registry=http://127.0.0.1:4873/
+17
View File
@@ -0,0 +1,17 @@
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
+10
View File
@@ -0,0 +1,10 @@
'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)
+45
View File
@@ -0,0 +1,45 @@
'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)
}))
}))
}
+33
View File
@@ -0,0 +1,33 @@
'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')
})
})
}
}))
}
+57
View File
@@ -0,0 +1,57 @@
'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')
})
})
})
}))
}
+50
View File
@@ -0,0 +1,50 @@
'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)
})
})
})
}
}))
}
+37
View File
@@ -0,0 +1,37 @@
'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')
})
})
}))
}
})
}