Skip to content

Commit e9ce32d

Browse files
committed
Change order of checks in tryUploadSarifIfRunFailed
1 parent 0f3e632 commit e9ce32d

File tree

2 files changed

+36
-23
lines changed

2 files changed

+36
-23
lines changed

lib/init-action-post.js

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

src/init-action-post-helper.ts

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -125,31 +125,43 @@ async function maybeUploadFailedSarif(
125125
: {};
126126
}
127127

128+
/**
129+
* Tries to upload a SARIF file with information about the run, if it failed.
130+
*
131+
* @param config The CodeQL Action configuration.
132+
* @param repositoryNwo The name and owner of the repository.
133+
* @param features Information about enabled features.
134+
* @param logger The logger to use.
135+
* @returns The results of uploading the SARIF file for the failure.
136+
*/
128137
export async function tryUploadSarifIfRunFailed(
129138
config: Config,
130139
repositoryNwo: RepositoryNwo,
131140
features: FeatureEnablement,
132141
logger: Logger,
133142
): Promise<UploadFailedSarifResult> {
134-
// Only upload the failed SARIF to Code scanning if Code scanning is enabled.
135-
if (!isCodeScanningEnabled(config)) {
136-
return {
137-
upload_failed_run_skipped_because: "Code Scanning is not enabled.",
138-
};
139-
}
143+
// There's nothing to do here if the analysis succeeded.
140144
if (process.env[EnvVar.ANALYZE_DID_COMPLETE_SUCCESSFULLY] === "true") {
141145
return {
142146
upload_failed_run_skipped_because:
143147
"Analyze Action completed successfully",
144148
};
145149
}
150+
146151
try {
147-
return await maybeUploadFailedSarif(
148-
config,
149-
repositoryNwo,
150-
features,
151-
logger,
152-
);
152+
// Only upload the failed SARIF to Code scanning if Code scanning is enabled.
153+
if (isCodeScanningEnabled(config)) {
154+
return await maybeUploadFailedSarif(
155+
config,
156+
repositoryNwo,
157+
features,
158+
logger,
159+
);
160+
} else {
161+
return {
162+
upload_failed_run_skipped_because: "Code Scanning is not enabled.",
163+
};
164+
}
153165
} catch (e) {
154166
logger.debug(
155167
`Failed to upload a SARIF file for this failed CodeQL code scanning run. ${e}`,

0 commit comments

Comments
 (0)