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

Add hello world workflow to help diagnose GitHub token issues #86

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
12 changes: 12 additions & 0 deletions .github/workflows/hello_world_workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: Hello World Job

on:
workflow_dispatch:

jobs:
say-hello:
runs-on: ubuntu-latest

steps:
- name: Say Hello
run: echo "Hello, world!"
37 changes: 37 additions & 0 deletions src/discord-cluster-manager/run_hello_world_workflow.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from consts import GITHUB_REPO, GITHUB_TOKEN
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this go in scripts/?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally, it should go in scripts/. The awkward thing about scripts/ is that there's no easy way to import these constants (or am I missing something?). On the other hand, I don't really need the constants (I can use os.getenv(...) instead), I can use print instead of setup_logging, and I don't need get_github_branch_name. Let me try moving it to scripts and see if that's not too bad.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new commit moves it to scripts/ - @msaroufim, please have another look when you have a moment.

from github import Github
from github.GithubException import GithubException
from utils import get_github_branch_name, setup_logging

logger = setup_logging()


def trigger_workflow():
try:
gh = Github(GITHUB_TOKEN)
repo = gh.get_repo(GITHUB_REPO)

workflows = repo.get_workflows()
for w in workflows:
logger.info(f"Found workflow: {w.name}")

workflow = repo.get_workflow("Hello World Job")

if not workflow:
raise ValueError("Could not find hello world workflow")

branch = get_github_branch_name()
workflow.create_dispatch(branch)
logger.info("Successfully triggered hello world workflow")

except GithubException as e:
logger.error(f"GitHub API error: {e.status} - {e.data.get('message', 'Unknown error')}")
except Exception as e:
logger.error(f"Error: {str(e)}")
finally:
if "gh" in locals():
gh.close()


if __name__ == "__main__":
trigger_workflow()
Loading