From 87db4660bb4c06cdadfbb872d4d7c8317c6cb57c Mon Sep 17 00:00:00 2001 From: "hanzhi.421" Date: Thu, 25 Dec 2025 15:58:30 +0800 Subject: [PATCH 1/5] feat: workflow for agentkit pr check and build --- .github/workflows/agentkit-build.yaml | 43 ++++++++++ .github/workflows/agentkit-check.yaml | 39 +++++++++ samples_check/__init__.py | 0 samples_check/check_usecases.py | 109 ++++++++++++++++++++++++++ 4 files changed, 191 insertions(+) create mode 100644 .github/workflows/agentkit-build.yaml create mode 100644 .github/workflows/agentkit-check.yaml create mode 100644 samples_check/__init__.py create mode 100644 samples_check/check_usecases.py diff --git a/.github/workflows/agentkit-build.yaml b/.github/workflows/agentkit-build.yaml new file mode 100644 index 0000000..f02c0a8 --- /dev/null +++ b/.github/workflows/agentkit-build.yaml @@ -0,0 +1,43 @@ +name: agentkit-build + +on: + pull_request: + types: + - closed + +jobs: + agentkit-build: + if: ${{ github.event.pull_request.merged == true }} + runs-on: ubuntu-latest + + env: + VOLCENGINE_ACCESS_KEY: ${{ secrets.VOLCENGINE_ACCESS_KEY }} + VOLCENGINE_SECRET_KEY: ${{ secrets.VOLCENGINE_SECRET_KEY }} + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.12" + + - name: Install AgentKit CLI + run: | + python -m pip install --upgrade pip + pip install agentkit-sdk-python + + - name: Generate .env for CI + run: | + cat > .env << 'EOF' + EOF + + - name: Run main.py in changed use-case directories (build) + env: + BASE_SHA: ${{ github.event.pull_request.base.sha }} + HEAD_SHA: ${{ github.event.pull_request.head.sha }} + AGENTKIT_COMMAND: build + run: | + python -m samples_check.check_usecases diff --git a/.github/workflows/agentkit-check.yaml b/.github/workflows/agentkit-check.yaml new file mode 100644 index 0000000..233e9cd --- /dev/null +++ b/.github/workflows/agentkit-check.yaml @@ -0,0 +1,39 @@ +name: agentkit-check + +on: + pull_request: + +jobs: + agentkit-launch: + runs-on: ubuntu-latest + + env: + VOLCENGINE_ACCESS_KEY: ${{ secrets.VOLCENGINE_ACCESS_KEY }} + VOLCENGINE_SECRET_KEY: ${{ secrets.VOLCENGINE_SECRET_KEY }} + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.12" + + - name: Install AgentKit CLI + run: | + python -m pip install --upgrade pip + pip install agentkit-sdk-python + + - name: Generate .env for CI + run: | + cat > .env << 'EOF' + EOF + + - name: Run main.py in changed use-case directories + env: + BASE_SHA: ${{ github.event.pull_request.base.sha }} + HEAD_SHA: ${{ github.event.pull_request.head.sha }} + run: | + python -m samples_check.check_usecases diff --git a/samples_check/__init__.py b/samples_check/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/samples_check/check_usecases.py b/samples_check/check_usecases.py new file mode 100644 index 0000000..b45937a --- /dev/null +++ b/samples_check/check_usecases.py @@ -0,0 +1,109 @@ +import os +import subprocess +import sys +from pathlib import Path + + +def get_changed_files(base_sha: str, head_sha: str) -> list[str]: + if not base_sha or not head_sha: + return [] + try: + output = subprocess.check_output( + ["git", "diff", "--name-only", base_sha, head_sha], + text=True, + stderr=subprocess.STDOUT, + ) + except subprocess.CalledProcessError as exc: + sys.stderr.write(exc.output) + return [] + return [line.strip() for line in output.splitlines() if line.strip()] + + +def main() -> None: + base_sha = os.environ.get("BASE_SHA", "") + head_sha = os.environ.get("HEAD_SHA", "") + + changed = get_changed_files(base_sha, head_sha) + changed_use_cases = [p for p in changed if p.startswith("02-use-cases/")] + + if not changed_use_cases: + print("No changes under 02-use-cases, skipping main.py checks.") + return + + candidate_dirs: set[Path] = set() + for rel_path in changed_use_cases: + parts = Path(rel_path).parts + if len(parts) >= 2 and parts[0] == "02-use-cases": + candidate_dirs.add(Path(parts[0]) / parts[1]) + + if not candidate_dirs: + print( + "No top-level 02-use-cases/* directories detected, skipping main.py checks." + ) + return + + print("Use-case directories to check:") + for d in sorted(candidate_dirs): + print(f" - {d}") + + failed_dirs: list[Path] = [] + + for d in sorted(candidate_dirs): + # deploy_sh = d / "deploy.sh" + # if deploy_sh.is_file(): + # print(f"Found deploy.sh in {d}, running it") + # result = subprocess.run(["bash", "deploy.sh"], cwd=str(d)) + # if result.returncode != 0: + # failed_dirs.append(d) + # continue + + agent_py = d / "agent.py" + if not agent_py.is_file(): + print(f"No agent.py in {d}, skipping agentkit commands.") + continue + + agent_name = d.name + workflow_name = os.environ.get("GITHUB_WORKFLOW", "") + if workflow_name == "agentkit-check": + agent_name = f"check_{agent_name}" + print(f"Running 'agentkit config' in {d} for agent_name={agent_name}") + config_cmd = [ + "agentkit", + "config", + "--agent_name", + agent_name, + "--entry_point", + "agent.py", + "--description", + "a helpful agent", + "--launch_type", + "cloud", + "--image_tag", + "v1.0.0", + "--region", + "cn-beijing", + ] + result = subprocess.run(config_cmd, cwd=str(d)) + if result.returncode != 0: + failed_dirs.append(d) + print(f"'agentkit config' failed in {d}, skipping launch.") + continue + + command = os.environ.get("AGENTKIT_COMMAND", "launch") + print(f"Running 'agentkit {command}' in {d}") + launch_cmd = ["agentkit", command] + result = subprocess.run(launch_cmd, cwd=str(d)) + if result.returncode != 0: + failed_dirs.append(d) + + if failed_dirs: + sys.stderr.write( + "agentkit checks failed in directories: " + + ", ".join(str(d) for d in failed_dirs) + + "\n" + ) + raise SystemExit(1) + + +if __name__ == "__main__": + main() From 37723482d30a7e715f34b6b01199d32dbd072e2b Mon Sep 17 00:00:00 2001 From: "hanzhi.421" Date: Thu, 25 Dec 2025 20:58:38 +0800 Subject: [PATCH 2/5] fix: check --- .github/workflows/agentkit-build.yaml | 2 +- .github/workflows/agentkit-check.yaml | 2 +- {samples_check => workflow_utils}/__init__.py | 0 {samples_check => workflow_utils}/check_usecases.py | 2 +- 4 files changed, 3 insertions(+), 3 deletions(-) rename {samples_check => workflow_utils}/__init__.py (100%) rename {samples_check => workflow_utils}/check_usecases.py (97%) diff --git a/.github/workflows/agentkit-build.yaml b/.github/workflows/agentkit-build.yaml index f02c0a8..4fbb529 100644 --- a/.github/workflows/agentkit-build.yaml +++ b/.github/workflows/agentkit-build.yaml @@ -40,4 +40,4 @@ jobs: HEAD_SHA: ${{ github.event.pull_request.head.sha }} AGENTKIT_COMMAND: build run: | - python -m samples_check.check_usecases + python -m workflow_utils.check_usecases diff --git a/.github/workflows/agentkit-check.yaml b/.github/workflows/agentkit-check.yaml index 233e9cd..d7558f3 100644 --- a/.github/workflows/agentkit-check.yaml +++ b/.github/workflows/agentkit-check.yaml @@ -36,4 +36,4 @@ jobs: BASE_SHA: ${{ github.event.pull_request.base.sha }} HEAD_SHA: ${{ github.event.pull_request.head.sha }} run: | - python -m samples_check.check_usecases + python -m workflow_utils.check_usecases diff --git a/samples_check/__init__.py b/workflow_utils/__init__.py similarity index 100% rename from samples_check/__init__.py rename to workflow_utils/__init__.py diff --git a/samples_check/check_usecases.py b/workflow_utils/check_usecases.py similarity index 97% rename from samples_check/check_usecases.py rename to workflow_utils/check_usecases.py index b45937a..0d1a6ec 100644 --- a/samples_check/check_usecases.py +++ b/workflow_utils/check_usecases.py @@ -33,7 +33,7 @@ def main() -> None: candidate_dirs: set[Path] = set() for rel_path in changed_use_cases: parts = Path(rel_path).parts - if len(parts) >= 2 and parts[0] == "02-use-cases": + if len(parts) >= 2 and parts[0] == "02-use-cases" and parts[1] != "beginner": candidate_dirs.add(Path(parts[0]) / parts[1]) if not candidate_dirs: From ad2be1d7387e879f0c21f9593af035a0f23d84ed Mon Sep 17 00:00:00 2001 From: "hanzhi.421" Date: Thu, 25 Dec 2025 21:04:28 +0800 Subject: [PATCH 3/5] fix: check 2 --- workflow_utils/check_usecases.py | 1 + 1 file changed, 1 insertion(+) diff --git a/workflow_utils/check_usecases.py b/workflow_utils/check_usecases.py index 0d1a6ec..20cb5d7 100644 --- a/workflow_utils/check_usecases.py +++ b/workflow_utils/check_usecases.py @@ -58,6 +58,7 @@ def main() -> None: # continue agent_py = d / "agent.py" + if not agent_py.is_file(): print(f"No agent.py in {d}, skipping agentkit commands.") continue From 969382991f6f892c0048828c12716c3b0718bef8 Mon Sep 17 00:00:00 2001 From: "hanzhi.421" Date: Thu, 25 Dec 2025 21:08:53 +0800 Subject: [PATCH 4/5] fix: check 3 --- workflow_utils/check_usecases.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/workflow_utils/check_usecases.py b/workflow_utils/check_usecases.py index 20cb5d7..bc6634b 100644 --- a/workflow_utils/check_usecases.py +++ b/workflow_utils/check_usecases.py @@ -60,7 +60,7 @@ def main() -> None: agent_py = d / "agent.py" if not agent_py.is_file(): - print(f"No agent.py in {d}, skipping agentkit commands.") + print(f"No agent.py in {d}, skipping agentkit commands now.") continue agent_name = d.name From 19ed5131a820f3ec90c5ad5363dc9686c508a30e Mon Sep 17 00:00:00 2001 From: "hanzhi.421" Date: Sun, 28 Dec 2025 14:13:05 +0800 Subject: [PATCH 5/5] fix: dispatch --- .github/workflows/agentkit-build.yaml | 15 ++++++++++++--- .github/workflows/agentkit-check.yaml | 12 ++++++++++-- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/.github/workflows/agentkit-build.yaml b/.github/workflows/agentkit-build.yaml index 4fbb529..fd14c3e 100644 --- a/.github/workflows/agentkit-build.yaml +++ b/.github/workflows/agentkit-build.yaml @@ -4,10 +4,19 @@ on: pull_request: types: - closed + workflow_dispatch: + inputs: + base_sha: + description: "Base commit SHA (optional)" + required: false + head_sha: + description: "Head commit SHA (optional)" + required: false jobs: agentkit-build: - if: ${{ github.event.pull_request.merged == true }} + if: > + ${{ (github.event_name == 'pull_request' && github.event.pull_request.merged == true) || github.event_name == 'workflow_dispatch' }} runs-on: ubuntu-latest env: @@ -36,8 +45,8 @@ jobs: - name: Run main.py in changed use-case directories (build) env: - BASE_SHA: ${{ github.event.pull_request.base.sha }} - HEAD_SHA: ${{ github.event.pull_request.head.sha }} + BASE_SHA: ${{ github.event_name == 'pull_request' && github.event.pull_request.base.sha || github.event.inputs.base_sha }} + HEAD_SHA: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.event.inputs.head_sha }} AGENTKIT_COMMAND: build run: | python -m workflow_utils.check_usecases diff --git a/.github/workflows/agentkit-check.yaml b/.github/workflows/agentkit-check.yaml index d7558f3..5c95469 100644 --- a/.github/workflows/agentkit-check.yaml +++ b/.github/workflows/agentkit-check.yaml @@ -2,6 +2,14 @@ name: agentkit-check on: pull_request: + workflow_dispatch: + inputs: + base_sha: + description: "Base commit SHA (optional)" + required: false + head_sha: + description: "Head commit SHA (optional)" + required: false jobs: agentkit-launch: @@ -33,7 +41,7 @@ jobs: - name: Run main.py in changed use-case directories env: - BASE_SHA: ${{ github.event.pull_request.base.sha }} - HEAD_SHA: ${{ github.event.pull_request.head.sha }} + BASE_SHA: ${{ github.event_name == 'pull_request' && github.event.pull_request.base.sha || github.event.inputs.base_sha }} + HEAD_SHA: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.event.inputs.head_sha }} run: | python -m workflow_utils.check_usecases