From c343162a04c97b383c58d19c8e1f06c21e48a23d Mon Sep 17 00:00:00 2001 From: Mark Saroufim Date: Mon, 4 Nov 2024 16:02:01 -0800 Subject: [PATCH] simplify bot script --- bot.py | 61 ++++++---------------------------------------------------- 1 file changed, 6 insertions(+), 55 deletions(-) diff --git a/bot.py b/bot.py index e1f6070..d1cb947 100644 --- a/bot.py +++ b/bot.py @@ -2,58 +2,23 @@ from github import Github import os import time -from github import GithubException # Load environment variables load_dotenv() -def trigger_github_action(file_path='train.py'): +def trigger_github_action(): """ - Triggers a GitHub action after updating train.py + Just triggers the GitHub action without modifying any files Returns the run ID for monitoring """ - # Initialize GitHub client gh = Github(os.getenv('GITHUB_TOKEN')) repo = gh.get_repo(os.getenv('GITHUB_REPO')) try: - # Read the local train.py file - with open(file_path, 'r') as file: - content = file.read() - - # Update or create train.py in the repository - try: - file = repo.get_contents("train.py") - repo.update_file( - "train.py", - "Update train.py via script", - content, - file.sha - ) - except GithubException as e: - if e.status == 404: # File doesn't exist yet - repo.create_file( - "train.py", - "Create train.py via script", - content - ) - else: - raise - - try: - # Trigger the workflow - workflow = repo.get_workflow("train_workflow.yml") - run = workflow.create_dispatch("main") - return run.id - except GithubException as e: - if e.status == 404: - print("Error: Workflow file 'train_workflow.yml' not found in repository") - print("Please ensure you have created .github/workflows/train_workflow.yml") - print("Check the README for the correct workflow file content") - else: - print(f"GitHub API Error: {e.data.get('message', str(e))}") - return None - + # Trigger the workflow + workflow = repo.get_workflow("train_workflow.yml") + run = workflow.create_dispatch("main") + return run.id except Exception as e: print(f"Error: {str(e)}") return None @@ -76,20 +41,6 @@ def check_workflow_status(run_id): time.sleep(30) if __name__ == "__main__": - # Validate environment variables - if not os.getenv('GITHUB_TOKEN'): - print("Error: GITHUB_TOKEN not found in .env file") - exit(1) - if not os.getenv('GITHUB_REPO'): - print("Error: GITHUB_REPO not found in .env file") - exit(1) - - # Check if train.py exists locally - if not os.path.exists('train.py'): - print("Error: train.py not found in current directory") - exit(1) - - # Trigger the action run_id = trigger_github_action() if run_id: