Skip to content

Commit 87db466

Browse files
committed
feat: workflow for agentkit pr check and build
1 parent eda59b6 commit 87db466

File tree

4 files changed

+191
-0
lines changed

4 files changed

+191
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: agentkit-build
2+
3+
on:
4+
pull_request:
5+
types:
6+
- closed
7+
8+
jobs:
9+
agentkit-build:
10+
if: ${{ github.event.pull_request.merged == true }}
11+
runs-on: ubuntu-latest
12+
13+
env:
14+
VOLCENGINE_ACCESS_KEY: ${{ secrets.VOLCENGINE_ACCESS_KEY }}
15+
VOLCENGINE_SECRET_KEY: ${{ secrets.VOLCENGINE_SECRET_KEY }}
16+
steps:
17+
- name: Checkout code
18+
uses: actions/checkout@v4
19+
with:
20+
fetch-depth: 0
21+
22+
- name: Set up Python
23+
uses: actions/setup-python@v5
24+
with:
25+
python-version: "3.12"
26+
27+
- name: Install AgentKit CLI
28+
run: |
29+
python -m pip install --upgrade pip
30+
pip install agentkit-sdk-python
31+
32+
- name: Generate .env for CI
33+
run: |
34+
cat > .env << 'EOF'
35+
EOF
36+
37+
- name: Run main.py in changed use-case directories (build)
38+
env:
39+
BASE_SHA: ${{ github.event.pull_request.base.sha }}
40+
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
41+
AGENTKIT_COMMAND: build
42+
run: |
43+
python -m samples_check.check_usecases
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: agentkit-check
2+
3+
on:
4+
pull_request:
5+
6+
jobs:
7+
agentkit-launch:
8+
runs-on: ubuntu-latest
9+
10+
env:
11+
VOLCENGINE_ACCESS_KEY: ${{ secrets.VOLCENGINE_ACCESS_KEY }}
12+
VOLCENGINE_SECRET_KEY: ${{ secrets.VOLCENGINE_SECRET_KEY }}
13+
steps:
14+
- name: Checkout code
15+
uses: actions/checkout@v4
16+
with:
17+
fetch-depth: 0
18+
19+
- name: Set up Python
20+
uses: actions/setup-python@v5
21+
with:
22+
python-version: "3.12"
23+
24+
- name: Install AgentKit CLI
25+
run: |
26+
python -m pip install --upgrade pip
27+
pip install agentkit-sdk-python
28+
29+
- name: Generate .env for CI
30+
run: |
31+
cat > .env << 'EOF'
32+
EOF
33+
34+
- name: Run main.py in changed use-case directories
35+
env:
36+
BASE_SHA: ${{ github.event.pull_request.base.sha }}
37+
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
38+
run: |
39+
python -m samples_check.check_usecases

samples_check/__init__.py

Whitespace-only changes.

samples_check/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":
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+
if not agent_py.is_file():
62+
print(f"No agent.py in {d}, skipping agentkit commands.")
63+
continue
64+
65+
agent_name = d.name
66+
workflow_name = os.environ.get("GITHUB_WORKFLOW", "")
67+
if workflow_name == "agentkit-check":
68+
agent_name = f"check_{agent_name}"
69+
print(f"Running 'agentkit config' in {d} for agent_name={agent_name}")
70+
config_cmd = [
71+
"agentkit",
72+
"config",
73+
"--agent_name",
74+
agent_name,
75+
"--entry_point",
76+
"agent.py",
77+
"--description",
78+
"a helpful agent",
79+
"--launch_type",
80+
"cloud",
81+
"--image_tag",
82+
"v1.0.0",
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)