Skip to content

Commit e5d0969

Browse files
fix: agentkit checkout and build workflow (#101)
2 parents 57890b7 + 52b684b commit e5d0969

File tree

3 files changed

+188
-0
lines changed

3 files changed

+188
-0
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
name: agentkit-check
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
pr_number:
7+
description: "Pull request number"
8+
required: true
9+
10+
jobs:
11+
agentkit-launch:
12+
runs-on: ubuntu-latest
13+
14+
env:
15+
VOLCENGINE_ACCESS_KEY: ${{ secrets.VOLCENGINE_ACCESS_KEY }}
16+
VOLCENGINE_SECRET_KEY: ${{ secrets.VOLCENGINE_SECRET_KEY }}
17+
steps:
18+
- name: Checkout code
19+
uses: actions/checkout@v4
20+
with:
21+
fetch-depth: 0
22+
ref: ${{ format('refs/pull/{0}/merge', github.event.inputs.pr_number) }}
23+
24+
- name: Set up Python
25+
uses: actions/setup-python@v5
26+
with:
27+
python-version: "3.12"
28+
29+
- name: Install AgentKit CLI
30+
run: |
31+
python -m pip install --upgrade pip
32+
pip install agentkit-sdk-python
33+
34+
- name: Generate .env for CI
35+
run: |
36+
cat > .env << 'EOF'
37+
EOF
38+
39+
- name: Resolve BASE/HEAD from PR number
40+
if: github.event.inputs.pr_number != ''
41+
env:
42+
PR_NUMBER: ${{ github.event.inputs.pr_number }}
43+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
44+
run: |
45+
python - << 'PY'
46+
import json
47+
import os
48+
import urllib.request
49+
50+
repo = os.environ["GITHUB_REPOSITORY"]
51+
pr_number = os.environ["PR_NUMBER"]
52+
token = os.environ["GITHUB_TOKEN"]
53+
54+
url = f"https://api.github.com/repos/{repo}/pulls/{pr_number}"
55+
req = urllib.request.Request(
56+
url,
57+
headers={
58+
"Authorization": f"Bearer {token}",
59+
"Accept": "application/vnd.github+json",
60+
},
61+
)
62+
with urllib.request.urlopen(req) as resp:
63+
data = json.load(resp)
64+
65+
base_sha = data["base"]["sha"]
66+
head_sha = data["head"]["sha"]
67+
68+
github_env = os.environ["GITHUB_ENV"]
69+
with open(github_env, "a", encoding="utf-8") as f:
70+
f.write(f"BASE_SHA={base_sha}\n")
71+
f.write(f"HEAD_SHA={head_sha}\n")
72+
PY
73+
74+
- name: Run main.py in changed use-case directories
75+
env:
76+
BASE_SHA: ${{ env.BASE_SHA }}
77+
HEAD_SHA: ${{ env.HEAD_SHA }}
78+
run: |
79+
python -m workflow_utils.check_usecases

workflow_utils/__init__.py

Whitespace-only changes.

workflow_utils/check_usecases.py

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
import os
2+
import subprocess
3+
import sys
4+
from pathlib import Path
5+
6+
7+
def get_changed_files(base_sha: str, head_sha: str) -> list[str]:
8+
if not base_sha or not head_sha:
9+
return []
10+
try:
11+
output = subprocess.check_output(
12+
["git", "diff", "--name-only", base_sha, head_sha],
13+
text=True,
14+
stderr=subprocess.STDOUT,
15+
)
16+
except subprocess.CalledProcessError as exc:
17+
sys.stderr.write(exc.output)
18+
return []
19+
return [line.strip() for line in output.splitlines() if line.strip()]
20+
21+
22+
def main() -> None:
23+
base_sha = os.environ.get("BASE_SHA", "")
24+
head_sha = os.environ.get("HEAD_SHA", "")
25+
26+
changed = get_changed_files(base_sha, head_sha)
27+
changed_use_cases = [p for p in changed if p.startswith("02-use-cases/")]
28+
29+
if not changed_use_cases:
30+
print("No changes under 02-use-cases, skipping main.py checks.")
31+
return
32+
33+
candidate_dirs: set[Path] = set()
34+
for rel_path in changed_use_cases:
35+
parts = Path(rel_path).parts
36+
if len(parts) >= 2 and parts[0] == "02-use-cases" and parts[1] != "beginner":
37+
candidate_dirs.add(Path(parts[0]) / parts[1])
38+
39+
if not candidate_dirs:
40+
print(
41+
"No top-level 02-use-cases/* directories detected, skipping main.py checks."
42+
)
43+
return
44+
45+
print("Use-case directories to check:")
46+
for d in sorted(candidate_dirs):
47+
print(f" - {d}")
48+
49+
failed_dirs: list[Path] = []
50+
51+
for d in sorted(candidate_dirs):
52+
# deploy_sh = d / "deploy.sh"
53+
# if deploy_sh.is_file():
54+
# print(f"Found deploy.sh in {d}, running it")
55+
# result = subprocess.run(["bash", "deploy.sh"], cwd=str(d))
56+
# if result.returncode != 0:
57+
# failed_dirs.append(d)
58+
# continue
59+
60+
agent_py = d / "agent.py"
61+
62+
if not agent_py.is_file():
63+
print(f"No agent.py in {d}, skipping agentkit commands now.")
64+
continue
65+
66+
agent_name = d.name
67+
print(f"Running 'agentkit config' in {d} for agent_name={agent_name}")
68+
config_cmd = [
69+
"agentkit",
70+
"config",
71+
"--agent_name",
72+
agent_name,
73+
"--entry_point",
74+
"agent.py",
75+
"--description",
76+
"a helpful agent",
77+
"--launch_type",
78+
"cloud",
79+
"--image_tag",
80+
"v1.0.0",
81+
"--cr_repo_name",
82+
agent_name,
83+
"--region",
84+
"cn-beijing",
85+
]
86+
result = subprocess.run(config_cmd, cwd=str(d))
87+
if result.returncode != 0:
88+
failed_dirs.append(d)
89+
print(f"'agentkit config' failed in {d}, skipping launch.")
90+
continue
91+
92+
command = os.environ.get("AGENTKIT_COMMAND", "launch")
93+
print(f"Running 'agentkit {command}' in {d}")
94+
launch_cmd = ["agentkit", command]
95+
result = subprocess.run(launch_cmd, cwd=str(d))
96+
if result.returncode != 0:
97+
failed_dirs.append(d)
98+
99+
if failed_dirs:
100+
sys.stderr.write(
101+
"agentkit checks failed in directories: "
102+
+ ", ".join(str(d) for d in failed_dirs)
103+
+ "\n"
104+
)
105+
raise SystemExit(1)
106+
107+
108+
if __name__ == "__main__":
109+
main()

0 commit comments

Comments
 (0)