Skip to content

Commit ee57721

Browse files
Initial commit
1 parent b1739d3 commit ee57721

File tree

3 files changed

+211
-0
lines changed

3 files changed

+211
-0
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: "Build, Test, and Release on new release branch"
2+
3+
on:
4+
push:
5+
branches:
6+
- "release/*"
7+
8+
jobs:
9+
build_and_test:
10+
name: "Build & Test"
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Check out repository
15+
uses: actions/checkout@v3
16+
17+
- name: Set up Node
18+
uses: actions/setup-node@v3
19+
with:
20+
node-version: "18"
21+
22+
- name: Install dependencies
23+
run: |
24+
cd streamlit_bokeh_chart/frontend
25+
npm ci
26+
27+
- name: Build component
28+
run: |
29+
cd streamlit_bokeh_chart/frontend
30+
npm run build
31+
32+
- name: Install Playwright
33+
# If your project doesn't already install Playwright as a devDependency, do so here:
34+
run: npm install -D @playwright/test
35+
36+
- name: Run Playwright E2E tests
37+
run: npx playwright test e2e_playwright
38+
# ^ Adjust path or script as needed:
39+
# Example: `npm run test:e2e` if you have it defined in package.json
40+
41+
release:
42+
name: "Create a Release"
43+
runs-on: ubuntu-latest
44+
needs: build_and_test # Only run if build_and_test succeeds
45+
46+
steps:
47+
- name: Check out repository
48+
uses: actions/checkout@v3
49+
50+
- name: Create GitHub Release
51+
id: create_release
52+
uses: actions/create-release@v1
53+
env:
54+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
55+
with:
56+
tag_name: ${{ github.ref_name }} # For example "release/1.2.3"
57+
release_name: "Release ${{ github.ref_name }}"
58+
draft: false
59+
prerelease: false

.github/workflows/update-bokeh.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: "Update Bokeh"
2+
3+
on:
4+
workflow_dispatch:
5+
6+
jobs:
7+
update-bokeh:
8+
runs-on: ubuntu-latest
9+
10+
# Ensure we can push back to the repository
11+
permissions:
12+
contents: write
13+
14+
steps:
15+
- name: Check out repository
16+
uses: actions/checkout@v3
17+
18+
- name: Set up Python
19+
uses: actions/setup-python@v4
20+
with:
21+
python-version: "3.12"
22+
23+
- name: Install dependencies
24+
run: pip install requests
25+
26+
- name: Run script
27+
id: compare_bokeh
28+
run: python scripts/update-bokeh.py
29+
env:
30+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
31+
32+
- name: Commit changes
33+
if: steps.compare_bokeh.outputs.needs_update == 'true'
34+
run: |
35+
echo "NEW_VERSION=${{ steps.compare_bokeh.outputs.new_version }}" >> $GITHUB_ENV
36+
BRANCH="release/${NEW_VERSION}"
37+
git config user.name "github-actions"
38+
git config user.email "github-actions@github.com"
39+
git checkout -b "${BRANCH}"
40+
git add .
41+
git commit -m "Update Bokeh to ${NEW_VERSION}"
42+
git push origin "${BRANCH}"

