-
Notifications
You must be signed in to change notification settings - Fork 1
130 lines (111 loc) · 3.81 KB
/
docs_preview.yml
File metadata and controls
130 lines (111 loc) · 3.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
name: Docs PR Preview
on:
pull_request:
types:
- opened
- synchronize
- reopened
- closed
paths:
- 'docs/**'
- 'renovate.json'
- '.github/workflows/docs_preview.yml'
permissions:
contents: write
pull-requests: write
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
cancel-in-progress: true
jobs:
deploy-preview:
runs-on: ubuntu-latest
if: github.event.action != 'closed'
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: '3.13'
- name: Install Python Dependencies
run: |
python -m pip install --upgrade pip
pip install .[test]
pip install Pillow
- name: Pre-install Addons (Web)
run: |
mkdir -p src/switchcraft/addons
python -c "import zipfile, os, glob; from pathlib import Path; [zipfile.ZipFile(z).extractall(Path('src/switchcraft/addons') / Path(z).stem.replace('switchcraft_', '')) for z in glob.glob('src/switchcraft/assets/addons/*.zip')]"
- name: Build Web Demo
run: |
python scripts/prepare_web_dist.py --bake
mkdir -p build_web
cp -r src/switchcraft build_web/
PR_NUMBER=${{ github.event.pull_request.number }}
cat > build_web/web_entry.py <<EOF
import os
import sys
import flet as ft
# WASM compatibility patches
if sys.platform == "emscripten":
import pyodide_http
pyodide_http.patch_all()
sys.path.insert(0, os.getcwd())
import switchcraft
switchcraft.IS_DEMO = True
import switchcraft.main
if __name__ == "__main__":
ft.run(switchcraft.main.main, assets_dir="assets")
EOF
cd build_web
# Simplified publish for preview - use the PR specific base-url
flet publish web_entry.py --app-name "SwitchCraft Demo PR-$PR_NUMBER" --base-url "/pr-preview/pr-$PR_NUMBER/demo/" --distpath ../dist --assets switchcraft/assets
cd ..
python scripts/prepare_web_dist.py --patch dist
rm -rf docs/public/demo
mkdir -p docs/public/demo
cp -r dist/* docs/public/demo/
shell: bash
- name: Setup Node
uses: actions/setup-node@v6
with:
node-version: 24.13.0
cache: 'npm'
cache-dependency-path: docs/package-lock.json
- name: Install dependencies
run: |
cd docs
if [ -f package-lock.json ]; then
npm ci
else
npm install vitepress vue
fi
- name: Build Docs
run: npm run docs:build
working-directory: docs
env:
BASE_URL: /pr-preview/pr-${{ github.event.pull_request.number }}/
- name: Deploy Preview
uses: rossjrw/pr-preview-action@v1
with:
source-dir: docs/.vitepress/dist
preview-branch: gh-pages
umbrella-dir: pr-preview
action: auto
comment: |
🚀 **PR Preview is ready!**
- 📄 [Documentation Preview](https://switchcraft.fabiseitz.de/pr-preview/pr-${{ github.event.pull_request.number }}/)
- 🎮 [Web Demo Preview](https://switchcraft.fabiseitz.de/pr-preview/pr-${{ github.event.pull_request.number }}/demo/)
*Built with love and GitHub Actions.*
cleanup-preview:
runs-on: ubuntu-latest
if: github.event.action == 'closed'
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Cleanup Preview
uses: rossjrw/pr-preview-action@v1
with:
preview-branch: gh-pages
umbrella-dir: pr-preview
action: delete