Skip to content

Commit e0dcc85

Browse files
authored
Merge pull request #117 from actions/ljones140/clean-detector-categories-pr
Add DetectorCategories input So we can run by ecosystem
2 parents 07208f2 + 4f5a062 commit e0dcc85

File tree

5 files changed

+27
-22
lines changed

5 files changed

+27
-22
lines changed

README.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Component detection dependency submission action
22

3-
This GitHub Action runs the [microsoft/component-detection](https://github.com/microsoft/component-detection) library to automate dependency extraction at build time. It uses a combination of static and dynamic scanning to build a dependency tree and then uploads that to GitHub's dependency graph via the dependency submission API. This gives you more accurate Dependabot alerts, and support for a bunch of additional ecosystems.
3+
This GitHub Action runs the [microsoft/component-detection](https://github.com/microsoft/component-detection) library to automate dependency extraction at build time. It uses a combination of static and dynamic scanning to build a dependency tree and then uploads that to GitHub's dependency graph via the dependency submission API. This gives you more accurate Dependabot alerts, and support for a bunch of additional ecosystems.
44

55
### Example workflow
66

@@ -12,7 +12,7 @@ on:
1212
workflow_dispatch:
1313
push:
1414

15-
permissions:
15+
permissions:
1616
id-token: write
1717
contents: write
1818

@@ -21,19 +21,20 @@ jobs:
2121
runs-on: ubuntu-latest
2222
steps:
2323
- uses: actions/checkout@v3
24-
- name: Component detection
24+
- name: Component detection
2525
uses: advanced-security/[email protected]
26-
```
26+
```
2727
2828
### Configuration options
2929
30-
| Parameter | Description | Example |
31-
| --- | --- | --- |
30+
| Parameter | Description | Example |
31+
| --- | --- | --- |
3232
filePath | The path to the directory containing the environment files to upload. Defaults to Actions working directory. | `'.'`
3333
directoryExclusionList | Filters out specific directories following a minimatch pattern. | `test`
3434
detectorArgs | Comma separated list of properties that can affect the detectors execution, like EnableIfDefaultOff that allows a specific detector that is in beta to run, the format for this property is DetectorId=EnableIfDefaultOff, for example Pip=EnableIfDefaultOff. | `Pip=EnableIfDefaultOff`
35-
dockerImagesToScan |Comma separated list of docker image names or hashes to execute container scanning on | ubuntu:16.04,56bab49eef2ef07505f6a1b0d5bd3a601dfc3c76ad4460f24c91d6fa298369ab |
35+
dockerImagesToScan |Comma separated list of docker image names or hashes to execute container scanning on | ubuntu:16.04,56bab49eef2ef07505f6a1b0d5bd3a601dfc3c76ad4460f24c91d6fa298369ab |
3636
detectorsFilter | A comma separated list with the identifiers of the specific detectors to be used. | `Pip, RustCrateDetector`
37+
detectorsCategories | A comma separated list with the categories of components that are going to be scanned. The detectors that are going to run are the ones that belongs to the categories. | `NuGet,Npm`
3738
correlator | An optional identifier to distinguish between multiple dependency snapshots of the same type. Defaults to the [job_id](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_id) of the current job | `csharp-backend`
3839

3940
For more information: https://github.com/microsoft/component-detection

action.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ inputs:
55
description: "GitHub Personal Access Token (PAT). Defaults to PAT provided by Actions runner."
66
required: false
77
default: ${{ github.token }}
8-
filePath:
8+
filePath:
99
description: 'The path to the directory containing the environment files to upload. Defaults to Actions working directory.'
1010
required: false
1111
default: '.'
@@ -18,12 +18,14 @@ inputs:
1818
dockerImagesToScan:
1919
description: 'Comma separated list of docker image names or hashes to execute container scanning on, ex: ubuntu:16.04,56bab49eef2ef07505f6a1b0d5bd3a601dfc3c76ad4460f24c91d6fa298369ab'
2020
required: false
21-
detectorsFilter:
21+
detectorsFilter:
2222
description: 'A comma separated list with the identifiers of the specific detectors to be used. This is meant to be used for testing purposes only.'
2323
required: false
24+
detectorsCategories:
25+
description: 'A comma separated list with the categories of components that are going to be scanned. The detectors that are going to run are the ones that belongs to the categories. The possible values are: Npm, NuGet, Maven, RubyGems, Cargo, Pip, GoMod, CocoaPods, Linux.'
26+
required: false
2427
correlator:
2528
description: 'An optional identifier to distinguish between multiple dependency snapshots of the same type.'
26-
type: string
2729
required: false
2830
runs:
2931
using: 'node20'

componentDetection.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export default class ComponentDetection {
2222
public static componentDetectionPath = process.platform === "win32" ? './component-detection.exe' : './component-detection';
2323
public static outputPath = './output.json';
2424

25-
// This is the default entry point for this class.
25+
// This is the default entry point for this class.
2626
static async scanAndGetManifests(path: string): Promise<Manifest[] | undefined> {
2727
await this.downloadLatestRelease();
2828
await this.runComponentDetection(path);
@@ -61,6 +61,7 @@ export default class ComponentDetection {
6161
parameters += (core.getInput('directoryExclusionList')) ? ` --DirectoryExclusionList ${core.getInput('directoryExclusionList')}` : "";
6262
parameters += (core.getInput('detectorArgs')) ? ` --DetectorArgs ${core.getInput('detectorArgs')}` : "";
6363
parameters += (core.getInput('detectorsFilter')) ? ` --DetectorsFilter ${core.getInput('detectorsFilter')}` : "";
64+
parameters += (core.getInput('detectorsCategories')) ? ` --DetectorCategories ${core.getInput('detectorsCategories')}` : "";
6465
parameters += (core.getInput('dockerImagesToScan')) ? ` --DockerImagesToScan ${core.getInput('dockerImagesToScan')}` : "";
6566
return parameters;
6667
}
@@ -86,7 +87,7 @@ export default class ComponentDetection {
8687
}
8788

8889
const packageUrl = ComponentDetection.makePackageUrl(component.component.packageUrl);
89-
90+
9091
// Skip if the packageUrl is empty (indicates an invalid or missing packageUrl)
9192
if (!packageUrl) {
9293
core.debug(`Skipping component with invalid packageUrl: ${component.component.id}`);
@@ -110,15 +111,15 @@ export default class ComponentDetection {
110111
core.debug(`Skipping referrer without packageUrl for component: ${pkg.id}`);
111112
return;
112113
}
113-
114+
114115
const referrerUrl = ComponentDetection.makePackageUrl(referrer.packageUrl);
115-
116+
116117
// Skip if the generated packageUrl is empty
117118
if (!referrerUrl) {
118119
core.debug(`Skipping referrer with invalid packageUrl for component: ${pkg.id}`);
119120
return;
120121
}
121-
122+
122123
try {
123124
const referrerPackage = packageCache.lookupPackage(referrerUrl);
124125
if (referrerPackage) {
@@ -195,10 +196,10 @@ export default class ComponentDetection {
195196
private static async getLatestReleaseURL(): Promise<string> {
196197
let githubToken = core.getInput('token') || process.env.GITHUB_TOKEN || "";
197198

198-
const githubAPIURL = 'https://api.github.com'
199+
const githubAPIURL = 'https://api.github.com'
199200

200201
let ghesMode = github.context.apiUrl != githubAPIURL;
201-
// If the we're running in GHES, then use an empty string as the token
202+
// If the we're running in GHES, then use an empty string as the token
202203
if (ghesMode) {
203204
githubToken = "";
204205
}
@@ -213,7 +214,7 @@ export default class ComponentDetection {
213214
const repo = "component-detection";
214215
core.debug("Attempting to download latest release from " + githubAPIURL);
215216

216-
try {
217+
try {
217218
const latestRelease = await octokit.request("GET /repos/{owner}/{repo}/releases/latest", {owner, repo});
218219

219220
var downloadURL: string = "";
@@ -229,7 +230,7 @@ export default class ComponentDetection {
229230
core.error(error);
230231
core.debug(error.message);
231232
core.debug(error.stack);
232-
throw new Error("Failed to download latest release");
233+
throw new Error("Failed to download latest release");
233234
}
234235
}
235236
}

dist/index.js

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)