Skip to content

Commit 0215485

Browse files
authored
bug/SP-3210_policy-does-not-exist-error
* Added handling if no policies are specified * Updated CHANGELOG.md * Removed test * Removed redundant param
1 parent a84216f commit 0215485

File tree

6 files changed

+115
-88
lines changed

6 files changed

+115
-88
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ 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.2.2] - 2025-09-09
9+
### Added
10+
- Added policies input trimming
11+
### Fixed
12+
- Fixed workflow erroring out if no policies were specified
13+
814
## [1.2.1] - 2025-08-28
915
### Added
1016
- Added url sanitisation
@@ -118,3 +124,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
118124
[1.1.0]: https://github.com/scanoss/gha-code-scan/compare/v1.0.6...v1.1.0
119125
[1.2.0]: https://github.com/scanoss/gha-code-scan/compare/v1.1.0...v1.2.0
120126
[1.2.1]: https://github.com/scanoss/gha-code-scan/compare/v1.2.0...v1.2.1
127+
[1.2.2]: https://github.com/scanoss/gha-code-scan/compare/v1.2.1...v1.2.2

__tests__/main.donottest.ts

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
// SPDX-License-Identifier: MIT
2+
/*
3+
Copyright (c) 2025, SCANOSS
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.
22+
*/
23+
24+
/**
25+
* Unit tests for the action's main functionality, src/main.ts
26+
*
27+
* These should be run as if the action was called from a workflow.
28+
* Specifically, the inputs listed in `action.yml` should be set as environment
29+
* variables following the pattern `INPUT_<INPUT_NAME>`.
30+
*/
31+
32+
// import * as core from '@actions/core';
33+
// import * as main from '../src/main';
34+
//
35+
// // Mock the action's main function
36+
// const runMock = jest.spyOn(main, 'run');
37+
//
38+
// // Mock the GitHub Actions core library
39+
// let debugMock: jest.SpyInstance;
40+
// let getInputMock: jest.SpyInstance;
41+
// let setFailedMock: jest.SpyInstance;
42+
// let setOutputMock: jest.SpyInstance;
43+
44+
// TODO Is this test necessary?
45+
// describe('action', () => {
46+
// beforeEach(() => {
47+
// jest.clearAllMocks();
48+
//
49+
// debugMock = jest.spyOn(core, 'debug').mockImplementation();
50+
// getInputMock = jest.spyOn(core, 'getInput').mockImplementation();
51+
// // setFailedMock = jest.spyOn(core, 'setFailed').mockImplementation();
52+
// // setOutputMock = jest.spyOn(core, 'setOutput').mockImplementation();
53+
// });
54+
//
55+
// it('SCANOSS Scan Action started', async () => {
56+
// // Set the action's inputs as return values from core.getInput()
57+
// getInputMock.mockImplementation((name: string): string => {
58+
// switch (name) {
59+
// case 'scanner-parameters':
60+
// return '';
61+
// case 'scanFiles':
62+
// return 'true'; // Enable file scanning to pass validation
63+
// case 'dependencies.enabled':
64+
// return 'true'; // Enable dependency scanning as backup
65+
// case 'policies':
66+
// return 'copyleft'; // Set a policy to avoid "No policies specified"
67+
// default:
68+
// return '';
69+
// }
70+
// });
71+
//
72+
// await main.run();
73+
// expect(runMock).toHaveReturned();
74+
//
75+
// // Verify that all of the core library functions were called correctly
76+
// expect(debugMock).toHaveBeenNthCalledWith(1, 'SCANOSS Scan Action started...');
77+
// // Note: The test environment doesn't have Docker, so scan execution will fail
78+
// // The important thing is that the action started and basic validation passed
79+
// });
80+
// });

__tests__/main.test.ts

Lines changed: 0 additions & 74 deletions
This file was deleted.

dist/index.js

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

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "scanoss-code-scan-action",
33
"description": "SCANOSS Code Scan Action",
4-
"version": "1.2.1",
4+
"version": "1.2.2",
55
"author": "SCANOSS",
66
"private": true,
77
"homepage": "https://github.com/scanoss/code-scan-action/",

src/policies/policy.manager.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,20 +50,26 @@ export class PolicyManager {
5050

5151
/**
5252
* Gets instances of the specified policy checks.
53-
* @param policiesNames - Array of policy names to instantiate. If not provided, uses POLICIES from app input.
5453
*/
55-
getPolicies(policiesNames?: string[]): PolicyCheck[] {
56-
core.info(`Policy Names: ${policiesNames}`);
54+
getPolicies(): PolicyCheck[] {
5755
core.debug(`Policy Registry: ${this.policyRegistry}`);
5856

59-
const pNames = policiesNames || inputs.POLICIES.split(',').map(pn => pn.trim());
60-
57+
if (!inputs.POLICIES || !inputs.POLICIES.trim()) {
58+
core.info(`No policies specified`);
59+
return [];
60+
}
61+
const pNames = inputs.POLICIES.split(',').map(pn => pn.trim());
62+
if (pNames.length === 0) {
63+
core.info(`No policies specified`);
64+
return [];
65+
}
6166
core.info(`Policies: ${pNames}`);
62-
6367
//throw error if policy does not exist
6468
pNames.forEach(pName => {
6569
core.info(`Policy: ${pName}`);
66-
if (!this.policyRegistry[pName]) throw new Error(`Policy ${pName} does not exist`);
70+
if (pName.length > 0) {
71+
if (!this.policyRegistry[pName]) throw new Error(`Policy ${pName} does not exist`);
72+
}
6773
});
6874

6975
return pNames.map(pName => new this.policyRegistry[pName]());

0 commit comments

Comments
 (0)