Files
send-mail/node_modules/@actions/glob/lib/internal-hash-files.js

76 lines
3.6 KiB
JavaScript
Raw Normal View History

2021-06-22 19:18:21 +02:00
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __asyncValues = (this && this.__asyncValues) || function (o) {
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
var m = o[Symbol.asyncIterator], i;
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
};
import * as crypto from 'crypto';
import * as core from '@actions/core';
import * as fs from 'fs';
import * as stream from 'stream';
import * as util from 'util';
import * as path from 'path';
export function hashFiles(globber_1, currentWorkspace_1) {
return __awaiter(this, arguments, void 0, function* (globber, currentWorkspace, verbose = false) {
var _a, e_1, _b, _c;
var _d;
2025-06-13 19:44:16 +02:00
const writeDelegate = verbose ? core.info : core.debug;
2021-06-22 19:18:21 +02:00
let hasMatch = false;
2025-06-13 19:44:16 +02:00
const githubWorkspace = currentWorkspace
? currentWorkspace
: ((_d = process.env['GITHUB_WORKSPACE']) !== null && _d !== void 0 ? _d : process.cwd());
2021-06-22 19:18:21 +02:00
const result = crypto.createHash('sha256');
let count = 0;
try {
2025-06-14 22:45:43 +02:00
for (var _e = true, _f = __asyncValues(globber.globGenerator()), _g; _g = yield _f.next(), _a = _g.done, !_a; _e = true) {
_c = _g.value;
_e = false;
const file = _c;
2025-06-13 19:44:16 +02:00
writeDelegate(file);
2021-06-22 19:18:21 +02:00
if (!file.startsWith(`${githubWorkspace}${path.sep}`)) {
2025-06-13 19:44:16 +02:00
writeDelegate(`Ignore '${file}' since it is not under GITHUB_WORKSPACE.`);
2021-06-22 19:18:21 +02:00
continue;
}
if (fs.statSync(file).isDirectory()) {
2025-06-13 19:44:16 +02:00
writeDelegate(`Skip directory '${file}'.`);
2021-06-22 19:18:21 +02:00
continue;
}
const hash = crypto.createHash('sha256');
const pipeline = util.promisify(stream.pipeline);
yield pipeline(fs.createReadStream(file), hash);
result.write(hash.digest());
count++;
if (!hasMatch) {
hasMatch = true;
}
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
2025-06-14 22:45:43 +02:00
if (!_e && !_a && (_b = _f.return)) yield _b.call(_f);
2021-06-22 19:18:21 +02:00
}
finally { if (e_1) throw e_1.error; }
}
result.end();
if (hasMatch) {
2025-06-13 19:44:16 +02:00
writeDelegate(`Found ${count} files to hash.`);
2021-06-22 19:18:21 +02:00
return result.digest('hex');
}
else {
2025-06-13 19:44:16 +02:00
writeDelegate(`No matches found for glob`);
2021-06-22 19:18:21 +02:00
return '';
}
});
}
//# sourceMappingURL=internal-hash-files.js.map