Skip to content

Commit

Permalink
[Feature] Check PyCafe is working with Vizro in CI (#1023)
Browse files Browse the repository at this point in the history
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
3 people authored Feb 19, 2025
1 parent 3e44988 commit 33dd93a
Show file tree
Hide file tree
Showing 6 changed files with 333 additions and 186 deletions.
11 changes: 9 additions & 2 deletions .github/workflows/pycafe-dashboards.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,21 @@ jobs:
python-version: ${{ env.PYTHON_VERSION }}
- name: Install Hatch
run: pip install hatch
- name: Install Playwright and browser
run: |
hatch run pip install playwright
hatch run playwright install --with-deps chromium
- name: Print PR Number
run: |
echo "Pull Request Number: ${{ github.event.workflow_run.pull_requests[0].number }}"
- name: Test PyCafe links
run: |
hatch run python ../tools/pycafe/test_pycafe_links.py --github-token ${{ github.token }} --repo-name ${{ github.repository }} --run-id ${{ github.event.workflow_run.id }} --commit-sha ${{ github.event.workflow_run.head_sha }}
- name: Create PyCafe links
run: |
PR_NUMBER=${{ github.event.workflow_run.pull_requests[0].number || '' }}
if [ -n "$PR_NUMBER" ]; then
hatch run python ../tools/pycafe/create_pycafe_links.py --github-token ${{ github.token }} --repo-name ${{ github.repository }} --pr-number $PR_NUMBER --run-id ${{ github.event.workflow_run.id }} --commit-sha ${{ github.event.workflow_run.head_sha }}
hatch run python ../tools/pycafe/create_pycafe_links_comments.py --github-token ${{ github.token }} --repo-name ${{ github.repository }} --pr-number $PR_NUMBER --run-id ${{ github.event.workflow_run.id }} --commit-sha ${{ github.event.workflow_run.head_sha }}
else
hatch run python ../tools/pycafe/create_pycafe_links.py --github-token ${{ github.token }} --repo-name ${{ github.repository }} --run-id ${{ github.event.workflow_run.id }} --commit-sha ${{ github.event.workflow_run.head_sha }}
hatch run python ../tools/pycafe/create_pycafe_links_comments.py --github-token ${{ github.token }} --repo-name ${{ github.repository }} --run-id ${{ github.event.workflow_run.id }} --commit-sha ${{ github.event.workflow_run.head_sha }}
fi
183 changes: 0 additions & 183 deletions tools/pycafe/create_pycafe_links.py

This file was deleted.

95 changes: 95 additions & 0 deletions tools/pycafe/create_pycafe_links_comments.py
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)
Loading

0 comments on commit 33dd93a

Please sign in to comment.