mirror of
https://github.com/github/codeql-action.git
synced 2026-01-06 22:50:17 +08:00
Move check whether there are files for hashing into getHashPatterns
This commit is contained in:
51
lib/analyze-action.js
generated
51
lib/analyze-action.js
generated
@@ -91052,6 +91052,12 @@ var os3 = __toESM(require("os"));
|
||||
var import_path = require("path");
|
||||
var actionsCache3 = __toESM(require_cache3());
|
||||
var glob = __toESM(require_glob2());
|
||||
var NoMatchingFilesError = class extends Error {
|
||||
constructor(msg) {
|
||||
super(msg);
|
||||
this.name = "NoMatchingFilesError";
|
||||
}
|
||||
};
|
||||
var CODEQL_DEPENDENCY_CACHE_PREFIX = "codeql-dependencies";
|
||||
var CODEQL_DEPENDENCY_CACHE_VERSION = 1;
|
||||
function getJavaTempDependencyDir() {
|
||||
@@ -91067,10 +91073,17 @@ function getJavaDependencyDirs() {
|
||||
getJavaTempDependencyDir()
|
||||
];
|
||||
}
|
||||
async function makePatternCheck(patterns) {
|
||||
const globber = await makeGlobber(patterns);
|
||||
if ((await globber.glob()).length === 0) {
|
||||
throw new NoMatchingFilesError();
|
||||
}
|
||||
return patterns;
|
||||
}
|
||||
var defaultCacheConfigs = {
|
||||
java: {
|
||||
getDependencyPaths: getJavaDependencyDirs,
|
||||
getHashPatterns: async () => [
|
||||
getHashPatterns: async () => makePatternCheck([
|
||||
// Maven
|
||||
"**/pom.xml",
|
||||
// Gradle
|
||||
@@ -91080,25 +91093,38 @@ var defaultCacheConfigs = {
|
||||
"buildSrc/**/Dependencies.kt",
|
||||
"gradle/*.versions.toml",
|
||||
"**/versions.properties"
|
||||
]
|
||||
])
|
||||
},
|
||||
csharp: {
|
||||
getDependencyPaths: () => [(0, import_path.join)(os3.homedir(), ".nuget", "packages")],
|
||||
getHashPatterns: async () => [
|
||||
getHashPatterns: async () => makePatternCheck([
|
||||
// NuGet
|
||||
"**/packages.lock.json",
|
||||
// Paket
|
||||
"**/paket.lock"
|
||||
]
|
||||
])
|
||||
},
|
||||
go: {
|
||||
getDependencyPaths: () => [(0, import_path.join)(os3.homedir(), "go", "pkg", "mod")],
|
||||
getHashPatterns: async () => ["**/go.sum"]
|
||||
getHashPatterns: async () => makePatternCheck(["**/go.sum"])
|
||||
}
|
||||
};
|
||||
async function makeGlobber(patterns) {
|
||||
return glob.create(patterns.join("\n"));
|
||||
}
|
||||
async function checkHashPatterns(codeql, features, language, cacheConfig, logger) {
|
||||
try {
|
||||
return cacheConfig.getHashPatterns(codeql, features);
|
||||
} catch (err) {
|
||||
if (err instanceof NoMatchingFilesError) {
|
||||
logger.info(
|
||||
`Skipping download of dependency cache for ${language} as we cannot calculate a hash for the cache key.`
|
||||
);
|
||||
return void 0;
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
async function uploadDependencyCaches(codeql, features, config, logger) {
|
||||
const status = [];
|
||||
for (const language of config.languages) {
|
||||
@@ -91109,13 +91135,14 @@ async function uploadDependencyCaches(codeql, features, config, logger) {
|
||||
);
|
||||
continue;
|
||||
}
|
||||
const patterns = await cacheConfig.getHashPatterns(codeql, features);
|
||||
const globber = await makeGlobber(patterns);
|
||||
if ((await globber.glob()).length === 0) {
|
||||
status.push({ language, result: "no-hash" /* NoHash */ });
|
||||
logger.info(
|
||||
`Skipping upload of dependency cache for ${language} as we cannot calculate a hash for the cache key.`
|
||||
);
|
||||
const patterns = await checkHashPatterns(
|
||||
codeql,
|
||||
features,
|
||||
language,
|
||||
cacheConfig,
|
||||
logger
|
||||
);
|
||||
if (patterns === void 0) {
|
||||
continue;
|
||||
}
|
||||
const size = await getTotalCacheSize(
|
||||
|
||||
50
lib/init-action.js
generated
50
lib/init-action.js
generated
@@ -87239,6 +87239,12 @@ var os2 = __toESM(require("os"));
|
||||
var import_path = require("path");
|
||||
var actionsCache3 = __toESM(require_cache3());
|
||||
var glob = __toESM(require_glob2());
|
||||
var NoMatchingFilesError = class extends Error {
|
||||
constructor(msg) {
|
||||
super(msg);
|
||||
this.name = "NoMatchingFilesError";
|
||||
}
|
||||
};
|
||||
var CODEQL_DEPENDENCY_CACHE_PREFIX = "codeql-dependencies";
|
||||
var CODEQL_DEPENDENCY_CACHE_VERSION = 1;
|
||||
function getJavaTempDependencyDir() {
|
||||
@@ -87254,10 +87260,17 @@ function getJavaDependencyDirs() {
|
||||
getJavaTempDependencyDir()
|
||||
];
|
||||
}
|
||||
async function makePatternCheck(patterns) {
|
||||
const globber = await makeGlobber(patterns);
|
||||
if ((await globber.glob()).length === 0) {
|
||||
throw new NoMatchingFilesError();
|
||||
}
|
||||
return patterns;
|
||||
}
|
||||
var defaultCacheConfigs = {
|
||||
java: {
|
||||
getDependencyPaths: getJavaDependencyDirs,
|
||||
getHashPatterns: async () => [
|
||||
getHashPatterns: async () => makePatternCheck([
|
||||
// Maven
|
||||
"**/pom.xml",
|
||||
// Gradle
|
||||
@@ -87267,25 +87280,38 @@ var defaultCacheConfigs = {
|
||||
"buildSrc/**/Dependencies.kt",
|
||||
"gradle/*.versions.toml",
|
||||
"**/versions.properties"
|
||||
]
|
||||
])
|
||||
},
|
||||
csharp: {
|
||||
getDependencyPaths: () => [(0, import_path.join)(os2.homedir(), ".nuget", "packages")],
|
||||
getHashPatterns: async () => [
|
||||
getHashPatterns: async () => makePatternCheck([
|
||||
// NuGet
|
||||
"**/packages.lock.json",
|
||||
// Paket
|
||||
"**/paket.lock"
|
||||
]
|
||||
])
|
||||
},
|
||||
go: {
|
||||
getDependencyPaths: () => [(0, import_path.join)(os2.homedir(), "go", "pkg", "mod")],
|
||||
getHashPatterns: async () => ["**/go.sum"]
|
||||
getHashPatterns: async () => makePatternCheck(["**/go.sum"])
|
||||
}
|
||||
};
|
||||
async function makeGlobber(patterns) {
|
||||
return glob.create(patterns.join("\n"));
|
||||
}
|
||||
async function checkHashPatterns(codeql, features, language, cacheConfig, logger) {
|
||||
try {
|
||||
return cacheConfig.getHashPatterns(codeql, features);
|
||||
} catch (err) {
|
||||
if (err instanceof NoMatchingFilesError) {
|
||||
logger.info(
|
||||
`Skipping download of dependency cache for ${language} as we cannot calculate a hash for the cache key.`
|
||||
);
|
||||
return void 0;
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
async function downloadDependencyCaches(codeql, features, languages, logger) {
|
||||
const status = [];
|
||||
for (const language of languages) {
|
||||
@@ -87296,13 +87322,15 @@ async function downloadDependencyCaches(codeql, features, languages, logger) {
|
||||
);
|
||||
continue;
|
||||
}
|
||||
const patterns = await cacheConfig.getHashPatterns(codeql, features);
|
||||
const globber = await makeGlobber(patterns);
|
||||
if ((await globber.glob()).length === 0) {
|
||||
const patterns = await checkHashPatterns(
|
||||
codeql,
|
||||
features,
|
||||
language,
|
||||
cacheConfig,
|
||||
logger
|
||||
);
|
||||
if (patterns === void 0) {
|
||||
status.push({ language, hit_kind: "no-hash" /* NoHash */ });
|
||||
logger.info(
|
||||
`Skipping download of dependency cache for ${language} as we cannot calculate a hash for the cache key.`
|
||||
);
|
||||
continue;
|
||||
}
|
||||
const primaryKey = await cacheKey2(codeql, features, language, patterns);
|
||||
|
||||
Reference in New Issue
Block a user