Skip to content

Automating release post #88

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 110 additions & 0 deletions scripts/release-post.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
#!/usr/bin/env node

'use strict';

const https = require('https');
const fs = require('fs');
const path = require('path');
const extend = require('util')._extend;
const Handlebars = require('handlebars');

function download (url, cb) {
return new Promise(function (resolve, reject) {
let data = '';
https.get(url, function (res) {
if (res.statusCode !== 200) {
return reject(new Error('Invalid status code (!= 200) while retrieving '+ url +': '+ res.statusCode));
}

res.on('data', function (chunk) { data += chunk; });
res.on('end', function () { resolve(data); });
}).on('error', function (err) {
reject(new Error('Error downloading file from %s: %s', url, err.message));
});
});
}

// matches a complete release section, support both old node and iojs releases:
// ## 2015-07-09, Version 0.12.7 (Stable)
// ## 2015-08-04, Version 3.0.0, @rvagg
const rxReleaseSection = /## \d{4}-\d{2}-\d{2}, Version ([^,( ]+)[\s\S]*?(?=## \d{4})/g;

function findLatestVersion (cb) {
return download('https://nodejs.org/dist/index.json')
.then(JSON.parse)
.then(function (versions) {
return versions[0].version.substr(1);
});
}

function fetchDocs (version) {
return Promise.all([ fetchChangelog(version), fetchShasums(version) ]).then(function (results) {
const changelog = results[0];
const shasums = results[1];

return {
version,
changelog,
shasums
};
});
}

function fetchChangelog (version) {
return download('https://raw.githubusercontent.com/nodejs/node/master/CHANGELOG.md')
.then(function (data) {
let matches;

while (matches = rxReleaseSection.exec(data)) {
const releaseVersion = matches[1];
if (releaseVersion === version) {
return matches[0];
}
}

return Promise.reject(new Error('Couldnt find matching changelog for ' + version));
});
}

function fetchShasums (version) {
return download(`https://nodejs.org/dist/v${version}/SHASUMS256.txt.asc`);
}

function renderPost (results) {
const templateStr = fs.readFileSync(path.resolve(__dirname, 'release.hbs')).toString('utf8');
const template = Handlebars.compile(templateStr, { noEscape: true });
const view = extend({
date: new Date().toISOString(),
versionSlug: slugify(results.version)
}, results);

return extend({
content: template(view)
}, results);
}

function writeToFile (results) {
const filepath = path.resolve(__dirname, '..', 'locale', 'en', 'blog', 'release', `v${results.version}.md`);

if (fs.existsSync(filepath)) {
return Promise.reject(new Error(`Release post for ${results.version} already exists!`));
}

fs.writeFileSync(filepath, results.content);
return Promise.resolve(filepath);
}

function slugify (str) {
return str.replace(/\./g, '-');
}

findLatestVersion()
.then(fetchDocs)
.then(renderPost)
.then(writeToFile)
.then(function (filepath) {
console.log('Release post created:', filepath);
}, function (err) {
console.error('Some error occured here!', err.stack);
process.exit(1);
});
49 changes: 49 additions & 0 deletions scripts/release.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
---
date: {{date}}
version: {{version}}
category: release
title: Node v{{version}} (Stable)
slug: node-v{{versionSlug}}-stable
layout: blog-post.hbs
---

{{changelog}}

Windows 32-bit Installer: http://nodejs.org/dist/v{{version}}/node-v{{version}}-x86.msi

Windows 64-bit Installer: http://nodejs.org/dist/v{{version}}/node-v{{version}}-x64.msi

Windows 32-bit Binary: http://nodejs.org/dist/v{{version}}/win-x86/node.exe

Windows 64-bit Binary: http://nodejs.org/dist/v{{version}}/win-x64/node.exe

Mac OS X 64-bit Installer: http://nodejs.org/dist/v{{version}}/node-v{{version}}.pkg

Mac OS X 64-bit Binary: http://nodejs.org/dist/v{{version}}/node-v{{version}}-darwin-x64.tar.gz

Linux 32-bit Binary: http://nodejs.org/dist/v{{version}}/node-v{{version}}-linux-x86.tar.gz

Linux 64-bit Binary: http://nodejs.org/dist/v{{version}}/node-v{{version}}-linux-x64.tar.gz

SunOS 32-bit Binary: http://nodejs.org/dist/v{{version}}/node-v{{version}}-sunos-x86.tar.gz

SunOS 64-bit Binary: http://nodejs.org/dist/v{{version}}/node-v{{version}}-sunos-x64.tar.gz

ARMv6 32-bit Binary: http://nodejs.org/dist/v{{version}}/node-v{{version}}-linux-armv6l.tar.gz

ARMv7 32-bit Binary: http://nodejs.org/dist/v{{version}}/node-v{{version}}-linux-armv7l.tar.gz

ARMv8 64-bit Binary: http://nodejs.org/dist/v{{version}}/node-v{{version}}-linux-arm64.tar.gz

Source Code: http://nodejs.org/dist/v{{version}}/node-v{{version}}.tar.gz

Other release files: http://nodejs.org/dist/v{{version}}/

Website: http://nodejs.org/docs/v{{version}}/

Documentation: http://nodejs.org/docs/v{{version}}/api/

Shasums:
```
{{shasums}}
```