Skip to content

Commit

Permalink
ci: include PyCafe playground link
Browse files Browse the repository at this point in the history
  • Loading branch information
maartenbreddels committed Dec 20, 2024
1 parent 925be8e commit 32af76f
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 7 deletions.
2 changes: 2 additions & 0 deletions .bumpversion.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ values =
b
g

[bumpversion:file:.github/pycafe-create-status.py]

[bumpversion:file:solara/__init__.py]

[bumpversion:file:packages/solara-assets/solara_assets/__init__.py]
Expand Down
73 changes: 73 additions & 0 deletions .github/pycafe-create-status.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import os
import sys
from urllib.parse import quote

from github import Github

# Authenticate with GitHub
access_token = os.getenv("GITHUB_TOKEN")
g = Github(access_token)


repo_name = "widgetti/solara"
commit_sha = sys.argv[1] # e.g d39677a321bca34df41ecc87ff7e539b450207f2
run_id = sys.argv[2] # e.g 1324, usually obtained via ${{ github.run_id }} or ${{ github.event.workflow_run.id }} in GitHub Actions workflow files
type = "solara" # streamlit/dash/vizro/solara/panel

# your default code
code = """# this is a playground snippet using solara build on GitHub Actions
# if this link is old, the build artifact might be old, which causes the installation
# to fail
import solara
# reactive variables will trigger a component rerender
# when changed.
# When you change the default (now 0), hit the embedded browser
# refresh button to reset the state
clicks = solara.reactive(0)
@solara.component
def Page():
print("The component render function gets called")
# change this code, and see the output refresh
color = "green"
if clicks.value >= 5:
color = "red"
def increment():
clicks.value += 1
print("clicks", clicks) # noqa
solara.Button(label=f"Clicked: {clicks}", on_click=increment, color=color)
# Solara also supports ipywidgets
# remove the Page component and assign an ipywidget to
# the page variable, e.g.
# page = mywidget
"""

artifact_name = "solara-builds" # name given in the GitHub Actions workflow file for the artifact

# your default requirements, the wheel version number (1.43.0) is bumped up for each new release using bump2version
requirements = f"""solara
https://py.cafe/gh/artifact/{repo_name}/actions/runs/{run_id}/{artifact_name}/solara-1.43.0-py2.py3-none-any.whl
https://py.cafe/gh/artifact/{repo_name}/actions/runs/{run_id}/{artifact_name}/solara_ui-1.43.0-py2.py3-none-any.whl
"""

# GitHub Python API
repo = g.get_repo(repo_name)

base_url = f"https://py.cafe/snippet/{type}/v1"
url = f"{base_url}#code={quote(code)}&requirements={quote(requirements)}"

# Define the deployment status
state = "success" # Options: 'error', 'failure', 'pending', 'success'
description = "Test out this PR on a PyCafe playground environment"
context = "PyCafe"

# Create the status on the commit
commit = repo.get_commit(commit_sha)
commit.create_status(state="success", target_url=url, description=description, context="PyCafe")
print(f"Deployment status added to commit {commit_sha}")
20 changes: 20 additions & 0 deletions .github/workflows/pycafe.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
name: PyCafe Playground Link
on:
workflow_run:
workflows: [Test]
types:
- completed

jobs:
create-status:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Create PyCafe status link
run: |
pip install PyGithub
python .github/pycafe-create-status.py ${{ github.event.workflow_run.head_sha }} ${{ github.event.workflow_run.id }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
14 changes: 7 additions & 7 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ jobs:
if: always()
uses: actions/upload-artifact@v4
with:
name: solara-builds-${{ github.run_number }}
name: solara-builds
path: |
dist
packages/solara-assets/dist
Expand Down Expand Up @@ -194,7 +194,7 @@ jobs:

- uses: actions/download-artifact@v4
with:
name: solara-builds-${{ github.run_number }}
name: solara-builds

- name: Debug
run: ls -R dist
Expand Down Expand Up @@ -251,7 +251,7 @@ jobs:

- uses: actions/download-artifact@v4
with:
name: solara-builds-${{ github.run_number }}
name: solara-builds

- name: Link solara app package
if: matrix.os != 'windows'
Expand Down Expand Up @@ -369,7 +369,7 @@ jobs:

- uses: actions/download-artifact@v4
with:
name: solara-builds-${{ github.run_number }}
name: solara-builds

- name: Link solara app package
if: matrix.os != 'windows'
Expand Down Expand Up @@ -483,7 +483,7 @@ jobs:

- uses: actions/download-artifact@v4
with:
name: solara-builds-${{ github.run_number }}
name: solara-builds

- name: Link solara app package
run: |
Expand Down Expand Up @@ -594,7 +594,7 @@ jobs:

- uses: actions/download-artifact@v4
with:
name: solara-builds-${{ github.run_number }}
name: solara-builds

- name: Prepare
id: prepare
Expand Down Expand Up @@ -729,7 +729,7 @@ jobs:

- uses: actions/download-artifact@v4
with:
name: solara-builds-${{ github.run_number }}
name: solara-builds

- name: Install build tools
run: pip install hatch
Expand Down

0 comments on commit 32af76f

Please sign in to comment.