diff --git a/.bumpversion.cfg b/.bumpversion.cfg index 2718f83..5dbab06 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -22,3 +22,5 @@ values = [bumpversion:file:ipyreact/_frontend.py] [bumpversion:file:package.json] + +[bumpversion:file:.github/pycafe-create-status.py] diff --git a/.github/pycafe-create-status.py b/.github/pycafe-create-status.py new file mode 100644 index 0000000..5aae0d2 --- /dev/null +++ b/.github/pycafe-create-status.py @@ -0,0 +1,55 @@ +import os +import sys +from urllib.parse import quote + +from github import Github + +# Authenticate with GitHub +access_token = os.getenv("GITHUB_TOKEN") +g = Github(access_token) + + +repo_name = "widgetti/ipyreact" +commit_sha = sys.argv[1] # e.g d39677a321bca34df41ecc87ff7e539b450207f2 +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 +type = "solara" # streamlit/dash/vizro/solara/panel + +# your default code +code = """import ipyreact + + +class ConfettiWidget(ipyreact.ValueWidget): + _esm = \""" + import confetti from "canvas-confetti"; + import * as React from "react"; + + export default function({value, setValue}) { + return + };\""" +page = ConfettiWidget() +""" + +artifact_name = "ipyreact-dist" # name given in the GitHub Actions workflow file for the artifact + +# your default requirements, the wheel version number (0.4.2) is bumped up for each new release using bump2version +requirements = f"""solara +https://py.cafe/gh/artifact/{repo_name}/actions/runs/{run_id}/{artifact_name}/ipyreact-0.4.2-py3-none-any.whl +""" + +# GitHub Python API +repo = g.get_repo(repo_name) + +base_url = f"https://py.cafe/snippet/{type}/v1" +url = f"{base_url}#code={quote(code)}&requirements={quote(requirements)}" + +# Define the deployment status +state = "success" # Options: 'error', 'failure', 'pending', 'success' +description = "Test out this PR on a PyCafe playground environment" +context = "PyCafe" + +# Create the status on the commit +commit = repo.get_commit(commit_sha) +commit.create_status(state="success", target_url=url, description=description, context="PyCafe") +print(f"Deployment status added to commit {commit_sha}") diff --git a/.github/workflows/pycafe.yml b/.github/workflows/pycafe.yml new file mode 100644 index 0000000..0fea679 --- /dev/null +++ b/.github/workflows/pycafe.yml @@ -0,0 +1,20 @@ +--- +name: PyCafe Playground Link +on: + workflow_run: + workflows: [Build] + types: + - completed + +jobs: + create-status: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + - name: Create PyCafe status link + run: | + pip install PyGithub + python .github/pycafe-create-status.py ${{ github.event.workflow_run.head_sha }} ${{ github.event.workflow_run.id }} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}