Skip to content

Commit

Permalink
Merge branch 'main' into tidy/update-light-theme
Browse files Browse the repository at this point in the history
  • Loading branch information
huong-li-nguyen committed Feb 25, 2025
2 parents 206c1ae + 15a3391 commit bbe244e
Show file tree
Hide file tree
Showing 20 changed files with 510 additions and 223 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 # Eventually we should merge this with the create_pycafe_links_comments.py script
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
29 changes: 5 additions & 24 deletions .github/workflows/update-static-files.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ env:
PYTHON_VERSION: "3.12"

jobs:
check-update:
update-static-files:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -33,27 +33,10 @@ jobs:

- name: Check for changes
id: changed-files
run: git diff --exit-code || echo "has_changes=true" >> $GITHUB_OUTPUT

outputs:
has_changes: ${{ steps.changed-files.outputs.has_changes }}

update-files:
runs-on: ubuntu-latest
needs: [check-update]
if: needs.check-update.outputs.has_changes == 'true'
steps:
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.config.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.config.python-version }}

- name: Install Hatch
run: pip install hatch
run: echo "static_files_changed=$(git diff --quiet || echo true)" >> $GITHUB_OUTPUT

- name: Create and push changes
if: steps.changed-files.outputs.static_files_changed
run: |
git config user.email "[email protected]"
git config user.name "Vizro Team"
Expand All @@ -64,12 +47,10 @@ jobs:
git push origin --delete bot/update-static-files || true
git push --set-upstream origin bot/update-static-files
- name: Install GitHub CLI
run: sudo apt-get install -y gh

- name: Create Pull Request
if: steps.changed-files.outputs.static_files_changed
run: |
sudo apt-get install -y gh
gh pr create -B main -H bot/update-static-files --title "[Bot] Update static files" --body "Automated update of static files"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
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 bbe244e

Please sign in to comment.