unity-builder/src/model/cli/remote-client/remote-client-services/lfs-hashing.ts

40 lines
1.5 KiB
TypeScript
Raw Normal View History

2021-12-27 21:25:46 +00:00
import path from 'path';
2022-01-02 22:48:43 +00:00
import { CloudRunnerState } from '../../../cloud-runner/state/cloud-runner-state';
import { CloudRunnerSystem } from './cloud-runner-system';
2021-12-27 21:25:46 +00:00
import fs from 'fs';
2021-12-31 20:33:55 +00:00
import { assert } from 'console';
2022-01-02 22:48:43 +00:00
import { Input } from '../../..';
2021-12-31 20:33:55 +00:00
import { RemoteClientLogger } from './remote-client-logger';
2021-12-27 21:25:46 +00:00
export class LFSHashing {
public static async createLFSHashFiles() {
2021-12-27 21:49:57 +00:00
try {
2022-01-02 22:48:43 +00:00
await CloudRunnerSystem.Run(`git lfs ls-files -l | cut -d ' ' -f1 | sort > .lfs-assets-guid`);
await CloudRunnerSystem.Run(`md5sum .lfs-assets-guid > .lfs-assets-guid-sum`);
2021-12-31 20:33:55 +00:00
assert(fs.existsSync(`.lfs-assets-guid-sum`));
assert(fs.existsSync(`.lfs-assets-guid`));
const lfsHashes = {
2021-12-31 23:06:38 +00:00
lfsGuid: fs
.readFileSync(`${path.join(CloudRunnerState.repoPathFull, `.lfs-assets-guid`)}`, 'utf8')
.replace(/\n/g, ``),
lfsGuidSum: fs
.readFileSync(`${path.join(CloudRunnerState.repoPathFull, `.lfs-assets-guid-sum`)}`, 'utf8')
.replace(/\n/g, ``),
2021-12-31 20:33:55 +00:00
};
if (Input.cloudRunnerTests) {
RemoteClientLogger.log(lfsHashes.lfsGuid);
RemoteClientLogger.log(lfsHashes.lfsGuidSum);
}
return lfsHashes;
2021-12-27 21:49:57 +00:00
} catch (error) {
throw error;
}
2021-12-27 21:25:46 +00:00
}
2022-01-01 02:42:57 +00:00
public static async hashAllFiles(folder: string) {
process.chdir(`${folder}`);
2022-01-02 22:48:43 +00:00
return await (await CloudRunnerSystem.Run(`find -type f -exec md5sum "{}" + | sort | md5sum`))
2022-01-01 03:03:04 +00:00
.replace(/\n/g, '')
.split(` `)[0];
2022-01-01 02:42:57 +00:00
}
2021-12-27 21:25:46 +00:00
}