Skip to content

Commit

Permalink
[CI] PyCafe CI (#832)
Browse files Browse the repository at this point in the history
  • Loading branch information
maxschulz-COL authored Oct 28, 2024
1 parent 1c3fa1c commit 3f9908b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 13 deletions.
9 changes: 7 additions & 2 deletions .github/workflows/pycafe-dashboards.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ jobs:
run: pip install hatch
- name: Print PR Number
run: |
echo "Pull Request Number: ${{ github.event.workflow_run.pull_requests }}"
echo "Pull Request Number: ${{ github.event.workflow_run.pull_requests[0].number }}"
- name: Create PyCafe links
run: |
hatch run python ../tools/pycafe/create_pycafe_links.py ${{ github.token }} ${{ github.repository }} ${{ github.event.workflow_run.pull_requests[0].number }} ${{ github.event.workflow_run.id }} ${{ github.event.workflow_run.head_sha }}
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 }}
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 }}
fi
31 changes: 21 additions & 10 deletions tools/pycafe/create_pycafe_links.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
"""Generate PyCafe links for the example dashboards and post them as a comment on the pull request and as status."""

import argparse
import base64
import datetime
import gzip
import json
import sys
import textwrap
from pathlib import Path
from typing import Optional
Expand All @@ -15,11 +15,22 @@

PACKAGE_VERSION = vizro.__version__

GITHUB_TOKEN = sys.argv[1]
REPO_NAME = sys.argv[2]
PR_NUMBER = int(sys.argv[3])
RUN_ID = sys.argv[4]
COMMIT_SHA = sys.argv[5]
# Parse arguments
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()

GITHUB_TOKEN = args.github_token
REPO_NAME = args.repo_name
PR_NUMBER = args.pr_number
RUN_ID = args.run_id
COMMIT_SHA = args.commit_sha
PYCAFE_URL = "https://py.cafe"
VIZRO_RAW_URL = "https://raw.githubusercontent.com/mckinsey/vizro"

Expand All @@ -36,14 +47,12 @@

# Get PR and commits
repo = g.get_repo(REPO_NAME)
pr = repo.get_pull(PR_NUMBER)
commit_sha_files = pr.head.sha
commit = repo.get_commit(COMMIT_SHA)


def generate_link(directory: str, extra_requirements: Optional[list[str]] = None):
"""Generate a PyCafe link for the example dashboards."""
base_url = f"{VIZRO_RAW_URL}/{commit_sha_files}/vizro-core/{directory}"
base_url = f"{VIZRO_RAW_URL}/{COMMIT_SHA}/vizro-core/{directory}"

# Requirements
requirements = "\n".join(
Expand Down Expand Up @@ -139,4 +148,6 @@ def post_comment(urls: dict[str, str]):
print(f"Status created for {context} with URL: {url}") # noqa

# Post the comment with the links
post_comment(urls)
if PR_NUMBER is not None:
pr = repo.get_pull(PR_NUMBER)
post_comment(urls)
2 changes: 1 addition & 1 deletion vizro-core/examples/scratch_dev/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@


page = vm.Page(
title="Test New III",
title="Test New IV",
components=[
vm.Graph(
figure=px.bar(
Expand Down

0 comments on commit 3f9908b

Please sign in to comment.