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

67 lines
1.9 KiB
TypeScript
Raw Normal View History

2023-01-20 01:43:53 +00:00
import * as core from '@actions/core';
import * as github from '@actions/github';
2022-08-25 09:12:00 -07:00
2022-08-25 11:50:14 -07:00
import {
PackageCache,
BuildTarget,
Package,
Snapshot,
2022-10-04 13:16:36 -07:00
Manifest,
2022-08-25 11:50:14 -07:00
submitSnapshot
2023-01-20 00:41:22 +00:00
} from '@github/dependency-submission-toolkit';
2022-08-25 09:12:00 -07:00
2023-01-22 01:06:08 +00:00
import ComponentDetection from './componentDetection';
2023-01-20 00:05:59 +00:00
2022-08-25 09:12:00 -07:00
async function run() {
2025-06-16 11:03:28 +01:00
let manifests = await ComponentDetection.scanAndGetManifests(
core.getInput("filePath")
);
const correlatorInput =
core.getInput("correlator")?.trim() || github.context.job;
// Get detector configuration inputs
const detectorName = core.getInput("detector-name")?.trim();
const detectorVersion = core.getInput("detector-version")?.trim();
const detectorUrl = core.getInput("detector-url")?.trim();
// Validate that if any detector config is provided, all must be provided
const hasAnyDetectorInput = detectorName || detectorVersion || detectorUrl;
const hasAllDetectorInputs = detectorName && detectorVersion && detectorUrl;
if (hasAnyDetectorInput && !hasAllDetectorInputs) {
core.setFailed(
"If any detector configuration is provided (detector-name, detector-version, detector-url), all three must be provided."
);
return;
}
// Use provided detector config or defaults
const detector = hasAllDetectorInputs
? {
name: detectorName,
version: detectorVersion,
url: detectorUrl,
}
: {
name: "Component Detection",
version: "0.0.1",
url: "https://github.com/advanced-security/component-detection-dependency-submission-action",
};
let snapshot = new Snapshot(detector, github.context, {
2025-04-03 05:21:10 +00:00
correlator: correlatorInput,
2025-06-16 11:03:28 +01:00
id: github.context.runId.toString(),
2022-08-25 11:50:14 -07:00
});
2023-01-22 08:20:54 +00:00
core.debug(`Manifests: ${manifests?.length}`);
2025-06-16 11:03:28 +01:00
manifests?.forEach((manifest) => {
2023-01-22 08:20:54 +00:00
core.debug(`Manifest: ${JSON.stringify(manifest)}`);
2022-08-25 12:49:25 -07:00
snapshot.addManifest(manifest);
2022-08-25 11:50:14 -07:00
});
submitSnapshot(snapshot);
}
2022-08-25 09:12:00 -07:00
run();