Skip to content
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

Make the release script work with the new changelog structure #739

Merged
merged 1 commit into from
May 31, 2016
Merged
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
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
},
"dependencies": {
"autoprefixer-stylus": "0.9.3",
"changelog-url": "1.0.2",
"cheerio": "0.20.0",
"chokidar": "1.5.0",
"handlebars": "4.0.5",
Expand Down
126 changes: 56 additions & 70 deletions scripts/release-post.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,48 +24,35 @@ const fs = require('fs')
const path = require('path')
const Handlebars = require('handlebars')
const request = require('request')
const changelogUrl = require('changelog-url')
const semver = require('semver')

const downloads = require('./helpers/downloads')

function sendRequest (uri, method) {
function sendRequest (opts) {
return new Promise((resolve, reject) => {
request({
headers: { 'User-Agent': 'nodejs.org release blog post script' },
method: method,
uri: uri
}, (err, res, body) => {
const options = Object.assign({
headers: { 'User-Agent': 'nodejs.org release blog post script' }
}, opts)

request(options, (err, res, body) => {
if (err) {
return reject(new Error(`Error requesting URL ${uri}: ${err.message}`))
return reject(new Error(`Error requesting URL ${options.url}: ${err.message}`))
}
if (res.statusCode !== 200) {
return reject(new Error(`Invalid status code (!= 200) while retrieving ${uri}: ${res.statusCode}`))
return reject(new Error(`Invalid status code (!= 200) while retrieving ${options.url}: ${res.statusCode}`))
}

resolve(body)
})
})
}

function download (url) {
return sendRequest(url, 'GET')
}

function explicitVersion (version) {
return version ? Promise.resolve(version) : Promise.reject()
}

function isLegacyVersion (version) {
return semver.satisfies(version, '< 1.0.0')
}

function findLatestVersion () {
return download('https://nodejs.org/dist/index.json')
.then(JSON.parse)
.then((versions) => {
return versions[0].version.substr(1)
})
return sendRequest({ url: 'https://nodejs.org/dist/index.json', json: true })
.then((versions) => versions[0].version.substr(1))
}

function fetchDocs (version) {
Expand All @@ -88,68 +75,64 @@ function fetchDocs (version) {
author,
versionPolicy,
shasums,
files}
files
}
})
}

function fetchAuthor (version) {
return fetchChangelog(version)
.then((section) => findAuthorLogin(version, section))
.then((author) => download(`https://api.github.com/users/${author}`))
.then(JSON.parse)
.then((author) => sendRequest({
url: `https://api.github.com/users/${author}`,
json: true
}))
.then((githubRes) => githubRes.name)
}

function fetchChangelog (version) {
// matches a complete release section,
// support release sections with headers like:
// ## 2015-09-22, Version 4.1.1 (Stable), @rvagg
// ## 2015-10-07, Version 4.2.0 'Argon' (LTS), @jasnell
// 2015-12-04, Version 0.12.9 (LTS), @rvagg
const rxSection = isLegacyVersion(version)
? new RegExp(`\\d{4}-\\d{2}-\\d{2}, Version ${version} \\([^\\)]+\\)[\\s\\S]*?(?=\\d{4}.\\d{2}.\\d{2})`)
: new RegExp(`## \\d{4}-\\d{2}-\\d{2}, Version ${version} ('\\w+' )?\\([^\\)]+\\)[\\s\\S]*?(?=## \\d{4})`)

return download(changelogUrl.rawUrl(version))
.then((data) => {
const matches = rxSection.exec(data)
return matches ? matches[0] : Promise.reject(new Error(`Couldn't find matching changelog for ${version}`))
})
const parts = version.split('.')
const releaseLine = parts[0] === '0'
? parts.slice(0, 2).join('')
: parts[0]

return sendRequest({
url: `https://raw.githubusercontent.com/nodejs/node/master/doc/changelogs/CHANGELOG_V${releaseLine}.md`
}).then((data) => {
// matches a complete release section
const rxSection = new RegExp(`<a id="${version}"></a>\\n([\\s\\S]+?)(?:\\n<a id="|$)`)
const matches = rxSection.exec(data)
return matches
? matches[1]
: Promise.reject(new Error(`Couldn't find matching changelog for ${version}`))
})
}

function fetchChangelogBody (version) {
const rxSectionBody = /(### )?(Notable [\s\S]*)/g

return fetchChangelog(version)
.then((section) => {
const bodyMatch = rxSectionBody.exec(section)
// ensure ### prefixed "Notable changes" header
// https://github.com/nodejs/nodejs.org/pull/551#issue-138257829
const body = bodyMatch ? `### ${bodyMatch[2]}` : ''

return bodyMatch
? body
: Promise.reject(new Error(`Could not find changelog body of ${version} release`))
})
return fetchChangelog(version).then((section) => {
const rxSectionBody = /(### Notable [\s\S]*)/
const matches = rxSectionBody.exec(section)
return matches
? matches[1]
: Promise.reject(new Error(`Could not find changelog body of ${version} release`))
})
}

function fetchVersionPolicy (version) {
// matches the policy for a given version (Stable, LTS etc) in the changelog
// ## 2015-10-07, Version 4.2.0 'Argon' (LTS), @jasnell
// 2015-12-04, Version 0.12.9 (LTS), @rvagg
const rxPolicy = new RegExp('^(## )?\\d{4}-\\d{2}-\\d{2}, Version [^(].*\\(([^\\)]+)\\)')

return fetchChangelog(version)
.then((section) => {
const matches = rxPolicy.exec(section)
return matches
? matches[2]
: Promise.reject(new Error(`Could not find version policy of ${version} in its changelog`))
})
return fetchChangelog(version).then((section) => {
// matches the policy for a given version (Stable, LTS etc) in the changelog
// ## 2015-10-07, Version 4.2.0 'Argon' (LTS), @jasnell
// ## 2015-12-04, Version 0.12.9 (LTS), @rvagg
const rxPolicy = /^## ?\d{4}-\d{2}-\d{2}, Version [^(].*\(([^\)]+)\)/
const matches = rxPolicy.exec(section)
return matches
? matches[1]
: Promise.reject(new Error(`Could not find version policy of ${version} in its changelog`))
})
}

function fetchShasums (version) {
return download(`https://nodejs.org/dist/v${version}/SHASUMS256.txt.asc`)
return sendRequest({ url: `https://nodejs.org/dist/v${version}/SHASUMS256.txt.asc` })
.then(null, () => '[INSERT SHASUMS HERE]')
}

Expand All @@ -164,15 +147,18 @@ function findAuthorLogin (version, section) {
// ## 2016-03-08, Version 5.8.0 (Stable). @Fishrock123
// ## 2015-10-13, Version 4.2.1 'Argon' (LTS), @jasnell
// ## 2015-09-08, Version 4.0.0 (Stable), @rvagg
const rxReleaseAuthor = /^(## )?.*? \([^\)]+\)[,.] @(\S+)/g
const rxReleaseAuthor = /^## .*? \([^)]+\)[,.] @(\S+)/
const matches = rxReleaseAuthor.exec(section)
return matches ? matches[2] : Promise.reject(new Error(`Couldn't find @author of ${version} release :(`))
return matches
? matches[1]
: Promise.reject(new Error(`Couldn't find @author of ${version} release :(`))
}

function urlOrComingSoon (binary) {
return sendRequest(binary.url, 'HEAD').then(
return sendRequest({ url: binary.url, method: 'HEAD' }).then(
() => `${binary.title}: ${binary.url}`,
() => `${binary.title}: *Coming soon*`)
() => `${binary.title}: *Coming soon*`
)
}

function renderPost (results) {
Expand Down
Loading