Skip to content

Commit 354f4a7

Browse files
committed
feat: replace the scan_dependencies job with the command
Replacing the job with the same-named command allows for better usability of dependency scanning.
1 parent 2dee5c7 commit 354f4a7

File tree

4 files changed

+40
-19
lines changed

4 files changed

+40
-19
lines changed

.circleci/test-deploy.yml

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
version: 2.1
22
orbs:
33
orb-tools: circleci/orb-tools@12.0
4+
core: studion/core@1.0.0
45
security: {}
56

67
filters: &filters
@@ -13,28 +14,39 @@ release-filters: &release-filters
1314
tags:
1415
only: /^v[0-9]+\.[0-9]+\.[0-9]+$/
1516

16-
workflows:
17-
test-deploy:
18-
jobs:
17+
jobs:
18+
scan_dependencies_prod_npm:
19+
executor: core/node
20+
steps:
1921
- security/scan_dependencies:
20-
name: scan_dependencies_npm
2122
pkg_manager: npm
2223
pkg_json_dir: ~/project/sample
23-
filters: *filters
24+
scan_dependencies_prod_pnpm:
25+
executor: core/node
26+
steps:
2427
- security/scan_dependencies:
25-
name: scan_dependencies_pnpm
2628
pkg_manager: pnpm
2729
pkg_json_dir: ~/project/sample
28-
filters: *filters
30+
scan_dependencies_command:
31+
executor: core/node
32+
steps:
2933
- security/scan_dependencies:
30-
name: scan_dependencies_command
3134
pkg_manager: npm
3235
pkg_json_dir: ~/project/sample
3336
scan_command: |
3437
#!/bin/bash
3538
if ! npm audit --audit-level=high; then
3639
echo "Scan found dependencies with high vulnerability level"
3740
fi
41+
42+
workflows:
43+
test-deploy:
44+
jobs:
45+
- scan_dependencies_prod_npm:
46+
filters: *filters
47+
- scan_dependencies_prod_pnpm:
48+
filters: *filters
49+
- scan_dependencies_command:
3850
filters: *filters
3951
- security/detect_secrets_dir:
4052
name: detect_secrets_dir
@@ -72,8 +84,8 @@ workflows:
7284
pub_type: production
7385
requires:
7486
- orb-tools/pack
75-
- scan_dependencies_npm
76-
- scan_dependencies_pnpm
87+
- scan_dependencies_prod_npm
88+
- scan_dependencies_prod_pnpm
7789
- scan_dependencies_command
7890
- detect_secrets_dir
7991
- detect_secrets_git_base_revision

src/jobs/scan_dependencies.yml renamed to src/commands/scan_dependencies.yml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
description: >
2-
Scan production dependencies for critical and high severity vulnerabilities.
2+
By default, scan production dependencies for critical and high severity vulnerabilities.
33
Uses the "audit" command of the targeted package manager.
44
5-
executor: core/node
6-
75
parameters:
86
pkg_manager:
97
type: string
10-
default: $DEFAULT_PKG_MANAGER
8+
default: ${DEFAULT_PKG_MANAGER}
119
description: |
1210
Choose Node.js package manager to use. Supports npm and pnpm.
1311
The package manager must follow the format <name>[@<version|tag>].
@@ -35,7 +33,7 @@ steps:
3533
- core/ensure_pkg_manager:
3634
ref: <<parameters.pkg_manager>>
3735
- run:
38-
name: Scan dependencies
36+
name: Scan dependencies <<^parameters.scan_command>>prod<</parameters.scan_command>>
3937
working_directory: <<parameters.pkg_json_dir>>
4038
environment:
4139
SCAN_CMD: <<parameters.scan_command>>

src/examples/pnpm_scan.yml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
description: |
2-
By default, the "scan_dependencies" job checks for production dependencies
2+
By default, the "scan_dependencies" command checks for production dependencies
33
with critical and high severity vulnerabilities.
44
There is an option to override the scan command, package manager, and root directory.
55
66
usage:
77
version: 2.1
88
orbs:
99
security: studion/security@x.y.z
10-
workflows:
11-
scan_app_dependencies:
12-
jobs:
10+
jobs:
11+
scan_command:
12+
executor: core/node
13+
steps:
1314
- security/scan_dependencies:
1415
pkg_json_dir: ~/app
1516
scan_command: pnpm audit
17+
workflows:
18+
scan_app_dependencies:
19+
jobs:
20+
- scan_command

src/scripts/scan-dependencies.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,17 @@
22

33
if [[ -n "$SCAN_CMD" ]]; then
44
echo "Running custom scan command: $SCAN_CMD"
5+
56
eval "$SCAN_CMD"
7+
68
elif [[ "$CURRENT_PKG_MANAGER" == "npm" ]]; then
79
echo "Running npm audit with high audit level omitting dev dependencies"
10+
811
npm audit --audit-level=high --omit=dev
12+
913
elif [[ "$CURRENT_PKG_MANAGER" == "pnpm" ]]; then
1014
echo "Running pnpm audit with high audit level on prod dependencies"
15+
1116
pnpm audit --audit-level=high --prod
17+
1218
fi

0 commit comments

Comments
 (0)