Skip to content

Commit 7c72e12

Browse files
committed
Expand try-catch to cover more of Actions
1 parent 1c4c0b3 commit 7c72e12

10 files changed

+184
-172
lines changed

lib/analyze-action.js

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

lib/init-action.js

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

lib/setup-codeql-action.js

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

lib/start-proxy-action.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/upload-sarif-action.js

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

src/analyze-action.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -222,14 +222,15 @@ async function run() {
222222
let didUploadTrapCaches = false;
223223
let dependencyCacheResults: DependencyCacheUploadStatusReport | undefined;
224224
let databaseUploadResults: DatabaseUploadResult[] = [];
225-
util.initializeEnvironment(actionsUtil.getActionVersion());
226-
227-
// Make inputs accessible in the `post` step, details at
228-
// https://github.com/github/codeql-action/issues/2553
229-
actionsUtil.persistInputs();
230-
231225
const logger = getActionsLogger();
226+
232227
try {
228+
util.initializeEnvironment(actionsUtil.getActionVersion());
229+
230+
// Make inputs accessible in the `post` step, details at
231+
// https://github.com/github/codeql-action/issues/2553
232+
actionsUtil.persistInputs();
233+
233234
const statusReportBase = await createStatusReportBase(
234235
ActionName.Analyze,
235236
"starting",

src/init-action.ts

Lines changed: 47 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
persistInputs,
1717
} from "./actions-util";
1818
import { AnalysisKind, getAnalysisKinds } from "./analyses";
19-
import { getGitHubVersion } from "./api-client";
19+
import { getGitHubVersion, GitHubApiCombinedDetails } from "./api-client";
2020
import {
2121
getDependencyCachingEnabled,
2222
getTotalCacheSize,
@@ -194,65 +194,70 @@ async function sendCompletedStatusReport(
194194
async 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

Comments
 (0)