repaired docker PATH export and added tests both for docker and k8s (#17)

* repaired docker PATH export and added tests both for docker and k8s

* added todo comments about next major version and typeof prepend path
This commit is contained in:
Nikola Jokic
2022-06-16 15:44:40 +02:00
committed by GitHub
parent 266b8edb99
commit 898063bddd
4 changed files with 86 additions and 2 deletions

View File

@@ -100,7 +100,10 @@ export function writeEntryPointScript(
): { containerPath: string; runnerPath: string } {
let exportPath = ''
if (prependPath?.length) {
exportPath = `export PATH=${prependPath.join(':')}:$PATH`
// TODO: remove compatibility with typeof prependPath === 'string' as we bump to next major version, the hooks will lose PrependPath compat with runners 2.293.0 and older
const prepend =
typeof prependPath === 'string' ? prependPath : prependPath.join(':')
exportPath = `export PATH=${prepend}:$PATH`
}
let environmentPrefix = ''

View File

@@ -71,4 +71,38 @@ describe('Run script step', () => {
)
).resolves.not.toThrow()
})
it('Should have path variable changed in container with prepend path string', async () => {
runScriptStepDefinition.args.prependPath = '/some/path'
runScriptStepDefinition.args.entryPoint = '/bin/bash'
runScriptStepDefinition.args.entryPointArgs = [
'-c',
`'if [[ ! $(env | grep "^PATH=") = "PATH=${runScriptStepDefinition.args.prependPath}:"* ]]; then exit 1; fi'`
]
await expect(
runScriptStep(
runScriptStepDefinition.args,
prepareJobOutputData.state,
null
)
).resolves.not.toThrow()
})
it('Should have path variable changed in container with prepend path string array', async () => {
runScriptStepDefinition.args.prependPath = ['/some/other/path']
runScriptStepDefinition.args.entryPoint = '/bin/bash'
runScriptStepDefinition.args.entryPointArgs = [
'-c',
`'if [[ ! $(env | grep "^PATH=") = "PATH=${runScriptStepDefinition.args.prependPath}:"* ]]; then exit 1; fi'`
]
await expect(
runScriptStep(
runScriptStepDefinition.args,
prepareJobOutputData.state,
null
)
).resolves.not.toThrow()
})
})