From 94810b2b5acc6b860df4dfa2881b62030806d518 Mon Sep 17 00:00:00 2001 From: Brian Vaughn Date: Thu, 11 Apr 2019 19:06:07 -0700 Subject: [PATCH] Add Git revision to extension manifests --- shells/browser/shared/build.js | 10 +++++++++- shells/utils.js | 12 ++++++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/shells/browser/shared/build.js b/shells/browser/shared/build.js index 2a6929feeb..63b38b993c 100644 --- a/shells/browser/shared/build.js +++ b/shells/browser/shared/build.js @@ -2,8 +2,10 @@ const AdmZip = require('adm-zip'); const { execSync } = require('child_process'); +const { readFileSync, writeFileSync } = require('fs'); const { copy, ensureDir, move, remove } = require('fs-extra'); const { join } = require('path'); +const { getGitCommit } = require('../../utils'); // These files are copied along with Webpack-bundled files // to produce the final web extension @@ -52,13 +54,19 @@ const build = async (tempPath, manifestPath) => { // Make temp dir await ensureDir(zipPath); + const copiedManifestPath = join(zipPath, 'manifest.json'); + // Copy unbuilt source files to zip dir to be packaged: await copy(binPath, join(zipPath, 'build')); - await copy(manifestPath, join(zipPath, 'manifest.json')); + await copy(manifestPath, copiedManifestPath); await Promise.all( STATIC_FILES.map(file => copy(join(__dirname, file), join(zipPath, file))) ); + let manifest = JSON.parse(readFileSync(copiedManifestPath).toString()); + manifest.description += `\n\nCreated from revision ${getGitCommit()}`; + writeFileSync(copiedManifestPath, JSON.stringify(manifest, null, 2)); + // Pack the extension const zip = new AdmZip(); zip.addLocalFolder(zipPath); diff --git a/shells/utils.js b/shells/utils.js index 8f0d875d32..6f55ca8158 100644 --- a/shells/utils.js +++ b/shells/utils.js @@ -2,6 +2,12 @@ const { execSync } = require('child_process'); const { readFileSync } = require('fs'); const { resolve } = require('path'); +function getGitCommit() { + return execSync('git show -s --format=%h') + .toString() + .trim(); +} + function getGitHubURL() { // TODO potentially replac this with an fb.me URL (if it can forward the query params) return execSync('git remote get-url origin') @@ -17,11 +23,9 @@ function getVersionString() { readFileSync(resolve(__dirname, '../package.json')) ).version; - const commit = execSync('git show -s --format=%h') - .toString() - .trim(); + const commit = getGitCommit(); return `${packageVersion}-${commit}`; } -module.exports = { getGitHubURL, getVersionString }; +module.exports = { getGitCommit, getGitHubURL, getVersionString };