Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions .github/pycafe-create-status.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
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 = "tvst/st-annotated-text"
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 = "streamlit" # streamlit/dash/vizro/solara/panel

# take the code from the PR/commit, not master
code = f"https://github.com/tvst/st-annotated-text/raw/{commit_sha}/example.py"

artifact_name = "st-annotated-text-wheel" # name given in the GitHub Actions workflow file for the artifact


# parse the version from the setup.py file, i.e.
# version="4.0.1",

path = "setup.py"
import re
content = open(path).read()
version = re.search(r'version="(.*)",', content).group(1)
print(f"Version: {version}")

requirements = f"""
https://py.cafe/gh/artifact/{repo_name}/actions/runs/{run_id}/{artifact_name}/st_annotated_text-{version}-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}")
32 changes: 32 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Build

on:
push:
branches:
- master
pull_request:
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.x"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel
- name: Build package
run: |
python setup.py sdist bdist_wheel

- name: Upload builds
uses: actions/upload-artifact@v4
with:
name: st-annotated-text-wheel
path: |
./dist
20 changes: 20 additions & 0 deletions .github/workflows/pycafe.yml
Original file line number Diff line number Diff line change
@@ -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@v4
- 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 }}