Skip to content

Commit

Permalink
Add dry-run parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
tylercamp committed Dec 17, 2021
1 parent e446071 commit 2b33717
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 17 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ The workflow will be set to fail if:
| `tool-outputs-glob` | A comma-separated list of file globs matching tool output/scan result files | `undefined` | No |
| `wait-for-completion` | Whether to wait for the analysis to complete before exiting | `false` | No |
| `ca-cert` | A custom CA cert to use for HTTPS connections to Code Dx | `undefined` | No |
| `dry-run` | Whether to submit an analysis (false/undefined) or only test the connection and credentials (true) | `undefined` | No |

## Sample Workflow

Expand Down
2 changes: 2 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ inputs:
ca-cert:
description: 'a custom CA cert to use for HTTPS requests to Code Dx'
required: false
dry-run:
description: 'whether to submit an analysis (false/undefined), or only test the connection and credentials (true). an error in validation will fail the build.'
runs:
using: 'node12'
main: 'dist/index.js'
5 changes: 5 additions & 0 deletions analyze.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ module.exports = async function run() {
await client.validatePermissions(config.projectId)
core.info("Connection to Code Dx server is OK.")

if (config.dryRun) {
core.info("dry-run is enabled, exiting without analysis")
return
}

const formData = new FormData()

core.info("Preparing source/binaries ZIP...")
Expand Down
23 changes: 15 additions & 8 deletions config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
const core = require('@actions/core');

function isYamlTrue(value) {
value = value.toLowerCase().trim()
return ["yes", "on", "true"].indexOf(value) >= 0
}

function fixBoolean(target, field) {
const value = target[field]
if (typeof value == 'string') {
target[field] = isYamlTrue(value)
}
}

class Config {
constructor() {
this.serverUrl = core.getInput('server-url', { required: true })
Expand All @@ -10,20 +22,15 @@ class Config {

this.waitForCompletion = core.getInput('wait-for-completion')
this.caCert = core.getInput('ca-cert')
this.dryRun = core.getInput('dry-run')

// debug vars
this.tmpDir = ""
}

sanitize() {
function isYamlTrue(value) {
value = value.toLowerCase().trim()
return ["yes", "on", "true"].indexOf(value) >= 0
}

if (typeof this.waitForCompletion == 'string') {
this.waitForCompletion = isYamlTrue(this.waitForCompletion)
}
fixBoolean(this, 'waitForCompletion')
fixBoolean(this, 'dryRun')

if (typeof this.projectId != 'number') {
try {
Expand Down
28 changes: 20 additions & 8 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ module.exports = async function run() {
await client.validatePermissions(config.projectId)
core.info("Connection to Code Dx server is OK.")

if (config.dryRun) {
core.info("dry-run is enabled, exiting without analysis")
return
}

const formData = new FormData()

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

const core = __nccwpck_require__(2186);

function isYamlTrue(value) {
value = value.toLowerCase().trim()
return ["yes", "on", "true"].indexOf(value) >= 0
}

function fixBoolean(target, field) {
const value = target[field]
if (typeof value == 'string') {
target[field] = isYamlTrue(value)
}
}

class Config {
constructor() {
this.serverUrl = core.getInput('server-url', { required: true })
Expand All @@ -288,20 +305,15 @@ class Config {

this.waitForCompletion = core.getInput('wait-for-completion')
this.caCert = core.getInput('ca-cert')
this.dryRun = core.getInput('dry-run')

// debug vars
this.tmpDir = ""
}

sanitize() {
function isYamlTrue(value) {
value = value.toLowerCase().trim()
return ["yes", "on", "true"].indexOf(value) >= 0
}

if (typeof this.waitForCompletion == 'string') {
this.waitForCompletion = isYamlTrue(this.waitForCompletion)
}
fixBoolean(this, 'waitForCompletion')
fixBoolean(this, 'dryRun')

if (typeof this.projectId != 'number') {
try {
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

0 comments on commit 2b33717

Please sign in to comment.