Skip to content

Commit 39bbd41

Browse files
committed
Avoid getCheckoutPath
1 parent a966508 commit 39bbd41

15 files changed

Lines changed: 228 additions & 149 deletions

lib/entry-points.js

Lines changed: 53 additions & 38 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/actions-util.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ export function getActionVersion(): string {
9494
*
9595
* This will be "dynamic" for default setup workflow runs.
9696
*/
97-
export function getWorkflowEventName(env: Env = getEnv()) {
97+
export function getWorkflowEventName(env: ReadOnlyEnv = getEnv()) {
9898
return env.getRequired(ActionsEnvVars.GITHUB_EVENT_NAME);
9999
}
100100

@@ -121,7 +121,7 @@ function getRelativeScriptPath(env: Env): string {
121121
}
122122

123123
/** Returns the contents of `GITHUB_EVENT_PATH` as a JSON object. */
124-
export function getWorkflowEvent(env: Env = getEnv()): any {
124+
export function getWorkflowEvent(env: ReadOnlyEnv = getEnv()): any {
125125
const eventJsonFile = env.getRequired(ActionsEnvVars.GITHUB_EVENT_PATH);
126126
try {
127127
return JSON.parse(fs.readFileSync(eventJsonFile, "utf-8"));

src/analyze-action.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ async function run(action: ActionState<["Base", "Logger", "Env", "Actions"]>) {
406406
// Note: Take care with the ordering of this call since databases may be cleaned up
407407
// at the `overlay` or `clear` level.
408408
databaseUploadResults = await cleanupAndUploadDatabases(
409-
{ logger, features },
409+
{ ...action, features },
410410
repositoryNwo,
411411
codeql,
412412
config,

src/codeql.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1212,7 +1212,7 @@ export async function getTrapCachingExtractorConfigArgsForLang(
12121212
): Promise<string[]> {
12131213
const cacheDir = config.trapCaches[language];
12141214
if (cacheDir === undefined) return [];
1215-
const write = await isAnalyzingDefaultBranch();
1215+
const write = await isAnalyzingDefaultBranch(getEnv(), config.repositoryRoot);
12161216
return [
12171217
`-O=${language}.trap.cache.dir=${cacheDir}`,
12181218
`-O=${language}.trap.cache.bound=${TRAP_CACHE_SIZE_MB}`,

src/config-utils.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ import {
4646
makeTelemetryDiagnostic,
4747
} from "./diagnostics";
4848
import { prepareDiffInformedAnalysis } from "./diff-informed-analysis-utils";
49-
import { EnvVar } from "./environment";
49+
import { EnvVar, getEnv } from "./environment";
5050
import * as errorMessages from "./error-messages";
5151
import { Feature, FeatureEnablement, FeatureWithoutCLI } from "./feature-flags";
5252
import {
@@ -467,12 +467,18 @@ async function downloadCacheWithTime(
467467
codeQL: CodeQL,
468468
languages: Language[],
469469
logger: Logger,
470+
repositoryRoot: string | undefined,
470471
): Promise<{
471472
trapCaches: { [language: string]: string };
472473
trapCacheDownloadTime: number;
473474
}> {
474475
const start = performance.now();
475-
const trapCaches = await downloadTrapCaches(codeQL, languages, logger);
476+
const trapCaches = await downloadTrapCaches(
477+
codeQL,
478+
languages,
479+
logger,
480+
repositoryRoot,
481+
);
476482
const trapCacheDownloadTime = performance.now() - start;
477483
return { trapCaches, trapCacheDownloadTime };
478484
}
@@ -824,7 +830,7 @@ export async function checkOverlayEnablement(
824830
`Setting overlay database mode to ${overlayDatabaseMode} ` +
825831
"with caching because we are analyzing a pull request.",
826832
);
827-
} else if (await isAnalyzingDefaultBranch()) {
833+
} else if (await isAnalyzingDefaultBranch(getEnv(), repositoryRoot)) {
828834
overlayDatabaseMode = OverlayDatabaseMode.OverlayBase;
829835
logger.info(
830836
`Setting overlay database mode to ${overlayDatabaseMode} ` +
@@ -1305,6 +1311,7 @@ export async function initConfig(
13051311
inputs.codeql,
13061312
config.languages,
13071313
logger,
1314+
repositoryRoot,
13081315
);
13091316
config.trapCaches = trapCaches;
13101317
config.trapCacheDownloadTime = trapCacheDownloadTime;

src/database-upload.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export interface DatabaseUploadResult {
4646
}
4747

4848
export async function cleanupAndUploadDatabases(
49-
action: ActionState<["Logger", "FeatureFlags"]>,
49+
action: ActionState<["ReadOnlyEnv", "Logger", "FeatureFlags"]>,
5050
repositoryNwo: RepositoryNwo,
5151
codeql: CodeQL,
5252
config: Config,
@@ -81,7 +81,7 @@ export async function cleanupAndUploadDatabases(
8181
return [];
8282
}
8383

84-
if (!(await gitUtils.isAnalyzingDefaultBranch())) {
84+
if (!(await gitUtils.isAnalyzingDefaultBranch(action.env, checkoutPath))) {
8585
// We only want to upload a database if we are analyzing the default branch.
8686
logger.debug("Not analyzing default branch. Skipping upload.");
8787
return [];
@@ -113,7 +113,7 @@ export async function cleanupAndUploadDatabases(
113113
includeDiagnostics: false,
114114
});
115115
bundledDbSize = fs.statSync(bundledDb).size;
116-
const commitOid = await gitUtils.getCommitOid(checkoutPath);
116+
const commitOid = await gitUtils.getCommitOid(action.env, checkoutPath);
117117
// Upload with manual retry logic. We disable Octokit's built-in retries
118118
// because the request body is a ReadStream, which can only be consumed
119119
// once.

0 commit comments

Comments
 (0)