-
Notifications
You must be signed in to change notification settings - Fork 451
Refactor: prepare debug artifacts for artifact upgrades
#2475
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
b296f26
c098b25
4ba2440
82ce313
d4bfd40
cb7faf5
e771680
bc660fc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
Previously, we uploaded SARIF artifacts in the `analyze-post` step and database and log artifacts in the `init-post` step. As we migrate to the updated `artifact` dependencies, we want to switch to uploading all artifacts in one step. In order to upload all artifacts in one go and maintain the artifacts at the root of the debug directory, we first move SARIF artifacts to the database directory. This should not affect any other consumers of the SARIF file as this occurs in the `init-post` step.
- Loading branch information
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -10,6 +10,7 @@ import { getRequiredInput } from "./actions-util"; | |||||
| import { dbIsFinalized } from "./analyze"; | ||||||
| import { getCodeQL } from "./codeql"; | ||||||
| import { Config } from "./config-utils"; | ||||||
| import { EnvVar } from "./environment"; | ||||||
| import { Language } from "./languages"; | ||||||
| import { Logger } from "./logging"; | ||||||
| import { | ||||||
|
|
@@ -23,6 +24,67 @@ export function sanitizeArifactName(name: string): string { | |||||
| return name.replace(/[^a-zA-Z0-9_\\-]+/g, ""); | ||||||
| } | ||||||
|
|
||||||
| export async function uploadAllAvailableDebugArtifacts( | ||||||
| config: Config, | ||||||
| logger: Logger, | ||||||
| ) { | ||||||
| let filesToUpload: string[] = []; | ||||||
|
|
||||||
| const analyzeActionOutputDir = process.env[EnvVar.SARIF_RESULTS_OUTPUT_DIR]; | ||||||
| for (const lang of config.languages) { | ||||||
| // Add any SARIF files, if they exist | ||||||
| if ( | ||||||
| analyzeActionOutputDir !== undefined && | ||||||
| fs.existsSync(analyzeActionOutputDir) && | ||||||
| fs.lstatSync(analyzeActionOutputDir).isDirectory() | ||||||
| ) { | ||||||
| const sarifFile = path.resolve(analyzeActionOutputDir, `${lang}.sarif`); | ||||||
| // Move SARIF to DB location so that they can be uploaded with the same root directory as the other artifacts. | ||||||
| if (fs.existsSync(sarifFile)) { | ||||||
| const sarifInDbLocation = path.resolve( | ||||||
| config.dbLocation, | ||||||
| `${lang}.sarif`, | ||||||
| ); | ||||||
| fs.renameSync(sarifFile, sarifInDbLocation); | ||||||
|
henrymercer marked this conversation as resolved.
Outdated
|
||||||
| filesToUpload = filesToUpload.concat(sarifInDbLocation); | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. minor: Avoids reassigning a variable and the declaration above can be turned into a
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, makes sense — I had been meaning to make this change!
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there any reason to use the |
||||||
| } | ||||||
| } | ||||||
|
|
||||||
| // Add any log files | ||||||
| const databaseDirectory = getCodeQLDatabasePath(config, lang); | ||||||
| const logsDirectory = path.resolve(databaseDirectory, "log"); | ||||||
| if (doesDirectoryExist(logsDirectory)) { | ||||||
| filesToUpload = filesToUpload.concat(listFolder(logsDirectory)); | ||||||
|
angelapwen marked this conversation as resolved.
Outdated
|
||||||
| } | ||||||
|
|
||||||
| // Multilanguage tracing: there are additional logs in the root of the cluster | ||||||
| const multiLanguageTracingLogsDirectory = path.resolve( | ||||||
| config.dbLocation, | ||||||
| "log", | ||||||
| ); | ||||||
| if (doesDirectoryExist(multiLanguageTracingLogsDirectory)) { | ||||||
| filesToUpload = filesToUpload.concat( | ||||||
| listFolder(multiLanguageTracingLogsDirectory), | ||||||
| ); | ||||||
| } | ||||||
|
|
||||||
| // Add database bundle | ||||||
| let databaseBundlePath: string; | ||||||
| if (!dbIsFinalized(config, lang, logger)) { | ||||||
| databaseBundlePath = await createPartialDatabaseBundle(config, lang); | ||||||
| } else { | ||||||
| databaseBundlePath = await createDatabaseBundleCli(config, lang); | ||||||
| } | ||||||
| filesToUpload = filesToUpload.concat(databaseBundlePath); | ||||||
| } | ||||||
|
|
||||||
| await uploadDebugArtifacts( | ||||||
| filesToUpload, | ||||||
| config.dbLocation, | ||||||
| config.debugArtifactName, | ||||||
| ); | ||||||
| } | ||||||
|
|
||||||
| export async function uploadDebugArtifacts( | ||||||
| toUpload: string[], | ||||||
| rootDir: string, | ||||||
|
|
@@ -63,50 +125,6 @@ export async function uploadDebugArtifacts( | |||||
| } | ||||||
| } | ||||||
|
|
||||||
| export async function uploadSarifDebugArtifact( | ||||||
| config: Config, | ||||||
| outputDir: string, | ||||||
| ) { | ||||||
| if (!doesDirectoryExist(outputDir)) { | ||||||
| return; | ||||||
| } | ||||||
|
|
||||||
| let toUpload: string[] = []; | ||||||
| for (const lang of config.languages) { | ||||||
| const sarifFile = path.resolve(outputDir, `${lang}.sarif`); | ||||||
| if (fs.existsSync(sarifFile)) { | ||||||
| toUpload = toUpload.concat(sarifFile); | ||||||
| } | ||||||
| } | ||||||
| await uploadDebugArtifacts(toUpload, outputDir, config.debugArtifactName); | ||||||
| } | ||||||
|
|
||||||
| export async function uploadLogsDebugArtifact(config: Config) { | ||||||
| let toUpload: string[] = []; | ||||||
| for (const language of config.languages) { | ||||||
| const databaseDirectory = getCodeQLDatabasePath(config, language); | ||||||
| const logsDirectory = path.resolve(databaseDirectory, "log"); | ||||||
| if (doesDirectoryExist(logsDirectory)) { | ||||||
| toUpload = toUpload.concat(listFolder(logsDirectory)); | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| // Multilanguage tracing: there are additional logs in the root of the cluster | ||||||
| const multiLanguageTracingLogsDirectory = path.resolve( | ||||||
| config.dbLocation, | ||||||
| "log", | ||||||
| ); | ||||||
| if (doesDirectoryExist(multiLanguageTracingLogsDirectory)) { | ||||||
| toUpload = toUpload.concat(listFolder(multiLanguageTracingLogsDirectory)); | ||||||
| } | ||||||
|
|
||||||
| await uploadDebugArtifacts( | ||||||
| toUpload, | ||||||
| config.dbLocation, | ||||||
| config.debugArtifactName, | ||||||
| ); | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * If a database has not been finalized, we cannot run the `codeql database bundle` | ||||||
| * command in the CLI because it will return an error. Instead we directly zip | ||||||
|
|
@@ -150,31 +168,3 @@ async function createDatabaseBundleCli( | |||||
| ); | ||||||
| return databaseBundlePath; | ||||||
| } | ||||||
|
|
||||||
| export async function uploadDatabaseBundleDebugArtifact( | ||||||
| config: Config, | ||||||
| logger: Logger, | ||||||
| ) { | ||||||
| for (const language of config.languages) { | ||||||
| try { | ||||||
| let databaseBundlePath: string; | ||||||
| if (!dbIsFinalized(config, language, logger)) { | ||||||
| databaseBundlePath = await createPartialDatabaseBundle( | ||||||
| config, | ||||||
| language, | ||||||
| ); | ||||||
| } else { | ||||||
| databaseBundlePath = await createDatabaseBundleCli(config, language); | ||||||
| } | ||||||
| await uploadDebugArtifacts( | ||||||
| [databaseBundlePath], | ||||||
| config.dbLocation, | ||||||
| config.debugArtifactName, | ||||||
| ); | ||||||
| } catch (error) { | ||||||
| core.info( | ||||||
| `Failed to upload database debug bundle for ${config.debugDatabaseName}-${language}: ${error}`, | ||||||
| ); | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
Uh oh!
There was an error while loading. Please reload this page.