Skip to content

Commit c2bf577

Browse files
Merge pull request #6 from yuichielectric/check-if-config-file-exists
Check if config file exists
2 parents a359341 + 4043f22 commit c2bf577

File tree

3 files changed

+22
-19
lines changed

3 files changed

+22
-19
lines changed

dist/index.js

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

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.

src/main.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as core from '@actions/core'
22
import * as exec from '@actions/exec'
33
import * as github from '@actions/github'
44
import stripAnsi from 'strip-ansi'
5+
import fs from 'fs'
56

67
function format(output: string): string {
78
const ret = ['**The container image has inefficient files.**']
@@ -51,21 +52,25 @@ async function run(): Promise<void> {
5152
await exec.exec('docker', ['pull', diveImage])
5253

5354
const commandOptions = [
54-
'run',
5555
'-e',
5656
'CI=true',
5757
'-e',
5858
'DOCKER_API_VERSION=1.37',
5959
'--rm',
60-
'--mount',
61-
`type=bind,source=${configFile},target=/.dive-ci`,
6260
'-v',
63-
'/var/run/docker.sock:/var/run/docker.sock',
64-
diveImage,
65-
'--ci-config',
66-
'/.dive-ci',
67-
image
61+
'/var/run/docker.sock:/var/run/docker.sock'
6862
]
63+
64+
if (fs.existsSync(configFile)) {
65+
commandOptions.push(
66+
'--mount',
67+
`type=bind,source=${configFile},target=/.dive-ci`,
68+
'--ci-config',
69+
'/.dive-ci'
70+
)
71+
}
72+
73+
const parameters = ['run', ...commandOptions, diveImage, image]
6974
let output = ''
7075
const execOptions = {
7176
ignoreReturnCode: true,
@@ -78,7 +83,7 @@ async function run(): Promise<void> {
7883
}
7984
}
8085
}
81-
const exitCode = await exec.exec('docker', commandOptions, execOptions)
86+
const exitCode = await exec.exec('docker', parameters, execOptions)
8287
if (exitCode === 0) {
8388
// success
8489
return

0 commit comments

Comments
 (0)