From 17e95f836fa17dbb9801f190330a6dcaa6a6a3dc Mon Sep 17 00:00:00 2001 From: Spencer Alger Date: Tue, 29 Apr 2014 19:17:29 -0700 Subject: [PATCH] moved away from multiple repos, to a single bare repo which we pull the resp-spec out of. --- .gitignore | 2 +- scripts/_spawn.js | 6 +++- scripts/generate/index.js | 68 ++++++++++++++++++++++++--------------- 3 files changed, 48 insertions(+), 28 deletions(-) diff --git a/.gitignore b/.gitignore index eaba4f82a..a58124675 100644 --- a/.gitignore +++ b/.gitignore @@ -9,7 +9,7 @@ test/integration/yaml_suite/log ## generated files test/integration/yaml_suite/yaml_tests*.json test/integration/yaml_suite/index*.js -src/elasticsearch*/ +src/_elasticsearch* src/bower*/ junit-*.xml elasticsearch*.log diff --git a/scripts/_spawn.js b/scripts/_spawn.js index 6f7d3c1e0..c0ffa7b0b 100644 --- a/scripts/_spawn.js +++ b/scripts/_spawn.js @@ -42,4 +42,8 @@ function _spawn(cmd, args, opts, cb) { } return cp; -} \ No newline at end of file +} + +_spawn.exec = function (cmd, cb) { + return _spawn('/bin/sh', ['-c', cmd], cb); +}; \ No newline at end of file diff --git a/scripts/generate/index.js b/scripts/generate/index.js index 9558897c1..501db1de3 100644 --- a/scripts/generate/index.js +++ b/scripts/generate/index.js @@ -1,3 +1,4 @@ +/*jshint curly: false */ var async = require('async'); var fs = require('fs'); var spawn = require('../_spawn'); @@ -48,6 +49,10 @@ if (argv.branch) { branches = utils.branches; } +var sourceDir = fromRoot('src/_elasticsearch_'); +function storeDir(branch) { + return fromRoot('src/_elasticsearch_' + _.snakeCase(branch)); +} function isDirectory(dir) { var stat; @@ -55,47 +60,55 @@ function isDirectory(dir) { return (stat && stat.isDirectory()); } -function storeDir(branch) { - return fromRoot('src/elasticsearch_' + _.snakeCase(branch)); -} - function spawnStep(cmd, args, cwd) { return function (done) { spawn(cmd, args, { - verbose: argv.versbose, + verbose: argv.verbose, cwd: cwd }, function (status) { - done(status ? new Error('Non-zero exit code: %d', status) : void 0); + done(status ? new Error('Non-zero exit code: ' + status) : void 0); }); }; } -function checkoutStep(branch) { +function execStep(cmd, cwd) { return function (done) { - var dir = storeDir(branch); - - if (isDirectory(dir)) { - return done(); - } - - spawnStep('git', [ - 'clone', '--depth', '50', '--branch', branch, '--', esUrl, dir - ], root)(done); + spawn.exec(cmd, { + verbose: argv.verbose, + cwd: cwd + }, function (status) { + done(status ? new Error('Non-zero exit code: ' + status) : void 0); + }); }; } -function updateStep(branch) { +function cloneStep() { return function (done) { - if (!argv.update) { - return done(); - } + if (isDirectory(sourceDir)) return done(); + spawnStep('git', ['clone', '--depth', '1', '--mirror', esUrl, sourceDir], root)(done); + }; +} +function fetchBranchStep(branch) { + return spawnStep('git', ['fetch', '--depth', '1', 'origin', branch], sourceDir); +} + +function removePrevArchive(branch) { + return function (done) { var dir = storeDir(branch); + if (!isDirectory(dir)) return done(); + else spawnStep('rm', ['-rf', dir], root)(done); + }; +} + +function createArchive(branch) { + return function (done) { + var dir = storeDir(branch); + if (isDirectory(dir)) return done(); async.series([ - spawnStep('git', ['fetch', 'origin', branch], dir), - spawnStep('git', ['reset', '--hard', 'origin/' + branch], dir), - spawnStep('git', ['clean', '-fdx'], dir) + spawnStep('mkdir', [dir], root), + execStep('git archive --format tar ' + branch + ' rest-api-spec | tar -x -C ' + dir, sourceDir) ], done); }; } @@ -109,11 +122,14 @@ function generateStep(branch) { }; } -var steps = []; +var steps = [ + cloneStep() +]; branches.forEach(function (branch) { + if (argv.update) steps.push(removePrevArchive(branch)); steps.push( - checkoutStep(branch), - updateStep(branch), + fetchBranchStep(branch), + createArchive(branch), generateStep(branch) ); });