|  | 
|  | 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/ipyreact" | 
|  | 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 = """import ipyreact | 
|  | 19 | +
 | 
|  | 20 | +
 | 
|  | 21 | +class ConfettiWidget(ipyreact.ValueWidget): | 
|  | 22 | +    _esm = \""" | 
|  | 23 | +    import confetti from "canvas-confetti"; | 
|  | 24 | +    import * as React from "react"; | 
|  | 25 | +
 | 
|  | 26 | +    export default function({value, setValue}) { | 
|  | 27 | +        return <button onClick={() => confetti() && setValue(value + 1)}> | 
|  | 28 | +            {value || 0} times confetti | 
|  | 29 | +        </button> | 
|  | 30 | +    };\""" | 
|  | 31 | +page = ConfettiWidget() | 
|  | 32 | +""" | 
|  | 33 | + | 
|  | 34 | +artifact_name = "ipyreact-dist"  # name given in the GitHub Actions workflow file for the artifact | 
|  | 35 | + | 
|  | 36 | +# your default requirements, the wheel version number (0.4.2) is bumped up for each new release using bump2version | 
|  | 37 | +requirements = f"""solara | 
|  | 38 | +https://py.cafe/gh/artifact/{repo_name}/actions/runs/{run_id}/{artifact_name}/ipyreact-0.4.2-py3-none-any.whl | 
|  | 39 | +""" | 
|  | 40 | + | 
|  | 41 | +# GitHub Python API | 
|  | 42 | +repo = g.get_repo(repo_name) | 
|  | 43 | + | 
|  | 44 | +base_url = f"https://py.cafe/snippet/{type}/v1" | 
|  | 45 | +url = f"{base_url}#code={quote(code)}&requirements={quote(requirements)}" | 
|  | 46 | + | 
|  | 47 | +# Define the deployment status | 
|  | 48 | +state = "success"  # Options: 'error', 'failure', 'pending', 'success' | 
|  | 49 | +description = "Test out this PR on a PyCafe playground environment" | 
|  | 50 | +context = "PyCafe" | 
|  | 51 | + | 
|  | 52 | +# Create the status on the commit | 
|  | 53 | +commit = repo.get_commit(commit_sha) | 
|  | 54 | +commit.create_status(state="success", target_url=url, description=description, context="PyCafe") | 
|  | 55 | +print(f"Deployment status added to commit {commit_sha}") | 
0 commit comments