Skip to content

Commit bb9faed

Browse files
authored
fix: properly pass configured env (renovatebot#35835)
1 parent 99d93ef commit bb9faed

File tree

8 files changed

+19
-34
lines changed

8 files changed

+19
-34
lines changed

lib/modules/datasource/crate/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { GlobalConfig } from '../../../config/global';
44
import { logger } from '../../../logger';
55
import * as memCache from '../../../util/cache/memory';
66
import { cache } from '../../../util/cache/package/decorator';
7-
import { getChildProcessEnv } from '../../../util/exec/env';
7+
import { getChildEnv } from '../../../util/exec/utils';
88
import { privateCacheDir, readCacheFile } from '../../../util/fs';
99
import { simpleGitConfig } from '../../../util/git/config';
1010
import { toSha256 } from '../../../util/hash';
@@ -323,7 +323,7 @@ export class CrateDatasource extends Datasource {
323323
const git = Git({
324324
...simpleGitConfig(),
325325
maxConcurrentProcesses: 1,
326-
}).env(getChildProcessEnv());
326+
}).env(getChildEnv());
327327
const clonePromise = git.clone(registryFetchUrl, clonePath, {
328328
'--depth': 1,
329329
});

lib/modules/datasource/git-refs/base.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import is from '@sindresorhus/is';
22
import { simpleGit } from 'simple-git';
33
import { logger } from '../../../logger';
44
import { cache } from '../../../util/cache/package/decorator';
5-
import { getChildProcessEnv } from '../../../util/exec/env';
5+
import { getChildEnv } from '../../../util/exec/utils';
66
import { getGitEnvironmentVariables } from '../../../util/git/auth';
77
import { simpleGitConfig } from '../../../util/git/config';
88
import { getRemoteUrlWithToken } from '../../../util/git/url';
@@ -34,12 +34,7 @@ export abstract class GitDatasource extends Datasource {
3434
const gitSubmoduleAuthEnvironmentVariables = getGitEnvironmentVariables([
3535
this.id,
3636
]);
37-
const gitEnv = {
38-
// pass all existing env variables
39-
...getChildProcessEnv(),
40-
// add all known git Variables
41-
...gitSubmoduleAuthEnvironmentVariables,
42-
};
37+
const gitEnv = getChildEnv({ env: gitSubmoduleAuthEnvironmentVariables });
4338
const git = simpleGit(simpleGitConfig()).env(gitEnv);
4439

4540
// fetch remote tags

lib/modules/manager/git-submodules/extract.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import Git from 'simple-git';
44
import upath from 'upath';
55
import { GlobalConfig } from '../../../config/global';
66
import { logger } from '../../../logger';
7-
import { getChildProcessEnv } from '../../../util/exec/env';
7+
import { getChildEnv } from '../../../util/exec/utils';
88
import { getGitEnvironmentVariables } from '../../../util/git/auth';
99
import { simpleGitConfig } from '../../../util/git/config';
1010
import { getHttpUrl } from '../../../util/git/url';
@@ -44,12 +44,7 @@ async function getDefaultBranch(subModuleUrl: string): Promise<string> {
4444
'git-tags',
4545
'git-refs',
4646
]);
47-
const gitEnv = {
48-
// pass all existing env variables
49-
...getChildProcessEnv(),
50-
// add all known git Variables
51-
...gitSubmoduleAuthEnvironmentVariables,
52-
};
47+
const gitEnv = getChildEnv({ env: gitSubmoduleAuthEnvironmentVariables });
5348
const val = await Git(simpleGitConfig())
5449
.env(gitEnv)
5550
.listRemote(['--symref', subModuleUrl, 'HEAD']);

