Factor out reimplementation of toolcache download into its own method.
This commit is contained in:
parent
f4e72f4a09
commit
175d681835
3 changed files with 38 additions and 29 deletions
30
lib/codeql.js
generated
30
lib/codeql.js
generated
|
|
@ -94,6 +94,22 @@ async function getCodeQLBundleDownloadURL() {
|
||||||
}
|
}
|
||||||
return `https://github.com/${CODEQL_DEFAULT_ACTION_REPOSITORY}/releases/download/${CODEQL_DEFAULT_BUNDLE_VERSION}/${CODEQL_DEFAULT_BUNDLE_NAME}`;
|
return `https://github.com/${CODEQL_DEFAULT_ACTION_REPOSITORY}/releases/download/${CODEQL_DEFAULT_BUNDLE_VERSION}/${CODEQL_DEFAULT_BUNDLE_NAME}`;
|
||||||
}
|
}
|
||||||
|
// We have to download CodeQL manually because the toolcache doesn't support Accept headers.
|
||||||
|
// This can be removed once https://github.com/actions/toolkit/pull/530 is merged and released.
|
||||||
|
async function toolcacheDownloadTool(url, headers) {
|
||||||
|
const client = new http.HttpClient('CodeQL Action');
|
||||||
|
const dest = path.join(util.getRequiredEnvParam('RUNNER_TEMP'), v4_1.default());
|
||||||
|
const response = await client.get(url, headers);
|
||||||
|
if (response.message.statusCode !== 200) {
|
||||||
|
const err = new toolcache.HTTPError(response.message.statusCode);
|
||||||
|
core.info(`Failed to download from "${url}". Code(${response.message.statusCode}) Message(${response.message.statusMessage})`);
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
const pipeline = globalutil.promisify(stream.pipeline);
|
||||||
|
await io.mkdirP(path.dirname(dest));
|
||||||
|
await pipeline(response.message, fs.createWriteStream(dest));
|
||||||
|
return dest;
|
||||||
|
}
|
||||||
async function setupCodeQL() {
|
async function setupCodeQL() {
|
||||||
try {
|
try {
|
||||||
let codeqlURL = core.getInput('tools');
|
let codeqlURL = core.getInput('tools');
|
||||||
|
|
@ -106,10 +122,6 @@ async function setupCodeQL() {
|
||||||
if (!codeqlURL) {
|
if (!codeqlURL) {
|
||||||
codeqlURL = await getCodeQLBundleDownloadURL();
|
codeqlURL = await getCodeQLBundleDownloadURL();
|
||||||
}
|
}
|
||||||
// We have to download CodeQL manually because the toolcache doesn't support Accept headers.
|
|
||||||
// This can be changed to a one-liner once https://github.com/actions/toolkit/pull/530 is merged and released.
|
|
||||||
const client = new http.HttpClient('CodeQL Action');
|
|
||||||
const codeqlPath = path.join(util.getRequiredEnvParam('RUNNER_TEMP'), v4_1.default());
|
|
||||||
const headers = { accept: 'application/octet-stream' };
|
const headers = { accept: 'application/octet-stream' };
|
||||||
// We only want to provide an authorization header if we are downloading
|
// We only want to provide an authorization header if we are downloading
|
||||||
// from the same GitHub instance the Action is running on.
|
// from the same GitHub instance the Action is running on.
|
||||||
|
|
@ -122,15 +134,7 @@ async function setupCodeQL() {
|
||||||
else {
|
else {
|
||||||
core.debug('Downloading CodeQL bundle without token.');
|
core.debug('Downloading CodeQL bundle without token.');
|
||||||
}
|
}
|
||||||
const response = await client.get(codeqlURL, headers);
|
let codeqlPath = await toolcacheDownloadTool(codeqlURL, headers);
|
||||||
if (response.message.statusCode !== 200) {
|
|
||||||
const err = new toolcache.HTTPError(response.message.statusCode);
|
|
||||||
core.info(`Failed to download from "${codeqlURL}". Code(${response.message.statusCode}) Message(${response.message.statusMessage})`);
|
|
||||||
throw err;
|
|
||||||
}
|
|
||||||
const pipeline = globalutil.promisify(stream.pipeline);
|
|
||||||
await io.mkdirP(path.dirname(codeqlPath));
|
|
||||||
await pipeline(response.message, fs.createWriteStream(codeqlPath));
|
|
||||||
core.debug(`CodeQL bundle download to ${codeqlPath} complete.`);
|
core.debug(`CodeQL bundle download to ${codeqlPath} complete.`);
|
||||||
const codeqlExtracted = await toolcache.extractTar(codeqlPath);
|
const codeqlExtracted = await toolcache.extractTar(codeqlPath);
|
||||||
codeqlFolder = await toolcache.cacheDir(codeqlExtracted, 'CodeQL', codeqlURLVersion);
|
codeqlFolder = await toolcache.cacheDir(codeqlExtracted, 'CodeQL', codeqlURLVersion);
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -145,6 +145,25 @@ async function getCodeQLBundleDownloadURL(): Promise<string> {
|
||||||
return `https://github.com/${CODEQL_DEFAULT_ACTION_REPOSITORY}/releases/download/${CODEQL_DEFAULT_BUNDLE_VERSION}/${CODEQL_DEFAULT_BUNDLE_NAME}`;
|
return `https://github.com/${CODEQL_DEFAULT_ACTION_REPOSITORY}/releases/download/${CODEQL_DEFAULT_BUNDLE_VERSION}/${CODEQL_DEFAULT_BUNDLE_NAME}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// We have to download CodeQL manually because the toolcache doesn't support Accept headers.
|
||||||
|
// This can be removed once https://github.com/actions/toolkit/pull/530 is merged and released.
|
||||||
|
async function toolcacheDownloadTool(url:string, headers?: IHeaders): Promise<string> {
|
||||||
|
const client = new http.HttpClient('CodeQL Action');
|
||||||
|
const dest = path.join(util.getRequiredEnvParam('RUNNER_TEMP'), uuidV4());
|
||||||
|
const response: http.HttpClientResponse = await client.get(url, headers);
|
||||||
|
if (response.message.statusCode !== 200) {
|
||||||
|
const err = new toolcache.HTTPError(response.message.statusCode);
|
||||||
|
core.info(
|
||||||
|
`Failed to download from "${url}". Code(${response.message.statusCode}) Message(${response.message.statusMessage})`
|
||||||
|
);
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
const pipeline = globalutil.promisify(stream.pipeline);
|
||||||
|
await io.mkdirP(path.dirname(dest));
|
||||||
|
await pipeline(response.message, fs.createWriteStream(dest));
|
||||||
|
return dest;
|
||||||
|
}
|
||||||
|
|
||||||
export async function setupCodeQL(): Promise<CodeQL> {
|
export async function setupCodeQL(): Promise<CodeQL> {
|
||||||
try {
|
try {
|
||||||
let codeqlURL = core.getInput('tools');
|
let codeqlURL = core.getInput('tools');
|
||||||
|
|
@ -158,10 +177,6 @@ export async function setupCodeQL(): Promise<CodeQL> {
|
||||||
codeqlURL = await getCodeQLBundleDownloadURL();
|
codeqlURL = await getCodeQLBundleDownloadURL();
|
||||||
}
|
}
|
||||||
|
|
||||||
// We have to download CodeQL manually because the toolcache doesn't support Accept headers.
|
|
||||||
// This can be changed to a one-liner once https://github.com/actions/toolkit/pull/530 is merged and released.
|
|
||||||
const client = new http.HttpClient('CodeQL Action');
|
|
||||||
const codeqlPath = path.join(util.getRequiredEnvParam('RUNNER_TEMP'), uuidV4());
|
|
||||||
const headers: IHeaders = {accept: 'application/octet-stream'};
|
const headers: IHeaders = {accept: 'application/octet-stream'};
|
||||||
// We only want to provide an authorization header if we are downloading
|
// We only want to provide an authorization header if we are downloading
|
||||||
// from the same GitHub instance the Action is running on.
|
// from the same GitHub instance the Action is running on.
|
||||||
|
|
@ -173,17 +188,7 @@ export async function setupCodeQL(): Promise<CodeQL> {
|
||||||
} else {
|
} else {
|
||||||
core.debug('Downloading CodeQL bundle without token.');
|
core.debug('Downloading CodeQL bundle without token.');
|
||||||
}
|
}
|
||||||
const response: http.HttpClientResponse = await client.get(codeqlURL, headers);
|
let codeqlPath = await toolcacheDownloadTool(codeqlURL, headers);
|
||||||
if (response.message.statusCode !== 200) {
|
|
||||||
const err = new toolcache.HTTPError(response.message.statusCode);
|
|
||||||
core.info(
|
|
||||||
`Failed to download from "${codeqlURL}". Code(${response.message.statusCode}) Message(${response.message.statusMessage})`
|
|
||||||
);
|
|
||||||
throw err;
|
|
||||||
}
|
|
||||||
const pipeline = globalutil.promisify(stream.pipeline);
|
|
||||||
await io.mkdirP(path.dirname(codeqlPath));
|
|
||||||
await pipeline(response.message, fs.createWriteStream(codeqlPath));
|
|
||||||
core.debug(`CodeQL bundle download to ${codeqlPath} complete.`);
|
core.debug(`CodeQL bundle download to ${codeqlPath} complete.`);
|
||||||
|
|
||||||
const codeqlExtracted = await toolcache.extractTar(codeqlPath);
|
const codeqlExtracted = await toolcache.extractTar(codeqlPath);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue