Skip to content

Commit

Permalink
Allow empty value for remote env (devcontainers/ci#231)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrmarti authored Mar 5, 2024
1 parent 30d2105 commit ab79dd6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/spec-node/devContainersSpecCLI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ function provisionOptions(y: Argv) {
throw new Error('Unmatched argument format: mount must match type=<bind|volume>,source=<source>,target=<target>[,external=<true|false>]');
}
const remoteEnvs = (argv['remote-env'] && (Array.isArray(argv['remote-env']) ? argv['remote-env'] : [argv['remote-env']])) as string[] | undefined;
if (remoteEnvs?.some(remoteEnv => !/.+=.+/.test(remoteEnv))) {
if (remoteEnvs?.some(remoteEnv => !/.+=.*/.test(remoteEnv))) {
throw new Error('Unmatched argument format: remote-env must match <name>=<value>');
}
return true;
Expand Down Expand Up @@ -334,7 +334,7 @@ function setUpOptions(y: Argv) {
})
.check(argv => {
const remoteEnvs = (argv['remote-env'] && (Array.isArray(argv['remote-env']) ? argv['remote-env'] : [argv['remote-env']])) as string[] | undefined;
if (remoteEnvs?.some(remoteEnv => !/.+=.+/.test(remoteEnv))) {
if (remoteEnvs?.some(remoteEnv => !/.+=.*/.test(remoteEnv))) {
throw new Error('Unmatched argument format: remote-env must match <name>=<value>');
}
return true;
Expand Down Expand Up @@ -742,7 +742,7 @@ function runUserCommandsOptions(y: Argv) {
throw new Error('Unmatched argument format: id-label must match <name>=<value>');
}
const remoteEnvs = (argv['remote-env'] && (Array.isArray(argv['remote-env']) ? argv['remote-env'] : [argv['remote-env']])) as string[] | undefined;
if (remoteEnvs?.some(remoteEnv => !/.+=.+/.test(remoteEnv))) {
if (remoteEnvs?.some(remoteEnv => !/.+=.*/.test(remoteEnv))) {
throw new Error('Unmatched argument format: remote-env must match <name>=<value>');
}
if (!argv['container-id'] && !idLabels?.length && !argv['workspace-folder']) {
Expand Down Expand Up @@ -1197,7 +1197,7 @@ function execOptions(y: Argv) {
throw new Error('Unmatched argument format: id-label must match <name>=<value>');
}
const remoteEnvs = (argv['remote-env'] && (Array.isArray(argv['remote-env']) ? argv['remote-env'] : [argv['remote-env']])) as string[] | undefined;
if (remoteEnvs?.some(remoteEnv => !/.+=.+/.test(remoteEnv))) {
if (remoteEnvs?.some(remoteEnv => !/.+=.*/.test(remoteEnv))) {
throw new Error('Unmatched argument format: remote-env must match <name>=<value>');
}
if (!argv['container-id'] && !idLabels?.length && !argv['workspace-folder']) {
Expand Down
12 changes: 12 additions & 0 deletions src/test/cli.exec.base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,18 @@ export function describeTests1({ text, options }: BuildKitOption) {
assert.equal(res.signal, undefined);
assert.match(res.cmdOutput, /BARhiBAR/);
});
it('should pass along --remote-env', async () => {
const res = await shellBufferExec(`${cli} exec --workspace-folder ${testFolder} --remote-env FOO=BAR --remote-env BAZ= printenv`);
assert.strictEqual(res.code, 0);
assert.equal(res.signal, undefined);
const stdout = res.stdout.toString();
const env = stdout
.split('\n')
.map(l => l.split('='))
.reduce((m, [k, v]) => { m[k] = v; return m; }, {} as { [key: string]: string });
assert.strictEqual(env.FOO, 'BAR');
assert.strictEqual(env.BAZ, '');
});
});
describe(`with valid (image) config containing features [${text}]`, () => {
let containerId: string | null = null;
Expand Down

0 comments on commit ab79dd6

Please sign in to comment.