Skip to content

Commit

Permalink
address pr feedback
Browse files Browse the repository at this point in the history
Signed-off-by: Aramis Sennyey <[email protected]>
  • Loading branch information
aramissennyeydd committed Jan 8, 2025
1 parent 28dcf92 commit 7977f26
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,23 +107,14 @@ export class CacheableOperationPlugin implements IPhasedCommandPlugin {

for (const [operation, record] of recordByOperation) {
const stateHash: string = (record as OperationExecutionRecord).calculateStateHash({
inputsSnapshot
inputsSnapshot,
buildCacheConfiguration
});
const { associatedProject, associatedPhase, runner, settings: operationSettings } = operation;
if (!associatedProject || !associatedPhase || !runner) {
return;
}

const { cacheHashSalt } = buildCacheConfiguration;
const hasher: crypto.Hash = crypto.createHash('sha1');
hasher.update(stateHash);
if (cacheHashSalt !== undefined) {
// This allows repository owners to force a cache bust by changing the salt.
// A common use case is to invalidate the cache when adding/removing/updating rush plugins that alter the build output.
hasher.update(cacheHashSalt);
}
const finalStateHash: string = hasher.digest('hex');

const { name: phaseName } = associatedPhase;

const projectConfiguration: RushProjectConfiguration | undefined =
Expand Down Expand Up @@ -158,7 +149,7 @@ export class CacheableOperationPlugin implements IPhasedCommandPlugin {
isCacheReadAllowed: isIncrementalBuildAllowed,
operationBuildCache: undefined,
outputFolderNames,
stateHash: finalStateHash,
stateHash,
cacheDisabledReason,
cobuildLock: undefined,
cobuildClusterId: undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
import type { IOperationExecutionResult } from './IOperationExecutionResult';
import type { IInputsSnapshot } from '../incremental/InputsSnapshot';
import { RushConstants } from '../RushConstants';
import type { BuildCacheConfiguration } from '../../api/BuildCacheConfiguration';

export interface IOperationExecutionRecordContext {
streamCollator: StreamCollator;
Expand Down Expand Up @@ -349,9 +350,15 @@ export class OperationExecutionRecord implements IOperationRunnerContext, IOpera
}
}

public calculateStateHash(options: { inputsSnapshot: IInputsSnapshot }): string {
public calculateStateHash(options: {
inputsSnapshot: IInputsSnapshot;
buildCacheConfiguration: BuildCacheConfiguration;
}): string {
if (!this._stateHash) {
const { inputsSnapshot } = options;
const {
inputsSnapshot,
buildCacheConfiguration: { cacheHashSalt }
} = options;

// Examples of data in the config hash:
// - CLI parameters (ShellOperationRunner)
Expand All @@ -378,6 +385,12 @@ export class OperationExecutionRecord implements IOperationRunnerContext, IOpera
// of the build cache.
hasher.update(`${RushConstants.buildCacheVersion}`);

if (cacheHashSalt !== undefined) {
// This allows repository owners to force a cache bust by changing the salt.
// A common use case is to invalidate the cache when adding/removing/updating rush plugins that alter the build output.
hasher.update(cacheHashSalt);
}

for (const dependencyHash of dependencyHashes) {
hasher.update(dependencyHash);
}
Expand Down

0 comments on commit 7977f26

Please sign in to comment.