Skip to content

Commit 265c40a

Browse files
authored
Updates for v1.1
2 parents 64af6c6 + 1fa0128 commit 265c40a

7 files changed

Lines changed: 55 additions & 29 deletions

File tree

action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ inputs:
1212
description: 'the ID of a project (an integer) created in Code Dx'
1313
required: true
1414
source-and-binaries-glob:
15-
description: 'a file glob matching source and binary files (accepts multiple comma-separated globs)'
15+
description: 'a file glob matching source and binary files (accepts multiple comma-separated globs). if not set, no source/binary files will be sent to Code Dx'
1616
required: true
1717
tool-outputs-glob:
1818
description: 'a file glob matching output files (ie scan results) from an analysis tool (accepts multiple comma-separated globs)'

analyze.js

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ function areGlobsValid(globsArray) {
3131
}
3232

3333
function buildGlobObject(globsArray) {
34-
return glob.create(globsArray.join('\n'))
34+
return glob.create(globsArray.join('\n'), { matchDirectories: false })
3535
}
3636

3737
function makeRelative(workingDir, path) {
@@ -55,15 +55,18 @@ async function prepareInputsZip(inputsGlob, targetFile) {
5555
const output = fs.createWriteStream(targetFile);
5656
const archive = archiver('zip');
5757
archive.on('end', () => core.info("Finished writing ZIP"))
58-
archive.on('warning', (err) => core.warning("Warning when writing ZIP: ", err))
59-
archive.on('error', (err) => core.error("Error when writing ZIP: ", err))
58+
archive.on('warning', (err) => core.warning("Warning when writing ZIP: " + err))
59+
archive.on('error', (err) => core.error("Error when writing ZIP: " + err))
6060

6161
archive.pipe(output);
6262

6363
let numWritten = 0
6464
const workingDir = process.cwd()
6565
for await (const file of inputFilesGlob.globGenerator()) {
66-
archive.file(makeRelative(workingDir, file))
66+
const relPath = makeRelative(workingDir, file)
67+
if (file == targetFile || relPath == targetFile) continue
68+
69+
archive.file(relPath)
6770
numWritten += 1
6871
}
6972
await archive.finalize()
@@ -74,12 +77,11 @@ async function attachInputsZip(inputGlobs, formData, tmpDir) {
7477
const zipTarget = path.join(tmpDir, "codedx-inputfiles.zip")
7578
const numFiles = await prepareInputsZip(inputGlobs, zipTarget)
7679
if (numFiles == 0) {
77-
throw new Error("No files were matched by the source/binary glob(s)")
80+
core.warning("No files were matched by the 'source-and-binaries-glob' values, skipping source/binaries ZIP attachment")
7881
} else {
7982
core.info(`Added ${numFiles} files`)
83+
formData.append('source-and-binaries.zip', fs.createReadStream(zipTarget))
8084
}
81-
82-
formData.append('source-and-binaries.zip', fs.createReadStream(zipTarget))
8385
}
8486

8587
async function attachScanFiles(scanGlobs, formData) {
@@ -123,11 +125,19 @@ module.exports = async function run() {
123125

124126
const formData = new FormData()
125127

126-
core.info("Preparing source/binaries ZIP...")
127-
await attachInputsZip(config.inputGlobs, formData, config.tmpDir)
128+
if (config.inputGlobs) {
129+
core.info("Preparing source/binaries ZIP...")
130+
await attachInputsZip(config.inputGlobs, formData, config.tmpDir)
131+
} else {
132+
core.info("Source/binary inputs glob not specified, skipping ZIP creation")
133+
}
128134

129-
core.info("Adding scan files...")
130-
await attachScanFiles(config.scanGlobs, formData)
135+
if (config.scanGlobs) {
136+
core.info("Adding scan files...")
137+
await attachScanFiles(config.scanGlobs, formData)
138+
} else {
139+
core.info("Scan files glob not specified, skipping scan file attachment")
140+
}
131141

132142
core.info("Uploading to Code Dx...")
133143
const { analysisId, jobId } = await client.runAnalysis(config.projectId, formData)

config.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class Config {
1717
this.serverUrl = core.getInput('server-url', { required: true })
1818
this.apiKey = core.getInput('api-key', { required: true })
1919
this.projectId = core.getInput('project-id', { required: true })
20-
this.inputGlobs = core.getInput('source-and-binaries-glob', { required: true })
20+
this.inputGlobs = core.getInput('source-and-binaries-glob')
2121
this.scanGlobs = core.getInput('tool-outputs-glob')
2222

2323
this.waitForCompletion = core.getInput('wait-for-completion')
@@ -31,6 +31,9 @@ class Config {
3131
sanitize() {
3232
fixBoolean(this, 'waitForCompletion')
3333
fixBoolean(this, 'dryRun')
34+
fixBoolean(this, 'requireInputFiles')
35+
36+
this.inputGlobs = this.inputGlobs.trim()
3437

3538
if (typeof this.projectId != 'number') {
3639
try {

dist/index.js

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ function areGlobsValid(globsArray) {
3838
}
3939

4040
function buildGlobObject(globsArray) {
41-
return glob.create(globsArray.join('\n'))
41+
return glob.create(globsArray.join('\n'), { matchDirectories: false })
4242
}
4343

4444
function makeRelative(workingDir, path) {
@@ -62,15 +62,18 @@ async function prepareInputsZip(inputsGlob, targetFile) {
6262
const output = fs.createWriteStream(targetFile);
6363
const archive = archiver('zip');
6464
archive.on('end', () => core.info("Finished writing ZIP"))
65-
archive.on('warning', (err) => core.warning("Warning when writing ZIP: ", err))
66-
archive.on('error', (err) => core.error("Error when writing ZIP: ", err))
65+
archive.on('warning', (err) => core.warning("Warning when writing ZIP: " + err))
66+
archive.on('error', (err) => core.error("Error when writing ZIP: " + err))
6767

6868
archive.pipe(output);
6969

7070
let numWritten = 0
7171
const workingDir = process.cwd()
7272
for await (const file of inputFilesGlob.globGenerator()) {
73-
archive.file(makeRelative(workingDir, file))
73+
const relPath = makeRelative(workingDir, file)
74+
if (file == targetFile || relPath == targetFile) continue
75+
76+
archive.file(relPath)
7477
numWritten += 1
7578
}
7679
await archive.finalize()
@@ -81,12 +84,11 @@ async function attachInputsZip(inputGlobs, formData, tmpDir) {
8184
const zipTarget = path.join(tmpDir, "codedx-inputfiles.zip")
8285
const numFiles = await prepareInputsZip(inputGlobs, zipTarget)
8386
if (numFiles == 0) {
84-
throw new Error("No files were matched by the source/binary glob(s)")
87+
core.warning("No files were matched by the 'source-and-binaries-glob' values, skipping source/binaries ZIP attachment")
8588
} else {
8689
core.info(`Added ${numFiles} files`)
90+
formData.append('source-and-binaries.zip', fs.createReadStream(zipTarget))
8791
}
88-
89-
formData.append('source-and-binaries.zip', fs.createReadStream(zipTarget))
9092
}
9193

9294
async function attachScanFiles(scanGlobs, formData) {
@@ -130,11 +132,19 @@ module.exports = async function run() {
130132

131133
const formData = new FormData()
132134

133-
core.info("Preparing source/binaries ZIP...")
134-
await attachInputsZip(config.inputGlobs, formData, config.tmpDir)
135+
if (config.inputGlobs) {
136+
core.info("Preparing source/binaries ZIP...")
137+
await attachInputsZip(config.inputGlobs, formData, config.tmpDir)
138+
} else {
139+
core.info("Source/binary inputs glob not specified, skipping ZIP creation")
140+
}
135141

136-
core.info("Adding scan files...")
137-
await attachScanFiles(config.scanGlobs, formData)
142+
if (config.scanGlobs) {
143+
core.info("Adding scan files...")
144+
await attachScanFiles(config.scanGlobs, formData)
145+
} else {
146+
core.info("Scan files glob not specified, skipping scan file attachment")
147+
}
138148

139149
core.info("Uploading to Code Dx...")
140150
const { analysisId, jobId } = await client.runAnalysis(config.projectId, formData)
@@ -311,7 +321,7 @@ class Config {
311321
this.serverUrl = core.getInput('server-url', { required: true })
312322
this.apiKey = core.getInput('api-key', { required: true })
313323
this.projectId = core.getInput('project-id', { required: true })
314-
this.inputGlobs = core.getInput('source-and-binaries-glob', { required: true })
324+
this.inputGlobs = core.getInput('source-and-binaries-glob')
315325
this.scanGlobs = core.getInput('tool-outputs-glob')
316326

317327
this.waitForCompletion = core.getInput('wait-for-completion')
@@ -325,6 +335,9 @@ class Config {
325335
sanitize() {
326336
fixBoolean(this, 'waitForCompletion')
327337
fixBoolean(this, 'dryRun')
338+
fixBoolean(this, 'requireInputFiles')
339+
340+
this.inputGlobs = this.inputGlobs.trim()
328341

329342
if (typeof this.projectId != 'number') {
330343
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.

package-lock.json

Lines changed: 2 additions & 2 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,6 +1,6 @@
11
{
22
"name": "codedx-upload",
3-
"version": "1.0.0",
3+
"version": "1.1.0",
44
"description": "Analyze your source code and binaries with Code Dx",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)