From e1506b21276caa1d68f53ecaea685d7133f5cb98 Mon Sep 17 00:00:00 2001 From: Rod Vagg Date: Tue, 30 Jun 2015 19:49:19 +1000 Subject: [PATCH] extraced decode-ref.js, add tests, add rc builds --- tools/dist/dist-indexer/decode-ref.js | 28 +++++ tools/dist/dist-indexer/dist-indexer.js | 103 ++++++++---------- tools/dist/dist-indexer/transform-filename.js | 90 ++++++++++++++- 3 files changed, 163 insertions(+), 58 deletions(-) create mode 100644 tools/dist/dist-indexer/decode-ref.js diff --git a/tools/dist/dist-indexer/decode-ref.js b/tools/dist/dist-indexer/decode-ref.js new file mode 100644 index 000000000..7e857d865 --- /dev/null +++ b/tools/dist/dist-indexer/decode-ref.js @@ -0,0 +1,28 @@ +const assert = require('assert') + , dirre = /^(v\d+\.\d+\.\d+(?:-rc\.\d+)?)(?:-(?:next-)?nightly\d{8}(\w+))?$/ // get version or commit from dir name + + +function decodeRef (dir) { + var m = dir.match(dirre) + return m && (m[2] || m[1]) +} + + +module.exports = decodeRef + + +if (module === require.main) { + var tests = [ + { dir: 'v1.0.0' , ref: 'v1.0.0' } + , { dir: 'v10.11.12' , ref: 'v10.11.12' } + , { dir: 'v2.3.2-nightly20150625dcbb9e1da6' , ref: 'dcbb9e1da6' } + , { dir: 'v2.3.1-next-nightly201506308f6f4280c6' , ref: '8f6f4280c6' } + , { dir: 'v3.0.0-rc.1' , ref: 'v3.0.0-rc.1' } + , { dir: 'v33.22.1-rc.111' , ref: 'v33.22.1-rc.111' } + ] + + tests.forEach(function (test) { + console.log(`testing ${test.dir} -> ${test.ref}`) + assert.equal(decodeRef(test.dir), test.ref) + }) +} diff --git a/tools/dist/dist-indexer/dist-indexer.js b/tools/dist/dist-indexer/dist-indexer.js index a7b8f5823..f8ab8e92f 100755 --- a/tools/dist/dist-indexer/dist-indexer.js +++ b/tools/dist/dist-indexer/dist-indexer.js @@ -11,13 +11,12 @@ const fs = require('fs') , bl = require('bl') , transformFilename = require('./transform-filename') + , decodeRef = require('./decode-ref') , versionCachePath = path.join(process.env.HOME, '.dist-indexer-version-cache') - , dirre = /^(v\d\.\d\.\d)(?:-(?:next-)?nightly\d{8}(\w+))?$/ // get version or commit from dir name - // needs auth: githubContentUrl = 'https://api.github.com/repos/nodejs/io.js/contents' - , githubContentUrl = 'https://raw.githubusercontent.com/nodejs/io.js/{commit}' + , githubContentUrl = 'https://raw.githubusercontent.com/nodejs/io.js/{gitref}' , npmPkgJsonUrl = `${githubContentUrl}/deps/npm/package.json` , v8VersionUrl = [ `${githubContentUrl}/deps/v8/src/version.cc` @@ -57,25 +56,19 @@ function saveVersionCache () { } -function cacheGet (commit, prop) { - return versionCache[commit] && versionCache[commit][prop] +function cacheGet (gitref, prop) { + return versionCache[gitref] && versionCache[gitref][prop] } -function cachePut (commit, prop, value) { +function cachePut (gitref, prop, value) { if (prop && value) - (versionCache[commit] || (versionCache[commit] = {}))[prop] = value -} - - -function commitFromDir (dir) { - var m = dir.match(dirre) - return m && (m[2] || m[1]) + (versionCache[gitref] || (versionCache[gitref] = {}))[prop] = value } -function fetch (url, commit, callback) { - url = url.replace('{commit}', commit) + `?rev=${commit}` +function fetch (url, gitref, callback) { + url = url.replace('{gitref}', gitref) + `?rev=${gitref}` hyperquest.get(url, githubOptions).pipe(bl(function (err, data) { if (err) return callback(err) @@ -85,12 +78,12 @@ function fetch (url, commit, callback) { } -function fetchNpmVersion (commit, callback) { - var version = cacheGet(commit, 'npm') +function fetchNpmVersion (gitref, callback) { + var version = cacheGet(gitref, 'npm') if (version) return setImmediate(callback.bind(null, null, version)) - fetch(npmPkgJsonUrl, commit, function (err, rawData) { + fetch(npmPkgJsonUrl, gitref, function (err, rawData) { if (err) return callback(err) @@ -102,18 +95,18 @@ function fetchNpmVersion (commit, callback) { return callback(e) } - cachePut(commit, 'npm', data.version) + cachePut(gitref, 'npm', data.version) return callback(null, data.version) }) } -function fetchV8Version (commit, callback) { - var version = cacheGet(commit, 'v8') +function fetchV8Version (gitref, callback) { + var version = cacheGet(gitref, 'v8') if (version) return setImmediate(callback.bind(null, null, version)) - fetch(v8VersionUrl[0], commit, function (err, rawData) { + fetch(v8VersionUrl[0], gitref, function (err, rawData) { if (err) return callback(err) @@ -125,11 +118,11 @@ function fetchV8Version (commit, callback) { .join('.') if (version) { - cachePut(commit, 'v8', version) + cachePut(gitref, 'v8', version) return callback(null, version) } - fetch(v8VersionUrl[1], commit, function (err, rawData) { + fetch(v8VersionUrl[1], gitref, function (err, rawData) { if (err) return callback(err) @@ -140,19 +133,19 @@ function fetchV8Version (commit, callback) { .map(function (m) { return m[1] }) .join('.') - cachePut(commit, 'v8', version) + cachePut(gitref, 'v8', version) callback(null, version) }) }) } -function fetchUvVersion (commit, callback) { - var version = cacheGet(commit, 'uv') +function fetchUvVersion (gitref, callback) { + var version = cacheGet(gitref, 'uv') if (version) return setImmediate(callback.bind(null, null, version)) - fetch(uvVersionUrl, commit, function (err, rawData) { + fetch(uvVersionUrl, gitref, function (err, rawData) { if (err) return callback(err) @@ -163,60 +156,60 @@ function fetchUvVersion (commit, callback) { .map(function (m) { return m[1] }) .join('.') - cachePut(commit, 'uv', version) + cachePut(gitref, 'uv', version) callback(null, version) }) } -function fetchSslVersion (commit, callback) { - var version = cacheGet(commit, 'ssl') +function fetchSslVersion (gitref, callback) { + var version = cacheGet(gitref, 'ssl') if (version) return setImmediate(callback.bind(null, null, version)) - fetch(sslVersionUrl, commit, function (err, rawData) { + fetch(sslVersionUrl, gitref, function (err, rawData) { if (err) return callback(err) var m = rawData.match(/^VERSION=(.+)$/m) version = m && m[1] - cachePut(commit, 'ssl', version) + cachePut(gitref, 'ssl', version) callback(null, version) }) } -function fetchZlibVersion (commit, callback) { - var version = cacheGet(commit, 'zlib') +function fetchZlibVersion (gitref, callback) { + var version = cacheGet(gitref, 'zlib') if (version) return setImmediate(callback.bind(null, null, version)) - fetch(zlibVersionUrl, commit, function (err, rawData) { + fetch(zlibVersionUrl, gitref, function (err, rawData) { if (err) return callback(err) var m = rawData.match(/^#define ZLIB_VERSION\s+"(.+)"$/m) version = m && m[1] - cachePut(commit, 'zlib', version) + cachePut(gitref, 'zlib', version) callback(null, version) }) } -function fetchModVersion (commit, callback) { - var version = cacheGet(commit, 'mod') +function fetchModVersion (gitref, callback) { + var version = cacheGet(gitref, 'mod') if (version) return setImmediate(callback.bind(null, null, version)) - fetch(modVersionUrl, commit, function (err, rawData) { + fetch(modVersionUrl, gitref, function (err, rawData) { if (err) return callback(err) var m = rawData.match(/^#define NODE_MODULE_VERSION\s+([^\s]+)\s+.+$/m) version = m && m[1] - cachePut(commit, 'mod', version) + cachePut(gitref, 'mod', version) callback(null, version) }) @@ -265,7 +258,7 @@ function dirFiles (dir, callback) { function inspectDir (dir, callback) { - var commit = commitFromDir(dir) + var gitref = decodeRef(dir) , files , npmVersion , v8Version @@ -275,7 +268,7 @@ function inspectDir (dir, callback) { , modVersion , date - if (!commit) { + if (!gitref) { console.error('Ignoring directory "%s"', dir) return callback() } @@ -298,55 +291,55 @@ function inspectDir (dir, callback) { done() }) - fetchNpmVersion(commit, function (err, version) { + fetchNpmVersion(gitref, function (err, version) { if (err) { console.error(err) - console.error('(ignoring error fetching npm version for %s)', commit) + console.error('(ignoring error fetching npm version for %s)', gitref) } npmVersion = version done() }) - fetchV8Version(commit, function (err, version) { + fetchV8Version(gitref, function (err, version) { if (err) { console.error(err) - console.error('(ignoring error fetching V8 version for %s)', commit) + console.error('(ignoring error fetching V8 version for %s)', gitref) } v8Version = version done() }) - fetchUvVersion(commit, function (err, version) { + fetchUvVersion(gitref, function (err, version) { if (err) { console.error(err) - console.error('(ignoring error fetching uv version for %s)', commit) + console.error('(ignoring error fetching uv version for %s)', gitref) } uvVersion = version done() }) - fetchSslVersion(commit, function (err, version) { + fetchSslVersion(gitref, function (err, version) { if (err) { console.error(err) - console.error('(ignoring error fetching OpenSSL version for %s)', commit) + console.error('(ignoring error fetching OpenSSL version for %s)', gitref) } sslVersion = version done() }) - fetchZlibVersion(commit, function (err, version) { + fetchZlibVersion(gitref, function (err, version) { if (err) { console.error(err) - console.error('(ignoring error fetching zlib version for %s)', commit) + console.error('(ignoring error fetching zlib version for %s)', gitref) } zlibVersion = version done() }) - fetchModVersion(commit, function (err, version) { + fetchModVersion(gitref, function (err, version) { if (err) { console.error(err) - console.error('(ignoring error fetching modules version for %s)', commit) + console.error('(ignoring error fetching modules version for %s)', gitref) } modVersion = version done() diff --git a/tools/dist/dist-indexer/transform-filename.js b/tools/dist/dist-indexer/transform-filename.js index 8846d5456..67709e696 100644 --- a/tools/dist/dist-indexer/transform-filename.js +++ b/tools/dist/dist-indexer/transform-filename.js @@ -1,4 +1,5 @@ -const types = { +const assert = require('assert') + , types = { 'tar.gz' : 'src' , 'darwin-x64' : 'osx-x64-tar' , 'pkg' : 'osx-x64-pkg' @@ -11,12 +12,12 @@ const types = { , 'x86.msi' : 'win-x86-msi' , 'win-x64/iojs.exe' : 'win-x64-exe' , 'win-x86/iojs.exe' : 'win-x86-exe' - , 'headers' : 'heaaders' + , 'headers' : 'headers' } function transformFilename (file) { - file = file && file.replace(/^iojs-v\d\.\d\.\d-?((next-)?nightly\d{8}[^-\.]+-?)?\.?/, '') + file = file && file.replace(/^iojs-v\d\.\d\.\d-?((rc\.\d+|(next-)?nightly\d{8}[^-\.]+)-?)?\.?/, '') .replace(/\.tar\.gz$/, '') return types[file] @@ -24,3 +25,86 @@ function transformFilename (file) { module.exports = transformFilename + + +if (module === require.main) { + var tests = [ + { file: 'doc' } + , { file: 'iojs-v3.0.0-darwin-x64.tar.gz', type: 'osx-x64-tar' } + , { file: 'iojs-v3.0.0-darwin-x64.tar.xz' } + , { file: 'iojs-v3.0.0-headers.tar.gz', type: 'headers' } + , { file: 'iojs-v3.0.0-headers.tar.xz' } + , { file: 'iojs-v3.0.0-linux-armv7l.tar.gz', type: 'linux-armv7l' } + , { file: 'iojs-v3.0.0-linux-armv7l.tar.xz' } + , { file: 'iojs-v3.0.0-linux-armv6l.tar.gz', type: 'linux-armv6l' } + , { file: 'iojs-v3.0.0-linux-armv6l.tar.xz' } + , { file: 'iojs-v3.0.0-linux-x64.tar.gz', type: 'linux-x64' } + , { file: 'iojs-v3.0.0-linux-x64.tar.xz' } + , { file: 'iojs-v3.0.0-linux-x86.tar.gz', type: 'linux-x86' } + , { file: 'iojs-v3.0.0-linux-x86.tar.xz' } + , { file: 'iojs-v3.0.0.pkg', type: 'osx-x64-pkg' } + , { file: 'iojs-v3.0.0.tar.gz', type: 'src' } + , { file: 'iojs-v3.0.0.tar.xz' } + , { file: 'iojs-v3.0.0-x64.msi', type: 'win-x64-msi' } + , { file: 'iojs-v3.0.0-x86.msi', type: 'win-x86-msi' } + , { file: 'iojs-v3.0.0-nightly20150625dcbb9e1da6-darwin-x64.tar.gz', type: 'osx-x64-tar' } + , { file: 'iojs-v3.0.0-nightly20150625dcbb9e1da6-darwin-x64.tar.xz' } + , { file: 'iojs-v3.0.0-nightly20150625dcbb9e1da6-headers.tar.gz', type: 'headers' } + , { file: 'iojs-v3.0.0-nightly20150625dcbb9e1da6-headers.tar.xz' } + , { file: 'iojs-v3.0.0-nightly20150625dcbb9e1da6-linux-armv7l.tar.gz', type: 'linux-armv7l' } + , { file: 'iojs-v3.0.0-nightly20150625dcbb9e1da6-linux-armv7l.tar.xz' } + , { file: 'iojs-v3.0.0-nightly20150625dcbb9e1da6-linux-armv6l.tar.gz', type: 'linux-armv6l' } + , { file: 'iojs-v3.0.0-nightly20150625dcbb9e1da6-linux-armv6l.tar.xz' } + , { file: 'iojs-v3.0.0-nightly20150625dcbb9e1da6-linux-x64.tar.gz', type: 'linux-x64' } + , { file: 'iojs-v3.0.0-nightly20150625dcbb9e1da6-linux-x64.tar.xz' } + , { file: 'iojs-v3.0.0-nightly20150625dcbb9e1da6-linux-x86.tar.gz', type: 'linux-x86' } + , { file: 'iojs-v3.0.0-nightly20150625dcbb9e1da6-linux-x86.tar.xz' } + , { file: 'iojs-v3.0.0-nightly20150625dcbb9e1da6.pkg', type: 'osx-x64-pkg' } + , { file: 'iojs-v3.0.0-nightly20150625dcbb9e1da6.tar.gz', type: 'src' } + , { file: 'iojs-v3.0.0-nightly20150625dcbb9e1da6.tar.xz' } + , { file: 'iojs-v3.0.0-nightly20150625dcbb9e1da6-x64.msi', type: 'win-x64-msi' } + , { file: 'iojs-v3.0.0-nightly20150625dcbb9e1da6-x86.msi', type: 'win-x86-msi' } + , { file: 'iojs-v3.0.0-next-nightly20150625dcbb9e1da6-darwin-x64.tar.gz', type: 'osx-x64-tar' } + , { file: 'iojs-v3.0.0-next-nightly20150625dcbb9e1da6-darwin-x64.tar.xz' } + , { file: 'iojs-v3.0.0-next-nightly20150625dcbb9e1da6-headers.tar.gz', type: 'headers' } + , { file: 'iojs-v3.0.0-next-nightly20150625dcbb9e1da6-headers.tar.xz' } + , { file: 'iojs-v3.0.0-next-nightly20150625dcbb9e1da6-linux-armv7l.tar.gz', type: 'linux-armv7l' } + , { file: 'iojs-v3.0.0-next-nightly20150625dcbb9e1da6-linux-armv7l.tar.xz' } + , { file: 'iojs-v3.0.0-next-nightly20150625dcbb9e1da6-linux-armv6l.tar.gz', type: 'linux-armv6l' } + , { file: 'iojs-v3.0.0-next-nightly20150625dcbb9e1da6-linux-armv6l.tar.xz' } + , { file: 'iojs-v3.0.0-next-nightly20150625dcbb9e1da6-linux-x64.tar.gz', type: 'linux-x64' } + , { file: 'iojs-v3.0.0-next-nightly20150625dcbb9e1da6-linux-x64.tar.xz' } + , { file: 'iojs-v3.0.0-next-nightly20150625dcbb9e1da6-linux-x86.tar.gz', type: 'linux-x86' } + , { file: 'iojs-v3.0.0-next-nightly20150625dcbb9e1da6-linux-x86.tar.xz' } + , { file: 'iojs-v3.0.0-next-nightly20150625dcbb9e1da6.pkg', type: 'osx-x64-pkg' } + , { file: 'iojs-v3.0.0-next-nightly20150625dcbb9e1da6.tar.gz', type: 'src' } + , { file: 'iojs-v3.0.0-next-nightly20150625dcbb9e1da6.tar.xz' } + , { file: 'iojs-v3.0.0-next-nightly20150625dcbb9e1da6-x64.msi', type: 'win-x64-msi' } + , { file: 'iojs-v3.0.0-next-nightly20150625dcbb9e1da6-x86.msi', type: 'win-x86-msi' } + , { file: 'iojs-v3.0.0-rc.1-darwin-x64.tar.gz', type: 'osx-x64-tar' } + , { file: 'iojs-v3.0.0-rc.1-darwin-x64.tar.xz' } + , { file: 'iojs-v3.0.0-rc.1-headers.tar.gz', type: 'headers' } + , { file: 'iojs-v3.0.0-rc.1-headers.tar.xz' } + , { file: 'iojs-v3.0.0-rc.1-linux-armv7l.tar.gz', type: 'linux-armv7l' } + , { file: 'iojs-v3.0.0-rc.1-linux-armv7l.tar.xz' } + , { file: 'iojs-v3.0.0-rc.1-linux-armv6l.tar.gz', type: 'linux-armv6l' } + , { file: 'iojs-v3.0.0-rc.1-linux-armv6l.tar.xz' } + , { file: 'iojs-v3.0.0-rc.1-linux-x64.tar.gz', type: 'linux-x64' } + , { file: 'iojs-v3.0.0-rc.1-linux-x64.tar.xz' } + , { file: 'iojs-v3.0.0-rc.1-linux-x86.tar.gz', type: 'linux-x86' } + , { file: 'iojs-v3.0.0-rc.1-linux-x86.tar.xz' } + , { file: 'iojs-v3.0.0-rc.1.pkg', type: 'osx-x64-pkg' } + , { file: 'iojs-v3.0.0-rc.1.tar.gz', type: 'src' } + , { file: 'iojs-v3.0.0-rc.1.tar.xz' } + , { file: 'iojs-v3.0.0-rc.1-x64.msi', type: 'win-x64-msi' } + , { file: 'iojs-v3.0.0-rc.1-x86.msi', type: 'win-x86-msi' } + , { file: 'SHASUMS256.txt' } + , { file: 'win-x64/iojs.exe', type: 'win-x64-exe' } + , { file: 'win-x86/iojs.exe', type: 'win-x86-exe' } + ] + + tests.forEach(function (test) { + console.log(`testing ${test.file} -> ${test.type}`) + assert.equal(transformFilename(test.file), test.type) + }) +}