electron/script/generate-deps-hash.js
Samuel Attard e9114b3c00
build: optimize the happy path when syncing on CI (#17827)
* build: optimize the happy path when syncing on CI

This adds a new cache for the "src" directory that is only ever used if
the cache key matches exactly.  If there is no exact match we fall back
to the old strategy of using the git cache.

On the happy path this can make the checkout on linux/macOS take around
5-6 minutes which is **significantly** faster than the original 15-18
minutes.

* build: sort readdir result to ensure stability

* build: increment cache key

* Update config.yml

* build: ensure that the cleanly checked out Electron has had hooks run on it

* build: do not remove deps/v8

* build: ensure clean git directory when generating deps hash

* chore: add comments to caching logic

* Update .circleci/config.yml

Co-Authored-By: MarshallOfSound <samuel.r.attard@gmail.com>
2019-04-22 15:36:59 -07:00

38 lines
998 B
JavaScript

const crypto = require('crypto')
const fs = require('fs')
const path = require('path')
// Fallback to blow away old cache keys
const HASH_VERSION = 1
// Base files to hash
const filesToHash = [
path.resolve(__dirname, '../DEPS'),
path.resolve(__dirname, '../package-lock.json')
]
const addAllFiles = (dir) => {
for (const child of fs.readdirSync(dir).sort()) {
const childPath = path.resolve(dir, child)
if (fs.statSync(childPath).isDirectory()) {
addAllFiles(childPath)
} else {
filesToHash.push(childPath)
}
}
}
// Add all patch files to the hash
addAllFiles(path.resolve(__dirname, '../patches'))
// Create Hash
const hasher = crypto.createHash('SHA256')
for (const file of filesToHash) {
hasher.update(fs.readFileSync(file))
}
// Add the GCLIENT_EXTRA_ARGS variable to the hash
hasher.update(process.env.GCLIENT_EXTRA_ARGS || 'no_extra_args')
// Write the hash to disk
fs.writeFileSync(path.resolve(__dirname, '../.depshash'), hasher.digest('hex'))