Skip to content

Commit cded5b2

Browse files
ci: include PyCafe playground link
1 parent 925be8e commit cded5b2

File tree

3 files changed

+95
-0
lines changed

3 files changed

+95
-0
lines changed

.bumpversion.cfg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ values =
1515
b
1616
g
1717

18+
[bumpversion:file:.github/pycafe-create-status.py]
19+
1820
[bumpversion:file:solara/__init__.py]
1921

2022
[bumpversion:file:packages/solara-assets/solara_assets/__init__.py]

.github/pycafe-create-status.py

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import os
2+
import sys
3+
from urllib.parse import quote
4+
5+
from github import Github
6+
7+
# Authenticate with GitHub
8+
access_token = os.getenv("GITHUB_TOKEN")
9+
g = Github(access_token)
10+
11+
12+
repo_name = "widgetti/solara"
13+
commit_sha = sys.argv[1] # e.g d39677a321bca34df41ecc87ff7e539b450207f2
14+
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
15+
type = "solara" # streamlit/dash/vizro/solara/panel
16+
17+
# your default code
18+
code = """# this is a playground snippet using solara build on GitHub Actions
19+
# if this link is old, the build artifact might be old, which causes the installation
20+
# to fail
21+
import solara
22+
23+
# reactive variables will trigger a component rerender
24+
# when changed.
25+
# When you change the default (now 0), hit the embedded browser
26+
# refresh button to reset the state
27+
clicks = solara.reactive(0)
28+
29+
30+
@solara.component
31+
def Page():
32+
print("The component render function gets called")
33+
# change this code, and see the output refresh
34+
color = "green"
35+
if clicks.value >= 5:
36+
color = "red"
37+
38+
def increment():
39+
clicks.value += 1
40+
print("clicks", clicks) # noqa
41+
42+
solara.Button(label=f"Clicked: {clicks}", on_click=increment, color=color)
43+
44+
45+
# Solara also supports ipywidgets
46+
# remove the Page component and assign an ipywidget to
47+
# the page variable, e.g.
48+
# page = mywidget
49+
"""
50+
51+
artifact_name = "solara-builds" # name given in the GitHub Actions workflow file for the artifact
52+
53+
# your default requirements, the wheel version number (1.43.0) is bumped up for each new release using bump2version
54+
requirements = f"""solara
55+
https://py.cafe/gh/artifact/{repo_name}/actions/runs/{run_id}/{artifact_name}/solara-1.43.0-py2.py3-none-any.whl
56+
https://py.cafe/gh/artifact/{repo_name}/actions/runs/{run_id}/{artifact_name}/solara_ui-1.43.0-py2.py3-none-any.whl
57+
"""
58+
59+
# GitHub Python API
60+
repo = g.get_repo(repo_name)
61+
62+
base_url = f"https://py.cafe/snippet/{type}/v1"
63+
url = f"{base_url}#code={quote(code)}&requirements={quote(requirements)}"
64+
65+
# Define the deployment status
66+
state = "success" # Options: 'error', 'failure', 'pending', 'success'
67+
description = "Test out this PR on a PyCafe playground environment"
68+
context = "PyCafe"
69+
70+
# Create the status on the commit
71+
commit = repo.get_commit(commit_sha)
72+
commit.create_status(state="success", target_url=url, description=description, context="PyCafe")
73+
print(f"Deployment status added to commit {commit_sha}")

.github/workflows/pycafe.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
name: PyCafe Playground Link
3+
on:
4+
workflow_run:
5+
workflows: [Test]
6+
types:
7+
- completed
8+
9+
jobs:
10+
create-status:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout code
14+
uses: actions/checkout@v2
15+
- name: Create PyCafe status link
16+
run: |
17+
pip install PyGithub
18+
python .github/pycafe-create-status.py ${{ github.event.workflow_run.head_sha }} ${{ github.event.workflow_run.id }}
19+
env:
20+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)