From 50ee67763d3fbba41f6ff3b8f045033f94d4c443 Mon Sep 17 00:00:00 2001 From: Andrew Date: Wed, 6 Aug 2014 14:40:33 -0600 Subject: [PATCH] chore(release): make discourse task work --- config/DISCOURSE_POST_URL | 1 + config/RELEASE_POST_URL | 1 - config/build.config.js | 5 +- gulpfile.js | 111 ++++++++++++++++++++++++++++++------- scripts/bump/release.sh | 2 +- scripts/release/publish.sh | 3 +- 6 files changed, 99 insertions(+), 24 deletions(-) create mode 100644 config/DISCOURSE_POST_URL delete mode 100644 config/RELEASE_POST_URL diff --git a/config/DISCOURSE_POST_URL b/config/DISCOURSE_POST_URL new file mode 100644 index 0000000000..695ac638dd --- /dev/null +++ b/config/DISCOURSE_POST_URL @@ -0,0 +1 @@ +http://forum.ionicframework.com/t/1-0-0-beta-10-hafnium-heron-released/7326/ diff --git a/config/RELEASE_POST_URL b/config/RELEASE_POST_URL deleted file mode 100644 index d89b2cf2e9..0000000000 --- a/config/RELEASE_POST_URL +++ /dev/null @@ -1 +0,0 @@ -http://forum.ionicframework.com/t/v1-0-0-beta-5b-cadmium-camel-released/4277 diff --git a/config/build.config.js b/config/build.config.js index 15a49b17e9..51f9230722 100644 --- a/config/build.config.js +++ b/config/build.config.js @@ -1,9 +1,12 @@ var pkg = require('../package.json'); var fs = require('fs'); +var DISCOURSE_FILE = __dirname + '/DISCOURSE_POST_URL'; + module.exports = { dist: 'dist', - releasePostUrl: fs.readFileSync('config/RELEASE_POST_URL'), + releasePostUrl: fs.readFileSync(DISCOURSE_FILE).toString(), + releasePostFile: DISCOURSE_FILE, protractorPort: 8876, diff --git a/gulpfile.js b/gulpfile.js index 4596368109..89c636890d 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,6 +1,8 @@ var gulp = require('gulp'); var path = require('canonical-path'); var pkg = require('./package.json'); +var request = require('request'); +var q = require('q'); var semver = require('semver'); var through = require('through'); @@ -59,7 +61,6 @@ gulp.task('default', ['build']); gulp.task('build', ['bundle', 'sass']); gulp.task('validate', ['jshint', 'ddescribe-iit', 'karma']); - var IS_WATCH = false; gulp.task('watch', ['build'], function() { IS_WATCH = true; @@ -67,31 +68,39 @@ gulp.task('watch', ['build'], function() { gulp.watch('scss/**/*.scss', ['sass']); }); -gulp.task('changelog', function(done) { - var codename = pkg.codename; - var file = argv.standalone ? '' : __dirname + '/CHANGELOG.md'; - var subtitle = argv.subtitle || '"' + codename + '"'; - var toHtml = !!argv.html; +gulp.task('changelog', function() { var dest = argv.dest || 'CHANGELOG.md'; - var from = argv.from; - changelog({ - repository: 'https://github.com/driftyco/ionic', - version: pkg.version, - subtitle: subtitle, - file: file, - from: from - }, function(err, data) { - if (err) return done(err); + var toHtml = !!argv.html; + return makeChangelog(argv).then(function(log) { if (toHtml) { - data = marked(data, { + log = marked(log, { gfm: true }); } - fs.writeFileSync(dest, data); - done(); + fs.writeFileSync(dest, log); }); }); +function makeChangelog(options) { + var codename = pkg.codename; + var file = options.standalone ? '' : __dirname + '/CHANGELOG.md'; + var subtitle = options.subtitle || '"' + codename + '"'; + var from = options.from; + var version = options.version || pkg.version; + var deferred = q.defer(); + changelog({ + repository: 'https://github.com/driftyco/ionic', + version: version, + subtitle: subtitle, + file: file, + from: from + }, function(err, log) { + if (err) deferred.reject(err); + else deferred.resolve(log); + }); + return deferred.promise; +} + gulp.task('bundle', [ 'scripts', 'scripts-ng', @@ -220,7 +229,11 @@ gulp.task('release-tweet', function(done) { var client = new twitter(oauth); client.statuses( 'update', - { status: buildConfig.releaseMessage() }, + { + status: argv.test ? + 'This is a test.' : + buildConfig.releaseMessage() + }, oauth.accessToken, oauth.accessTokenSecret, done @@ -236,12 +249,62 @@ gulp.task('release-irc', function(done) { realName: 'ionitron', channels: ['#ionic'] }, function() { - client.say('#ionic', buildConfig.releaseMessage(), function() { + client.say('#ionic', argv.test ? 'This is a test.' : buildConfig.releaseMessage(), function() { client.quit('', done); }); }); }); +gulp.task('release-discourse', function(done) { + var oldPostUrl = buildConfig.releasePostUrl; + var newPostUrl; + + return makeChangelog({ + standalone: true + }) + .then(function(changelog) { + var content = 'Download Instructions: https://github.com/driftyco/ionic#quick-start\n\n' + changelog; + return qRequest({ + url: 'http://forum.ionicframework.com/posts', + method: 'post', + form: { + api_key: process.env.DISCOURSE_TOKEN, + api_username: 'Ionitron', + title: argv.test ? + ('This is a test. ' + Date.now()) : + 'v' + pkg.version + ' "' + pkg.codename + '" released!', + raw: argv.test ? + ('This is a test. Again! ' + Date.now()) : + content + } + }); + }) + .then(function(res) { + var body = JSON.parse(res.body); + newPostUrl = 'http://forum.ionicframework.com/t/' + body.topic_slug + '/' + body.topic_id; + fs.writeFileSync(buildConfig.releasePostFile, newPostUrl); + + return q.all([ + updatePost(newPostUrl, 'closed', true), + updatePost(newPostUrl, 'visible', false), + oldPostUrl && updatePost(oldPostUrl, 'pinned', true) + ]); + }); + + function updatePost(url, statusType, isEnabled) { + return qRequest({ + url: url + '/status', + method: 'put', + form: { + api_key: process.env.DISCOURSE_TOKEN, + api_username: 'Ionitron', + status: statusType, + enabled: !!isEnabled + } + }); + } +}); + function notContains(disallowed) { disallowed = disallowed || []; @@ -274,3 +337,11 @@ function pad(n) { if (n<10) { return '0' + n; } return n; } +function qRequest(opts) { + var deferred = q.defer(); + request(opts, function(err, res, body) { + if (err) deferred.reject(err); + else deferred.resolve(res); + }); + return deferred.promise; +} diff --git a/scripts/bump/release.sh b/scripts/bump/release.sh index a432c1d225..7cf516743b 100755 --- a/scripts/bump/release.sh +++ b/scripts/bump/release.sh @@ -11,7 +11,7 @@ echo "#####" function run { cd ../.. - CODENAME=$(cat config/CODENAMES | head -n 1) + CODENAME=$(head -n 1 config/CODENAMES) echo "$(tail -n +2 config/CODENAMES)" > config/CODENAMES replaceJsonProp "package.json" "codename" "$CODENAME" diff --git a/scripts/release/publish.sh b/scripts/release/publish.sh index 0aef4112d2..4b415a25d2 100755 --- a/scripts/release/publish.sh +++ b/scripts/release/publish.sh @@ -3,7 +3,6 @@ function init { RELEASE_DIR=$HOME/ionic-release ../clone/clone.sh --repository="driftyco/ionic" \ - --depth="1" \ --directory="$RELEASE_DIR" \ --branch="master" } @@ -18,7 +17,9 @@ function run { node_modules/.bin/gulp build --release --dist="$RELEASE_DIR/release" node_modules/.bin/gulp changelog --dest="$RELEASE_DIR/CHANGELOG.md" + # Move modified files into the repo copy we're going to push cp package.json $RELEASE_DIR + cp config/CODENAMES $RELEASE_DIR cd $RELEASE_DIR