Created
July 2, 2023 13:16
-
-
Save ohaval/4ab354d23fb1f793c13ae0194b6fba5d to your computer and use it in GitHub Desktop.
Print all workflows logs from a specific repository in GitHub Actions using PyGithub
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import datetime | |
import os | |
import requests | |
from github import Github | |
REPO_NAME = 'some-repo' | |
REPO_OWNER = 'some-owner' | |
LAST_WF_DATE_TO_SHOW = datetime.datetime(2023, 7, 2, 9, 11) | |
# Authenticate to GitHub with an API token | |
github = Github(login_or_token=os.environ['GITHUB_TOKEN']) | |
# Get the repository object | |
repo = github.get_repo(f"{REPO_OWNER}/{REPO_NAME}") | |
# Iterate through workflow runs | |
for workflow_run in repo.get_workflow_runs(): | |
print(f"workflow_run.id: {workflow_run.id}") | |
print(f"workflow_run.created_at: {workflow_run.created_at}") | |
if workflow_run.created_at < LAST_WF_DATE_TO_SHOW: | |
print(f"Reached workflow_run.created_at: {workflow_run.created_at}, breaking") | |
break | |
# Iterate through jobs and print the logs of non-skipped jobs | |
for job in workflow_run.jobs(): | |
if job.conclusion == 'skipped': | |
continue | |
print(f"===Job: {job.name}===") | |
logs = requests.get(url=job.logs_url()) | |
print(logs.text) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment