Hook up the front end
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import {downloadLatestRelease, runComponentDetection} from './componentDetection';
|
import {downloadLatestRelease, getManifestsFromResults, runComponentDetection} from './componentDetection';
|
||||||
|
|
||||||
test('Downloads CLI', async () => {
|
test('Downloads CLI', async () => {
|
||||||
downloadLatestRelease();
|
downloadLatestRelease();
|
||||||
@@ -7,3 +7,7 @@ test('Downloads CLI', async () => {
|
|||||||
test('Runs CLI', async () => {
|
test('Runs CLI', async () => {
|
||||||
runComponentDetection('./test');
|
runComponentDetection('./test');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('Parses CLI output', async () => {
|
||||||
|
getManifestsFromResults();
|
||||||
|
});
|
||||||
+45
-76
@@ -16,76 +16,18 @@ import dotenv from 'dotenv'
|
|||||||
import { Context } from '@actions/github/lib/context'
|
import { Context } from '@actions/github/lib/context'
|
||||||
import { unmockedModulePathPatterns } from './jest.config'
|
import { unmockedModulePathPatterns } from './jest.config'
|
||||||
dotenv.config();
|
dotenv.config();
|
||||||
|
export default class ComponentDetection {
|
||||||
|
private componentDetectionPath = './component-detection';
|
||||||
|
private outputPath = './output.json';
|
||||||
|
|
||||||
export const componentDetectionPath = './component-detection';
|
// This is the default entry point for this class.
|
||||||
const outputPath = './output.json';
|
static async scanAndGetManifests(path: string): Promise<Manifest[] | undefined> {
|
||||||
dependencyGraphs: {
|
await this.downloadLatestRelease();
|
||||||
manifest: {
|
await this.runComponentDetection(path);
|
||||||
graph: {
|
return await this.getManifestsFromResults();
|
||||||
dependencies: [],
|
|
||||||
},
|
|
||||||
explicitlyReferencedComponentIds: [],
|
|
||||||
developmentDependencies: [],
|
|
||||||
dependencies: []
|
|
||||||
}
|
}
|
||||||
},
|
|
||||||
componentsFound: [
|
|
||||||
{
|
|
||||||
locationsFoundAt: [
|
|
||||||
filePath: string
|
|
||||||
],
|
|
||||||
component: {
|
|
||||||
name: string,
|
|
||||||
version: string,
|
|
||||||
hash: string,
|
|
||||||
author: string,
|
|
||||||
type: string,
|
|
||||||
id: string,
|
|
||||||
packageUrl: {
|
|
||||||
Scheme: string,
|
|
||||||
Type: string,
|
|
||||||
Namespace: string,
|
|
||||||
Name: string,
|
|
||||||
Version: string,
|
|
||||||
Qualifiers: string,
|
|
||||||
Subpath: string
|
|
||||||
},
|
|
||||||
},
|
|
||||||
detectorId: string,
|
|
||||||
isDevelopmentDependency: boolean,
|
|
||||||
dependencyScope: string,
|
|
||||||
topLevelReferrers: [],
|
|
||||||
containerDetailIds: [],
|
|
||||||
containerLayerIds: []
|
|
||||||
}
|
|
||||||
],
|
|
||||||
detectorsInScan: [],
|
|
||||||
sourceDirectory: string,
|
|
||||||
};
|
|
||||||
*/
|
|
||||||
|
|
||||||
class ComponentDetectionPackage extends Package {
|
|
||||||
constructor(packageUrl: string, id: string, isDevelopmentDependency:boolean, topLevelReferrers: [],
|
|
||||||
locationsFoundAt: [], containerDetailIds: [], containerLayerIds: []) {
|
|
||||||
super(packageUrl);
|
|
||||||
this.id = id;
|
|
||||||
this.isDevelopmentDependency = isDevelopmentDependency;
|
|
||||||
this.toplevelReferrers = topLevelReferrers;
|
|
||||||
this.locationsFoundAt = locationsFoundAt;
|
|
||||||
this.containerDetailIds = containerDetailIds;
|
|
||||||
this.containerLayerIds = containerLayerIds;
|
|
||||||
}
|
|
||||||
id: string;
|
|
||||||
isDevelopmentDependency: boolean;
|
|
||||||
toplevelReferrers: [];
|
|
||||||
locationsFoundAt: [];
|
|
||||||
containerDetailIds: [];
|
|
||||||
containerLayerIds: [];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Get the latest release from the component-detection repo, download the tarball, and extract it
|
// Get the latest release from the component-detection repo, download the tarball, and extract it
|
||||||
export async function downloadLatestRelease() {
|
private static async downloadLatestRelease() {
|
||||||
try {
|
try {
|
||||||
const downloadURL = await getLatestReleaseURL();
|
const downloadURL = await getLatestReleaseURL();
|
||||||
const blob = await (await fetch(new URL(downloadURL))).blob();
|
const blob = await (await fetch(new URL(downloadURL))).blob();
|
||||||
@@ -105,7 +47,7 @@ export async function downloadLatestRelease() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Run the component-detection CLI on the path specified
|
// Run the component-detection CLI on the path specified
|
||||||
export async function runComponentDetection(path: string) {
|
private static async runComponentDetection(path: string) {
|
||||||
try {
|
try {
|
||||||
await exec.exec(`${componentDetectionPath} scan --SourceDirectory ${path} --ManifestFile ${outputPath}`);
|
await exec.exec(`${componentDetectionPath} scan --SourceDirectory ${path} --ManifestFile ${outputPath}`);
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
@@ -113,9 +55,7 @@ export async function runComponentDetection(path: string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static async getManifestsFromResults(): Promise<Manifest[]| undefined> {
|
||||||
|
|
||||||
export async function getManifestsFromResults(): Promise<Manifest[]| undefined> {
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Parse the result file and add the packages to the package cache
|
// Parse the result file and add the packages to the package cache
|
||||||
@@ -170,13 +110,11 @@ export async function getManifestsFromResults(): Promise<Manifest[]| undefined>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static getDependencyScope(pkg: ComponentDetectionPackage) {
|
||||||
|
|
||||||
function getDependencyScope(pkg: ComponentDetectionPackage) {
|
|
||||||
return pkg.isDevelopmentDependency ? 'development' : 'runtime'
|
return pkg.isDevelopmentDependency ? 'development' : 'runtime'
|
||||||
}
|
}
|
||||||
|
|
||||||
function makePackageUrl(packageUrlJson: any): string {
|
private static makePackageUrl(packageUrlJson: any): string {
|
||||||
var packageUrl = `${packageUrlJson.Scheme}:${packageUrlJson.Type}/`;
|
var packageUrl = `${packageUrlJson.Scheme}:${packageUrlJson.Type}/`;
|
||||||
if (packageUrlJson.Namespace) {
|
if (packageUrlJson.Namespace) {
|
||||||
packageUrl += `${packageUrlJson.Namespace.replace("@", "%40")}/`;
|
packageUrl += `${packageUrlJson.Namespace.replace("@", "%40")}/`;
|
||||||
@@ -191,7 +129,7 @@ function makePackageUrl(packageUrlJson: any): string {
|
|||||||
return packageUrl;
|
return packageUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getLatestReleaseURL(): Promise<string> {
|
private static getLatestReleaseURL(): Promise<string> {
|
||||||
const githubToken = core.getInput('token') || process.env.GITHUB_TOKEN2 || "";
|
const githubToken = core.getInput('token') || process.env.GITHUB_TOKEN2 || "";
|
||||||
const octokit = github.getOctokit(githubToken);
|
const octokit = github.getOctokit(githubToken);
|
||||||
const owner = "microsoft";
|
const owner = "microsoft";
|
||||||
@@ -210,3 +148,34 @@ async function getLatestReleaseURL(): Promise<string> {
|
|||||||
|
|
||||||
return downloadURL;
|
return downloadURL;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class ComponentDetectionPackage extends Package {
|
||||||
|
|
||||||
|
constructor(packageUrl: string, id: string, isDevelopmentDependency:boolean, topLevelReferrers: [],
|
||||||
|
locationsFoundAt: [], containerDetailIds: [], containerLayerIds: []) {
|
||||||
|
super(packageUrl);
|
||||||
|
this.id = id;
|
||||||
|
this.isDevelopmentDependency = isDevelopmentDependency;
|
||||||
|
this.toplevelReferrers = topLevelReferrers;
|
||||||
|
this.locationsFoundAt = locationsFoundAt;
|
||||||
|
this.containerDetailIds = containerDetailIds;
|
||||||
|
this.containerLayerIds = containerLayerIds;
|
||||||
|
}
|
||||||
|
id: string;
|
||||||
|
isDevelopmentDependency: boolean;
|
||||||
|
toplevelReferrers: [];
|
||||||
|
locationsFoundAt: [];
|
||||||
|
containerDetailIds: [];
|
||||||
|
containerLayerIds: [];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -10,16 +10,15 @@ import {
|
|||||||
submitSnapshot
|
submitSnapshot
|
||||||
} from '@github/dependency-submission-toolkit';
|
} from '@github/dependency-submission-toolkit';
|
||||||
|
|
||||||
import CondaParser from './condaParser';
|
import ComponentDetection from './componentDetection';
|
||||||
|
|
||||||
async function run() {
|
async function run() {
|
||||||
let manifests = CondaParser.getManifestsFromEnvironmentFiles(
|
let manifests = await ComponentDetection.scanAndGetManifests(core.getInput('path'));
|
||||||
CondaParser.searchFiles(core.getInput('filePath'), core.getInput('filePattern')));
|
|
||||||
|
|
||||||
let snapshot = new Snapshot({
|
let snapshot = new Snapshot({
|
||||||
name: "conda-dependency-submission-action",
|
name: "Component Detection",
|
||||||
version: "0.0.1",
|
version: "0.0.1",
|
||||||
url: "https://github.com/jhutchings1/conda-dependency-submission-action",
|
url: "https://github.com/jhutchings1/component-detection-action",
|
||||||
},
|
},
|
||||||
github.context,
|
github.context,
|
||||||
{
|
{
|
||||||
|
|||||||
+5
-5
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "Conda-dependency-submission-action",
|
"name": "component-detection-action",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"description": "Conda dependency submission action",
|
"description": "Component detection action",
|
||||||
"main": "index.ts",
|
"main": "index.ts",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"lint": "eslint .",
|
"lint": "eslint .",
|
||||||
@@ -11,7 +11,7 @@
|
|||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "git+https://github.com/jhutchings1/spdx-to-dependency-graph-action.git"
|
"url": "git+https://github.com/jhutchings1/component-detection-action.git"
|
||||||
},
|
},
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"GitHub",
|
"GitHub",
|
||||||
@@ -21,9 +21,9 @@
|
|||||||
"author": "",
|
"author": "",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://github.com/jhutchings1/spdx-to-dependency-graph-action/issues"
|
"url": "https://github.com/jhutchings1/component-detection-action/issues"
|
||||||
},
|
},
|
||||||
"homepage": "https://github.com/jhutchings1/spdx-to-dependency-graph-action#readme",
|
"homepage": "https://github.com/jhutchings1/component-detection-action#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "^1.10.0",
|
"@actions/core": "^1.10.0",
|
||||||
"@actions/github": "^5.1.1",
|
"@actions/github": "^5.1.1",
|
||||||
|
|||||||
Generated
+8494
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,45 @@
|
|||||||
|
{
|
||||||
|
"name": "Conda-dependency-submission-action",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "Conda dependency submission action",
|
||||||
|
"main": "index.ts",
|
||||||
|
"scripts": {
|
||||||
|
"lint": "eslint .",
|
||||||
|
"prepare": "ncc build index.ts -o dist --source-map --license licenses.txt",
|
||||||
|
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js",
|
||||||
|
"all": "npm run lint && npm run prepare && npm run test"
|
||||||
|
},
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "git+https://github.com/jhutchings1/spdx-to-dependency-graph-action.git"
|
||||||
|
},
|
||||||
|
"keywords": [
|
||||||
|
"GitHub",
|
||||||
|
"Actions",
|
||||||
|
"JavaScript"
|
||||||
|
],
|
||||||
|
"author": "",
|
||||||
|
"license": "MIT",
|
||||||
|
"bugs": {
|
||||||
|
"url": "https://github.com/jhutchings1/spdx-to-dependency-graph-action/issues"
|
||||||
|
},
|
||||||
|
"homepage": "https://github.com/jhutchings1/spdx-to-dependency-graph-action#readme",
|
||||||
|
"dependencies": {
|
||||||
|
"@actions/core": "^1.10.0",
|
||||||
|
"@actions/github": "^5.1.1",
|
||||||
|
"@github/dependency-submission-toolkit": "^1.2.7",
|
||||||
|
"cross-fetch": "^3.1.5",
|
||||||
|
"dotenv": "^16.0.3",
|
||||||
|
"fs": "^0.0.1-security",
|
||||||
|
"tar": "^6.1.13",
|
||||||
|
"yaml": "^2.2.1"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@types/glob": "^8.0.0",
|
||||||
|
"@types/jest": "^29.2.6",
|
||||||
|
"@vercel/ncc": "^0.36.0",
|
||||||
|
"eslint": "^8.29.0",
|
||||||
|
"jest": "^29.3.1",
|
||||||
|
"ts-jest": "^29.0.5"
|
||||||
|
}
|
||||||
|
}
|
||||||
+2
-1
@@ -9,7 +9,8 @@
|
|||||||
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
|
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
|
||||||
"skipLibCheck": true,
|
"skipLibCheck": true,
|
||||||
"declaration": true,
|
"declaration": true,
|
||||||
"sourceMap": true
|
"sourceMap": true,
|
||||||
|
"strictPropertyInitialization": false,
|
||||||
},
|
},
|
||||||
"exclude": [
|
"exclude": [
|
||||||
"node_modules",
|
"node_modules",
|
||||||
|
|||||||
Reference in New Issue
Block a user