diff --git a/workflow-steps/cache/generated_protos/cache_connect.ts b/workflow-steps/cache/generated_protos/cache_connect.ts index 57bbb7f..1d0cd85 100644 --- a/workflow-steps/cache/generated_protos/cache_connect.ts +++ b/workflow-steps/cache/generated_protos/cache_connect.ts @@ -35,5 +35,14 @@ export const CacheService = { O: StoreResponse, kind: MethodKind.Unary, }, + /** + * @generated from rpc nrwl.grpc.CacheService.StoreV2 + */ + storeV2: { + name: 'StoreV2', + I: StoreRequest, + O: StoreResponse, + kind: MethodKind.Unary, + }, }, } as const; diff --git a/workflow-steps/cache/generated_protos/cache_pb.ts b/workflow-steps/cache/generated_protos/cache_pb.ts index 7835dcc..4a0caec 100644 --- a/workflow-steps/cache/generated_protos/cache_pb.ts +++ b/workflow-steps/cache/generated_protos/cache_pb.ts @@ -1,4 +1,4 @@ -// @generated by protoc-gen-es v1.3.1 with parameter "target=ts" +// @generated by protoc-gen-es v1.7.2 with parameter "target=ts" // @generated from file cache.proto (package nrwl.grpc, syntax proto3) /* eslint-disable */ // @ts-nocheck @@ -53,28 +53,28 @@ export class RestoreRequest extends Message { static fromBinary( bytes: Uint8Array, - options?: Partial + options?: Partial, ): RestoreRequest { return new RestoreRequest().fromBinary(bytes, options); } static fromJson( jsonValue: JsonValue, - options?: Partial + options?: Partial, ): RestoreRequest { return new RestoreRequest().fromJson(jsonValue, options); } static fromJsonString( jsonString: string, - options?: Partial + options?: Partial, ): RestoreRequest { return new RestoreRequest().fromJsonString(jsonString, options); } static equals( a: RestoreRequest | PlainMessage | undefined, - b: RestoreRequest | PlainMessage | undefined + b: RestoreRequest | PlainMessage | undefined, ): boolean { return proto3.util.equals(RestoreRequest, a, b); } @@ -108,28 +108,28 @@ export class RestoreResponse extends Message { static fromBinary( bytes: Uint8Array, - options?: Partial + options?: Partial, ): RestoreResponse { return new RestoreResponse().fromBinary(bytes, options); } static fromJson( jsonValue: JsonValue, - options?: Partial + options?: Partial, ): RestoreResponse { return new RestoreResponse().fromJson(jsonValue, options); } static fromJsonString( jsonString: string, - options?: Partial + options?: Partial, ): RestoreResponse { return new RestoreResponse().fromJsonString(jsonString, options); } static equals( a: RestoreResponse | PlainMessage | undefined, - b: RestoreResponse | PlainMessage | undefined + b: RestoreResponse | PlainMessage | undefined, ): boolean { return proto3.util.equals(RestoreResponse, a, b); } @@ -169,28 +169,28 @@ export class StoreRequest extends Message { static fromBinary( bytes: Uint8Array, - options?: Partial + options?: Partial, ): StoreRequest { return new StoreRequest().fromBinary(bytes, options); } static fromJson( jsonValue: JsonValue, - options?: Partial + options?: Partial, ): StoreRequest { return new StoreRequest().fromJson(jsonValue, options); } static fromJsonString( jsonString: string, - options?: Partial + options?: Partial, ): StoreRequest { return new StoreRequest().fromJsonString(jsonString, options); } static equals( a: StoreRequest | PlainMessage | undefined, - b: StoreRequest | PlainMessage | undefined + b: StoreRequest | PlainMessage | undefined, ): boolean { return proto3.util.equals(StoreRequest, a, b); } @@ -224,28 +224,28 @@ export class StoreResponse extends Message { static fromBinary( bytes: Uint8Array, - options?: Partial + options?: Partial, ): StoreResponse { return new StoreResponse().fromBinary(bytes, options); } static fromJson( jsonValue: JsonValue, - options?: Partial + options?: Partial, ): StoreResponse { return new StoreResponse().fromJson(jsonValue, options); } static fromJsonString( jsonString: string, - options?: Partial + options?: Partial, ): StoreResponse { return new StoreResponse().fromJsonString(jsonString, options); } static equals( a: StoreResponse | PlainMessage | undefined, - b: StoreResponse | PlainMessage | undefined + b: StoreResponse | PlainMessage | undefined, ): boolean { return proto3.util.equals(StoreResponse, a, b); } diff --git a/workflow-steps/cache/hashing-utils.ts b/workflow-steps/cache/hashing-utils.ts index b0aeb88..9728815 100644 --- a/workflow-steps/cache/hashing-utils.ts +++ b/workflow-steps/cache/hashing-utils.ts @@ -3,42 +3,42 @@ const crypto = require('crypto'); import { glob } from 'glob'; function hashFileContents(pattern: string) { - const files = glob - .sync(pattern, { ignore: 'node_modules/**' }) - .filter((path) => { - return fs.statSync(path).isFile(); - }); - let megaHash = ''; - files.forEach((file) => { - const fileContent = fs.readFileSync(file); - const fileHash = crypto - .createHash('sha256') - .update(fileContent) - .digest('hex'); - megaHash = crypto - .createHash('sha256') - .update(fileHash + megaHash) - .digest('hex'); + const files = glob + .sync(pattern, { ignore: 'node_modules/**' }) + .filter((path) => { + return fs.statSync(path).isFile(); }); - return megaHash; + let megaHash = ''; + files.forEach((file) => { + const fileContent = fs.readFileSync(file); + const fileHash = crypto + .createHash('sha256') + .update(fileContent) + .digest('hex'); + megaHash = crypto + .createHash('sha256') + .update(fileHash + megaHash) + .digest('hex'); + }); + return megaHash; } export function hashKey(key: string): string { - const keyParts = key.split('|').map((s) => s.trim()); + const keyParts = key.split('|').map((s) => s.trim()); - const hardcodedKeys: string[] = []; - const globsToHash: string[] = []; + const hardcodedKeys: string[] = []; + const globsToHash: string[] = []; - keyParts.forEach((key) => { - if (key.startsWith('"') && key.endsWith('"')) { - hardcodedKeys.push(key.slice(1, -1)); - } else { - globsToHash.push(key); - } - }); + keyParts.forEach((key) => { + if (key.startsWith('"') && key.endsWith('"')) { + hardcodedKeys.push(key.slice(1, -1)); + } else { + globsToHash.push(key); + } + }); - const globHashes = globsToHash.map((globPattern) => { - return hashFileContents(globPattern); - }); - return [...hardcodedKeys, ...globHashes].join(' | '); + const globHashes = globsToHash.map((globPattern) => { + return hashFileContents(globPattern); + }); + return [...hardcodedKeys, ...globHashes].join(' | '); } diff --git a/workflow-steps/cache/output/main.js b/workflow-steps/cache/output/main.js index a66fb3d..0c95863 100644 --- a/workflow-steps/cache/output/main.js +++ b/workflow-steps/cache/output/main.js @@ -5935,6 +5935,15 @@ var CacheService = { I: StoreRequest, O: StoreResponse, kind: MethodKind.Unary + }, + /** + * @generated from rpc nrwl.grpc.CacheService.StoreV2 + */ + storeV2: { + name: "StoreV2", + I: StoreRequest, + O: StoreResponse, + kind: MethodKind.Unary } } }; diff --git a/workflow-steps/cache/output/post.js b/workflow-steps/cache/output/post.js index fa8dd71..11e0c68 100644 --- a/workflow-steps/cache/output/post.js +++ b/workflow-steps/cache/output/post.js @@ -5923,6 +5923,15 @@ var CacheService = { I: StoreRequest, O: StoreResponse, kind: MethodKind.Unary + }, + /** + * @generated from rpc nrwl.grpc.CacheService.StoreV2 + */ + storeV2: { + name: "StoreV2", + I: StoreRequest, + O: StoreResponse, + kind: MethodKind.Unary } } }; @@ -5973,15 +5982,14 @@ if (!!cacheWasHit) { baseUrl: "http://127.0.0.1:9000" }) ); - const currentBranch = process.env.NX_BRANCH; if (!input_key || !input_paths) { throw new Error("No cache restore key or paths provided."); } const key = hashKey(input_key); const paths = input_paths.split("\n").filter((p) => p); - cacheClient.store( + cacheClient.storeV2( new StoreRequest({ - key: `${currentBranch}-${key}`, + key, paths }) ).then((r) => { diff --git a/workflow-steps/cache/post.ts b/workflow-steps/cache/post.ts index 04810e7..676255c 100644 --- a/workflow-steps/cache/post.ts +++ b/workflow-steps/cache/post.ts @@ -21,7 +21,6 @@ if (!!cacheWasHit) { }), ); - const currentBranch = process.env.NX_BRANCH; if (!input_key || !input_paths) { throw new Error('No cache restore key or paths provided.'); } @@ -29,9 +28,9 @@ if (!!cacheWasHit) { const paths = input_paths.split('\n').filter((p) => p); cacheClient - .store( + .storeV2( new StoreRequest({ - key: `${currentBranch}-${key}`, + key, paths, }), )