Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement action that deploys solana project to the devnet #7

Merged
merged 1 commit into from
Jul 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions autogpts/SoloAgent/forge/actions/infra_gen/infra_gen.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
from __future__ import annotations
from ..registry import action
from forge.sdk import ForgeLogger, Agent
import os
import subprocess
from typing import Dict

LOG = ForgeLogger(__name__)


@action(
name="deploy_code",
description="Deploy the Anchor project to Solana Devnet",
parameters=[
{
"name": "project_path",
"description": "Path to the Anchor project directory",
"type": "string",
"required": True,
}
],
output_type="str",
)
async def deploy_code(agent: Agent, task_id: str, project_path: str) -> str:
try:
# Ensure that the Solana CLI is installed and configured to use the devnet
subprocess.run(['solana', 'config', 'set', '--url',
'https://api.devnet.solana.com'], check=True)
subprocess.run(['solana', 'config', 'set', '--keypair',
os.path.expanduser('~/.config/solana/id.json')], check=True)

# Build the Anchor project
result = subprocess.run(
['anchor', 'build'], cwd=project_path, capture_output=True, text=True)
if result.returncode != 0:
LOG.error(f"Build failed with errors: {result.stderr}")
return f"Build failed: {result.stderr}"

# Deploy the Anchor project to Devnet
result = subprocess.run(
['anchor', 'deploy'], cwd=project_path, capture_output=True, text=True)
if result.returncode != 0:
LOG.error(f"Deployment failed with errors: {result.stderr}")
return f"Deployment failed: {result.stderr}"

LOG.info(f"Deployment successful: {result.stdout}")
return f"Deployment successful: {result.stdout}"

except subprocess.CalledProcessError as e:
LOG.error(f"Error during deployment: {e}")
return f"Deployment process failed: {e}"
except Exception as e:
LOG.error(f"Unexpected error during deployment: {e}")
return f"Unexpected error: {e}"
Loading