Skip to content

Commit 32af76f

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

File tree

4 files changed

+102
-7
lines changed

4 files changed

+102
-7
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 }}

.github/workflows/test.yaml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ jobs:
9696
if: always()
9797
uses: actions/upload-artifact@v4
9898
with:
99-
name: solara-builds-${{ github.run_number }}
99+
name: solara-builds
100100
path: |
101101
dist
102102
packages/solara-assets/dist
@@ -194,7 +194,7 @@ jobs:
194194

195195
- uses: actions/download-artifact@v4
196196
with:
197-
name: solara-builds-${{ github.run_number }}
197+
name: solara-builds
198198

199199
- name: Debug
200200
run: ls -R dist
@@ -251,7 +251,7 @@ jobs:
251251

252252
- uses: actions/download-artifact@v4
253253
with:
254-
name: solara-builds-${{ github.run_number }}
254+
name: solara-builds
255255

256256
- name: Link solara app package
257257
if: matrix.os != 'windows'
@@ -369,7 +369,7 @@ jobs:
369369

370370
- uses: actions/download-artifact@v4
371371
with:
372-
name: solara-builds-${{ github.run_number }}
372+
name: solara-builds
373373

374374
- name: Link solara app package
375375
if: matrix.os != 'windows'
@@ -483,7 +483,7 @@ jobs:
483483

484484
- uses: actions/download-artifact@v4
485485
with:
486-
name: solara-builds-${{ github.run_number }}
486+
name: solara-builds
487487

488488
- name: Link solara app package
489489
run: |
@@ -594,7 +594,7 @@ jobs:
594594

595595
- uses: actions/download-artifact@v4
596596
with:
597-
name: solara-builds-${{ github.run_number }}
597+
name: solara-builds
598598

599599
- name: Prepare
600600
id: prepare
@@ -729,7 +729,7 @@ jobs:
729729

730730
- uses: actions/download-artifact@v4
731731
with:
732-
name: solara-builds-${{ github.run_number }}
732+
name: solara-builds
733733

734734
- name: Install build tools
735735
run: pip install hatch

0 commit comments

Comments
 (0)