Skip to content

Commit de2161a

Browse files
ci: add pycafe sandbox link
1 parent f0b98fc commit de2161a

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed

.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/solara"
13+
pr_number = int(sys.argv[1]) # e.g 65
14+
type = "solara" # streamlit/dash/vizro/solara/panel
15+
16+
# your default code
17+
code = """import ipyreact
18+
19+
20+
class ConfettiWidget(ipyreact.ValueWidget):
21+
_esm = \"""
22+
import confetti from "canvas-confetti";
23+
import * as React from "react";
24+
25+
export default function({value, setValue}) {
26+
return <button onClick={() => confetti() && setValue(value + 1)}>
27+
{value || 0} times confetti
28+
</button>
29+
};\"""
30+
page = ConfettiWidget()
31+
"""
32+
33+
# your default requirements
34+
requirements = """solara
35+
ipyreact
36+
"""
37+
38+
# GitHub Python API
39+
repo = g.get_repo(repo_name)
40+
pr = repo.get_pull(pr_number)
41+
42+
base_url = f"https://py.cafe/snippet/{type}/v1"
43+
url = f"{base_url}#code={quote(code)}&requirements={quote(requirements)}"
44+
45+
commit_sha = pr.head.sha
46+
47+
# Define the deployment status
48+
state = "success" # Options: 'error', 'failure', 'pending', 'success'
49+
description = "Test out this PR on a PyCafe 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="Test this PR in PyCafe environment", context="PyCafe")
55+
print(f"Deployment status added to commit {commit_sha}, PR https://github.com/{repo_name}/pull/{pr_number}")

.github/workflows/pycafe.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
name: PyCafe Sandbox Link
3+
on:
4+
pull_request_target:
5+
types:
6+
- opened
7+
- synchronize
8+
jobs:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Checkout code
12+
uses: actions/checkout@v2
13+
- name: Create PyCafe status link
14+
run: python .github/pycafe-create-status.py ${{ github.event.number }}
15+
env:
16+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)