-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feature] Check PyCafe is working with Vizro in CI (#1023)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Copilot <[email protected]>
- Loading branch information
1 parent
3e44988
commit 33dd93a
Showing
6 changed files
with
333 additions
and
186 deletions.
There are no files selected for viewing
This file contains 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
This file was deleted.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
"""Script to generate PyCafe links and create GitHub comments and status checks.""" | ||
|
||
import argparse | ||
import datetime | ||
|
||
from pycafe_utils import ( | ||
PyCafeConfig, | ||
create_github_client, | ||
create_status_check, | ||
generate_comparison_links, | ||
get_example_directories, | ||
) | ||
|
||
|
||
def post_comment(pr_object, config: PyCafeConfig, comparison_urls_dict: dict[str, dict[str, str]]): | ||
"""Post a comment on the pull request with the PyCafe dashboard links.""" | ||
template = """## View the example dashboards of the current commit live on PyCafe :coffee: :rocket:\n | ||
Updated on: {current_utc_time} | ||
Commit: {commit_sha} | ||
Compare the examples using the commit's wheel file vs the latest released version: | ||
{dashboards} | ||
""" | ||
|
||
# Find existing comments by the bot | ||
comments = pr_object.get_issue_comments() | ||
bot_comment = None | ||
for comment in comments: | ||
if comment.body.startswith("## View the example dashboards of the current commit live"): | ||
bot_comment = comment | ||
break | ||
|
||
# Get current UTC datetime | ||
current_utc_time = datetime.datetime.now(datetime.timezone.utc).strftime("%Y-%m-%d %H:%M:%S UTC") | ||
# Format the comparison links | ||
dashboards = "\n\n".join( | ||
f"### {directory}\n" | ||
f"[View with commit's wheel]({urls['commit']}) vs [View with latest release]({urls['release']})" | ||
for directory, urls in comparison_urls_dict.items() | ||
) | ||
|
||
# Update the existing comment or create a new one | ||
comment_body = template.format( | ||
current_utc_time=current_utc_time, | ||
commit_sha=config.commit_sha, | ||
dashboards=dashboards, | ||
) | ||
|
||
if bot_comment: | ||
bot_comment.edit(comment_body) | ||
print("Comment updated on the pull request.") # noqa | ||
else: | ||
pr_object.create_issue_comment(comment_body) | ||
print("Comment added to the pull request.") # noqa | ||
|
||
|
||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser(description="Generate PyCafe links for the example dashboards.") | ||
parser.add_argument("--github-token", required=True, help="GitHub token for authentication") | ||
parser.add_argument("--repo-name", required=True, help="Name of the GitHub repository") | ||
parser.add_argument("--run-id", required=True, help="GitHub Actions run ID") | ||
parser.add_argument("--commit-sha", required=True, help="Commit SHA") | ||
parser.add_argument("--pr-number", type=int, help="Pull request number (optional)") | ||
|
||
args = parser.parse_args() | ||
|
||
# Create configuration | ||
config = PyCafeConfig( | ||
github_token=args.github_token, | ||
repo_name=args.repo_name, | ||
run_id=args.run_id, | ||
commit_sha=args.commit_sha, | ||
pr_number=args.pr_number, | ||
) | ||
|
||
# Initialize GitHub connection | ||
repo, commit = create_github_client(config) | ||
|
||
# Get example directories | ||
directories_with_requirements = get_example_directories() | ||
|
||
# Generate comparison links for each directory | ||
comparison_urls = { | ||
directory: generate_comparison_links(config, directory, extra_requirements) | ||
for directory, extra_requirements in directories_with_requirements.items() | ||
} | ||
|
||
# Create status for each URL - use the commit version for status | ||
for directory, urls in comparison_urls.items(): | ||
create_status_check(commit, directory, urls["commit"]) | ||
|
||
# Post the comment with the comparison links | ||
if config.pr_number is not None: | ||
pr = repo.get_pull(config.pr_number) | ||
post_comment(pr, config, comparison_urls) |
Oops, something went wrong.