scanoss.json configuration. By catching undeclared components at commit time, issues
are identified early in the development process rather than later in the pipeline.
Prerequisites
Before you begin, ensure the following are installed and configured:- Pre-Commit Framework: The framework that manages and runs the hooks.
- SCANOSS Pre-Commit Plugin: The SCANOSS hook for detecting undeclared open-source components.
- SCANOSS Code Compare (
scanoss-cc): A CLI tool for reviewing and declaring detected components. - SCANOSS Settings (
scanoss.json): The configuration file in which component declarations are managed. This file must exist at the root of your repository before the hook can validate against it.
Installation
Getting Started
Configure the Hook
Create.pre-commit-config.yaml at the root of your repository:
Verify Configuration
Install the Hook
Test the Hook
Configuration
Environment Variables
The hook automatically loads variables from a.env file in your project root:
How It Works
Example Workflow
Given this project structure:- Scans staged files for open-source components.
- Compares detected components against the declarations in your
scanoss.jsonfile. A declaration is an explicit acknowledgement that a given open-source component is present and approved for use in your project. - Blocks the commit if any undeclared components are found.
Example Output
The following is an example of output produced when undeclared components are detected. File paths and package identifiers are truncated for brevity.
Note: The files were modified by this hook message indicates that the hook
wrote scan result metadata to your working directory as part of its analysis.
These modifications are rolled back if a conflict with unstaged changes is detected,
as shown in the output above.
The commit is blocked until you take one of the following actions:
- Declare the components in
scanoss.json. - Run
scanoss-ccin the terminal to review and declare the components interactively. - Remove the non-compliant or undeclared code.
Troubleshooting
Enable Debug Mode
Method 1: Environment Variable.env File