Skip to content

Commit

Permalink
Log globalInputHash in TargetHasher init (#680)
Browse files Browse the repository at this point in the history
* Change files

* Adding global input hash logging in TargetHasher

* Dependency Update

---------

Co-authored-by: brunoru <[email protected]>
  • Loading branch information
BrunoRDS and brunoru authored Jun 21, 2023
1 parent 28f8a90 commit 3efba30
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "Passing logger object to TargetHasher for hasher init logging",
"packageName": "@lage-run/cli",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "Added logging in TargetHasher, now logs hash of glob-hashed files for global input hash comparison",
"packageName": "@lage-run/hasher",
"email": "[email protected]",
"dependentChangeType": "patch"
}
3 changes: 2 additions & 1 deletion packages/cli/src/cache/createCacheProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ interface CreateCacheOptions {
}

export async function createCache(options: CreateCacheOptions) {
const { cacheOptions, root, cliArgs } = options;
const { cacheOptions, root, cliArgs, logger } = options;

const hasher = new TargetHasher({
root,
environmentGlob: cacheOptions?.environmentGlob ?? [],
cacheKey: cacheOptions?.cacheKey,
cliArgs,
logger,
});

await hasher.initialize();
Expand Down
1 change: 1 addition & 0 deletions packages/hasher/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
},
"dependencies": {
"@lage-run/target-graph": "^0.8.6",
"@lage-run/logger": "^1.3.0",
"execa": "5.1.1",
"workspace-tools": "0.30.0",
"fast-glob": "3.2.12",
Expand Down
11 changes: 10 additions & 1 deletion packages/hasher/src/TargetHasher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ import { hashStrings } from "./hashStrings.js";
import { resolveInternalDependencies } from "./resolveInternalDependencies.js";
import { resolveExternalDependencies } from "./resolveExternalDependencies.js";
import { FileHasher } from "./FileHasher.js";
import type { Logger } from "@lage-run/logger";
import { PackageTree } from "./PackageTree.js";

export interface TargetHasherOptions {
root: string;
environmentGlob: string[];
cacheKey?: string;
cliArgs?: string[];
logger?: Logger;
}

export interface TargetManifest {
Expand All @@ -50,6 +52,7 @@ export interface TargetManifest {
* Currently, it encapsulates the use of `backfill-hasher` to generate a hash.
*/
export class TargetHasher {
logger: Logger | undefined;
fileHasher: FileHasher;
packageTree: PackageTree | undefined;

Expand Down Expand Up @@ -136,7 +139,8 @@ export class TargetHasher {
}

constructor(private options: TargetHasherOptions) {
const { root } = options;
const { root, logger } = options;
this.logger = logger;

this.fileHasher = new FileHasher({
root,
Expand Down Expand Up @@ -185,6 +189,11 @@ export class TargetHasher {
]);

await this.initializedPromise;

if (this.logger !== undefined) {
const globalInputsHash = hashStrings(Object.values(this.globalInputsHash ?? {}));
this.logger.verbose(`Global inputs hash: ${globalInputsHash}`);
}
}

async hash(target: Target): Promise<string> {
Expand Down

0 comments on commit 3efba30

Please sign in to comment.