Skip to content

Commit 8e921c3

Browse files
committed
Return status report from cleanupAndUploadDatabases
1 parent 52f930e commit 8e921c3

File tree

3 files changed

+72
-16
lines changed

3 files changed

+72
-16
lines changed

lib/analyze-action.js

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

package-lock.json

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

src/database-upload.ts

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,29 +13,43 @@ import { RepositoryNwo } from "./repository";
1313
import * as util from "./util";
1414
import { bundleDb, CleanupLevel, parseGitHubUrl } from "./util";
1515

16+
/** Status report for a database upload. */
17+
interface DatabaseUploadReport {
18+
/** Language of the database. */
19+
language: string;
20+
/** Size of the zipped database in bytes. */
21+
zipped_upload_size_bytes?: number;
22+
/** Whether the uploaded database is an overlay base. */
23+
is_overlay_base?: boolean;
24+
/** Time taken to upload database in milliseconds. */
25+
upload_duration_ms?: number;
26+
/** If there was an error during database upload, this is its message. */
27+
error?: string;
28+
}
29+
1630
export async function cleanupAndUploadDatabases(
1731
repositoryNwo: RepositoryNwo,
1832
codeql: CodeQL,
1933
config: Config,
2034
apiDetails: GitHubApiDetails,
2135
features: FeatureEnablement,
2236
logger: Logger,
23-
): Promise<void> {
37+
): Promise<DatabaseUploadReport[]> {
2438
if (actionsUtil.getRequiredInput("upload-database") !== "true") {
2539
logger.debug("Database upload disabled in workflow. Skipping upload.");
26-
return;
40+
return [];
2741
}
2842

2943
if (!config.analysisKinds.includes(AnalysisKind.CodeScanning)) {
3044
logger.debug(
3145
`Not uploading database because 'analysis-kinds: ${AnalysisKind.CodeScanning}' is not enabled.`,
3246
);
33-
return;
47+
return [];
3448
}
3549

3650
if (util.isInTestMode()) {
3751
logger.debug("In test mode. Skipping database upload.");
38-
return;
52+
return [];
3953
}
4054

4155
// Do nothing when not running against github.com
@@ -44,20 +58,22 @@ export async function cleanupAndUploadDatabases(
4458
config.gitHubVersion.type !== util.GitHubVariant.GHE_DOTCOM
4559
) {
4660
logger.debug("Not running against github.com or GHEC-DR. Skipping upload.");
47-
return;
61+
return [];
4862
}
4963

5064
if (!(await gitUtils.isAnalyzingDefaultBranch())) {
5165
// We only want to upload a database if we are analyzing the default branch.
5266
logger.debug("Not analyzing default branch. Skipping upload.");
53-
return;
67+
return [];
5468
}
5569

56-
const cleanupLevel =
70+
// If config.overlayDatabaseMode is OverlayBase, then we have overlay base databases for all languages.
71+
const isOverlayBase =
5772
config.overlayDatabaseMode === OverlayDatabaseMode.OverlayBase &&
58-
(await features.getValue(Feature.UploadOverlayDbToApi))
59-
? CleanupLevel.Overlay
60-
: CleanupLevel.Clear;
73+
(await features.getValue(Feature.UploadOverlayDbToApi));
74+
const cleanupLevel = isOverlayBase
75+
? CleanupLevel.Overlay
76+
: CleanupLevel.Clear;
6177

6278
// Clean up the database, since intermediate results may still be written to the
6379
// database if there is high RAM pressure.
@@ -77,6 +93,7 @@ export async function cleanupAndUploadDatabases(
7793
uploadsBaseUrl = uploadsBaseUrl.slice(0, -1);
7894
}
7995

96+
const reports: DatabaseUploadReport[] = [];
8097
for (const language of config.languages) {
8198
try {
8299
// Upload the database bundle.
@@ -90,6 +107,7 @@ export async function cleanupAndUploadDatabases(
90107
actionsUtil.getRequiredInput("checkout_path"),
91108
);
92109
try {
110+
const startTime = Date.now();
93111
await client.request(
94112
`POST /repos/:owner/:repo/code-scanning/codeql/databases/:language?name=:name&commit_oid=:commit_oid`,
95113
{
@@ -107,13 +125,25 @@ export async function cleanupAndUploadDatabases(
107125
},
108126
},
109127
);
128+
const endTime = Date.now();
129+
reports.push({
130+
language,
131+
zipped_upload_size_bytes: bundledDbSize,
132+
is_overlay_base: isOverlayBase,
133+
upload_duration_ms: endTime - startTime,
134+
});
110135
logger.debug(`Successfully uploaded database for ${language}`);
111136
} finally {
112137
bundledDbReadStream.close();
113138
}
114139
} catch (e) {
115140
// Log a warning but don't fail the workflow
116141
logger.warning(`Failed to upload database for ${language}: ${e}`);
142+
reports.push({
143+
language,
144+
error: util.getErrorMessage(e),
145+
});
117146
}
118147
}
148+
return reports;
119149
}

0 commit comments

Comments
 (0)