diff --git a/lib/util/exec/docker/index.ts b/lib/util/exec/docker/index.ts index 4090231cde7b42a30ea4b3f2a094681efae105b8..65a2b4fbb0cd94164cce53247f669c5fc27829a6 100644 --- a/lib/util/exec/docker/index.ts +++ b/lib/util/exec/docker/index.ts @@ -59,7 +59,7 @@ function volumesEql(x: VolumesPair, y: VolumesPair): boolean { return xFrom === yFrom && xTo === yTo; } -function prepareVolumes(volumes: VolumeOption[] = []): string[] { +function prepareVolumes(volumes: VolumeOption[]): string[] { const expanded: (VolumesPair | null)[] = volumes.map(expandVolumeOption); const filtered: VolumesPair[] = expanded.filter( (vol): vol is VolumesPair => vol !== null diff --git a/lib/util/exec/hermit.spec.ts b/lib/util/exec/hermit.spec.ts index 702402b8617acc15d3080358b9b340558aed0c19..8152713811903e990d80cb1c949ad3e59e369f8a 100644 --- a/lib/util/exec/hermit.spec.ts +++ b/lib/util/exec/hermit.spec.ts @@ -1,4 +1,4 @@ -import os from 'node:os'; +import { codeBlock } from 'common-tags'; import _findUp from 'find-up'; import upath from 'upath'; import { mockExecAll } from '../../../test/exec-util'; @@ -62,11 +62,10 @@ describe('util/exec/hermit', () => { it('should return hermit environment variables when hermit env returns successfully', async () => { findUp.mockResolvedValueOnce(upath.join(localDir, 'bin/hermit')); mockExecAll({ - stdout: - [ - 'GOBIN=/usr/src/app/repository-a/.hermit/go/bin', - 'PATH=/usr/src/app/repository-a/bin', - ].join(os.EOL) + os.EOL, + stdout: codeBlock` + GOBIN=/usr/src/app/repository-a/.hermit/go/bin + PATH=/usr/src/app/repository-a/bin + `, stderr: '', }); diff --git a/lib/util/exec/hermit.ts b/lib/util/exec/hermit.ts index 11d9ba023e40f4727bc77bcb7d1ead20096db9f6..d47f31bffce2e1ef0198e1737523ba00598c1eaf 100644 --- a/lib/util/exec/hermit.ts +++ b/lib/util/exec/hermit.ts @@ -1,8 +1,8 @@ -import os from 'node:os'; import upath from 'upath'; import { GlobalConfig } from '../../config/global'; import { logger } from '../../logger'; import { findUpLocal } from '../fs'; +import { newlineRegex } from '../regex'; import { rawExec } from './common'; import type { RawExecOptions } from './types'; @@ -24,7 +24,7 @@ export async function findHermitCwd(cwd: string): Promise<string> { export async function getHermitEnvs( rawOptions: RawExecOptions ): Promise<Record<string, string>> { - const cwd = rawOptions.cwd ?? ''; + const cwd = rawOptions.cwd ?? /* istanbul ignore next */ ''; const hermitCwd = await findHermitCwd(cwd); logger.debug({ cwd, hermitCwd }, 'fetching hermit environment variables'); // with -r will output the raw unquoted environment variables to consume @@ -33,18 +33,16 @@ export async function getHermitEnvs( cwd: hermitCwd, }); - const lines = hermitEnvResp.stdout.split(os.EOL); - const out: Record<string, string> = {}; + const lines = hermitEnvResp.stdout + .split(newlineRegex) + .map((line) => line.trim()) + .filter((line) => line.includes('=')); for (const line of lines) { - const trimmedLine = line.trim(); - if (trimmedLine === '') { - continue; - } - const equalIndex = trimmedLine.indexOf('='); - const name = trimmedLine.substring(0, equalIndex); - out[name] = trimmedLine.substring(equalIndex + 1); + const equalIndex = line.indexOf('='); + const name = line.substring(0, equalIndex); + out[name] = line.substring(equalIndex + 1); } return out; diff --git a/lib/util/exec/index.spec.ts b/lib/util/exec/index.spec.ts index 19f18c32268b14166f4b63fed3b085f3008ee619..a36cd1c717f586be502bcc30acefed4464031bad 100644 --- a/lib/util/exec/index.spec.ts +++ b/lib/util/exec/index.spec.ts @@ -20,7 +20,7 @@ jest.mock('../../modules/datasource'); interface TestInput { processEnv: Record<string, string>; inCmd: string | string[]; - inOpts: ExecOptions; + inOpts?: ExecOptions; outCmd: string[]; outOpts: RawExecOptions[]; adminConfig?: Partial<RepoGlobalConfig>; @@ -106,6 +106,25 @@ describe('util/exec/index', () => { }, ], + [ + 'Command without options', + { + processEnv, + inCmd, + inOpts: undefined, + outCmd, + outOpts: [ + { + cwd, + encoding, + env: envMock.basic, + timeout: 900000, + maxBuffer: 10485760, + }, + ], + }, + ], + [ 'Multiple commands', {