Skip to content

Commit 2b33717

Browse files
committed
Add dry-run parameter
1 parent e446071 commit 2b33717

File tree

6 files changed

+44
-17
lines changed

6 files changed

+44
-17
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ The workflow will be set to fail if:
3232
| `tool-outputs-glob` | A comma-separated list of file globs matching tool output/scan result files | `undefined` | No |
3333
| `wait-for-completion` | Whether to wait for the analysis to complete before exiting | `false` | No |
3434
| `ca-cert` | A custom CA cert to use for HTTPS connections to Code Dx | `undefined` | No |
35+
| `dry-run` | Whether to submit an analysis (false/undefined) or only test the connection and credentials (true) | `undefined` | No |
3536

3637
## Sample Workflow
3738

action.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ inputs:
2626
ca-cert:
2727
description: 'a custom CA cert to use for HTTPS requests to Code Dx'
2828
required: false
29+
dry-run:
30+
description: 'whether to submit an analysis (false/undefined), or only test the connection and credentials (true). an error in validation will fail the build.'
2931
runs:
3032
using: 'node12'
3133
main: 'dist/index.js'

analyze.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,11 @@ module.exports = async function run() {
105105
await client.validatePermissions(config.projectId)
106106
core.info("Connection to Code Dx server is OK.")
107107

108+
if (config.dryRun) {
109+
core.info("dry-run is enabled, exiting without analysis")
110+
return
111+
}
112+
108113
const formData = new FormData()
109114

110115
core.info("Preparing source/binaries ZIP...")

config.js

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
const core = require('@actions/core');
22

3+
function isYamlTrue(value) {
4+
value = value.toLowerCase().trim()
5+
return ["yes", "on", "true"].indexOf(value) >= 0
6+
}
7+
8+
function fixBoolean(target, field) {
9+
const value = target[field]
10+
if (typeof value == 'string') {
11+
target[field] = isYamlTrue(value)
12+
}
13+
}
14+
315
class Config {
416
constructor() {
517
this.serverUrl = core.getInput('server-url', { required: true })
@@ -10,20 +22,15 @@ class Config {
1022

1123
this.waitForCompletion = core.getInput('wait-for-completion')
1224
this.caCert = core.getInput('ca-cert')
25+
this.dryRun = core.getInput('dry-run')
1326

1427
// debug vars
1528
this.tmpDir = ""
1629
}
1730

1831
sanitize() {
19-
function isYamlTrue(value) {
20-
value = value.toLowerCase().trim()
21-
return ["yes", "on", "true"].indexOf(value) >= 0
22-
}
23-
24-
if (typeof this.waitForCompletion == 'string') {
25-
this.waitForCompletion = isYamlTrue(this.waitForCompletion)
26-
}
32+
fixBoolean(this, 'waitForCompletion')
33+
fixBoolean(this, 'dryRun')
2734

2835
if (typeof this.projectId != 'number') {
2936
try {

dist/index.js

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,11 @@ module.exports = async function run() {
112112
await client.validatePermissions(config.projectId)
113113
core.info("Connection to Code Dx server is OK.")
114114

115+
if (config.dryRun) {
116+
core.info("dry-run is enabled, exiting without analysis")
117+
return
118+
}
119+
115120
const formData = new FormData()
116121

117122
core.info("Preparing source/binaries ZIP...")
@@ -278,6 +283,18 @@ module.exports = CodeDxApiClient
278283

279284
const core = __nccwpck_require__(2186);
280285

286+
function isYamlTrue(value) {
287+
value = value.toLowerCase().trim()
288+
return ["yes", "on", "true"].indexOf(value) >= 0
289+
}
290+
291+
function fixBoolean(target, field) {
292+
const value = target[field]
293+
if (typeof value == 'string') {
294+
target[field] = isYamlTrue(value)
295+
}
296+
}
297+
281298
class Config {
282299
constructor() {
283300
this.serverUrl = core.getInput('server-url', { required: true })
@@ -288,20 +305,15 @@ class Config {
288305

289306
this.waitForCompletion = core.getInput('wait-for-completion')
290307
this.caCert = core.getInput('ca-cert')
308+
this.dryRun = core.getInput('dry-run')
291309

292310
// debug vars
293311
this.tmpDir = ""
294312
}
295313

296314
sanitize() {
297-
function isYamlTrue(value) {
298-
value = value.toLowerCase().trim()
299-
return ["yes", "on", "true"].indexOf(value) >= 0
300-
}
301-
302-
if (typeof this.waitForCompletion == 'string') {
303-
this.waitForCompletion = isYamlTrue(this.waitForCompletion)
304-
}
315+
fixBoolean(this, 'waitForCompletion')
316+
fixBoolean(this, 'dryRun')
305317

306318
if (typeof this.projectId != 'number') {
307319
try {

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)