mirror of https://github.com/actions/setup-go.git
perf: improve setup-go cache for build-cache + use improved version of hash dir based on file's meta
parent
cdcb360436
commit
ed099b7083
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -0,0 +1,30 @@
|
||||
import {Hash, createHash} from 'node:crypto';
|
||||
import {readdirSync, statSync} from 'node:fs';
|
||||
import {join} from 'node:path';
|
||||
|
||||
/**
|
||||
* Creates hash of given files/folders. Used to conditionally deploy custom
|
||||
* resources depending if source files have changed
|
||||
*/
|
||||
export function computeMetaHash(paths: string[], inputHash?: Hash) {
|
||||
const hash = inputHash ? inputHash : createHash('sha1');
|
||||
for (const path of paths) {
|
||||
const statInfo = statSync(path);
|
||||
if (statInfo.isDirectory()) {
|
||||
const directoryEntries = readdirSync(path, {withFileTypes: true});
|
||||
const fullPaths = directoryEntries.map(e => join(path, e.name));
|
||||
// recursively walk sub-folders
|
||||
computeMetaHash(fullPaths, hash);
|
||||
} else {
|
||||
const statInfo = statSync(path);
|
||||
// compute hash string name:size:mtime
|
||||
const fileInfo = `${path}:${statInfo.size}:${statInfo.mtimeMs}`;
|
||||
hash.update(fileInfo);
|
||||
}
|
||||
}
|
||||
// if not being called recursively, get the digest and return it as the hash result
|
||||
if (!inputHash) {
|
||||
return hash.digest('hex');
|
||||
}
|
||||
return;
|
||||
}
|
||||
Loading…
Reference in New Issue