Detect OS when installing
This commit is contained in:
+16
-14
@@ -38,10 +38,10 @@ export default class ComponentDetection {
|
|||||||
|
|
||||||
// Write the blob to a file
|
// Write the blob to a file
|
||||||
core.debug("Writing binary to file");
|
core.debug("Writing binary to file");
|
||||||
await fs.writeFileSync(this.componentDetectionPath, buffer, {mode: 0o777, flag: 'w'});
|
await fs.writeFileSync(this.componentDetectionPath, buffer, { mode: 0o777, flag: 'w' });
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
core.error(error);
|
core.error(error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run the component-detection CLI on the path specified
|
// Run the component-detection CLI on the path specified
|
||||||
@@ -64,21 +64,21 @@ export default class ComponentDetection {
|
|||||||
return parameters;
|
return parameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async getManifestsFromResults(): Promise<Manifest[]| undefined> {
|
public static async getManifestsFromResults(): Promise<Manifest[] | undefined> {
|
||||||
core.info("Getting manifests from results");
|
core.info("Getting manifests from results");
|
||||||
// Parse the result file and add the packages to the package cache
|
// Parse the result file and add the packages to the package cache
|
||||||
const packageCache = new PackageCache();
|
const packageCache = new PackageCache();
|
||||||
const packages: Array<ComponentDetectionPackage>= [];
|
const packages: Array<ComponentDetectionPackage> = [];
|
||||||
|
|
||||||
const results = await fs.readFileSync(this.outputPath, 'utf8');
|
const results = await fs.readFileSync(this.outputPath, 'utf8');
|
||||||
|
|
||||||
var json: any = JSON.parse(results);
|
var json: any = JSON.parse(results);
|
||||||
json.componentsFound.forEach(async (component: any) => {
|
json.componentsFound.forEach(async (component: any) => {
|
||||||
const packageUrl = ComponentDetection.makePackageUrl(component.component.packageUrl);
|
const packageUrl = ComponentDetection.makePackageUrl(component.component.packageUrl);
|
||||||
|
|
||||||
if (!packageCache.hasPackage(packageUrl)) {
|
if (!packageCache.hasPackage(packageUrl)) {
|
||||||
const pkg = new ComponentDetectionPackage(packageUrl, component.component.id,
|
const pkg = new ComponentDetectionPackage(packageUrl, component.component.id,
|
||||||
component.isDevelopmentDependency,component.topLevelReferrers,component.locationsFoundAt, component.containerDetailIds, component.containerLayerIds);
|
component.isDevelopmentDependency, component.topLevelReferrers, component.locationsFoundAt, component.containerDetailIds, component.containerLayerIds);
|
||||||
packageCache.addPackage(pkg);
|
packageCache.addPackage(pkg);
|
||||||
packages.push(pkg);
|
packages.push(pkg);
|
||||||
}
|
}
|
||||||
@@ -108,7 +108,8 @@ export default class ComponentDetection {
|
|||||||
if (pkg.topLevelReferrers.length == 0) {
|
if (pkg.topLevelReferrers.length == 0) {
|
||||||
manifests.find((manifest: Manifest) => manifest.name == location)?.addDirectDependency(pkg, ComponentDetection.getDependencyScope(pkg));
|
manifests.find((manifest: Manifest) => manifest.name == location)?.addDirectDependency(pkg, ComponentDetection.getDependencyScope(pkg));
|
||||||
} else {
|
} else {
|
||||||
manifests.find((manifest: Manifest) => manifest.name == location)?.addIndirectDependency(pkg, ComponentDetection.getDependencyScope(pkg)); }
|
manifests.find((manifest: Manifest) => manifest.name == location)?.addIndirectDependency(pkg, ComponentDetection.getDependencyScope(pkg));
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
return manifests;
|
return manifests;
|
||||||
@@ -134,7 +135,7 @@ export default class ComponentDetection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static async getLatestReleaseURL(): Promise<string> {
|
private static async getLatestReleaseURL(): Promise<string> {
|
||||||
const githubToken = core.getInput('token') || process.env.GITHUB_TOKEN || "";
|
const githubToken = core.getInput('token') || process.env.GITHUB_TOKEN || "";
|
||||||
const octokit = github.getOctokit(githubToken);
|
const octokit = github.getOctokit(githubToken);
|
||||||
const owner = "microsoft";
|
const owner = "microsoft";
|
||||||
const repo = "component-detection";
|
const repo = "component-detection";
|
||||||
@@ -144,8 +145,9 @@ export default class ComponentDetection {
|
|||||||
});
|
});
|
||||||
|
|
||||||
var downloadURL: string = "";
|
var downloadURL: string = "";
|
||||||
|
const assetName = process.platform === "win32" ? "component-detection-win-x64.exe" : "component-detection-linux-x64";
|
||||||
latestRelease.data.assets.forEach((asset: any) => {
|
latestRelease.data.assets.forEach((asset: any) => {
|
||||||
if (asset.name === "component-detection-linux-x64") {
|
if (asset.name === assetName) {
|
||||||
downloadURL = asset.browser_download_url;
|
downloadURL = asset.browser_download_url;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -155,8 +157,8 @@ export default class ComponentDetection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class ComponentDetectionPackage extends Package {
|
class ComponentDetectionPackage extends Package {
|
||||||
|
|
||||||
constructor(packageUrl: string, public id: string, public isDevelopmentDependency:boolean, public topLevelReferrers: [],
|
constructor(packageUrl: string, public id: string, public isDevelopmentDependency: boolean, public topLevelReferrers: [],
|
||||||
public locationsFoundAt: [], public containerDetailIds: [], public containerLayerIds: []) {
|
public locationsFoundAt: [], public containerDetailIds: [], public containerLayerIds: []) {
|
||||||
super(packageUrl);
|
super(packageUrl);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user