Skip to content

Commit f2679fa

Browse files
committed
feat: always set CI=true for subprocesses
As noted in #43761, we had recently set `CI=true` for the Renovate and Containerbase orgs on Mend-hosted apps due to a pnpm v11 requirement: ERR_PNPM_ABORTED_REMOVE_MODULES_DIR_NO_TTY  Aborted removal of modules directory due to no TTY If you are running pnpm in CI, set the CI environment variable to "true", or set "confirmModulesPurge" to "false". Similarly in #43606, it was noted that we should do this for `mise lock` to mark the workspace as "trusted". Although we went with a different situation, there will be cases where this is useful for tools being executed, for instance when we invoke `yarn`. We also make sure to keep our documentation up-to-date as we add to the specific overrides.
1 parent 62030b2 commit f2679fa

6 files changed

Lines changed: 71 additions & 3 deletions

File tree

docs/usage/environment-variable-handling.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ By default, Renovate will **always** pass the following environment variables to
2727

2828
<!-- Autogenerate basicEnvVars -->
2929

30+
Additionally, Renovate will **always** set the following environment variables to these exact values:
31+
32+
<!-- Autogenerate hardcodedProcessEnv -->
33+
3034
!!! note
3135
Some managers pass additional environment variables where necessary.
3236
<br>

lib/util/exec/env.spec.ts

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import { GlobalConfig } from '../../config/global.ts';
2-
import { getChildProcessEnv } from './env.ts';
2+
import {
3+
basicEnvVars,
4+
getChildProcessEnv,
5+
hardcodedProcessEnv,
6+
} from './env.ts';
37

48
describe('util/exec/env', () => {
59
const envVars = [
@@ -51,7 +55,25 @@ describe('util/exec/env', () => {
5155
'PROGRAMFILES(X86)': 'PROGRAMFILES(X86)',
5256
APPDATA: 'APPDATA',
5357
LOCALAPPDATA: 'LOCALAPPDATA',
58+
59+
CI: 'true',
60+
});
61+
});
62+
63+
it('always sets static values for CI', () => {
64+
expect(getChildProcessEnv()).toMatchObject({
65+
CI: 'true',
66+
});
67+
});
68+
69+
it('static environment variables override the process environment variables', () => {
70+
process.env.CI = 'false';
71+
72+
expect(getChildProcessEnv()).toMatchObject({
73+
CI: 'true',
5474
});
75+
76+
delete process.env.CI;
5577
});
5678

5779
it('returns environment variable only if defined', () => {
@@ -81,4 +103,22 @@ describe('util/exec/env', () => {
81103
expect(getChildProcessEnv()).toMatchObject(process.env);
82104
});
83105
});
106+
107+
describe('basicEnvVars and hardcodedProcessEnv should not have any overlap', () => {
108+
describe('basicEnvVars does not include any environment variables in hardcodedProcessEnv', () => {
109+
for (const env of Object.keys(hardcodedProcessEnv)) {
110+
it(`${env} is not in basicEnvVars`, () => {
111+
expect(basicEnvVars).not.toContain(env);
112+
});
113+
}
114+
});
115+
116+
describe('hardcodedProcessEnv does not include any environment variables in basicEnvVars', () => {
117+
for (const env of basicEnvVars) {
118+
it(`${env} is not in hardcodedProcessEnv`, () => {
119+
expect(hardcodedProcessEnv).not.toContainKey(env);
120+
});
121+
}
122+
});
123+
});
84124
});

lib/util/exec/env.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { GlobalConfig } from '../../config/global.ts';
22
import { regEx } from '../regex.ts';
33

44
export const basicEnvVars = [
5-
'CI',
65
'HTTP_PROXY',
76
'HTTPS_PROXY',
87
'NO_PROXY',
@@ -49,6 +48,10 @@ export const basicEnvVars = [
4948
'PNPM_MAX_WORKERS',
5049
] as const;
5150

51+
export const hardcodedProcessEnv: Readonly<NodeJS.ProcessEnv> = {
52+
CI: 'true',
53+
} as const;
54+
5255
export function getChildProcessEnv(
5356
customEnvVars: string[] = [],
5457
): NodeJS.ProcessEnv {
@@ -69,5 +72,10 @@ export function getChildProcessEnv(
6972
env[key] = process.env[key];
7073
}
7174
}
75+
76+
for (const [key, value] of Object.entries(hardcodedProcessEnv)) {
77+
env[key] = value;
78+
}
79+
7280
return env;
7381
}

lib/util/exec/index.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,6 +1137,7 @@ describe('util/exec/index', () => {
11371137
'PATH',
11381138
'LC_ALL',
11391139
'LANG',
1140+
'CI',
11401141
],
11411142
},
11421143
'Executing command',

test/exec-util.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ export function mockExecSequence(execResults: ExecResult[]): ExecSnapshots {
7575
}
7676

7777
const basicEnvMock = {
78+
CI: 'true',
7879
HTTP_PROXY: 'http://example.com',
7980
HTTPS_PROXY: 'https://example.com',
8081
NO_PROXY: 'localhost',

tools/docs/env-vars.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { basicEnvVars } from '../../lib/util/exec/env.ts';
1+
import { basicEnvVars, hardcodedProcessEnv } from '../../lib/util/exec/env.ts';
22
import { readFile, updateFile } from '../utils/index.ts';
33
import { replaceContent } from './utils.ts';
44

@@ -11,12 +11,26 @@ function basicEnvVarsToMarkdown(): string {
1111
return `${list}\n\n`;
1212
}
1313

14+
function hardcodedProcessEnvToMarkdown(): string {
15+
const list = Object.keys(hardcodedProcessEnv)
16+
// case-insensitive sort
17+
.sort((a, b) => a.localeCompare(b, undefined, { sensitivity: 'base' }))
18+
.map((k) => ` - \`${k}=${hardcodedProcessEnv[k]}\``)
19+
.join('\n');
20+
return `${list}\n\n`;
21+
}
22+
1423
export async function generateEnvVars(dist: string): Promise<void> {
1524
let content = await readFile('docs/usage/environment-variable-handling.md');
1625
content = replaceContent(
1726
content,
1827
basicEnvVarsToMarkdown(),
1928
'<!-- Autogenerate basicEnvVars -->',
2029
);
30+
content = replaceContent(
31+
content,
32+
hardcodedProcessEnvToMarkdown(),
33+
'<!-- Autogenerate hardcodedProcessEnv -->',
34+
);
2135
await updateFile(`${dist}/environment-variable-handling.md`, content);
2236
}

0 commit comments

Comments
 (0)