Skip to content

Commit cf697c6

Browse files
committed
fix: agentkit checkout and build
1 parent eda59b6 commit cf697c6

File tree

4 files changed

+209
-0
lines changed

4 files changed

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

workflow_utils/__init__.py

Whitespace-only changes.

workflow_utils/check_usecases.py

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
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+
workflow_name = os.environ.get("GITHUB_WORKFLOW", "")
68+
if workflow_name == "agentkit-check":
69+
agent_name = f"check_{agent_name}"
70+
print(f"Running 'agentkit config' in {d} for agent_name={agent_name}")
71+
config_cmd = [
72+
"agentkit",
73+
"config",
74+
"--agent_name",
75+
agent_name,
76+
"--entry_point",
77+
"agent.py",
78+
"--description",
79+
"a helpful agent",
80+
"--launch_type",
81+
"cloud",
82+
"--image_tag",
83+
"v1.0.0",
84+
"--region",
85+
"cn-beijing",
86+
]
87+
result = subprocess.run(config_cmd, cwd=str(d))
88+
if result.returncode != 0:
89+
failed_dirs.append(d)
90+
print(f"'agentkit config' failed in {d}, skipping launch.")
91+
continue
92+
93+
command = os.environ.get("AGENTKIT_COMMAND", "launch")
94+
print(f"Running 'agentkit {command}' in {d}")
95+
launch_cmd = ["agentkit", command]
96+
result = subprocess.run(launch_cmd, cwd=str(d))
97+
if result.returncode != 0:
98+
failed_dirs.append(d)
99+
100+
if failed_dirs:
101+
sys.stderr.write(
102+
"agentkit checks failed in directories: "
103+
+ ", ".join(str(d) for d in failed_dirs)
104+
+ "\n"
105+
)
106+
raise SystemExit(1)
107+
108+
109+
if __name__ == "__main__":
110+
main()

0 commit comments

Comments
 (0)