@@ -16,7 +16,7 @@ import {
1616 persistInputs,
1717} from "./actions-util";
1818import { AnalysisKind, getAnalysisKinds } from "./analyses";
19- import { getGitHubVersion } from "./api-client";
19+ import { getGitHubVersion, GitHubApiCombinedDetails } from "./api-client";
2020import {
2121 getDependencyCachingEnabled,
2222 getTotalCacheSize,
@@ -194,65 +194,70 @@ async function sendCompletedStatusReport(
194194async function run() {
195195 const startedAt = new Date();
196196 const logger = getActionsLogger();
197- initializeEnvironment(getActionVersion());
198-
199- // Make inputs accessible in the `post` step.
200- persistInputs();
201197
198+ let apiDetails: GitHubApiCombinedDetails;
202199 let config: configUtils.Config | undefined;
200+ let configFile: string | undefined;
203201 let codeql: CodeQL;
202+ let features: Features;
203+ let sourceRoot: string;
204204 let toolsDownloadStatusReport: ToolsDownloadStatusReport | undefined;
205205 let toolsFeatureFlagsValid: boolean | undefined;
206206 let toolsSource: ToolsSource;
207207 let toolsVersion: string;
208208 let zstdAvailability: ZstdAvailability | undefined;
209209
210- const apiDetails = {
211- auth: getRequiredInput("token"),
212- externalRepoAuth: getOptionalInput("external-repository-token"),
213- url: getRequiredEnvParam("GITHUB_SERVER_URL"),
214- apiURL: getRequiredEnvParam("GITHUB_API_URL"),
215- };
210+ try {
211+ initializeEnvironment(getActionVersion());
212+
213+ // Make inputs accessible in the `post` step.
214+ persistInputs();
216215
217- const gitHubVersion = await getGitHubVersion();
218- checkGitHubVersionInRange(gitHubVersion, logger);
219- checkActionVersion(getActionVersion(), gitHubVersion);
216+ apiDetails = {
217+ auth: getRequiredInput("token"),
218+ externalRepoAuth: getOptionalInput("external-repository-token"),
219+ url: getRequiredEnvParam("GITHUB_SERVER_URL"),
220+ apiURL: getRequiredEnvParam("GITHUB_API_URL"),
221+ };
220222
221- const repositoryNwo = getRepositoryNwo();
223+ const gitHubVersion = await getGitHubVersion();
224+ checkGitHubVersionInRange(gitHubVersion, logger);
225+ checkActionVersion(getActionVersion(), gitHubVersion);
222226
223- const features = new Features(
224- gitHubVersion,
225- repositoryNwo,
226- getTemporaryDirectory(),
227- logger,
228- );
227+ const repositoryNwo = getRepositoryNwo();
229228
230- // Fetch the values of known repository properties that affect us.
231- const enableRepoProps = await features.getValue(
232- Feature.UseRepositoryProperties,
233- );
234- const repositoryProperties = enableRepoProps
235- ? await loadPropertiesFromApi(gitHubVersion, logger, repositoryNwo)
236- : {};
229+ features = new Features(
230+ gitHubVersion,
231+ repositoryNwo,
232+ getTemporaryDirectory(),
233+ logger,
234+ );
235+
236+ // Fetch the values of known repository properties that affect us.
237+ const enableRepoProps = await features.getValue(
238+ Feature.UseRepositoryProperties,
239+ );
240+ const repositoryProperties = enableRepoProps
241+ ? await loadPropertiesFromApi(gitHubVersion, logger, repositoryNwo)
242+ : {};
237243
238- // Create a unique identifier for this run.
239- const jobRunUuid = uuidV4();
240- logger.info(`Job run UUID is ${jobRunUuid}.`);
241- core.exportVariable(EnvVar.JOB_RUN_UUID, jobRunUuid);
244+ // Create a unique identifier for this run.
245+ const jobRunUuid = uuidV4();
246+ logger.info(`Job run UUID is ${jobRunUuid}.`);
247+ core.exportVariable(EnvVar.JOB_RUN_UUID, jobRunUuid);
242248
243- core.exportVariable(EnvVar.INIT_ACTION_HAS_RUN, "true");
249+ core.exportVariable(EnvVar.INIT_ACTION_HAS_RUN, "true");
244250
245- const configFile = getOptionalInput("config-file");
251+ configFile = getOptionalInput("config-file");
246252
247- // path.resolve() respects the intended semantics of source-root. If
248- // source-root is relative, it is relative to the GITHUB_WORKSPACE. If
249- // source-root is absolute, it is used as given.
250- const sourceRoot = path.resolve(
251- getRequiredEnvParam("GITHUB_WORKSPACE"),
252- getOptionalInput("source-root") || "",
253- );
253+ // path.resolve() respects the intended semantics of source-root. If
254+ // source-root is relative, it is relative to the GITHUB_WORKSPACE. If
255+ // source-root is absolute, it is used as given.
256+ sourceRoot = path.resolve(
257+ getRequiredEnvParam("GITHUB_WORKSPACE"),
258+ getOptionalInput("source-root") || "",
259+ );
254260
255- try {
256261 // Parsing the `analysis-kinds` input may throw a `ConfigurationError`, which we don't want before
257262 // we have called `sendStartingStatusReport` below. However, we want the analysis kinds for that status
258263 // report. To work around this, we ignore exceptions that are thrown here and then call `getAnalysisKinds`
0 commit comments