|
13 | 13 |
|
14 | 14 | import argparse |
15 | 15 | import json |
| 16 | +import shlex |
| 17 | +import subprocess |
16 | 18 | import sys |
17 | 19 | import time |
18 | 20 | from typing import Any |
|
24 | 26 | logger = get_logger("launch", emoji="🚀") |
25 | 27 |
|
26 | 28 |
|
| 29 | +def get_current_git_branch() -> str: |
| 30 | + """Get the current git branch name.""" |
| 31 | + try: |
| 32 | + result = subprocess.run( |
| 33 | + ["git", "rev-parse", "--abbrev-ref", "HEAD"], capture_output=True, text=True, check=True |
| 34 | + ) |
| 35 | + return result.stdout.strip() |
| 36 | + except subprocess.CalledProcessError as e: |
| 37 | + logger.error(f"Failed to get git branch: {e}") |
| 38 | + raise |
| 39 | + |
| 40 | + |
27 | 41 | class AWSBatchJobLauncher: |
28 | 42 | def __init__(self, job_definition_name: str = "codeclash-yolo-test", job_queue: str = "codeclash-test-queue"): |
29 | 43 | self.batch_client = boto3.client("batch") |
@@ -54,21 +68,26 @@ def submit_job(self, command: list[str], job_name: str | None = None) -> str: |
54 | 68 | timestamp = int(time.time()) |
55 | 69 | job_name = f"codeclash-{cmd_name}-{timestamp}" |
56 | 70 |
|
| 71 | + # Get current git branch and prepend it to the command |
| 72 | + current_branch = get_current_git_branch() |
| 73 | + full_command = [current_branch] + command |
| 74 | + |
57 | 75 | # Get the latest job definition |
58 | 76 | job_definition_arn = self.get_latest_job_definition_arn() |
59 | 77 |
|
60 | 78 | response = self.batch_client.submit_job( |
61 | 79 | jobName=job_name, |
62 | 80 | jobQueue=self.job_queue, |
63 | 81 | jobDefinition=job_definition_arn, |
64 | | - containerOverrides={"command": command}, |
| 82 | + containerOverrides={"command": full_command}, |
65 | 83 | ) |
66 | 84 |
|
67 | 85 | job_id = response["jobId"] |
68 | 86 | logger.info("Job submitted successfully!") |
69 | 87 | logger.info(f"Job ID: {job_id}") |
70 | 88 | logger.info(f"Job Name: {job_name}") |
71 | | - logger.info(f"Command: {' '.join(command)}") |
| 89 | + logger.info(f"Original Command: {shlex.join(command)}") |
| 90 | + logger.info(f"Full Command (passed to container entrypoint/bootstrap.sh): {shlex.join(full_command)}") |
72 | 91 | logger.info(f"To retrieve logs later, run: python get_job_log.py {job_id}") |
73 | 92 |
|
74 | 93 | return job_id |
@@ -132,12 +151,6 @@ def main(): |
132 | 151 | parser = argparse.ArgumentParser( |
133 | 152 | description="Submit jobs to AWS Batch", |
134 | 153 | formatter_class=argparse.RawDescriptionHelpFormatter, |
135 | | - epilog=""" |
136 | | -Examples: |
137 | | - %(prog)s -- main.py configs/test/battlesnake_pvp_test.yaml |
138 | | - %(prog)s --job-name my-test -- main.py @battlesnake_pvp_test.yaml --suffix test-run |
139 | | - %(prog)s --wait --show-logs -- python -m pytest tests/ |
140 | | - """, |
141 | 154 | ) |
142 | 155 | parser.add_argument("--job-name", help="Custom job name (auto-generated if not specified)") |
143 | 156 | parser.add_argument( |
|
0 commit comments