Merge pull request #1139 from github/aeisenberg/concat-not-push

Use concat instead of push around `listFolders`
This commit is contained in:
Andrew Eisenberg 2022-07-13 02:39:34 -07:00 committed by GitHub
commit 548f07e307
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 12 deletions

10
lib/analyze-action.js generated
View file

@ -91,13 +91,13 @@ async function run() {
const codeql = await (0, codeql_1.getCodeQL)(config.codeQLCmd); const codeql = await (0, codeql_1.getCodeQL)(config.codeQLCmd);
if (config.debugMode) { if (config.debugMode) {
// Upload the logs as an Actions artifact for debugging // Upload the logs as an Actions artifact for debugging
const toUpload = []; let toUpload = [];
for (const language of config.languages) { for (const language of config.languages) {
toUpload.push(...listFolder(path.resolve(util.getCodeQLDatabasePath(config, language), "log"))); toUpload = toUpload.concat(listFolder(path.resolve(util.getCodeQLDatabasePath(config, language), "log")));
} }
if (await (0, util_1.codeQlVersionAbove)(codeql, codeql_1.CODEQL_VERSION_NEW_TRACING)) { if (await (0, util_1.codeQlVersionAbove)(codeql, codeql_1.CODEQL_VERSION_NEW_TRACING)) {
// Multilanguage tracing: there are additional logs in the root of the cluster // Multilanguage tracing: there are additional logs in the root of the cluster
toUpload.push(...listFolder(path.resolve(config.dbLocation, "log"))); toUpload = toUpload.concat(listFolder(path.resolve(config.dbLocation, "log")));
} }
await uploadDebugArtifacts(toUpload, config.dbLocation, config.debugArtifactName); await uploadDebugArtifacts(toUpload, config.dbLocation, config.debugArtifactName);
if (!(await (0, util_1.codeQlVersionAbove)(codeql, codeql_1.CODEQL_VERSION_NEW_TRACING))) { if (!(await (0, util_1.codeQlVersionAbove)(codeql, codeql_1.CODEQL_VERSION_NEW_TRACING))) {
@ -204,13 +204,13 @@ async function uploadDebugArtifacts(toUpload, rootDir, artifactName) {
} }
function listFolder(dir) { function listFolder(dir) {
const entries = fs.readdirSync(dir, { withFileTypes: true }); const entries = fs.readdirSync(dir, { withFileTypes: true });
const files = []; let files = [];
for (const entry of entries) { for (const entry of entries) {
if (entry.isFile()) { if (entry.isFile()) {
files.push(path.resolve(dir, entry.name)); files.push(path.resolve(dir, entry.name));
} }
else if (entry.isDirectory()) { else if (entry.isDirectory()) {
files.push(...listFolder(path.resolve(dir, entry.name))); files = files.concat(listFolder(path.resolve(dir, entry.name)));
} }
} }
return files; return files;

File diff suppressed because one or more lines are too long

View file

@ -151,17 +151,19 @@ async function run() {
if (config.debugMode) { if (config.debugMode) {
// Upload the logs as an Actions artifact for debugging // Upload the logs as an Actions artifact for debugging
const toUpload: string[] = []; let toUpload: string[] = [];
for (const language of config.languages) { for (const language of config.languages) {
toUpload.push( toUpload = toUpload.concat(
...listFolder( listFolder(
path.resolve(util.getCodeQLDatabasePath(config, language), "log") path.resolve(util.getCodeQLDatabasePath(config, language), "log")
) )
); );
} }
if (await codeQlVersionAbove(codeql, CODEQL_VERSION_NEW_TRACING)) { if (await codeQlVersionAbove(codeql, CODEQL_VERSION_NEW_TRACING)) {
// Multilanguage tracing: there are additional logs in the root of the cluster // Multilanguage tracing: there are additional logs in the root of the cluster
toUpload.push(...listFolder(path.resolve(config.dbLocation, "log"))); toUpload = toUpload.concat(
listFolder(path.resolve(config.dbLocation, "log"))
);
} }
await uploadDebugArtifacts( await uploadDebugArtifacts(
toUpload, toUpload,
@ -319,12 +321,12 @@ async function uploadDebugArtifacts(
function listFolder(dir: string): string[] { function listFolder(dir: string): string[] {
const entries = fs.readdirSync(dir, { withFileTypes: true }); const entries = fs.readdirSync(dir, { withFileTypes: true });
const files: string[] = []; let files: string[] = [];
for (const entry of entries) { for (const entry of entries) {
if (entry.isFile()) { if (entry.isFile()) {
files.push(path.resolve(dir, entry.name)); files.push(path.resolve(dir, entry.name));
} else if (entry.isDirectory()) { } else if (entry.isDirectory()) {
files.push(...listFolder(path.resolve(dir, entry.name))); files = files.concat(listFolder(path.resolve(dir, entry.name)));
} }
} }
return files; return files;