|
| 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}") |
0 commit comments