Skip to content

Commit 146c247

Browse files
committed
Correctly activate envs
1 parent 680bd88 commit 146c247

1 file changed

Lines changed: 25 additions & 10 deletions

File tree

.github/scripts/run_playbook_tests.py

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -477,19 +477,28 @@ def run_test(
477477

478478
if test.language in ["bash", "sh", "shell"]:
479479
if is_windows:
480-
shell_cmd = ["powershell", "-Command"]
481-
script_content = effective_code
480+
if setup_prefix:
481+
# Use cmd.exe instead of PowerShell so .bat setup commands
482+
# (e.g. venv activation) run in the same session and their
483+
# environment changes persist for subsequent commands.
484+
shell_cmd = ["cmd", "/c"]
485+
lines = [l for l in effective_code.strip().splitlines() if l.strip()]
486+
script_content = " && ".join([setup_prefix] + lines)
487+
else:
488+
shell_cmd = ["powershell", "-Command"]
489+
script_content = effective_code
482490
else:
483491
shell_cmd = ["bash", "-c"]
484492
script_content = effective_code
485-
# Prepend setup commands to the shell script body
486-
if setup_prefix:
487-
script_content = f"{setup_prefix}\n{script_content}"
493+
if setup_prefix:
494+
script_content = f"{setup_prefix}\n{script_content}"
488495
elif test.language in ["cmd", "batch"]:
489496
shell_cmd = ["cmd", "/c"]
490497
script_content = effective_code
491498
if setup_prefix:
492-
script_content = f"{setup_prefix}\n{script_content}"
499+
# Use && so setup and code share the same cmd.exe session
500+
lines = [l for l in effective_code.strip().splitlines() if l.strip()]
501+
script_content = " && ".join([setup_prefix] + lines)
493502
elif test.language in ["powershell", "pwsh", "ps1"]:
494503
shell_cmd = ["powershell", "-Command"]
495504
script_content = effective_code
@@ -513,12 +522,18 @@ def run_test(
513522
else:
514523
# Default to shell execution
515524
if is_windows:
516-
shell_cmd = ["powershell", "-Command"]
525+
if setup_prefix:
526+
shell_cmd = ["cmd", "/c"]
527+
lines = [l for l in effective_code.strip().splitlines() if l.strip()]
528+
script_content = " && ".join([setup_prefix] + lines)
529+
else:
530+
shell_cmd = ["powershell", "-Command"]
531+
script_content = effective_code
517532
else:
518533
shell_cmd = ["bash", "-c"]
519-
script_content = effective_code
520-
if setup_prefix:
521-
script_content = f"{setup_prefix}\n{script_content}"
534+
script_content = effective_code
535+
if setup_prefix:
536+
script_content = f"{setup_prefix}\n{script_content}"
522537

523538
# Build the command
524539
if script_content is not None:

0 commit comments

Comments
 (0)