Skip to content

Commit

Permalink
rename workflows file
Browse files Browse the repository at this point in the history
  • Loading branch information
msaroufim committed Nov 5, 2024
1 parent 55dfab4 commit ae5856e
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 10 deletions.
File renamed without changes.
46 changes: 36 additions & 10 deletions bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from github import Github
import os
import time
from github import GithubException

# Load environment variables
load_dotenv()
Expand Down Expand Up @@ -29,17 +30,29 @@ def trigger_github_action(file_path='train.py'):
content,
file.sha
)
except Exception:
repo.create_file(
"train.py",
"Create train.py via script",
content
)
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

# Trigger the workflow
workflow = repo.get_workflow("train_workflow.yml")
run = workflow.create_dispatch("main")
return run.id
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

except Exception as e:
print(f"Error: {str(e)}")
Expand All @@ -63,6 +76,19 @@ 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()

Expand Down

0 comments on commit ae5856e

Please sign in to comment.