Skip to content

Commit 50ee677

Browse files
committed
chore(release): make discourse task work
1 parent d3ed66e commit 50ee677

File tree

6 files changed

+99
-24
lines changed

6 files changed

+99
-24
lines changed

config/DISCOURSE_POST_URL

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
http://forum.ionicframework.com/t/1-0-0-beta-10-hafnium-heron-released/7326/

config/RELEASE_POST_URL

Lines changed: 0 additions & 1 deletion
This file was deleted.

config/build.config.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
var pkg = require('../package.json');
22
var fs = require('fs');
33

4+
var DISCOURSE_FILE = __dirname + '/DISCOURSE_POST_URL';
5+
46
module.exports = {
57
dist: 'dist',
6-
releasePostUrl: fs.readFileSync('config/RELEASE_POST_URL'),
8+
releasePostUrl: fs.readFileSync(DISCOURSE_FILE).toString(),
9+
releasePostFile: DISCOURSE_FILE,
710

811
protractorPort: 8876,
912

gulpfile.js

Lines changed: 91 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
var gulp = require('gulp');
22
var path = require('canonical-path');
33
var pkg = require('./package.json');
4+
var request = require('request');
5+
var q = require('q');
46
var semver = require('semver');
57
var through = require('through');
68

@@ -59,39 +61,46 @@ gulp.task('default', ['build']);
5961
gulp.task('build', ['bundle', 'sass']);
6062
gulp.task('validate', ['jshint', 'ddescribe-iit', 'karma']);
6163

62-
6364
var IS_WATCH = false;
6465
gulp.task('watch', ['build'], function() {
6566
IS_WATCH = true;
6667
gulp.watch('js/**/*.js', ['bundle']);
6768
gulp.watch('scss/**/*.scss', ['sass']);
6869
});
6970

70-
gulp.task('changelog', function(done) {
71-
var codename = pkg.codename;
72-
var file = argv.standalone ? '' : __dirname + '/CHANGELOG.md';
73-
var subtitle = argv.subtitle || '"' + codename + '"';
74-
var toHtml = !!argv.html;
71+
gulp.task('changelog', function() {
7572
var dest = argv.dest || 'CHANGELOG.md';
76-
var from = argv.from;
77-
changelog({
78-
repository: 'https://github.com/driftyco/ionic',
79-
version: pkg.version,
80-
subtitle: subtitle,
81-
file: file,
82-
from: from
83-
}, function(err, data) {
84-
if (err) return done(err);
73+
var toHtml = !!argv.html;
74+
return makeChangelog(argv).then(function(log) {
8575
if (toHtml) {
86-
data = marked(data, {
76+
log = marked(log, {
8777
gfm: true
8878
});
8979
}
90-
fs.writeFileSync(dest, data);
91-
done();
80+
fs.writeFileSync(dest, log);
9281
});
9382
});
9483

84+
function makeChangelog(options) {
85+
var codename = pkg.codename;
86+
var file = options.standalone ? '' : __dirname + '/CHANGELOG.md';
87+
var subtitle = options.subtitle || '"' + codename + '"';
88+
var from = options.from;
89+
var version = options.version || pkg.version;
90+
var deferred = q.defer();
91+
changelog({
92+
repository: 'https://github.com/driftyco/ionic',
93+
version: version,
94+
subtitle: subtitle,
95+
file: file,
96+
from: from
97+
}, function(err, log) {
98+
if (err) deferred.reject(err);
99+
else deferred.resolve(log);
100+
});
101+
return deferred.promise;
102+
}
103+
95104
gulp.task('bundle', [
96105
'scripts',
97106
'scripts-ng',
@@ -220,7 +229,11 @@ gulp.task('release-tweet', function(done) {
220229
var client = new twitter(oauth);
221230
client.statuses(
222231
'update',
223-
{ status: buildConfig.releaseMessage() },
232+
{
233+
status: argv.test ?
234+
'This is a test.' :
235+
buildConfig.releaseMessage()
236+
},
224237
oauth.accessToken,
225238
oauth.accessTokenSecret,
226239
done
@@ -236,12 +249,62 @@ gulp.task('release-irc', function(done) {
236249
realName: 'ionitron',
237250
channels: ['#ionic']
238251
}, function() {
239-
client.say('#ionic', buildConfig.releaseMessage(), function() {
252+
client.say('#ionic', argv.test ? 'This is a test.' : buildConfig.releaseMessage(), function() {
240253
client.quit('', done);
241254
});
242255
});
243256
});
244257

258+
gulp.task('release-discourse', function(done) {
259+
var oldPostUrl = buildConfig.releasePostUrl;
260+
var newPostUrl;
261+
262+
return makeChangelog({
263+
standalone: true
264+
})
265+
.then(function(changelog) {
266+
var content = 'Download Instructions: https://github.com/driftyco/ionic#quick-start\n\n' + changelog;
267+
return qRequest({
268+
url: 'http://forum.ionicframework.com/posts',
269+
method: 'post',
270+
form: {
271+
api_key: process.env.DISCOURSE_TOKEN,
272+
api_username: 'Ionitron',
273+
title: argv.test ?
274+
('This is a test. ' + Date.now()) :
275+
'v' + pkg.version + ' "' + pkg.codename + '" released!',
276+
raw: argv.test ?
277+
('This is a test. Again! ' + Date.now()) :
278+
content
279+
}
280+
});
281+
})
282+
.then(function(res) {
283+
var body = JSON.parse(res.body);
284+
newPostUrl = 'http://forum.ionicframework.com/t/' + body.topic_slug + '/' + body.topic_id;
285+
fs.writeFileSync(buildConfig.releasePostFile, newPostUrl);
286+
287+
return q.all([
288+
updatePost(newPostUrl, 'closed', true),
289+
updatePost(newPostUrl, 'visible', false),
290+
oldPostUrl && updatePost(oldPostUrl, 'pinned', true)
291+
]);
292+
});
293+
294+
function updatePost(url, statusType, isEnabled) {
295+
return qRequest({
296+
url: url + '/status',
297+
method: 'put',
298+
form: {
299+
api_key: process.env.DISCOURSE_TOKEN,
300+
api_username: 'Ionitron',
301+
status: statusType,
302+
enabled: !!isEnabled
303+
}
304+
});
305+
}
306+
});
307+
245308
function notContains(disallowed) {
246309
disallowed = disallowed || [];
247310

@@ -274,3 +337,11 @@ function pad(n) {
274337
if (n<10) { return '0' + n; }
275338
return n;
276339
}
340+
function qRequest(opts) {
341+
var deferred = q.defer();
342+
request(opts, function(err, res, body) {
343+
if (err) deferred.reject(err);
344+
else deferred.resolve(res);
345+
});
346+
return deferred.promise;
347+
}

scripts/bump/release.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ echo "#####"
1111
function run {
1212
cd ../..
1313

14-
CODENAME=$(cat config/CODENAMES | head -n 1)
14+
CODENAME=$(head -n 1 config/CODENAMES)
1515
echo "$(tail -n +2 config/CODENAMES)" > config/CODENAMES
1616

1717
replaceJsonProp "package.json" "codename" "$CODENAME"

scripts/release/publish.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
function init {
44
RELEASE_DIR=$HOME/ionic-release
55
../clone/clone.sh --repository="driftyco/ionic" \
6-
--depth="1" \
76
--directory="$RELEASE_DIR" \
87
--branch="master"
98
}
@@ -18,7 +17,9 @@ function run {
1817
node_modules/.bin/gulp build --release --dist="$RELEASE_DIR/release"
1918
node_modules/.bin/gulp changelog --dest="$RELEASE_DIR/CHANGELOG.md"
2019

20+
# Move modified files into the repo copy we're going to push
2121
cp package.json $RELEASE_DIR
22+
cp config/CODENAMES $RELEASE_DIR
2223

2324
cd $RELEASE_DIR
2425

0 commit comments

Comments
 (0)