Skip to content

Commit 7da0dbb

Browse files
authored
Add alternate scan root
Add the option to scan sub-folders inside a repository. feat/SP-3754_alternate-scan-root
2 parents a0ded05 + 9a2aebe commit 7da0dbb

27 files changed

Lines changed: 2004 additions & 99 deletions

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,6 @@ __tests__/runner/*
101101
.idea
102102
.vscode
103103
*.code-workspace
104+
105+
# Ignore tmp
106+
tmp/

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [1.4.0] - 2025-12-09
9+
### Added
10+
- Added basic subfolder scanning
11+
- Added input scanPath to specify a folder to scan
12+
- Added [MONOREPO_SETUP.md](MONOREPO_SETUP.md) to guide workflow setup for individual folder scanning
13+
### Changed
14+
- Upgraded scanoss-py version to v1.41.0
15+
816
## [1.3.1] - 2025-10-21
917
### Added
1018
- Added results conversion to spdxlite and csv
@@ -158,3 +166,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
158166
[1.2.5]: https://github.com/scanoss/gha-code-scan/compare/v1.2.4...v1.2.5
159167
[1.3.0]: https://github.com/scanoss/gha-code-scan/compare/v1.2.5...v1.3.0
160168
[1.3.1]: https://github.com/scanoss/gha-code-scan/compare/v1.3.0...v1.3.1
169+
[1.4.0]: https://github.com/scanoss/gha-code-scan/compare/v1.3.1...v1.4.0

MONOREPO_SETUP.md

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
# SCANOSS GitHub Actions Code Scan: Monorepo Setup Guide
2+
3+
## Introduction
4+
5+
This guide explains how to configure SCANOSS code scanning for monorepos where you want to scan specific subdirectories independently.
6+
7+
## Overview
8+
9+
Instead of scanning the entire repository on every change, you can create separate workflows that:
10+
- Trigger only when specific paths are modified
11+
- Scan only the relevant subdirectory
12+
- Run independently with their own results
13+
14+
## Architecture
15+
16+
The setup uses a **reusable workflow** pattern:
17+
1. **Base workflow** (`scanoss.yml`) - The reusable workflow that performs the actual scanning
18+
2. **Trigger workflows** (e.g., `scanoss-component1.yml`, `scanoss-component2.yml`) - Individual workflows that call the base workflow with specific parameters
19+
20+
## Setup Instructions
21+
22+
### Step 1: Modify Your Existing scanoss.yml
23+
24+
Add these sections to make it reusable:
25+
26+
```yaml
27+
on:
28+
workflow_call:
29+
inputs:
30+
FILTERED_PATH:
31+
description: 'Directory to scan'
32+
required: true
33+
type: string
34+
secrets:
35+
SC_API_KEY:
36+
required: false
37+
DT_API_KEY:
38+
required: false
39+
```
40+
41+
Then update the scanPath parameter to use the input:
42+
43+
```yaml
44+
- name: Run SCANOSS Code Scan
45+
uses: scanoss/code-scan-action@v1.4.0
46+
with:
47+
scanPath: ${{ inputs.FILTERED_PATH }}
48+
# ... other parameters
49+
```
50+
51+
### Step 2: Create Trigger Workflows
52+
53+
Create separate workflow files for each component:
54+
55+
`.github/workflows/scanoss-component1.yml`:
56+
```yaml
57+
name: SCANOSS - Component1
58+
59+
on:
60+
push:
61+
paths:
62+
- 'component1/**' <--
63+
64+
# OR
65+
66+
pull_request:
67+
paths:
68+
- 'component1/**' <--
69+
70+
jobs:
71+
call-scanoss-workflow:
72+
uses: ./.github/workflows/scanoss.yml # Exact path to scanoss.yml inside your repo
73+
with:
74+
FILTERED_PATH: 'component1' <-- Remove /** and add here
75+
secrets: inherit
76+
```
77+
78+
`.github/workflows/scanoss-component2.yml`:
79+
```yaml
80+
name: SCANOSS - Component2
81+
82+
on:
83+
push:
84+
paths:
85+
- 'component2/**' <--
86+
87+
# OR
88+
89+
pull_request:
90+
paths:
91+
- 'component2/**' <--
92+
93+
jobs:
94+
call-scanoss-workflow:
95+
uses: ./.github/workflows/scanoss.yml # Exact path to scanoss.yml inside your repo
96+
with:
97+
FILTERED_PATH: 'component2' <-- Remove /** and add here
98+
secrets: inherit
99+
```
100+
101+
## Example Structure
102+
103+
my-monorepo/
104+
├── .github/workflows/
105+
│ ├── scanoss.yml # Reusable workflow
106+
│ ├── scanoss-component1.yml # Triggers on component1/**
107+
│ ├── scanoss-component2.yml # Triggers on component2/**
108+
│ └── scanoss-common.yml # Triggers on common/**
109+
├── component1/
110+
├── component2/
111+
└── common/
112+
113+
## Key Points
114+
115+
- Path filters: Only trigger workflows when specific directories change
116+
- secrets: inherit: Required to pass repository secrets to the reusable workflow
117+
- Local workflow reference: for example ./.github/workflows/scanoss.yml (no branch name)
118+
- Secrets are optional: SC_API_KEY and DT_API_KEY (dt required if Dependency Track is enabled)
119+
120+
## Benefits
121+
122+
- Faster CI/CD - only scan affected components
123+
- Clearer results - each component has its own scan
124+
- Parallel execution - multiple components scan simultaneously
125+
- Reduced noise - PRs only show results for changed components

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,13 @@ For example workflow runs, check out our
103103
| licenses.copyleft.include | List of Copyleft licenses to append to the default list. Provide licenses as a comma-separated list. | Optional | - |
104104
| licenses.copyleft.exclude | List of Copyleft licenses to remove from default list. Provide licenses as a comma-separated list. | Optional | - |
105105
| licenses.copyleft.explicit | Explicit list of Copyleft licenses to consider. Provide licenses as a comma-separated list. | Optional | - |
106-
| runtimeContainer | Runtime URL | Optional | `ghcr.io/scanoss/scanoss-py:v1.37.1` |
106+
| runtimeContainer | Runtime URL | Optional | `ghcr.io/scanoss/scanoss-py:v1.41.0` |
107107
| skipSnippets | Skip the generation of snippets. (scanFiles option must be enabled) | Optional | `false` |
108108
| scanFiles | Enable or disable file and snippet scanning | Optional | `true` |
109109
| scanossSettings | Settings file to use for scanning. See the SCANOSS settings [documentation](https://scanoss.readthedocs.io/projects/scanoss-py/en/latest/#settings-file) | Optional | `true` |
110110
| settingsFilepath | Filepath of the SCANOSS settings to be used for scanning | Optional | `scanoss.json` |
111111
| scanMode | Choose between delta scan and full scan | Optional | `full` |
112+
| scanPath | Relative path within the repository to scan (e.g., `src` or `packages/api`) | Optional | `.` |
112113
| debug | Enable debugging | Optional | `false` |
113114
| deptrack.upload | Enable automatic upload of scan results to Dependency Track | Optional | `false` |
114115
| deptrack.url | URL of the Dependency Track instance. Required when Dependency Track is enabled | Required* | - |

0 commit comments

Comments
 (0)