Add release shell script for automated build, tagging, and releasing to npm

This commit is contained in:
Tankred Hase 2015-02-11 19:55:03 +01:00
parent d25c90bff1
commit fcf7242c10
4 changed files with 80 additions and 28 deletions

2
.gitignore vendored
View File

@ -5,5 +5,7 @@ npm*
src/compression/
test/lib/
dist/
dist/*.tgz
dist/*_debug.js
openpgp.store/
doc/

View File

@ -1,4 +1,7 @@
module.exports = function(grunt) {
'use strict';
var version = grunt.option('release');
// Project configuration.
grunt.initConfig({
@ -150,8 +153,36 @@ module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.registerTask('set_version', function() {
if (!version) {
throw new Error('You must specify the version: "--release=1.0.0"');
}
patchFile({
fileName: 'package.json',
version: version
});
patchFile({
fileName: 'bower.json',
version: version
});
});
function patchFile(options) {
var fs = require('fs'),
path = './' + options.fileName,
file = require(path);
if (options.version) {
file.version = options.version;
}
fs.writeFileSync(path, JSON.stringify(file, null, 2));
}
grunt.registerTask('default', 'Build OpenPGP.js', function() {
grunt.task.run(['clean', 'copy:zlib', 'browserify', 'replace', 'uglify', 'npm_pack']);
grunt.task.run(['clean', 'copy:zlib', 'browserify', 'replace', 'uglify']);
//TODO jshint is not run because of too many discovered issues, once these are addressed it should autorun
grunt.log.ok('Before Submitting a Pull Request please also run `grunt jshint`.');
});
@ -168,25 +199,6 @@ module.exports = function(grunt) {
mocha.stderr.pipe(process.stderr);
});
// Alias the `npm_pack` task to run `npm pack`
grunt.registerTask('npm_pack', 'npm pack', function () {
var done = this.async();
var npm = require('child_process').exec('npm pack ../', { cwd: 'dist'}, function (err, stdout) {
var package = stdout;
if (err === null) {
var install = require('child_process').exec('npm install dist/' + package, function (err) {
done(err);
});
install.stdout.pipe(process.stdout);
install.stderr.pipe(process.stderr);
} else {
done(err);
}
});
npm.stdout.pipe(process.stdout);
npm.stderr.pipe(process.stderr);
});
// Test/Dev tasks
// Test/Dev tasks
grunt.registerTask('test', ['copy:npm', 'mochaTest', 'mocha_phantomjs']);
};

View File

@ -1,12 +1,17 @@
{
"name": "openpgpjs",
"version": "0.7.2",
"name": "openpgp",
"version": "0.10.0",
"homepage": "http://openpgpjs.org/",
"authors": [
"OpenPGP Development Team <list@openpgpjs.org> (https://github.com/openpgpjs/openpgpjs/graphs/contributors)"
],
"description": "OpenPGP.js is a Javascript implementation of the OpenPGP protocol. This is defined in RFC 4880.",
"main": "src/index.js",
"main": [
"dist/openpgp.js",
"dist/openpgp.worker.js",
"dist/openpgp.min.js",
"dist/openpgp.worker.min.js"
],
"moduleType": [
"amd",
"es6",
@ -23,13 +28,12 @@
"license": "LGPL 3.0 or any later version",
"ignore": [
"**/.*",
"dist/openpgp*.tgz",
"dist/*.tgz",
"dist/*_debug.js",
"node_modules",
"bower_components",
"test",
"tests",
"dist",
"doc"
]
}
}

34
release.sh Executable file
View File

@ -0,0 +1,34 @@
#!/bin/sh
# abort if tests fail
set -e
# go to root
cd `dirname $0`
if [ "$#" -ne 1 ] ; then
echo 'Usage: ./release.sh 0.0.0'
exit 0
fi
# install dependencies
rm -rf node_modules/
npm install
# set version
grunt set_version --release=$1
# build and test
npm test
# Add build files to git
sed -i "" '/dist/d' .gitignore
git add dist/ *.json
git commit -m "Release new version"
git checkout .gitignore
git tag v$1
git push
git push --tag
# publish to npm
npm publish