-
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.
Merge branch 'main' into tidy/update-light-theme
- Loading branch information
Showing
20 changed files
with
510 additions
and
223 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 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 |
---|---|---|
|
@@ -12,7 +12,7 @@ env: | |
PYTHON_VERSION: "3.12" | ||
|
||
jobs: | ||
check-update: | ||
update-static-files: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
@@ -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" | ||
|
@@ -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 }} |
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.