scripts/update_bokeh_version.py

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
import importlib.metadata
2+
import os
3+
import re
4+
import requests
5+
6+
def get_latest_bokeh_version():
7+
url = "https://pypi.org/pypi/bokeh/json"
8+
response = requests.get(url)
9+
response.raise_for_status() # Raises an HTTPError if the status is not 200
10+
data = response.json()
11+
return data["info"]["version"]
12+
13+
def download_files(new_version, destination):
14+
files_to_download = [
15+
f"https://cdn.bokeh.org/bokeh/release/bokeh-mathjax-{new_version}.min.js",
16+
f"https://cdn.bokeh.org/bokeh/release/bokeh-gl-{new_version}.min.js",
17+
f"https://cdn.bokeh.org/bokeh/release/bokeh-api-{new_version}.min.js",
18+
f"https://cdn.bokeh.org/bokeh/release/bokeh-tables-{new_version}.min.js",
19+
f"https://cdn.bokeh.org/bokeh/release/bokeh-widgets-{new_version}.min.js",
20+
f"https://cdn.bokeh.org/bokeh/release/bokeh-{new_version}.min.js"
21+
]
22+
23+
for url in files_to_download:
24+
filename = os.path.basename(url)
25+
print(f"Downloading {filename}")
26+
r = requests.get(url, stream=True)
27+
r.raise_for_status()
28+
with open(os.path.join(destination, filename), "wb") as f:
29+
for chunk in r.iter_content(chunk_size=8192):
30+
f.write(chunk)
31+
32+
def update_setup_py(old_version, new_version):
33+
setup_py_path = "setup.py"
34+
with open(setup_py_path, "r") as f:
35+
setup_content = f.read()
36+
37+
# Replace package version in `version='...'`
38+
# This pattern is naive; adapt as needed for your file structure.
39+
setup_content = re.sub(
40+
r"(version\s*=\s*['\"])([\d\.]+)(['\"])",
41+
rf"\g<1>{new_version}\g<3>",
42+
setup_content
43+
)
44+
45+
# Replace bokeh==old_version with bokeh==new_version
46+
if old_version:
47+
setup_content = re.sub(
48+
rf"(bokeh\s*==\s*){old_version}",
49+
rf"\g<1>{new_version}",
50+
setup_content
51+
)
52+
53+
with open(setup_py_path, "w") as f:
54+
f.write(setup_content)
55+
56+
def update_index_html(public_dir, old_version, new_version):
57+
index_html_path = os.path.join(public_dir, "index.html")
58+
if os.path.exists(index_html_path):
59+
with open(index_html_path, "r", encoding="utf-8") as f:
60+
html_content = f.read()
61+
62+
# If old_version is known, do a direct replacement
63+
if old_version:
64+
# Replace each script reference with the new version
65+
cdn_suffixes = [
66+
"mathjax",
67+
"gl",
68+
"api",
69+
"tables",
70+
"widgets",
71+
""
72+
]
73+
for suffix in cdn_suffixes:
74+
old_str = f"bokeh-{suffix}-{old_version}.min.js" if suffix else f"bokeh-{old_version}.min.js"
75+
new_str = f"bokeh-{suffix}-{new_version}.min.js" if suffix else f"bokeh-{new_version}.min.js"
76+
html_content = html_content.replace(old_str, new_str)
77+
78+
with open(index_html_path, "w", encoding="utf-8") as f:
79+
f.write(html_content)
80+
else:
81+
print("No index.html found in frontend/public. Skipping HTML update.")
82+
83+
84+
if __name__ == "__main__":
85+
new_version = get_latest_bokeh_version()
86+
old_version = importlib.metadata.version("streamlit_bokeh_chart")
87+
88+
print(f"Current local bokeh version: {old_version}")
89+
print(f"Latest PyPI bokeh version: {new_version}")
90+
91+
if new_version == old_version:
92+
print("No new version available")
93+
print(f"::set-output name=needs_update::false")
94+
exit(0)
95+
96+
print("New version available!")
97+
public_dir = "streamlit_bokeh_chart/frontend/public"
98+
99+
# Remove original files
100+
for filename in os.listdir(public_dir):
101+
if "bokeh" in filename and filename.endswith(".js"):
102+
os.remove(os.path.join(public_dir, filename))
103+
104+
download_files(new_version, public_dir)
105+
update_setup_py(old_version, new_version)
106+
update_index_html(public_dir, old_version, new_version)
107+
108+
print(f"::set-output name=needs_update::true")
109+
print(f"::set-output name=old_version::{old_version}")
110+
print(f"::set-output name=new_version::{new_version}")

0 commit comments

Comments
 (0)