Skip to content
This repository has been archived by the owner on Sep 5, 2020. It is now read-only.

Add gulp task 'update-nodes' #1637

Merged
merged 1 commit into from
Feb 2, 2017
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
77 changes: 77 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ const fs = require('fs');
const got = require('got');
const Q = require('bluebird');
const githubUpload = Q.promisify(require('gh-release-assets'));
const cmp = require('semver-compare');
const parseJson = require('xml2js').parseString;

const options = minimist(process.argv.slice(2), {
string: ['platform', 'walletSource'],
Expand Down Expand Up @@ -413,6 +415,81 @@ gulp.task('get-release-checksums', (done) => {
return done();
});

gulp.task('update-nodes', (cb) => {
const clientBinaries = require('./clientBinaries.json'); // eslint-disable-line global-require
const clientBinariesGeth = clientBinaries.clients.Geth;
const localGethVersion = clientBinariesGeth.version;
const newJson = clientBinaries;
const geth = newJson.clients.Geth;

// Query latest geth version
got('https://api.github.com/repos/ethereum/go-ethereum/releases/latest', { json: true })
.then((response) => {
return response.body.tag_name;
})
// Return tag name (e.g. 'v1.5.0')
.then((tagName) => {
const latestGethVersion = tagName.match(/\d+\.\d+\.\d+/)[0];

// Compare to current geth version in clientBinaries.json
if (cmp(latestGethVersion, localGethVersion)) {
geth.version = latestGethVersion;

// Query commit hash (first 8 characters)
got(`https://api.github.com/repos/ethereum/go-ethereum/commits/${tagName}`, { json: true })
.then((response) => {
return String(response.body.sha).substr(0, 8);
})
.then((hash) => {
let blobs; // geth blobs

// Query Azure assets for md5 hashes
got('https://gethstore.blob.core.windows.net/builds?restype=container&comp=list', {
xml: true,
})
.then((response) => {
parseJson(response.body, (err, data) => {
blobs = data.EnumerationResults.Blobs[0].Blob;
});

// For each platform/arch in clientBinaries.json
_.keys(geth.platforms).forEach((platform) => {
_.keys(geth.platforms[platform]).forEach((arch) => {
// Update URL
let url = geth.platforms[platform][arch].download.url;
url = url.replace(/\d+\.\d+\.\d+-[a-z0-9]{8}/, `${latestGethVersion}-${hash}`);
geth.platforms[platform][arch].download.url = url;

// Update bin name (path in archive)
let bin = geth.platforms[platform][arch].download.bin;
bin = bin.replace(/\d+\.\d+\.\d+-[a-z0-9]{8}/, `${latestGethVersion}-${hash}`);
geth.platforms[platform][arch].download.bin = bin;

// Update expected sanity-command version output
geth.platforms[platform][arch].commands.sanity.output[1] =
String(latestGethVersion);

// Update md5 checksum
blobs.forEach((blob) => {
if (String(blob.Name) === _.last(geth.platforms[platform][arch].download.url.split('/'))) {
const sum = new Buffer(blob.Properties[0]['Content-MD5'][0], 'base64');

geth.platforms[platform][arch].download.md5 = sum.toString('hex');
}
});
});
});
})
// Update clientBinares.json
.then(() => {
fs.writeFile('./clientBinaries.json', JSON.stringify(newJson, null, 4));
cb();
});
});
} else cb(); // Already up-to-date
})
.catch(cb);
});

gulp.task('download-signatures', (cb) => {
got('https://www.4byte.directory/api/v1/signatures/?page_size=20000&ordering=created_at', {
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@
"mocha": "^3.2.0",
"optimist": "^0.6.1",
"run-sequence": "^1.2.1",
"semver-compare": "^1.0.0",
"shelljs": "^0.7.6",
"spectron": "3.3.0"
"spectron": "3.3.0",
"xml2js": "^0.4.17"
}
}
21 changes: 21 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3508,6 +3508,10 @@ sanitize-filename@^1.6.1:
dependencies:
truncate-utf8-bytes "^1.0.0"

sax@>=0.6.0:
version "1.2.1"
resolved "https://registry.yarnpkg.com/sax/-/sax-1.2.1.tgz#7b8e656190b228e81a66aea748480d828cd2d37a"

secp256k1@^3.0.1:
version "3.2.2"
resolved "https://registry.yarnpkg.com/secp256k1/-/secp256k1-3.2.2.tgz#2103620789ca2c9b79650cdf8cfc9c542be36597"
Expand All @@ -3526,6 +3530,10 @@ seek-bzip@^1.0.3:
dependencies:
commander "~2.8.1"

semver-compare@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/semver-compare/-/semver-compare-1.0.0.tgz#0dee216a1c941ab37e9efb1788f6afc5ff5537fc"

semver-diff@^2.0.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/semver-diff/-/semver-diff-2.1.0.tgz#4bbb8437c8d37e4b0cf1a68fd726ec6d645d6d36"
Expand Down Expand Up @@ -4327,10 +4335,23 @@ xdg-basedir@^2.0.0:
dependencies:
os-homedir "^1.0.0"

xml2js@^0.4.17:
version "0.4.17"
resolved "https://registry.yarnpkg.com/xml2js/-/xml2js-0.4.17.tgz#17be93eaae3f3b779359c795b419705a8817e868"
dependencies:
sax ">=0.6.0"
xmlbuilder "^4.1.0"

xmlbuilder@8.2.2:
version "8.2.2"
resolved "https://registry.yarnpkg.com/xmlbuilder/-/xmlbuilder-8.2.2.tgz#69248673410b4ba42e1a6136551d2922335aa773"

xmlbuilder@^4.1.0:
version "4.2.1"
resolved "https://registry.yarnpkg.com/xmlbuilder/-/xmlbuilder-4.2.1.tgz#aa58a3041a066f90eaa16c2f5389ff19f3f461a5"
dependencies:
lodash "^4.0.0"

xmldom@0.1.x:
version "0.1.27"
resolved "https://registry.yarnpkg.com/xmldom/-/xmldom-0.1.27.tgz#d501f97b3bdb403af8ef9ecc20573187aadac0e9"
Expand Down