From a7ee51cace0a0032050e84e87ef4842fba96861c Mon Sep 17 00:00:00 2001 From: Maximiliano Korp Date: Thu, 4 Dec 2014 13:02:57 -0700 Subject: [PATCH 1/5] start prepublishing generation --- .npmignore | 22 +++++++- install.js | 136 ++++++++++++++++++++++++++++++-------------------- package.json | 17 ++++--- prepublish.js | 8 +++ 4 files changed, 120 insertions(+), 63 deletions(-) create mode 100644 prepublish.js diff --git a/.npmignore b/.npmignore index 5b5b9304e..db6d57ba3 100644 --- a/.npmignore +++ b/.npmignore @@ -1,4 +1,22 @@ -/doc/ +/build/ /example/ -/node_modules/ +/generate/ /test/ +/vendor/libgit2/ +/vendor/libssh2/ +/vendor/http_parser/ +/vendor/Release/ + +.astylerc +.editorconfig +.gitignore +.gitmodules +.jshintrc +.travis.yml +.appveyor.yml + +*.vcxproj +*.filters +*.sln +*.log +*.md diff --git a/install.js b/install.js index e86a2bbff..235e1268a 100644 --- a/install.js +++ b/install.js @@ -48,7 +48,7 @@ function systemPath(parts) { } // Will be used near the end to configure `node-gyp`. -var pythonPath = '/usr/bin/python'; +var pythonPath = ""; var local = path.join.bind(path, __dirname); @@ -58,12 +58,7 @@ var paths = envOverride({ libgit2: local("vendor/libgit2/"), libssh2: local("vendor/libssh2/"), http_parser: local("vendor/http_parser/"), - sys: { - include: local("include/sys/"), - src: local("src/sys/"), - build: local("build/Release/obj.target/src/sys/") - }, - release: local("build/Release/") + release: local("build/Release/"), }); // Load the package.json. @@ -76,8 +71,7 @@ if (NODE_VERSION === 0.1) { fse.ensureDir(path.resolve(__dirname, paths.release)) .then(detectNodeWebkit.call(null, __dirname)) .then(fetch) -.then(finish, compile) -.done() +.then(finish, compile); function fetch() { console.info("[nodegit] Fetching binary from S3."); @@ -104,83 +98,103 @@ function compile(err) { console.info("[nodegit] Determining dependencies."); - return python() - .then(getVendorLib("libgit2", "https://github.com/libgit2/libgit2/tarball/" + pkg.libgit2.sha)) - .then(getVendorLib("libssh2", pkg.libssh2.url)) - .then(getVendorLib("http_parser", pkg.http_parser.url)) - .then(buildNative) - .then(finish, fail); - + return Promise.all([ + python(), + getVendorLib("libgit2", "https://github.com/libgit2/libgit2/tarball/" + pkg.libgit2.sha), + getVendorLib("libssh2", pkg.libssh2.url), + getVendorLib("http_parser", pkg.http_parser.url), + guardGenerated() + ]) + .then(buildNative) + .then(finish, fail); } function python() { - return exec("which python2") + var pathFinderCommand = process.platform === "win32" ? "where" : "which"; + + return exec(pathFinderCommand + " python2") .then(function(which){ return which; }, function(err) { return null; }) .then(function(path) { - return path || exec("which python"); + return path || exec(pathFinderCommand + " python"); }) - .then(function(which) { - return which; + .then(function(path) { + return path; }, function(err) { return null; }) .then(function(path) { - pythonPath = path.trim(); - if (!pythonPath) { + if (!path) { throw new Error("Python is required to build libgit2."); } + return path.trim(); + }, function(err) { + throw new Error("Error finding python."); }) - .then(function() { - return exec(pythonPath + " -V 2>&1"); + .then(function(path) { + pythonPath = path; + return exec(path + " -V 2>&1"); }) .then(function(version) { - if (version[1].indexOf("Python 3") === 0) { + if (version.trim().indexOf("Python 3") === 0) { throw new Error("Incorrect version of Python, gyp requires < 3."); } }); } function getVendorLib(name, url) { - return function() { - var version = pkg[name].sha || pkg[name].version; - console.info("[nodegit] Detecting vendor/" + name + "."); - if (fse.existsSync(paths[name] + version)) { - console.info("[nodegit] vendor/" + name + " already exists."); - return new Promise(function(resolve, reject) {resolve() }); - } - else { - console.info("[nodegit] Removing outdated vendor/" + name + "."); - return fse.remove(paths[name]) - .then(function() { - return new Promise(function (resolve, reject) { - - console.info("[nodegit] Fetching vendor/" + name + "."); + var version = pkg[name].sha || pkg[name].version; + console.info("[nodegit] Detecting vendor/" + name + "."); + if (fse.existsSync(paths[name] + version)) { + console.info("[nodegit] vendor/" + name + " already exists."); + return Promise.resolve(); + } + else { + console.info("[nodegit] Removing outdated vendor/" + name + "."); + return fse.remove(paths[name]) + .then(function() { + return new Promise(function (resolve, reject) { - var extract = tar.Extract({ - path: paths[name], - strip: true - }); + console.info("[nodegit] Fetching vendor/" + name + "."); - request.get(url).pipe(zlib.createUnzip()).pipe(extract) - .on("error", reject) - .on("end", resolve); + var extract = tar.Extract({ + path: paths[name], + strip: true }); - }).then(function() { - return fse.writeFile(paths[name] + version, ""); - }).then(function() { - if ((name == "libssh2") && (process.platform !== "win32")) { - return exec(paths[name] + "configure", {cwd: paths[name]}); - } + request.get(url).pipe(zlib.createUnzip()).pipe(extract) + .on("error", reject) + .on("end", resolve); }); - } + }).then(function() { + return fse.writeFile(paths[name] + version, ""); + }).then(function() { + if ((name == "libssh2") && (process.platform !== "win32")) { + return exec(paths[name] + "configure", {cwd: paths[name]}); + } + }); } } +function guardGenerated() { + return Promise.all([ + fse.stat(path.resolve(__dirname, "src/")), + fse.stat(path.resolve(__dirname, "include/")) + ]).then(function() { + return Promise.resolve(); + }, function() { + console.info("[nodegit] C++ files not found, generating now."); + console.info("[nodegit] Installing all devDependencies"); + return exec("npm install --ignore-scripts --dont-prepublish") + .then(function() { + return exec("node generate"); + }); + }); +} + function buildNative() { return exec("cd " + __dirname).then(function() { if (nodeWebkit) { @@ -221,7 +235,21 @@ function detectNodeWebkit(directory) { function finish() { console.info("[nodegit] Completed installation successfully."); - return Promise.resolve().done(); + if (!buildOnly) { + console.info("[nodegit] Cleaning up"); + return Promise.all([ + fse.remove(path.resolve(__dirname, "src")), + fse.remove(path.resolve(__dirname, "include")), + fse.remove(path.resolve(__dirname, "generate/output")), + fse.remove(path.resolve(__dirname, paths.libgit2)), + fse.remove(path.resolve(__dirname, paths.libssh2)), + fse.remove(path.resolve(__dirname, paths.http_parser)) + // exec("npm prune --production") + ]).done(); + } + else { + return Promise.resolve().done(); + } } function fail(message) { diff --git a/package.json b/package.json index a495da515..000825f7b 100644 --- a/package.json +++ b/package.json @@ -60,14 +60,8 @@ "node-pre-gyp" ], "dependencies": { - "combyne": "~0.6.2", "find-parent-dir": "^0.3.0", "fs-extra": "^0.12.0", - "istanbul": "~0.3.2", - "js-beautify": "^1.5.4", - "jshint": "~2.5.6", - "lodash": "^2.4.1", - "mocha": "~1.21.4", "nan": "~1.3.0", "node-gyp": "~1.0.2", "node-pre-gyp": "~0.5.27", @@ -77,6 +71,14 @@ "request": "~2.45.0", "tar": "~1.0.1" }, + "devDependencies": { + "mocha": "~1.21.4", + "combyne": "~0.6.2", + "istanbul": "~0.3.2", + "js-beautify": "^1.5.4", + "jshint": "~2.5.6", + "lodash": "^2.4.1" + }, "binary": { "module_name": "nodegit", "module_path": "./build/Release/", @@ -91,8 +93,9 @@ "generateJson": "node generate/scripts/generateJson", "generateNativeCode": "node generate/scripts/generateNativeCode", "generateMissingTests": "node generate/scripts/generateMissingTests", + "prepublish": "node prepublish", "publish": "node-pre-gyp package && node-pre-gyp publish", - "install": "node generate && node install", + "install": "node install", "recompile": "BUILD_ONLY=true npm install", "rebuild": "BUILD_ONLY=true node generate && node-gyp configure build" } diff --git a/prepublish.js b/prepublish.js new file mode 100644 index 000000000..7fddbecdd --- /dev/null +++ b/prepublish.js @@ -0,0 +1,8 @@ +var exec = require('child_process').exec; +try { + require("./build/Release/nodegit"); + console.info("[nodegit] Nothing to do.") +} +catch (e) { + exec("node generate"); +} From a34e978285f86882ff347be7a09b58cd3a51a4de Mon Sep 17 00:00:00 2001 From: Maximiliano Korp Date: Thu, 4 Dec 2014 13:03:44 -0700 Subject: [PATCH 2/5] add default gitconfig user info to CI --- .travis.yml | 8 ++++++++ appveyor.yml | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/.travis.yml b/.travis.yml index 8a78fce67..f1390db23 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,6 +23,8 @@ before_script: - chmod 600 ~/.ssh/id_rsa* - eval `ssh-agent -s` - ssh-add ~/.ssh/id_rsa + - git config --global user.name "John Doe" + - git config --global user.email johndoe@example.com git: depth: 1 branches: @@ -35,3 +37,9 @@ script: npm test notifications: slack: secure: KglNSqZiid9YudCwkPFDh+sZfW5BwFlM70y67E4peHwwlbbV1sSBPHcs74ZHP/lqgEZ4hMv4N2NI58oYFD5/1a+tKIQP1TkdIMuq4j2LXheuirA2HDcydOVrsC8kRx5XFGKdVRg/uyX2dlRHcOWFhxrS6yc6IxtxYWlRTD2SmEc= + webhooks: + urls: + - https://webhooks.gitter.im/e/cbafdb27ad32ba746a73 + on_success: always # options: [always|never|change] default: always + on_failure: always # options: [always|never|change] default: always + on_start: false # default: false diff --git a/appveyor.yml b/appveyor.yml index 47e35efe3..af22a86ff 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -14,6 +14,8 @@ clone_folder: c:\projects\nodegit # fix lineendings in Windows init: - git config --global core.autocrlf input + - git config --global user.name "John Doe" + - git config --global user.email johndoe@example.com # what combinations to test environment: @@ -39,3 +41,9 @@ test_script: - cmd: npm test build: off + +notifications: + - provider: Slack + auth_token: + secure: ZsaMCvRMfDZhNsiUvZtvszXXF3z4pLIGJmAj5MuDaa40JvmMC6wnBWIR+LHJuJPM + channel: nodegit From 791a7ce4848197f873f4c263f7f9b1b6d7cdb33e Mon Sep 17 00:00:00 2001 From: Maximiliano Korp Date: Thu, 4 Dec 2014 13:04:14 -0700 Subject: [PATCH 3/5] fix invalid error code returns from tests --- test/index.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/index.js b/test/index.js index 288e7a720..dab2fcdaa 100644 --- a/test/index.js +++ b/test/index.js @@ -10,4 +10,6 @@ var args = [ require("child_process").fork("../node_modules/istanbul/lib/cli.js", args, { cwd: __dirname +}).on("close", function(code) { + process.exit(code); }); From f0bebe4490d1dd71626d592bbb01baabf6397d31 Mon Sep 17 00:00:00 2001 From: Maximiliano Korp Date: Thu, 4 Dec 2014 13:04:30 -0700 Subject: [PATCH 4/5] fix and add tests --- test/tests/merge.js | 5 ++++- test/tests/repository.js | 7 +++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/test/tests/merge.js b/test/tests/merge.js index b66eeb03f..90d666c59 100644 --- a/test/tests/merge.js +++ b/test/tests/merge.js @@ -213,7 +213,10 @@ describe("Merge", function() { }); }) .then(function() { - return repository.mergeBranches(ourBranchName, theirBranchName); + return repository.mergeBranches( + ourBranchName, + theirBranchName, + ourSignature); }) .then(function(oid) { assert.equal(oid.toString(), diff --git a/test/tests/repository.js b/test/tests/repository.js index c172604ff..ef45a630a 100644 --- a/test/tests/repository.js +++ b/test/tests/repository.js @@ -7,6 +7,7 @@ describe("Repository", function() { var Repository = require("../../lib/repository"); var Index = require("../../lib/index"); + var Signature = require("../../lib/signature"); before(function() { var test = this; @@ -58,4 +59,10 @@ describe("Repository", function() { assert.equal(branch.shorthand(), "master"); }); }); + + it("can get the default signature", function() { + var sig = this.repository.defaultSignature(); + + assert(sig instanceof Signature); + }); }); From bf20af51b53c1a2e7b91d0f61059c540ae3990f7 Mon Sep 17 00:00:00 2001 From: Maximiliano Korp Date: Thu, 4 Dec 2014 19:27:05 -0800 Subject: [PATCH 5/5] Only test master and pull requests on appveyor --- appveyor.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/appveyor.yml b/appveyor.yml index af22a86ff..23f3768a6 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -47,3 +47,7 @@ notifications: auth_token: secure: ZsaMCvRMfDZhNsiUvZtvszXXF3z4pLIGJmAj5MuDaa40JvmMC6wnBWIR+LHJuJPM channel: nodegit + +branches: + only: + - master