From 7e7d792ba561a2761ba8ead4d50870cce3dc7afc Mon Sep 17 00:00:00 2001 From: Jonathan Beezley Date: Wed, 20 Apr 2016 14:47:05 -0400 Subject: [PATCH] Add git sha to the built bundle. --- .eslintignore | 1 + src/index.js | 1 + src/sha.js | 1 + src/version.js | 2 +- tests/cases/version.js | 7 +++++++ webpack.config.js | 12 +++++++++++- 6 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 src/sha.js diff --git a/.eslintignore b/.eslintignore index 200ccbcfc8..a8b1cbe073 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,5 +1,6 @@ src/vgl/** src/version.js +src/sha.js src/util/wigglemaps.js src/util/distanceGrid.js geo.js diff --git a/src/index.js b/src/index.js index 9a5e2282a6..6d0c576e0b 100644 --- a/src/index.js +++ b/src/index.js @@ -63,6 +63,7 @@ module.exports = $.extend({ vectorFeature: require('./vectorFeature'), inherit: require('./inherit'), version: require('./version'), + sha: require('./sha'), util: require('./util'), d3: require('./d3'), diff --git a/src/sha.js b/src/sha.js new file mode 100644 index 0000000000..69abf4c005 --- /dev/null +++ b/src/sha.js @@ -0,0 +1 @@ +module.exports = GEO_SHA; diff --git a/src/version.js b/src/version.js index c1546992cb..21169a32d6 100644 --- a/src/version.js +++ b/src/version.js @@ -1 +1 @@ -module.exports = VERSION; +module.exports = GEO_VERSION; diff --git a/tests/cases/version.js b/tests/cases/version.js index 733c402d97..99d234fad3 100644 --- a/tests/cases/version.js +++ b/tests/cases/version.js @@ -4,3 +4,10 @@ describe('geo.version', function () { expect(geo.version).toMatch(/[0-9]+\.[0-9]+\.[0-9]+[_a-zA-Z]*/); }); }); + +describe('geo.version', function () { + var geo = require('../test-utils').geo; + it('Git SHA is defined', function () { + expect(geo.sha).toMatch(/^[0-9a-f]{8,}$/); + }); +}); diff --git a/webpack.config.js b/webpack.config.js index 634e3c5394..1a38daa900 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -1,7 +1,17 @@ var path = require('path'); var webpack = require('webpack'); +var exec = require('child_process').execSync; +var sha = ''; + +try { + sha = exec('git rev-parse HEAD', {cwd: __dirname}).toString().trim(); +} catch (e) { + console.warn('Could not determine git hash.'); +} + var define_plugin = new webpack.DefinePlugin({ - VERSION: JSON.stringify(require('./package.json').version) + GEO_SHA: JSON.stringify(sha), + GEO_VERSION: JSON.stringify(require('./package.json').version) }); module.exports = {