cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alsoro...@apache.org
Subject [2/3] cordova-medic git commit: Add medic command to download BuildBot CI logs
Date Wed, 20 Apr 2016 16:12:51 GMT
Add medic command to download BuildBot CI logs


Project: http://git-wip-us.apache.org/repos/asf/cordova-medic/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-medic/commit/cfe4e828
Tree: http://git-wip-us.apache.org/repos/asf/cordova-medic/tree/cfe4e828
Diff: http://git-wip-us.apache.org/repos/asf/cordova-medic/diff/cfe4e828

Branch: refs/heads/master
Commit: cfe4e828fb392709ee97f4da1df46264e6d0faa7
Parents: 4cbdf65
Author: Nikhil Khandelwal <nikhilkh@microsoft.com>
Authored: Tue Apr 12 16:45:39 2016 -0700
Committer: Nikhil Khandelwal <nikhilkh@microsoft.com>
Committed: Tue Apr 19 10:46:06 2016 -0700

----------------------------------------------------------------------
 medic/medic-downloadlogs.js | 83 ++++++++++++++++++++++++++++++++++++++++
 medic/medic.js              |  1 +
 package.json                |  3 +-
 3 files changed, 86 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-medic/blob/cfe4e828/medic/medic-downloadlogs.js
----------------------------------------------------------------------
diff --git a/medic/medic-downloadlogs.js b/medic/medic-downloadlogs.js
new file mode 100644
index 0000000..2e58c40
--- /dev/null
+++ b/medic/medic-downloadlogs.js
@@ -0,0 +1,83 @@
+var path = require('path'),
+    fs = require('fs'),
+    https = require('https'),
+    optimist = require('optimist'),
+    q = require('Q'),
+    mkdirp = require('mkdirp'),
+    util = require('util');
+
+var SERVER = "https://ci.apache.org";
+var BUILDERS = ["cordova-windows-store8.1", "cordova-ios", "cordova-windows-phone8.1", "cordova-android-osx","cordova-android-win"];
+var STEPS = ["running-tests", "gathering-logs", "getting-test-results"];
+
+function downloadLogs(outputDir) {
+    var counter = 0;
+    var builderPromises = BUILDERS.map(function(builder) {
+        var buildInfoFile = path.join(outputDir, builder + ".json");
+       
+        //Donwload JSON data on all builds - https://ci.apache.org/json/builders/cordova-ios/builds/_all
+        var buildInfoUrl = util.format("%s/json/builders/%s/builds/_all", SERVER, builder);
+        return download(buildInfoUrl, buildInfoFile).then(function() {
+            var buildInfo = JSON.parse(fs.readFileSync(buildInfoFile));
+            var promises = [];
+            for(var buildNumber in buildInfo) {
+                // find all the build steps that have logs 
+                var steps = buildInfo[buildNumber].steps.filter(function (step) {
+                        return STEPS.indexOf(step.name) !== -1 && step.logs &&
step.logs.length > 0;
+                    });
+                steps.forEach(function (step) {
+                    var filename = util.format("%s_%s_%s_stdio.log", builder, buildNumber,
step.name);
+                    if(step.logs[0].length !== 2) {
+                        throw new Error("Unexpected build info schema");
+                    }
+                    counter++;
+                    var downloadPromise = download(step.logs[0][1] + "/text", path.join(outputDir,
filename));
+                    promises.push(downloadPromise);
+                });
+            }
+            return q.all(promises);
+        });
+    });
+    
+    q.all(builderPromises).done(function() {
+        console.log("Downloaded " + counter + " logs to " + outputDir);
+    }, function(error) {
+        console.log("Error: " + error);
+    });
+}
+
+function download(url, filename){
+    var defer = q.defer();
+    
+    https.get(url, function(res) {
+        res.setEncoding('utf-8');
+        if (res.statusCode == 200) {
+            var file = fs.createWriteStream(filename);
+            res.pipe(file);
+            file.on('finish', function() {
+               console.log(url + " -> " + filename);
+               file.end();
+               defer.resolve(); 
+            });
+        } else {
+            defer.reject(url + " Status code: " + res.statusCode);
+        }
+    }).on('error', function(error) {
+        defer.reject(url + " Error: " + error);
+    });
+    
+    return defer.promise;   
+}
+
+// main
+function main() {
+    // get args
+    var argv = optimist
+        .usage("Usage: $0 --outpdir {path}")
+        .default("outputDir", ".")
+        .argv;
+        
+    mkdirp.sync(argv.outputDir);
+    downloadLogs(argv.outputDir);
+}
+main();

http://git-wip-us.apache.org/repos/asf/cordova-medic/blob/cfe4e828/medic/medic.js
----------------------------------------------------------------------
diff --git a/medic/medic.js b/medic/medic.js
index 206c856..2566ead 100755
--- a/medic/medic.js
+++ b/medic/medic.js
@@ -37,6 +37,7 @@ function main() {
         .command("check",    "analyze test runs from a medic DB")
         .command("log",      "output platform-specific logs to console")
         .command("appium",   "run Appium tests")
+        .command("downloadLogs", "download logs from the CI server")
         .parse(process.argv);
 }
 

http://git-wip-us.apache.org/repos/asf/cordova-medic/blob/cfe4e828/package.json
----------------------------------------------------------------------
diff --git a/package.json b/package.json
index ff03c55..594a176 100644
--- a/package.json
+++ b/package.json
@@ -19,7 +19,8 @@
     "shelljs": "^0.4.0",
     "tree-kill": "^1.0.0",
     "unorm": "^1.4.1",
-    "wd": "^0.3.11"
+    "wd": "^0.3.11",
+    "mkdirp": "^0.5.1"
   },
   "subdomain": "cordova.medic",
   "engines": {


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org


Mime
View raw message