Files
component-detection-depende…/index.js
T

71 lines
1.7 KiB
JavaScript
Raw Normal View History

2022-08-25 09:12:00 -07:00
const core = require('@actions/core');
2022-10-04 09:44:26 -07:00
const github = require('@actions/github');
2022-08-25 11:50:14 -07:00
const fs = require('fs');
const glob = require('glob');
2022-08-25 09:12:00 -07:00
2022-08-25 11:50:14 -07:00
import {
PackageCache,
BuildTarget,
Package,
Snapshot,
submitSnapshot
} from '@github/dependency-submission-toolkit'
2022-08-25 09:12:00 -07:00
async function run() {
2022-10-04 12:03:50 -07:00
let manifests = getManifestsFromSpdxFiles(searchFiles());
2022-08-25 11:50:14 -07:00
let snapshot = new Snapshot({
name: "spdx-to-dependency-graph-action",
version: "0.0.1",
url: "https://github.com/jhutchings1/spdx-to-dependency-graph-action",
2022-10-04 09:44:26 -07:00
},
github.context,
{
correlator:`${github.context.job}`,
id: github.context.runId.toString()
2022-08-25 11:50:14 -07:00
});
2022-08-25 12:49:25 -07:00
manifests?.forEach(manifest => {
snapshot.addManifest(manifest);
2022-08-25 11:50:14 -07:00
});
submitSnapshot(snapshot);
}
2022-10-04 09:44:26 -07:00
function getManifestFromSpdxFile(content, fileName) {
2022-10-04 11:30:52 -07:00
core.debug(`Processing ${fileName}`);
core.debug(`Content: ${content}`);
2022-08-25 12:49:25 -07:00
let manifest = new Manifest(fileName);
content.packages?.forEach(pkg => {
let packageName = pkg.packageName;
let packageVersion = pkg.packageVersion;
let purl = pkg.purl;
manifest.addPackage(new Package(packageName, packageVersion, purl));
snapshot.addManifest(manifest);
});
return manifest;
}
2022-10-04 09:44:26 -07:00
function getManifestsFromSpdxFiles(files) {
2022-10-04 12:03:50 -07:00
core.debug(`Processing ${files.length} files`);
2022-08-25 12:49:25 -07:00
let manifests = [];
files?.forEach(file => {
2022-10-04 11:51:27 -07:00
core.debug(`Processing ${file}`);
2022-08-25 11:50:14 -07:00
fs.readFile(file, (err, content) => {
2022-10-04 11:51:27 -07:00
core.debug(`Content: ${content}`);
2022-10-04 09:19:29 -07:00
manifests.push(getManifestFromSpdxFile(JSON.parse(content), file.name));
2022-08-25 11:50:14 -07:00
});
});
2022-08-25 12:49:25 -07:00
return manifests;
2022-08-25 11:50:14 -07:00
}
2022-10-04 12:03:50 -07:00
function searchFiles() {
2022-08-25 11:50:14 -07:00
let filePath = core.getInput('filePath');
let filePattern = core.getInput('filePattern');
2022-10-04 13:15:32 -07:00
return glob.sync(`${filePath}/${filePattern}`, {});
2022-08-25 09:12:00 -07:00
}
run();