lib/modules/manager/git-submodules/update.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import Git from 'simple-git';
22
import upath from 'upath';
33
import { GlobalConfig } from '../../../config/global';
44
import { logger } from '../../../logger';
5-
import { getChildProcessEnv } from '../../../util/exec/env';
5+
import { getChildEnv } from '../../../util/exec/utils';
66
import { readLocalFile } from '../../../util/fs';
77
import { getGitEnvironmentVariables } from '../../../util/git/auth';
88
import type { UpdateDependencyConfig } from '../types';
@@ -16,12 +16,7 @@ export default async function updateDependency({
1616
'git-tags',
1717
'git-refs',
1818
]);
19-
const gitEnv = {
20-
// pass all existing env variables
21-
...getChildProcessEnv(),
22-
// add all known git Variables
23-
...gitSubmoduleAuthEnvironmentVariables,
24-
};
19+
const gitEnv = getChildEnv({ env: gitSubmoduleAuthEnvironmentVariables });
2520
const git = Git(localDir).env(gitEnv);
2621
const submoduleGit = Git(upath.join(localDir, upgrade.depName)).env(gitEnv);
2722

lib/modules/manager/npm/post-update/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import deepmerge from 'deepmerge';
44
import upath from 'upath';
55
import { logger } from '../../../../logger';
66
import { ExternalHostError } from '../../../../types/errors/external-host-error';
7-
import { getChildProcessEnv } from '../../../../util/exec/env';
7+
import { getEnv } from '../../../../util/env';
88
import {
99
ensureCacheDir,
1010
getSiblingFileName,
@@ -391,8 +391,10 @@ export async function getAdditionalFiles(
391391

392392
const { additionalNpmrcContent, additionalYarnRcYml } = processHostRules();
393393

394+
// This isn't passed directly to the child process, so no need to filter.
395+
// But pass custom env and user vars.
394396
const env = {
395-
...getChildProcessEnv(),
397+
...getEnv(),
396398
NPM_CONFIG_CACHE: await ensureCacheDir('npm'),
397399
YARN_CACHE_FOLDER: await ensureCacheDir('yarn'),
398400
YARN_GLOBAL_FOLDER: await ensureCacheDir('berry'),

lib/util/exec/env.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { GlobalConfig } from '../../config/global';
2-
import { getEnv } from '../env';
32

43
const basicEnvVars = [
54
'HTTP_PROXY',
@@ -43,22 +42,21 @@ const basicEnvVars = [
4342
export function getChildProcessEnv(
4443
customEnvVars: string[] = [],
4544
): NodeJS.ProcessEnv {
46-
const combinedEnv = getEnv();
4745
const env: NodeJS.ProcessEnv = {};
4846
if (GlobalConfig.get('exposeAllEnv')) {
49-
return { ...combinedEnv };
47+
return { ...process.env };
5048
}
5149
const envVars = [...basicEnvVars, ...customEnvVars];
5250
envVars.forEach((envVar) => {
53-
if (typeof combinedEnv[envVar] !== 'undefined') {
54-
env[envVar] = combinedEnv[envVar];
51+
if (typeof process.env[envVar] !== 'undefined') {
52+
env[envVar] = process.env[envVar];
5553
}
5654
});
5755

5856
// Copy containerbase url replacements
59-
for (const key of Object.keys(combinedEnv)) {
57+
for (const key of Object.keys(process.env)) {
6058
if (/^URL_REPLACE_\d+_(?:FROM|TO)$/.test(key)) {
61-
env[key] = combinedEnv[key];
59+
env[key] = process.env[key];
6260
}
6361
}
6462
return env;

lib/util/exec/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import type { ExecOptions } from './types';
66
export function getChildEnv({
77
extraEnv,
88
env: forcedEnv = {},
9-
}: ExecOptions): Record<string, string> {
9+
}: Pick<ExecOptions, 'env' | 'extraEnv'> = {}): Record<string, string> {
1010
const globalConfigEnv = getCustomEnv();
1111
const userConfiguredEnv = getUserEnv();
1212

lib/util/git/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ export async function initRepo(args: StorageConfig): Promise<void> {
238238
config.ignoredAuthors = [];
239239
config.additionalBranches = [];
240240
config.branchIsModified = {};
241-
// TODO: safe to pass all env variables?
241+
// TODO: safe to pass all env variables? use `getChildEnv` instead?
242242
git = simpleGit(GlobalConfig.get('localDir'), simpleGitConfig()).env({
243243
...getEnv(),
244244
LANG: 'C.UTF-8',

0 commit comments

Comments
 (0)