12
0
Fork 0
mirror of https://github.com/astral-sh/setup-uv.git synced 2026-07-02 10:29:31 +00:00
setup-uv/src/hash/hash-files.ts
Kevin Stillhammer fd1049be7f
Wire all source files through logging module for quiet mode
Route all core.info and core.warning calls through the new
log.info/log.warning wrappers so quiet:true suppresses them.
The ##[add-matcher] directive in setup-uv.ts uses core.info
directly since it is a workflow command, not user-facing output.

Update action.yml, action-types.yml, and README.md with the
new quiet input (default: false).
2026-05-31 12:37:17 +02:00

48 lines
1.5 KiB
TypeScript

import * as crypto from "node:crypto";
import * as fs from "node:fs";
import * as stream from "node:stream";
import * as util from "node:util";
import { create } from "@actions/glob";
import * as log from "../utils/logging";
/**
* Hashes files matching the given glob pattern.
*
* Copied from https://github.com/actions/toolkit/blob/20ed2908f19538e9dfb66d8083f1171c0a50a87c/packages/glob/src/internal-hash-files.ts#L9-L49
* But supports hashing files outside the GITHUB_WORKSPACE.
* @param pattern The glob pattern to match files.
* @param verbose Whether to log the files being hashed.
*/
export async function hashFiles(
pattern: string,
verbose = false,
): Promise<string> {
const globber = await create(pattern);
let hasMatch = false;
const writeDelegate = verbose ? log.info : log.debug;
const result = crypto.createHash("sha256");
let count = 0;
for await (const file of globber.globGenerator()) {
writeDelegate(file);
if (fs.statSync(file).isDirectory()) {
writeDelegate(`Skip directory '${file}'.`);
continue;
}
const hash = crypto.createHash("sha256");
const pipeline = util.promisify(stream.pipeline);
await pipeline(fs.createReadStream(file), hash);
result.write(hash.digest());
count++;
if (!hasMatch) {
hasMatch = true;
}
}
result.end();
if (hasMatch) {
writeDelegate(`Found ${count} files to hash.`);
return result.digest("hex");
}
writeDelegate("No matches found for glob");
return "";
}