Chore: short circut output content hash comparision on CI

This commit is contained in:
SukkaW
2026-08-01 13:23:50 +08:00
parent 76bb899102
commit 879c95f744
3 changed files with 26 additions and 1 deletions

View File

@@ -1,6 +1,7 @@
import { isCI } from 'ci-info';
import type { Span } from '../../trace';
import { calculateContentHash } from '../content-hash';
import { compareAndWriteFile } from '../create-file';
import { compareAndWriteFile, writeFileLines } from '../create-file';
/**
* The class is not about holding rule data, instead it determines how the
@@ -27,6 +28,14 @@ export abstract class BaseWriteStrategy {
protected abstract result: string[] | null;
/**
* Whether the output has no volatile metadata (e.g. "Last Updated") to preserve,
* so on CI the previous file can simply be overwritten without comparison (the
* comparison would only serve to reduce SSD wear, which CI doesn't care about).
* Only enable this when withPadding emits neither a banner nor any date.
*/
protected readonly skipCompareOnCI: boolean = false;
abstract writeDomain(domain: string): void;
abstract writeDomainSuffix(domain: string): void;
abstract writeDomainKeywords(keyword: Set<string>): void;
@@ -59,6 +68,16 @@ export abstract class BaseWriteStrategy {
return;
}
// Without volatile metadata to preserve, the compare-before-write only serves
// to reduce SSD wear -- irrelevant on CI, so skip hashing and comparison alike.
if (isCI && this.skipCompareOnCI) {
return writeFileLines(
span,
this.withPadding(title, description, date, result, null),
filePath
);
}
// The hash covers the real content (title, description and rules) but not the
// volatile date, so compareAndWriteFile can bail out by only reading the head
// of the previous output. Strategies whose withPadding doesn't embed the marker