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 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
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!"
42 changes: 42 additions & 0 deletions scripts/run_hello_world_workflow.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import os

from dotenv import load_dotenv
from github import Github
from github.GithubException import GithubException

load_dotenv()

GITHUB_TOKEN = os.getenv("GITHUB_TOKEN")
GITHUB_REPO = os.getenv("GITHUB_REPO")

if not GITHUB_TOKEN:
print("Environment variable GITHUB_TOKEN is not defined.")
exit(1)

if not GITHUB_REPO:
print("Environment variable GITHUB_REPO is not defined.")
exit(1)

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

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

workflow = repo.get_workflow("hello_world_workflow.yml")

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

workflow.create_dispatch('main')
print("Successfully triggered hello world workflow")

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