cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agri...@apache.org
Subject [2/2] git commit: Move create-archive and verify-archive into their own modules
Date Thu, 24 Apr 2014 15:31:11 GMT
Move create-archive and verify-archive into their own modules


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

Branch: refs/heads/master
Commit: c41020ff49599a4d21a10fe9d248d841188847b3
Parents: 4bb3f9e
Author: Andrew Grieve <agrieve@chromium.org>
Authored: Thu Apr 24 11:30:50 2014 -0400
Committer: Andrew Grieve <agrieve@chromium.org>
Committed: Thu Apr 24 11:30:50 2014 -0400

----------------------------------------------------------------------
 src/create-verify-archive.js | 134 ++++++++++++++++++++++++++++++++++++++
 src/gitutil.js               |  26 ++++++++
 src/main.js                  | 115 ++------------------------------
 3 files changed, 164 insertions(+), 111 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-coho/blob/c41020ff/src/create-verify-archive.js
----------------------------------------------------------------------
diff --git a/src/create-verify-archive.js b/src/create-verify-archive.js
new file mode 100644
index 0000000..e8fd5f1
--- /dev/null
+++ b/src/create-verify-archive.js
@@ -0,0 +1,134 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+*/
+
+var optimist = require('optimist');
+var shelljs = require('shelljs');
+var fs = require('fs');
+var path = require('path');
+var apputil = require('./apputil');
+var executil = require('./executil');
+var flagutil = require('./flagutil');
+var gitutil = require('./gitutil');
+var repoutil = require('./repoutil');
+var print = apputil.print;
+
+exports.createCommand = function*(argv) {
+    var opt = flagutil.registerRepoFlag(optimist)
+    opt = opt
+        .options('tag', {
+            desc: 'The pre-existing tag to archive (defaults to newest tag on branch)'
+         })
+        .options('sign', {
+            desc: 'Whether to create .asc, .md5, .sha files (defaults to true)',
+            type: 'boolean',
+            default: true
+         })
+        .options('dest', {
+            desc: 'The directory to hold the resulting files.',
+            demand: true
+         });
+    opt = flagutil.registerHelpFlag(opt);
+    var argv = opt
+        .usage('Creates a .zip, .asc, .md5, .sha for a repo at a tag.\n' +
+               'Refer to https://wiki.apache.org/cordova/SetUpGpg for how to set up gpg\n'
+
+               '\n' +
+               'Usage: $0 create-archive -r plugman -r cli --dest cordova-dist-dev/CB-1111')
+        .argv;
+
+    if (argv.h) {
+        optimist.showHelp();
+        process.exit(1);
+    }
+    var repos = flagutil.computeReposFromFlag(argv.r);
+
+    if (argv.sign && !shelljs.which('gpg')) {
+        apputil.fatal('gpg command not found on your PATH. Refer to https://wiki.apache.org/cordova/SetUpGpg');
+    }
+
+    var outDir = argv.dest;
+    shelljs.mkdir('-p', outDir);
+    var absOutDir = path.resolve(outDir);
+
+    yield repoutil.forEachRepo(repos, function*(repo) {
+        var tag = argv.tag || (yield gitutil.findMostRecentTag());
+        print('Creating archive of ' + repo.repoName + '@' + tag);
+
+        if(repo.id==='plugman'|| repo.id==='cli'){
+            var tgzname = yield executil.execHelper(executil.ARGS('npm pack'), true);
+            var outPath = path.join(absOutDir, 'cordova-' + tgzname);
+            shelljs.mv(tgzname, outPath);
+        }else{
+            var outPath = path.join(absOutDir, repo.repoName + '-' + tag + '.zip');
+            yield executil.execHelper(executil.ARGS('git archive --format zip --prefix '
+ repo.repoName + '/ -o ', outPath, tag));
+        }
+        if (argv.sign) {
+            yield executil.execHelper(executil.ARGS('gpg --armor --detach-sig --output',
outPath + '.asc', outPath));
+            fs.writeFileSync(outPath + '.md5', (yield computeHash(outPath, 'MD5')) + '\n');
+            fs.writeFileSync(outPath + '.sha', (yield computeHash(outPath, 'SHA512')) + '\n');
+        }
+    });
+    print();
+    print('Archives created.');
+    print('Verify them using: coho verify-archive ' + path.join(outDir, '*.zip') + ' ' +
path.join(outDir, '*.tgz'));
+}
+
+exports.verifyCommand = function*(argv) {
+    var opt = flagutil.registerRepoFlag(optimist)
+    opt = flagutil.registerHelpFlag(opt);
+    var argv = opt
+        .usage('Ensures the given .zip files match their neighbouring .asc, .md5, .sha files.\n'
+
+               'Refer to https://wiki.apache.org/cordova/SetUpGpg for how to set up gpg\n'
+
+               '\n' +
+               'Usage: $0 verify-archive a.zip b.zip c.zip')
+        .argv;
+
+    var zipPaths = argv._.slice(1);
+    if (argv.h || !zipPaths.length) {
+        optimist.showHelp();
+        process.exit(1);
+    }
+    if (!shelljs.which('gpg')) {
+        apputil.fatal('gpg command not found on your PATH. Refer to https://wiki.apache.org/cordova/SetUpGpg');
+    }
+
+    for (var i = 0; i < zipPaths.length; ++i) {
+        var zipPath = zipPaths[i];
+        yield executil.execHelper(executil.ARGS('gpg --verify', zipPath + '.asc', zipPath));
+        var md5 = yield computeHash(zipPath, 'MD5');
+        if (extractHashFromOutput(fs.readFileSync(zipPath + '.md5', 'utf8')) !== md5) {
+            apputil.fatal('MD5 does not match.');
+        }
+        var sha = yield computeHash(zipPath, 'SHA512');
+        if (extractHashFromOutput(fs.readFileSync(zipPath + '.sha', 'utf8')) !== sha) {
+            apputil.fatal('SHA512 does not match.');
+        }
+        print(zipPath + ' signature and hashes verified.');
+    }
+}
+
+function *computeHash(path, algo) {
+    print('Computing ' + algo + ' for: ' + path);
+    var result = yield executil.execHelper(executil.ARGS('gpg --print-md', algo, path), true);
+    return extractHashFromOutput(result);
+}
+
+function extractHashFromOutput(output) {
+    return output.replace(/.*?:/, '').replace(/\s*/g, '').toLowerCase();
+}
+

