-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdev.sh
More file actions
executable file
·121 lines (100 loc) · 3.79 KB
/
Copy pathdev.sh
File metadata and controls
executable file
·121 lines (100 loc) · 3.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/bin/bash
# Start interactive Docker shell for a benchmark instance
# Usage: ./dev.sh <benchmark-name>
set -euo pipefail
if [ -z "${1:-}" ]; then
echo "Usage: ./dev.sh <benchmark-name>"
echo "Available: $(ls dataset/)"
exit 1
fi
ROOT_DIR="$(cd "$(dirname "$0")" && pwd)"
BENCHMARK_NAME="$1"
BENCHMARK_DIR="${ROOT_DIR}/dataset/${BENCHMARK_NAME}"
if [ ! -d "$BENCHMARK_DIR" ]; then
echo "Error: Unknown benchmark '${BENCHMARK_NAME}'"
echo "Available: $(ls dataset/)"
exit 1
fi
if [ ! -f "${ROOT_DIR}/.venv/bin/activate" ]; then
echo "Error: Missing .venv. Create it with: python3 -m venv .venv"
exit 1
fi
timestamp="$(date +%Y%m%d_%H%M%S)"
workspace_dir="${BENCHMARK_DIR}/workspace-${timestamp}"
compose_file="${BENCHMARK_DIR}/docker-compose.dev-${timestamp}.yml"
container_name="${BENCHMARK_NAME}-dev-${timestamp}"
source "${ROOT_DIR}/.venv/bin/activate"
eval "$(
python3 - <<PY
import re
import sys
from pathlib import Path
import yaml
root_dir = Path(${ROOT_DIR@Q})
benchmark_dir = Path(${BENCHMARK_DIR@Q})
workspace_dir = Path(${workspace_dir@Q})
compose_src = benchmark_dir / "docker-compose.dev.yml"
compose_dst = Path(${compose_file@Q})
container_name = ${container_name@Q}
workspace_dir.mkdir(parents=True, exist_ok=True)
(workspace_dir / "src").mkdir(exist_ok=True)
(workspace_dir / "dst").mkdir(exist_ok=True)
# Load metadata for provenance info
metadata_file = benchmark_dir / "metadata.yml"
source_repo = ""
source_commit = ""
if metadata_file.exists():
with open(metadata_file) as f:
metadata = yaml.safe_load(f)
provenance = metadata.get("provenance", {})
source_repo = provenance.get("source_repo") or ""
source_commit = provenance.get("source_commit") or ""
# Generate prompt.md from benchmark.yml
sys.path.insert(0, str(root_dir))
from generate_prompts import generate_prompt, load_benchmark_config
benchmark_config = load_benchmark_config(benchmark_dir)
if benchmark_config:
prompt_content = generate_prompt(benchmark_config, "v1")
with open(workspace_dir / "prompt.md", "w") as f:
f.write(prompt_content)
else:
print("Warning: Could not generate prompt.md", file=sys.stderr)
# Write compose file with isolated workspace mount and unique container name
compose_content = compose_src.read_text()
compose_content = re.sub(
r"\./workspace:/workspace",
f"{workspace_dir}:/workspace",
compose_content,
)
compose_content = re.sub(
r"container_name:\s*\S+",
f"container_name: {container_name}",
compose_content,
)
compose_dst.write_text(compose_content)
print(f"Workspace: {workspace_dir}", file=sys.stderr)
print(f"Compose file: {compose_dst}", file=sys.stderr)
print(f"SOURCE_REPO={source_repo!r}")
print(f"SOURCE_COMMIT={source_commit!r}")
PY
)"
trap 'docker compose -f "${compose_file}" down >/dev/null 2>&1 || true; rm -f "${compose_file}"' EXIT
docker compose -f "${compose_file}" up -d --build
if [ -n "${SOURCE_REPO}" ] && [ -n "${SOURCE_COMMIT}" ]; then
docker compose -f "${compose_file}" exec dev bash -c \
"cd /workspace && rm -rf src && git clone --recurse-submodules ${SOURCE_REPO} src && \
cd /workspace/src && git checkout ${SOURCE_COMMIT} && git submodule update --init --recursive"
else
if [ -d "${BENCHMARK_DIR}/workspace/src" ]; then
cp -a "${BENCHMARK_DIR}/workspace/src/." "${workspace_dir}/src/"
else
echo "No source_repo in metadata and no workspace/src"
exit 1
fi
fi
docker compose -f "${compose_file}" exec dev bash -c \
"set -e; mkdir -p /workspace/dst; \
git -C /workspace/dst init; \
GIT_DIR=/workspace/dst/.git GIT_WORK_TREE=/workspace/dst git config user.email 'agent@benchmark.local'; \
GIT_DIR=/workspace/dst/.git GIT_WORK_TREE=/workspace/dst git config user.name 'Benchmark Agent'"
docker compose -f "${compose_file}" exec dev bash