Use pre-built submodules to speed up building

This commit is contained in:
Martynas Bagdonas 2021-02-11 20:58:25 +02:00 committed by Dan Stillman
parent 88dc6638fe
commit 4c11d45679
4 changed files with 75 additions and 60 deletions

View file

@ -110,6 +110,8 @@ const scssFiles = [
'chrome/skin/default/zotero/**/*.scss' 'chrome/skin/default/zotero/**/*.scss'
]; ];
const buildsURL = 'https://zotero-download.s3.amazonaws.com/ci/';
module.exports = { module.exports = {
dirs, symlinkDirs, copyDirs, symlinkFiles, browserifyConfigs, jsFiles, scssFiles, ignoreMask dirs, symlinkDirs, copyDirs, symlinkFiles, browserifyConfigs, jsFiles, scssFiles, ignoreMask, buildsURL
}; };

View file

@ -4,35 +4,36 @@ const fs = require('fs-extra');
const util = require('util'); const util = require('util');
const exec = util.promisify(require('child_process').exec); const exec = util.promisify(require('child_process').exec);
const { getSignatures, writeSignatures, onSuccess, onError } = require('./utils'); const { getSignatures, writeSignatures, onSuccess, onError } = require('./utils');
const { buildsURL } = require('./config');
async function getPDFReader(signatures) { async function getPDFReader(signatures) {
const t1 = Date.now(); const t1 = Date.now();
var { stdout } = await exec('git rev-parse HEAD', { cwd: './pdf-reader/pdf.js' }); const { stdout } = await exec('git rev-parse HEAD', { cwd: './pdf-reader' });
const PDFJSHash = stdout.trim(); const hash = stdout.trim();
var { stdout } = await exec('git rev-parse HEAD', { cwd: './pdf-reader' }); if (!('pdf-reader' in signatures) || signatures['pdf-reader'].hash !== hash) {
const PDFReaderHash = stdout.trim(); const targetDir = 'build/resource/pdf-reader/';
try {
let updated = false; const filename = hash + '.zip';
let name = 'pdf-reader/pdf.js'; const tmpDir = 'tmp/builds/pdf-reader/';
if (!(name in signatures) || signatures[name].hash !== PDFJSHash) { const url = buildsURL + 'client-pdf-reader/' + filename;
await exec('npm run build:pdf.js', { cwd: './pdf-reader' }); await exec(
signatures[name] = { hash: PDFJSHash }; `mkdir -p ${tmpDir}`
updated = true; + `&& cd ${tmpDir}`
+ `&& (test -f ${filename} || curl -f ${url} -o ${filename})`
+ `&& rm -rf ../../../${targetDir}`
+ `&& mkdir -p ../../../${targetDir}`
+ `&& unzip -o ${filename} -d ../../../${targetDir}`
);
}
catch (e) {
await exec('npm ci;npm run build', { cwd: 'pdf-reader' });
await fs.copy('pdf-reader/build/zotero', targetDir);
}
signatures['pdf-reader'] = { hash };
} }
name = 'pdf-reader';
if (!(name in signatures) || signatures[name].hash !== PDFReaderHash) {
await exec('npm ci;npm run build:reader', { cwd: './pdf-reader' });
signatures[name] = { hash: PDFReaderHash };
updated = true;
}
if (updated) {
await fs.copy('./pdf-reader/build/zotero', './build/resource/pdf-reader');
}
const t2 = Date.now(); const t2 = Date.now();
return { return {

View file

@ -4,33 +4,33 @@ const fs = require('fs-extra');
const util = require('util'); const util = require('util');
const exec = util.promisify(require('child_process').exec); const exec = util.promisify(require('child_process').exec);
const { getSignatures, writeSignatures, onSuccess, onError } = require('./utils'); const { getSignatures, writeSignatures, onSuccess, onError } = require('./utils');
const { buildsURL } = require('./config');
async function getPDFWorker(signatures) { async function getPDFWorker(signatures) {
const t1 = Date.now(); const t1 = Date.now();
var { stdout } = await exec('git rev-parse HEAD', { cwd: './pdf-worker/pdf.js' }); const { stdout } = await exec('git rev-parse HEAD', { cwd: 'pdf-worker' });
const PDFJSHash = stdout.trim(); const hash = stdout.trim();
var { stdout } = await exec('git rev-parse HEAD', { cwd: './pdf-worker' }); if (!('pdf-worker' in signatures) || signatures['pdf-worker'].hash !== hash) {
const PDFWorkerHash = stdout.trim(); const targetDir = 'build/chrome/content/zotero/xpcom/pdfWorker/';
try {
let updated = false; const filename = hash + '.zip';
let name = 'pdf-worker/pdf.js'; const tmpDir = 'tmp/builds/pdf-worker';
if (!(name in signatures) || signatures[name].hash !== PDFJSHash) { const url = buildsURL + 'client-pdf-worker/' + filename;
await exec('npm run build:pdf.js', { cwd: './pdf-worker' }); await exec(
signatures[name] = { hash: PDFJSHash }; `mkdir -p ${tmpDir}`
updated = true; + `&& cd ${tmpDir}`
} + `&& (test -f ${filename} || curl -f ${url} -o ${filename})`
+ `&& mkdir -p ../../../${targetDir}`
name = 'pdf-worker'; + `&& unzip -o ${filename} -d ../../../${targetDir}`
if (!(name in signatures) || signatures[name].hash !== PDFWorkerHash) { );
await exec('npm ci;npm run build:worker', { cwd: './pdf-worker' }); }
signatures[name] = { hash: PDFWorkerHash }; catch (e) {
updated = true; await exec('npm ci;npm run build', { cwd: 'pdf-worker' });
} await fs.copy('pdf-worker/build/pdf-worker.js', targetDir + 'worker.js');
}
if (updated) { signatures['pdf-worker'] = { hash };
await fs.copy('./pdf-worker/build/pdf-worker.js', './build/chrome/content/zotero/xpcom/pdfWorker/worker.js');
} }
const t2 = Date.now(); const t2 = Date.now();

View file

@ -4,24 +4,36 @@ const fs = require('fs-extra');
const util = require('util'); const util = require('util');
const exec = util.promisify(require('child_process').exec); const exec = util.promisify(require('child_process').exec);
const { getSignatures, writeSignatures, onSuccess, onError } = require('./utils'); const { getSignatures, writeSignatures, onSuccess, onError } = require('./utils');
const { buildsURL } = require('./config');
async function getZoteroNoteEditor(signatures) { async function getZoteroNoteEditor(signatures) {
const t1 = Date.now(); const t1 = Date.now();
var { stdout } = await exec('git rev-parse HEAD', { cwd: './zotero-note-editor' }); const { stdout } = await exec('git rev-parse HEAD', { cwd: './zotero-note-editor' });
const zoteroNoteEditorHash = stdout.trim(); const hash = stdout.trim();
let updated = false; if (!('zotero-note-editor' in signatures) || signatures['zotero-note-editor'].hash !== hash) {
let name = 'zotero-note-editor'; const targetDir = 'build/resource/zotero-note-editor/';
if (!(name in signatures) || signatures[name].hash !== zoteroNoteEditorHash) { try {
await exec('npm ci;npm run build', { cwd: './zotero-note-editor' }); const filename = hash + '.zip';
signatures[name] = { hash: zoteroNoteEditorHash }; const tmpDir = 'tmp/builds/zotero-note-editor/';
updated = true; const url = buildsURL + 'client-note-editor/' + filename;
} await exec(
`mkdir -p ${tmpDir}`
if (updated) { + `&& cd ${tmpDir}`
await fs.copy('./zotero-note-editor/build/zotero', './build/resource/zotero-note-editor'); + `&& (test -f ${filename} || curl -f ${url} -o ${filename})`
+ `&& rm -rf ../../../${targetDir}`
+ `&& mkdir -p ../../../${targetDir}`
+ `&& unzip -o ${filename} -d ../../../${targetDir}`
);
}
catch (e) {
await exec('npm ci;npm run build', { cwd: 'zotero-note-editor' });
await fs.copy('zotero-note-editor/build/zotero', targetDir);
}
signatures['zotero-note-editor'] = { hash };
} }
const t2 = Date.now(); const t2 = Date.now();
return { return {