diff --git a/lib/util/exec/index.ts b/lib/util/exec/index.ts index f0b01f345c33316d8f53718e5b91fad80dedc642..7a65802e1a73ae77fa4d2f74e21bd275fe294610 100644 --- a/lib/util/exec/index.ts +++ b/lib/util/exec/index.ts @@ -10,7 +10,6 @@ import { removeDockerContainer, sideCarImage, } from './docker'; -import { getChildProcessEnv } from './env'; import { getHermitEnvs, isHermit } from './hermit'; import type { DockerOptions, @@ -20,37 +19,7 @@ import type { Opt, RawExecOptions, } from './types'; - -export function getChildEnv({ - extraEnv, - env: forcedEnv = {}, -}: ExecOptions): Record<string, string> { - const globalConfigEnv = GlobalConfig.get('customEnvVariables'); - - const inheritedKeys: string[] = []; - for (const [key, val] of Object.entries(extraEnv ?? {})) { - if (is.string(val)) { - inheritedKeys.push(key); - } - } - - const parentEnv = getChildProcessEnv(inheritedKeys); - const combinedEnv = { - ...extraEnv, - ...parentEnv, - ...globalConfigEnv, - ...forcedEnv, - }; - - const result: Record<string, string> = {}; - for (const [key, val] of Object.entries(combinedEnv)) { - if (is.string(val)) { - result[key] = `${val}`; - } - } - - return result; -} +import { getChildEnv } from './utils'; function dockerEnvVars(extraEnv: ExtraEnv, childEnv: ExtraEnv): string[] { const extraEnvKeys = Object.keys(extraEnv); diff --git a/lib/util/exec/utils.ts b/lib/util/exec/utils.ts new file mode 100644 index 0000000000000000000000000000000000000000..11c91967405fbab2d1f667ee6e4a578494a37a37 --- /dev/null +++ b/lib/util/exec/utils.ts @@ -0,0 +1,35 @@ +import is from '@sindresorhus/is'; +import { GlobalConfig } from '../../config/global'; +import { getChildProcessEnv } from './env'; +import type { ExecOptions } from './types'; + +export function getChildEnv({ + extraEnv, + env: forcedEnv = {}, +}: ExecOptions): Record<string, string> { + const globalConfigEnv = GlobalConfig.get('customEnvVariables'); + + const inheritedKeys: string[] = []; + for (const [key, val] of Object.entries(extraEnv ?? {})) { + if (is.string(val)) { + inheritedKeys.push(key); + } + } + + const parentEnv = getChildProcessEnv(inheritedKeys); + const combinedEnv = { + ...extraEnv, + ...parentEnv, + ...globalConfigEnv, + ...forcedEnv, + }; + + const result: Record<string, string> = {}; + for (const [key, val] of Object.entries(combinedEnv)) { + if (is.string(val)) { + result[key] = `${val}`; + } + } + + return result; +} diff --git a/lib/util/template/index.spec.ts b/lib/util/template/index.spec.ts index 5318304e33e98faaa01e7403b764861beda9d5dc..f60c5c276a26f34c38df5a236fb9d57fe2ea1555 100644 --- a/lib/util/template/index.spec.ts +++ b/lib/util/template/index.spec.ts @@ -1,15 +1,15 @@ import { mocked } from '../../../test/util'; import { getOptions } from '../../config/options'; -import * as _exec from '../exec'; +import * as _execUtils from '../exec/utils'; import * as template from '.'; -jest.mock('../exec'); +jest.mock('../exec/utils'); -const exec = mocked(_exec); +const execUtils = mocked(_execUtils); describe('util/template/index', () => { beforeEach(() => { - exec.getChildEnv.mockReturnValue({ + execUtils.getChildEnv.mockReturnValue({ CUSTOM_FOO: 'foo', HOME: '/root', }); diff --git a/lib/util/template/index.ts b/lib/util/template/index.ts index db40eabae6088d3aea59be4ff674d31c62099ce4..6af4fbaf6d93153b66eee99fa2640bda8b1b27c2 100644 --- a/lib/util/template/index.ts +++ b/lib/util/template/index.ts @@ -2,7 +2,7 @@ import is from '@sindresorhus/is'; import handlebars from 'handlebars'; import { GlobalConfig } from '../../config/global'; import { logger } from '../../logger'; -import { getChildEnv } from '../exec'; +import { getChildEnv } from '../exec/utils'; handlebars.registerHelper('encodeURIComponent', encodeURIComponent); handlebars.registerHelper('decodeURIComponent', decodeURIComponent);