Stub component detection download and execution
This commit is contained in:
@@ -1,43 +1,59 @@
|
||||
import * as github from '@actions/github'
|
||||
import * as core from '@actions/core'
|
||||
import fetch from 'node-fetch'
|
||||
import fetch from 'cross-fetch'
|
||||
import tar from 'tar'
|
||||
import fs from 'fs'
|
||||
import dotenv from 'dotenv'
|
||||
dotenv.config();
|
||||
|
||||
// Get the latest release from the component-detection repo, download the tarball, and extract it
|
||||
export async function downloadLatestRelease() {
|
||||
const githubToken = core.getInput('token') || (await core.getIDToken());
|
||||
const octokit = github.getOctokit(githubToken);
|
||||
const owner = "microsoft";
|
||||
const repo = "component-detection";
|
||||
import * as exec from '@actions/exec';
|
||||
|
||||
try {
|
||||
octokit.rest.repos.getLatestRelease({
|
||||
owner, repo
|
||||
}).then((response) => {
|
||||
fetch(response.data.assets[0].browser_download_url).then((response) => {
|
||||
response.json().then((data) => {
|
||||
// Write the tarball to a file
|
||||
fs.writeFile('component-detection.tar.gz', data, (err: any) => {
|
||||
if (err) {
|
||||
core.error(err);
|
||||
}
|
||||
});
|
||||
|
||||
// Extract the tarball
|
||||
tar.x({
|
||||
file: 'component-detection.tar.gz',
|
||||
C: './'
|
||||
}).then(() => {
|
||||
core.info('Extracted tarball');
|
||||
}
|
||||
})
|
||||
})
|
||||
});
|
||||
} catch (error: any) {
|
||||
core.error(error);
|
||||
}
|
||||
export const componentDetectionPath = './component-detection';
|
||||
// Get the latest release from the component-detection repo, download the tarball, and extract it
|
||||
export async function downloadLatestRelease() {
|
||||
try {
|
||||
const downloadURL = await getLatestReleaseURL();
|
||||
const blob = await (await fetch(new URL(downloadURL))).blob();
|
||||
const arrayBuffer = await blob.arrayBuffer();
|
||||
const buffer = Buffer.from(arrayBuffer);
|
||||
|
||||
// Write the blob to a file
|
||||
await fs.writeFile(componentDetectionPath, buffer, {mode: 0o777, flag: 'w'},
|
||||
(err: any) => {
|
||||
if (err) {
|
||||
core.error(err);
|
||||
}
|
||||
});
|
||||
} catch (error: any) {
|
||||
core.error(error);
|
||||
}
|
||||
}
|
||||
|
||||
// Run the component-detection CLI on the path specified
|
||||
export async function runComponentDetection(path: string) {
|
||||
try {
|
||||
await exec.exec(`${componentDetectionPath} ${path}`);
|
||||
} catch (error: any) {
|
||||
core.error(error);
|
||||
}
|
||||
}
|
||||
|
||||
async function getLatestReleaseURL(): Promise<string> {
|
||||
const githubToken = core.getInput('token') || process.env.GITHUB_TOKEN2 || "";
|
||||
const octokit = github.getOctokit(githubToken);
|
||||
const owner = "microsoft";
|
||||
const repo = "component-detection";
|
||||
|
||||
const latestRelease = await octokit.rest.repos.getLatestRelease({
|
||||
owner, repo
|
||||
});
|
||||
|
||||
var downloadURL: string = "";
|
||||
latestRelease.data.assets.forEach((asset: any) => {
|
||||
if (asset.name === "component-detection-linux-x64") {
|
||||
downloadURL = asset.browser_download_url;
|
||||
}
|
||||
});
|
||||
|
||||
return downloadURL;
|
||||
}
|
||||
Reference in New Issue
Block a user