Add logger to checkoutExternalRepository

This commit is contained in:
Robert Brignull 2020-09-01 13:53:59 +01:00
parent 1548b771cb
commit 8a821a9c35
9 changed files with 59 additions and 26 deletions

View file

@ -214,6 +214,7 @@ async function addRemoteQueries(
queryUses: string,
tempDir: string,
githubUrl: string,
logger: Logger,
configFile?: string) {
let tok = queryUses.split('@');
@ -241,7 +242,8 @@ async function addRemoteQueries(
nwo,
ref,
githubUrl,
tempDir);
tempDir,
logger);
const queryPath = tok.length > 2
? path.join(checkoutPath, tok.slice(2).join('/'))
@ -266,6 +268,7 @@ async function parseQueryUses(
tempDir: string,
checkoutPath: string,
githubUrl: string,
logger: Logger,
configFile?: string) {
queryUses = queryUses.trim();
@ -286,7 +289,7 @@ async function parseQueryUses(
}
// Otherwise, must be a reference to another repo
await addRemoteQueries(codeQL, resultMap, queryUses, tempDir, githubUrl, configFile);
await addRemoteQueries(codeQL, resultMap, queryUses, tempDir, githubUrl, logger, configFile);
}
// Regex validating stars in paths or paths-ignore entries.
@ -547,10 +550,19 @@ async function addQueriesFromWorkflow(
resultMap: { [language: string]: string[] },
tempDir: string,
checkoutPath: string,
githubUrl: string) {
githubUrl: string,
logger: Logger) {
for (const query of queriesInput.split(',')) {
await parseQueryUses(languages, codeQL, resultMap, query, tempDir, checkoutPath, githubUrl);
await parseQueryUses(
languages,
codeQL,
resultMap,
query,
tempDir,
checkoutPath,
githubUrl,
logger);
}
}
@ -578,7 +590,15 @@ export async function getDefaultConfig(
const queries = {};
await addDefaultQueries(codeQL, languages, queries);
if (queriesInput) {
await addQueriesFromWorkflow(codeQL, queriesInput, languages, queries, tempDir, checkoutPath, githubUrl);
await addQueriesFromWorkflow(
codeQL,
queriesInput,
languages,
queries,
tempDir,
checkoutPath,
githubUrl,
logger);
}
return {
@ -658,7 +678,15 @@ async function loadConfig(
// If queries were provided using `with` in the action configuration,
// they should take precedence over the queries in the config file
if (queriesInput) {
await addQueriesFromWorkflow(codeQL, queriesInput, languages, queries, tempDir, checkoutPath, githubUrl);
await addQueriesFromWorkflow(
codeQL,
queriesInput,
languages,
queries,
tempDir,
checkoutPath,
githubUrl,
logger);
} else if (QUERIES_PROPERTY in parsedYAML) {
if (!(parsedYAML[QUERIES_PROPERTY] instanceof Array)) {
throw new Error(getQueriesInvalid(configFile));
@ -675,6 +703,7 @@ async function loadConfig(
tempDir,
checkoutPath,
githubUrl,
logger,
configFile);
}
}

View file

@ -3,6 +3,7 @@ import * as fs from "fs";
import * as path from "path";
import * as externalQueries from "./external-queries";
import { getRunnerLogger } from './logging';
import {setupTests} from './testing-utils';
import * as util from "./util";
@ -15,7 +16,8 @@ test("checkoutExternalQueries", async t => {
"github/codeql-go",
ref,
'https://github.com',
tmpDir);
tmpDir,
getRunnerLogger(true));
// COPYRIGHT file existed in df4c6869212341b601005567381944ed90906b6b but not in the default branch
t.true(fs.existsSync(path.join(tmpDir, "github", "codeql-go", ref, "COPYRIGHT")));

View file

@ -1,8 +1,9 @@
import * as core from '@actions/core';
import * as toolrunnner from '@actions/exec/lib/toolrunner';
import * as fs from 'fs';
import * as path from 'path';
import { Logger } from './logging';
/**
* Check out repository at the given ref, and return the directory of the checkout.
*/
@ -10,9 +11,10 @@ export async function checkoutExternalRepository(
repository: string,
ref: string,
githubUrl: string,
tempDir: string): Promise<string> {
tempDir: string,
logger: Logger): Promise<string> {
core.info('Checking out ' + repository);
logger.info('Checking out ' + repository);
const checkoutLocation = path.join(tempDir, repository, ref);