Skip to content

Commit 27139d7

Browse files
Update scripts
1 parent ee57721 commit 27139d7

File tree

3 files changed

+115
-49
lines changed

3 files changed

+115
-49
lines changed

.github/workflows/test-and-release.yml

Lines changed: 69 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -6,54 +6,78 @@ on:
66
- "release/*"
77

88
jobs:
9-
build_and_test:
10-
name: "Build & Test"
11-
runs-on: ubuntu-latest
9+
run-playwright-tests:
10+
uses: ./.github/workflows/playwright.yml
11+
with:
12+
ref: ${{ inputs.ref }}
1213

14+
release:
15+
needs: run-playwright-tests
16+
environment: release
1317
steps:
14-
- name: Check out repository
15-
uses: actions/checkout@v3
16-
17-
- name: Set up Node
18-
uses: actions/setup-node@v3
18+
- name: Checkout Streamlit code
19+
uses: actions/checkout@v4
1920
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
21+
ref: ${{ inputs.ref }}
22+
persist-credentials: false
23+
submodules: "recursive"
24+
fetch-depth: 2
25+
- name: Set up Python 3.12
26+
uses: actions/setup-python@v5
27+
with:
28+
python-version: "3.12"
29+
- name: Setup Node
30+
uses: actions/setup-node@v4
31+
with:
32+
node-version-file: ".nvmrc"
33+
cache: "npm"
34+
cache-dependency-path: "**/package-lock.json"
35+
- name: Make frontend
2836
run: |
29-
cd streamlit_bokeh_chart/frontend
37+
cd streamlit_bokeh/frontend
38+
npm install
3039
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 }}
40+
# Combine hashes of the Python interpreter, Pipfile, and today's
41+
# date into a file whose hash will key the Python virtualenv.
42+
#
43+
# This means that our virtualenv cache will expire each day. We do
44+
# this because we are not using a lockfile to pin dependencies -
45+
# instead, each time Github Actions rebuilds the virtualenv, it uses the
46+
# latest compatible version of each dependency (which mirrors what
47+
# happens when a user installs Streamlit locally). So we expire our
48+
# virtualenv cache daily to prevent it from getting far out of sync
49+
# with what a fresh Streamlit installation would look like.
50+
- name: Create Python environment cache key
51+
run: |
52+
md5sum $(which python) > $GITHUB_WORKSPACE/python_cache_key.md5
53+
md5sum e2e_playwright/test-requirements.txt >> $GITHUB_WORKSPACE/python_cache_key.md5
54+
md5sum setup.py >> $GITHUB_WORKSPACE/python_cache_key.md5
55+
date +%F >> $GITHUB_WORKSPACE/python_cache_key.md5
56+
shell: bash
57+
- name: Restore virtualenv from cache
58+
id: cache-virtualenv
59+
uses: actions/cache@v4
60+
with:
61+
path: venv
62+
key: v1-python-venv-${{ hashFiles('**/python_cache_key.md5') }}
63+
- name: Build the package
64+
run: |
65+
python -m venv venv
66+
source venv/bin/activate
67+
pip install setuptools
68+
python setup.py sdist bdist_wheel
69+
- name: Store Package
70+
uses: actions/upload-artifact@v4
71+
with:
72+
name: Release
73+
path: dist
74+
- name: Upload to PyPI
75+
uses: pypa/gh-action-pypi-publish@release/v1
5576
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
77+
packages-dir: dist/
78+
- name: Merge to Main
79+
if: ${{ success() }}
80+
steps: |
81+
git checkout main
82+
git merge ${{ inputs.ref }}
83+
git push origin main

.github/workflows/update-bokeh.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
name: "Update Bokeh"
22

33
on:
4-
workflow_dispatch:
4+
schedule:
5+
# Run job at 9:30am PST or 10:30am PDT
6+
- cron: "30 17 * * *"
7+
pull_request:
8+
types: [opened, synchronize, reopened]
59

610
jobs:
711
update-bokeh:
@@ -25,9 +29,7 @@ jobs:
2529

2630
- name: Run script
2731
id: compare_bokeh
28-
run: python scripts/update-bokeh.py
29-
env:
30-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
32+
run: python scripts/update_bokeh_version.py
3133

3234
- name: Commit changes
3335
if: steps.compare_bokeh.outputs.needs_update == 'true'

scripts/update_bokeh_version.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,44 @@ def update_setup_py(old_version, new_version):
5353
with open(setup_py_path, "w") as f:
5454
f.write(setup_content)
5555

56+
def update_test_requirements(old_version, new_version):
57+
test_requirements_path = "e2e_playwright/test-requirements.txt"
58+
with open(test_requirements_path, "r") as f:
59+
test_requirements_contents = f.read()
60+
61+
# Replace bokeh==old_version with bokeh==new_version
62+
if old_version:
63+
test_requirements_contents = re.sub(
64+
rf"(bokeh\s*==\s*){old_version}",
65+
rf"\g<1>{new_version}",
66+
test_requirements_contents
67+
)
68+
69+
test_requirements_contents = re.sub(
70+
rf"(dist/streamlit_bokeh){old_version}(-py3-none-any.whl)",
71+
rf"\g<1>{new_version}",
72+
test_requirements_contents
73+
)
74+
75+
with open(test_requirements_path, "w") as f:
76+
f.write(test_requirements_contents)
77+
78+
def update_package_json(old_version, new_version):
79+
package_json_path = "streamlit_bokeh/frontend/package.json"
80+
with open(package_json_path, "r") as f:
81+
package_json_contents = f.read()
82+
83+
# Replace bokeh==old_version with bokeh==new_version
84+
if old_version:
85+
package_json_contents = re.sub(
86+
rf"(\"version\": \"){old_version}(\")",
87+
rf"\g<1>{new_version}",
88+
package_json_contents
89+
)
90+
91+
with open(package_json_path, "w") as f:
92+
f.write(package_json_contents)
93+
5694
def update_index_html(public_dir, old_version, new_version):
5795
index_html_path = os.path.join(public_dir, "index.html")
5896
if os.path.exists(index_html_path):
@@ -103,6 +141,8 @@ def update_index_html(public_dir, old_version, new_version):
103141

104142
download_files(new_version, public_dir)
105143
update_setup_py(old_version, new_version)
144+
update_test_requirements(old_version, new_version)
145+
update_package_json(old_version, new_version)
106146
update_index_html(public_dir, old_version, new_version)
107147

108148
print(f"::set-output name=needs_update::true")

0 commit comments

Comments
 (0)