http://git-wip-us.apache.org/repos/asf/cordova-coho/blob/c41020ff/src/gitutil.js
----------------------------------------------------------------------
diff --git a/src/gitutil.js b/src/gitutil.js
new file mode 100644
index 0000000..9a528c7
--- /dev/null
+++ b/src/gitutil.js
@@ -0,0 +1,26 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+*/
+
+var path = require('path');
+var executil = require('./executil');
+
+exports.findMostRecentTag = function() {
+    return executil.execHelper(executil.ARGS('git describe --tags --abbrev=0 HEAD'), true);
+}
+

http://git-wip-us.apache.org/repos/asf/cordova-coho/blob/c41020ff/src/main.js
----------------------------------------------------------------------
diff --git a/src/main.js b/src/main.js
index d84ff93..714e68a 100644
--- a/src/main.js
+++ b/src/main.js
@@ -23,6 +23,7 @@ var path = require('path');
 var flagutil = require('./flagutil');
 var apputil = require('./apputil');
 var executil = require('./executil');
+var gitutil = require('./gitutil');
 var repoutil = require('./repoutil');
 var print = apputil.print;
 try {
@@ -73,110 +74,6 @@ function createRepoUrl(repo) {
     return 'https://git-wip-us.apache.org/repos/asf/' + repo.repoName + '.git';
 }
 
-function *createArchiveCommand(argv) {
-    var opt = flagutil.registerRepoFlag(optimist)
-    opt = opt
-        .options('tag', {
-            desc: 'The pre-existing tag to archive (defaults to newest tag on branch)'
-         })
-        .options('sign', {
-            desc: 'Whether to create .asc, .md5, .sha files (defaults to true)',
-            type: 'boolean',
-            default: true
-         })
-        .options('dest', {
-            desc: 'The directory to hold the resulting files.',
-            demand: true
-         });
-    opt = flagutil.registerHelpFlag(opt);
-    var argv = opt
-        .usage('Creates a .zip, .asc, .md5, .sha for a repo at a tag.\n' +
-               'Refer to https://wiki.apache.org/cordova/SetUpGpg for how to set up gpg\n'
+
-               '\n' +
-               'Usage: $0 create-archive -r plugman -r cli --dest cordova-dist-dev/CB-1111')
-        .argv;
-
-    if (argv.h) {
-        optimist.showHelp();
-        process.exit(1);
-    }
-    var repos = flagutil.computeReposFromFlag(argv.r);
-
-    if (argv.sign && !shjs.which('gpg')) {
-        apputil.fatal('gpg command not found on your PATH. Refer to https://wiki.apache.org/cordova/SetUpGpg');
-    }
-
-    var outDir = argv.dest;
-    shjs.mkdir('-p', outDir);
-    var absOutDir = path.resolve(outDir);
-
-    yield repoutil.forEachRepo(repos, function*(repo) {
-        var tag = argv.tag || (yield findMostRecentTag());
-        print('Creating archive of ' + repo.repoName + '@' + tag);
-
-        if(repo.id==='plugman'|| repo.id==='cli'){
-            var tgzname = yield executil.execHelper(executil.ARGS('npm pack'), true);
-            var outPath = path.join(absOutDir, 'cordova-' + tgzname);
-            shjs.mv(tgzname, outPath);
-        }else{
-            var outPath = path.join(absOutDir, repo.repoName + '-' + tag + '.zip');
-            yield executil.execHelper(executil.ARGS('git archive --format zip --prefix '
+ repo.repoName + '/ -o ', outPath, tag));
-        }
-        if (argv.sign) {
-            yield executil.execHelper(executil.ARGS('gpg --armor --detach-sig --output',
outPath + '.asc', outPath));
-            fs.writeFileSync(outPath + '.md5', (yield computeHash(outPath, 'MD5')) + '\n');
-            fs.writeFileSync(outPath + '.sha', (yield computeHash(outPath, 'SHA512')) + '\n');
-        }
-    });
-    print();
-    print('Archives created.');
-    print('Verify them using: coho verify-archive ' + path.join(outDir, '*.zip') + ' ' +
path.join(outDir, '*.tgz'));
-}
-
-function *computeHash(path, algo) {
-    print('Computing ' + algo + ' for: ' + path);
-    var result = yield executil.execHelper(executil.ARGS('gpg --print-md', algo, path), true);
-    return extractHashFromOutput(result);
-}
-
-function extractHashFromOutput(output) {
-    return output.replace(/.*?:/, '').replace(/\s*/g, '').toLowerCase();
-}
-
-function *verifyArchiveCommand(argv) {
-    var opt = flagutil.registerRepoFlag(optimist)
-    opt = flagutil.registerHelpFlag(opt);
-    var argv = opt
-        .usage('Ensures the given .zip files match their neighbouring .asc, .md5, .sha files.\n'
+
-               'Refer to https://wiki.apache.org/cordova/SetUpGpg for how to set up gpg\n'
+
-               '\n' +
-               'Usage: $0 verify-archive a.zip b.zip c.zip')
-        .argv;
-
-    var zipPaths = argv._.slice(1);
-    if (argv.h || !zipPaths.length) {
-        optimist.showHelp();
-        process.exit(1);
-    }
-    if (!shjs.which('gpg')) {
-        apputil.fatal('gpg command not found on your PATH. Refer to https://wiki.apache.org/cordova/SetUpGpg');
-    }
-
-    for (var i = 0; i < zipPaths.length; ++i) {
-        var zipPath = zipPaths[i];
-        yield executil.execHelper(executil.ARGS('gpg --verify', zipPath + '.asc', zipPath));
-        var md5 = yield computeHash(zipPath, 'MD5');
-        if (extractHashFromOutput(fs.readFileSync(zipPath + '.md5', 'utf8')) !== md5) {
-            apputil.fatal('MD5 does not match.');
-        }
-        var sha = yield computeHash(zipPath, 'SHA512');
-        if (extractHashFromOutput(fs.readFileSync(zipPath + '.sha', 'utf8')) !== sha) {
-            apputil.fatal('SHA512 does not match.');
-        }
-        print(zipPath + ' signature and hashes verified.');
-    }
-}
-
 function *printTagsCommand(argv) {
     var opt = flagutil.registerRepoFlag(optimist)
     opt = flagutil.registerHelpFlag(opt);
@@ -193,7 +90,7 @@ function *printTagsCommand(argv) {
     var repos = flagutil.computeReposFromFlag(argv.r);
 
     yield repoutil.forEachRepo(repos, function*(repo) {
-        var tag = yield findMostRecentTag();
+        var tag = yield gitutil.findMostRecentTag();
         var ref = yield executil.execHelper(executil.ARGS('git show-ref ' + tag), true);
         console.log('    ' + repo.repoName + ': ' + tag.replace(/^r/, '') + ' (' + ref.slice(0,
10) + ')');
     });
@@ -254,10 +151,6 @@ function *retrieveCurrentBranchName(allowDetached) {
     return match[1];
 }
 
-function findMostRecentTag() {
-    return executil.execHelper(executil.ARGS('git describe --tags --abbrev=0 HEAD'), true);
-}
-
 function retrieveCurrentTagName() {
     // This will return the tag name plus commit info it not directly at a tag.
     // That's fine since all users of this function are meant to use the result
@@ -910,11 +803,11 @@ function main() {
         }, {
             name: 'create-archive',
             desc: 'Zips up a tag, signs it, and adds checksum files.',
-            entryPoint: createArchiveCommand
+            entryPoint: require('./create-verify-archive').createCommand
         }, {
             name: 'verify-archive',
             desc: 'Checks that archives are properly signed and hashed.',
-            entryPoint: verifyArchiveCommand
+            entryPoint: require('./create-verify-archive').verifyCommand
         }, {
             name: 'print-tags',
             desc: 'Prints out tags & hashes for the given repos. Used in VOTE emails.',


Mime
View raw message