Skip to content

Commit ca54694

Browse files
richardlaurvagg
authored andcommitted
add security release column to index
Parse the release notes for a release to determine if it is a security release. Refs: nodejs/Release#437
1 parent dfc0a5e commit ca54694

File tree

6 files changed

+1808
-3
lines changed

6 files changed

+1808
-3
lines changed

dist-indexer.js

+33-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const fs = require('fs')
1313

1414
, transformFilename = require('./transform-filename')
1515
, decodeRef = require('./decode-ref')
16+
, isSecurityRelease = require('./is-security-release')
1617

1718
, versionCachePath = path.join(process.env.HOME, '.dist-indexer-version-cache')
1819

@@ -39,6 +40,7 @@ const fs = require('fs')
3940
, `${githubContentUrl}/src/node.h`
4041
]
4142
, ltsVersionUrl = `${githubContentUrl}/src/node_version.h`
43+
, isSecurityUrl = 'https://github.com/nodejs/{repo}/commits/{gitref}.atom'
4244
, githubOptions = { headers: {
4345
'accept': 'text/plain,application/vnd.github.v3.raw'
4446
} }
@@ -339,6 +341,23 @@ function fetchLtsVersion (gitref, callback) {
339341
}
340342

341343

344+
function fetchSecurity (gitref, callback) {
345+
var security = cacheGet(gitref, 'security')
346+
347+
if (security || security === false)
348+
return setImmediate(callback.bind(null, null, security))
349+
350+
fetch(isSecurityUrl, gitref, function (err, rawData) {
351+
if (err)
352+
return callback(err)
353+
354+
security = isSecurityRelease(rawData)
355+
cachePut(gitref, 'security', security)
356+
callback(null, security)
357+
})
358+
}
359+
360+
342361
function dirDate (dir, callback) {
343362
fs.readdir(path.join(argv.dist, dir), function (err, files) {
344363
if (err)
@@ -392,6 +411,7 @@ function inspectDir (dir, callback) {
392411
, zlibVersion
393412
, modVersion
394413
, ltsVersion
414+
, securityRelease
395415
, date
396416

397417
if (!gitref) {
@@ -412,7 +432,7 @@ function inspectDir (dir, callback) {
412432

413433
files = _files
414434

415-
var done = after(8, afterAll)
435+
var done = after(9, afterAll)
416436

417437
dirDate(dir, function (err, _date) {
418438
if (err)
@@ -484,6 +504,15 @@ function inspectDir (dir, callback) {
484504
ltsVersion = version
485505
done()
486506
})
507+
508+
fetchSecurity(gitref, function (err, security) {
509+
if (err) {
510+
console.error(err)
511+
console.error('(ignoring error fetching security release for %s)', gitref)
512+
}
513+
securityRelease = security
514+
done()
515+
})
487516
})
488517

489518
function afterAll (err) {
@@ -504,6 +533,7 @@ function inspectDir (dir, callback) {
504533
, openssl : sslVersion
505534
, modules : modVersion
506535
, lts : ltsVersion
536+
, security : securityRelease
507537
})
508538
}
509539
}
@@ -533,7 +563,7 @@ function afterMap (err, dirs) {
533563
}
534564

535565
jsonOut.write('[\n')
536-
tabWrite('version', 'date', 'files', 'npm', 'v8', 'uv', 'zlib', 'openssl', 'modules', 'lts')
566+
tabWrite('version', 'date', 'files', 'npm', 'v8', 'uv', 'zlib', 'openssl', 'modules', 'lts', 'security')
537567

538568
dirs.forEach(function (dir, i) {
539569
jsonOut.write(JSON.stringify(dir) + (i != dirs.length - 1 ? ',\n' : '\n'))
@@ -548,6 +578,7 @@ function afterMap (err, dirs) {
548578
, dir.openssl
549579
, dir.modules
550580
, dir.lts
581+
, dir.security
551582
)
552583
})
553584

is-security-release.js

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
const notesre = /Version \d+\.\d+\.\d+.*\n(?!\w+<\/title>)\n(.*)\n/m
2+
, securityre = /This is a security release\./
3+
4+
5+
function isSecurityRelease (notes) {
6+
const m = notes.match(notesre)
7+
if (m && securityre.test(m[1]))
8+
return true
9+
10+
return false
11+
}
12+
13+
14+
module.exports = isSecurityRelease
15+
16+
17+
if (module === require.main) {
18+
const assert = require('assert')
19+
const fs = require('fs')
20+
const path = require('path')
21+
const fixturespath = path.join(__dirname, 'test', 'fixtures', 'release-notes')
22+
const tests = [
23+
{ fixture: 'v10.14.0.atom', expected: true }
24+
, { fixture: 'v10.14.1.atom', expected: false }
25+
, { fixture: 'v11.3.0.atom' , expected: true }
26+
]
27+
28+
tests.forEach(function (test) {
29+
console.log(`testing ${test.fixture} -> ${test.expected}`)
30+
const fixture = path.join(fixturespath, test.fixture)
31+
const notes = fs.readFileSync(fixture, { encoding: 'utf8' })
32+
assert.equal(isSecurityRelease(notes), test.expected)
33+
})
34+
}

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"semver": "~5.5.1"
1919
},
2020
"scripts": {
21-
"test": "node ls-types.js && node transform-filename.js && node decode-ref.js"
21+
"test": "node ls-types.js && node transform-filename.js && node decode-ref.js && node is-security-release.js"
2222
},
2323
"bin": {
2424
"nodejs-dist-indexer": "./dist-indexer.js",

0 commit comments

Comments
 (0)