Skip to content

Commit f5579db

Browse files
authored
Special handle variable option from .env file to mimic merge like behavior (#1509)
* Fix issue 1508 by special handling variable option from .env file * Fix * Bump to node-version 22 * Let's see * Fix it up * Will this work * Try without variable * Do not run concurrent shell-executor
1 parent 29839d3 commit f5579db

File tree

5 files changed

+42
-2
lines changed

5 files changed

+42
-2
lines changed

.github/workflows/build.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ jobs:
4646
- uses: actions/checkout@v4
4747
- uses: actions/setup-node@v4
4848
with:
49+
node-version: '22'
4950
cache: 'npm'
5051
- run: npm ci
5152
- run: npm run lint
@@ -56,6 +57,7 @@ jobs:
5657
- uses: actions/checkout@v4
5758
- uses: actions/setup-node@v4
5859
with:
60+
node-version: '22'
5961
cache: 'npm'
6062
- run: npm ci
6163
- run: npx depcheck --ignores depcheck
@@ -68,6 +70,7 @@ jobs:
6870
fetch-depth: 0
6971
- uses: actions/setup-node@v4.2.0
7072
with:
73+
node-version: '22'
7174
cache: 'npm'
7275
- run: npm ci
7376
- name: Run Tests

src/argv.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,21 @@ export class Argv {
8181
const config = dotenv.parse(fs.readFileSync(potentialDotenvFilepath));
8282
for (const [key, value] of Object.entries(config)) {
8383
const argKey = camelCase(key);
84-
if (argv[argKey] == null) {
84+
85+
// Special handle KEY=VALUE variable keys
86+
if (argKey === "variable") {
87+
let currentVal = argv[argKey];
88+
if (currentVal == null) {
89+
currentVal = [];
90+
this.map.set(argKey, currentVal);
91+
}
92+
if (!Array.isArray(currentVal)) {
93+
continue;
94+
}
95+
for (const pair of value.split(" ")) {
96+
currentVal.unshift(pair);
97+
}
98+
} else if (argv[argKey] == null) {
8599
// Work around `dotenv.parse` limitation https://github.com/motdotla/dotenv/issues/51#issuecomment-552559070
86100
if (value === "true") this.map.set(argKey, true);
87101
else if (value === "false") this.map.set(argKey, false);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
VARIABLE=KUBE_CONTEXT=minikube KUBECONFIG=/root/.kube/config XDEBUG_MODE=develop

tests/test-cases/project-variables-file/.gitlab-ci.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,9 @@ test-job:
1212
- echo "$FUNNY3"
1313
environment:
1414
name: $ENV
15+
16+
issue-1508:
17+
script:
18+
- echo $KUBE_CONTEXT
19+
- echo $KUBECONFIG
20+
- echo $XDEBUG_MODE

tests/test-cases/project-variables-file/integration.test.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ afterAll(() => {
1717
fs.removeSync(path.join(cwd, emptyFileVariable));
1818
});
1919

20-
test.concurrent("project-variables-file <test-job>", async () => {
20+
test("project-variables-file <test-job>", async () => {
2121
const writeStreams = new WriteStreamsMock();
2222
await handler({
2323
cwd: cwd,
@@ -31,6 +31,22 @@ test.concurrent("project-variables-file <test-job>", async () => {
3131
expect(writeStreams.stdoutLines).toEqual(expect.arrayContaining(expected));
3232
});
3333

34+
test("project-variables-file <issue-1508>", async () => {
35+
const writeStreams = new WriteStreamsMock();
36+
await handler({
37+
cwd: cwd,
38+
job: ["issue-1508"],
39+
variable: ["XDEBUG_MODE=debug,develop"],
40+
}, writeStreams);
41+
42+
const expected = [
43+
chalk`{blueBright issue-1508} {greenBright >} minikube`,
44+
chalk`{blueBright issue-1508} {greenBright >} /root/.kube/config`,
45+
chalk`{blueBright issue-1508} {greenBright >} debug,develop`,
46+
];
47+
expect(writeStreams.stdoutLines).toEqual(expect.arrayContaining(expected));
48+
});
49+
3450
test.concurrent("project-variables-file <issue-1333>", async () => {
3551
const writeStreams = new WriteStreamsMock();
3652
await handler({

0 commit comments

Comments
 (0)