Skip to content

Commit 511a7ba

Browse files
ci: add pycafe playground link
1 parent 4edbd54 commit 511a7ba

File tree

3 files changed

+77
-0
lines changed

3 files changed

+77
-0
lines changed

.bumpversion.cfg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,5 @@ values =
2222
[bumpversion:file:ipyreact/_frontend.py]
2323

2424
[bumpversion:file:package.json]
25+
26+
[bumpversion:file:.github/pycafe-create-status.py]

.github/pycafe-create-status.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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}")

.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: [Build]
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)