@@ -3,160 +3,147 @@ name: Build and Deploy Examples
33on : workflow_dispatch
44
55env :
6- COMMIT_SHORT_SHA : ${{ github.sha }}
6+ COMMIT_FULL_SHA : ${{ github.sha }}
77
88jobs :
9- build_expo :
9+ deploy_preview :
1010 runs-on : ubuntu-latest
1111 steps :
12- - uses : actions/checkout@v3
12+ - uses : actions/checkout@v4
1313
1414 - name : Get short commit SHA
1515 run : echo "COMMIT_SHORT_SHA=${GITHUB_SHA:0:7}" >> $GITHUB_ENV
1616
1717 - name : Setup Node.js
18- uses : actions/setup-node@v3
18+ uses : actions/setup-node@v4
1919 with :
2020 node-version : ' 22'
2121 registry-url : ' https://registry.npmjs.org'
22+
2223 - name : Install Dependencies
2324 run : |
2425 yarn
2526 yarn bootstrap
27+
2628 - name : Build All Packages
2729 run : yarn build
30+
2831 - name : Build Expo Example
2932 run : EXPO_PUBLIC_COMMIT_SHA=${{ env.COMMIT_SHORT_SHA }} yarn expo export:web
3033 working-directory : packages/connect-examples/expo-example
3134
32- - name : Add commit info to build output
35+ - name : Add commit info to Expo Example
3336 run : |
34- # 先备份原始构建产物到临时目录
3537 mkdir -p temp-build
3638 cp -r web-build/* temp-build/ 2>/dev/null || true
37- # 创建带有 commit id 的子目录
3839 mkdir -p web-build/commits/${{ env.COMMIT_SHORT_SHA }}
39- # 复制备份的构建产物到带有 commit id 的目录
4040 cp -r temp-build/* web-build/commits/${{ env.COMMIT_SHORT_SHA }}/
41- # 创建一个 commit 信息文件
4241 echo '{"commit": "${{ env.COMMIT_SHORT_SHA }}", "fullCommit": "${{ github.sha }}", "timestamp": "'$(date -u +%Y-%m-%dT%H:%M:%SZ)'"}' > web-build/commits/${{ env.COMMIT_SHORT_SHA }}/commit-info.json
43- # 为 commit 版本也创建 404.html
4442 cp web-build/commits/${{ env.COMMIT_SHORT_SHA }}/index.html web-build/commits/${{ env.COMMIT_SHORT_SHA }}/404.html
45- # 清理临时目录
4643 rm -rf temp-build
4744 working-directory : packages/connect-examples/expo-example
4845
49- - name : Upload Artifact
50- uses : actions/upload-artifact@v4
46+ - name : Build Expo Playground (testing preview)
47+ working-directory : packages/connect-examples/expo-playground
48+ run : yarn build
49+
50+ - name : Add SPA fallback pages
51+ run : |
52+ cp packages/connect-examples/expo-playground/dist/index.html packages/connect-examples/expo-playground/dist/404.html
53+ cp packages/connect-examples/expo-example/web-build/index.html packages/connect-examples/expo-example/web-build/404.html
54+
55+ - name : Prepare root static assets
56+ run : |
57+ rm -rf gh-pages-root
58+ mkdir -p gh-pages-root
59+ cp .github/templates/404.html gh-pages-root/404.html
60+ cp .github/templates/404.html gh-pages-root/index.html
61+ if [ -f "packages/connect-examples/expo-example/web-build/manifest.json" ]; then
62+ cp packages/connect-examples/expo-example/web-build/manifest.json gh-pages-root/manifest.json
63+ echo "✅ Copied manifest.json from expo-example"
64+ else
65+ cp .github/templates/manifest.json gh-pages-root/manifest.json
66+ echo "⚠️ expo-example manifest not found, using template"
67+ fi
68+ find packages/connect-examples/expo-example/web-build -maxdepth 1 -type f -name "favicon*" -exec cp {} gh-pages-root/ \;
69+
70+ - name : Deploy root assets
71+ uses : peaceiris/actions-gh-pages@v4
5172 with :
52- name : expo-build
53- path : packages/connect-examples/expo-example/web-build
73+ github_token : ${{ secrets.GITHUB_TOKEN }}
74+ publish_dir : ./gh-pages-root
75+ cname : hardware-example.onekeytest.com
76+ force_orphan : true
77+
78+ - name : Deploy Expo Example (GitHub Pages)
79+ uses : peaceiris/actions-gh-pages@v4
80+ with :
81+ github_token : ${{ secrets.GITHUB_TOKEN }}
82+ publish_dir : packages/connect-examples/expo-example/web-build
83+ destination_dir : expo-example
84+ keep_files : true
5485
55- build_new_example :
86+ - name : Deploy Expo Playground (GitHub Pages)
87+ uses : peaceiris/actions-gh-pages@v4
88+ with :
89+ github_token : ${{ secrets.GITHUB_TOKEN }}
90+ publish_dir : packages/connect-examples/expo-playground/dist
91+ destination_dir : expo-playground
92+ keep_files : true
93+
94+ build_playground_production :
5695 runs-on : ubuntu-latest
96+ needs : deploy_preview
5797 steps :
58- - uses : actions/checkout@v3
98+ - uses : actions/checkout@v4
5999
60100 - name : Get short commit SHA
61101 run : echo "COMMIT_SHORT_SHA=${GITHUB_SHA:0:7}" >> $GITHUB_ENV
62102
63103 - name : Setup Node.js
64- uses : actions/setup-node@v3
104+ uses : actions/setup-node@v4
65105 with :
66106 node-version : ' 22'
67107 registry-url : ' https://registry.npmjs.org'
108+
68109 - name : Install Dependencies
69110 run : |
70111 yarn
71112 yarn bootstrap
113+
72114 - name : Build All Packages
73115 run : yarn build
74- - name : Build New Example
75- run : COMMIT_SHA=${{ env.COMMIT_SHORT_SHA }} yarn build
76- working-directory : packages/connect-examples/expo-playground
77- - name : Upload Artifact
78- uses : actions/upload-artifact@v4
79- with :
80- name : expo-playground-build
81- path : packages/connect-examples/expo-playground/dist
82-
83- deploy :
84- runs-on : ubuntu-latest
85- needs : [build_expo, build_new_example]
86- steps :
87- - name : Checkout
88- uses : actions/checkout@v3
89-
90- - name : Get short commit SHA
91- run : echo "COMMIT_SHORT_SHA=${GITHUB_SHA:0:7}" >> $GITHUB_ENV
92-
93- - name : Setup Deploy Directory
94- run : mkdir -p deploy
95- - name : Download Expo Artifact
96- uses : actions/download-artifact@v4
97- with :
98- name : expo-build
99- path : deploy/temp-expo
100- - name : Download New Example Artifact
101- uses : actions/download-artifact@v4
102- with :
103- name : expo-playground-build
104- path : deploy/expo-playground
105- - name : Setup Expo as Root and create routing
106- run : |
107- # Create expo-example subdirectory and copy all build files
108- mkdir -p deploy/expo-example
109- cp -r deploy/temp-expo/* deploy/expo-example/
110-
111- # Debug: List files in expo-example directory
112- echo "=== Files in deploy/expo-example ==="
113- find deploy/expo-example -type f -name "*.json" -o -name "favicon*" -o -name "*.ico" | head -10
114-
115- # Copy all favicon-related files to root path
116- # Handle various favicon formats that Expo might generate
117- favicon_count=0
118- find deploy/expo-example -name "favicon*" -type f | while read file; do
119- filename=$(basename "$file")
120- cp "$file" "deploy/$filename"
121- echo "✅ Copied favicon: $filename"
122- favicon_count=$((favicon_count + 1))
123- done
124-
125- if [ $favicon_count -eq 0 ]; then
126- echo "⚠️ No favicon files found in build output"
127- fi
128116
129- # Copy manifest.json to root path for PWA support
130- if [ -f "deploy/expo-example/manifest.json" ]; then
131- cp deploy/expo-example/manifest.json deploy/manifest.json
132- echo "✅ Copied manifest.json to root"
133- echo "=== Generated manifest.json content ==="
134- cat deploy/manifest.json | head -10
135- else
136- # Use fallback manifest.json if Expo didn't generate one
137- cp .github/templates/manifest.json deploy/manifest.json
138- echo "⚠️ Used fallback manifest.json (Expo didn't generate one)"
139- fi
140-
141- # Clean up temp directory
142- rm -rf deploy/temp-expo
117+ - name : Build Expo Playground (production)
118+ working-directory : packages/connect-examples/expo-playground
119+ env :
120+ COMMIT_SHA : ${{ env.COMMIT_FULL_SHA }}
121+ run : yarn build
143122
144- - name : Add SPA fallback for client-side routing
123+ - name : Package production bundle with commit id
124+ working-directory : packages/connect-examples/expo-playground
125+ env :
126+ COMMIT_FULL_SHA : ${{ env.COMMIT_FULL_SHA }}
127+ COMMIT_SHORT_SHA : ${{ env.COMMIT_SHORT_SHA }}
145128 run : |
146- # 为各子应用创建简单的 SPA 回退 404.html
147- cp deploy/expo-playground/index.html deploy/expo-playground/404.html
148- cp deploy/expo-example/index.html deploy/expo-example/404.html
149-
150- # 复制统一的路由分发器模板到根目录
151- cp .github/templates/404.html deploy/404.html
152-
153- # 验证部署结构
154- echo "=== Deployment Structure ==="
155- find deploy -name "*.html" -o -name "manifest.json" -o -name "favicon*" | sort
156- - name : Deploy to Github Pages
157- uses : peaceiris/actions-gh-pages@v4
129+ RELEASE_ROOT="release"
130+ rm -rf "${RELEASE_ROOT}"
131+ mkdir -p "${RELEASE_ROOT}"
132+ cp dist/index.html "${RELEASE_ROOT}/index.html"
133+ cp dist/404.html "${RELEASE_ROOT}/404.html"
134+ mkdir -p "${RELEASE_ROOT}/${COMMIT_FULL_SHA}"
135+ cp -R dist/${COMMIT_FULL_SHA}/. "${RELEASE_ROOT}/${COMMIT_FULL_SHA}/"
136+ cat <<EOF > "${RELEASE_ROOT}/${COMMIT_FULL_SHA}/build-info.json"
137+ {
138+ "commit": "${COMMIT_FULL_SHA}",
139+ "shortCommit": "${COMMIT_SHORT_SHA}",
140+ "buildEnv": "production",
141+ "buildTime": "$(date -u +%Y-%m-%dT%H:%M:%SZ)"
142+ }
143+ EOF
144+
145+ - name : Upload Production Artifact
146+ uses : actions/upload-artifact@v4
158147 with :
159- github_token : ${{ secrets.GITHUB_TOKEN }}
160- publish_dir : ./deploy
161- cname : hardware-example.onekeytest.com
162- force_orphan : true
148+ name : ${{ env.COMMIT_FULL_SHA }}
149+ path : packages/connect-examples/expo-playground/release
0 commit comments