@@ -21,8 +21,73 @@ concurrency:
2121 cancel-in-progress : false
2222
2323jobs :
24- # Single deploy job since we're just deploying
25- deploy :
24+ # Deploy for non-main branches (no protected environment)
25+ deploy_unprotected :
26+ if : github.ref != 'refs/heads/main'
27+ runs-on : ubuntu-latest
28+ steps :
29+ - name : Checkout
30+ uses : actions/checkout@v4
31+
32+ - name : Setup Node.js
33+ uses : actions/setup-node@v4
34+ with :
35+ node-version : ' 18'
36+
37+ - name : Install dependencies
38+ run : |
39+ if [ -f package-lock.json ]; then npm ci; else npm install; fi
40+
41+ - name : Determine deploy subpath
42+ id : vars
43+ run : |
44+ BRANCH=${GITHUB_REF#refs/heads/}
45+ # Default folder for main is root (no vX prefix). For demo branches map to v1..v5
46+ case "$BRANCH" in
47+ demo_app_v1) SUBPATH="v1";;
48+ demo_app_v2) SUBPATH="v2";;
49+ demo_app_v3) SUBPATH="v3";;
50+ demo_app_v4) SUBPATH="v4";;
51+ demo_app_v5) SUBPATH="v5";;
52+ main) SUBPATH="";;
53+ *) SUBPATH="";;
54+ esac
55+ echo "subpath=$SUBPATH" >> $GITHUB_OUTPUT
56+
57+ - name : Build
58+ env :
59+ BASE_PATH : ${{ steps.vars.outputs.subpath }}
60+ APP_BASE : browserstack-demo-app
61+ run : |
62+ # Compute a single deploy base that always ends with a trailing slash
63+ if [ -n "$BASE_PATH" ]; then
64+ DEPLOY_BASE="/${APP_BASE}/${BASE_PATH}/"
65+ else
66+ DEPLOY_BASE="/${APP_BASE}/"
67+ fi
68+
69+ # Export to the build-tool env names expected by the project
70+ export PUBLIC_URL="$DEPLOY_BASE"
71+ export VITE_BASE_PATH="$DEPLOY_BASE"
72+ echo "Building with DEPLOY_BASE=$DEPLOY_BASE"
73+
74+ npm run build
75+
76+ - name : Setup Pages
77+ uses : actions/configure-pages@v5
78+
79+ - name : Upload build artifact
80+ uses : actions/upload-pages-artifact@v3
81+ with :
82+ path : ./build
83+
84+ - name : Deploy to GitHub Pages
85+ id : deployment
86+ uses : actions/deploy-pages@v4
87+
88+ # Deploy for main branch (keeps environment protections)
89+ deploy_protected :
90+ if : github.ref == 'refs/heads/main'
2691 environment :
2792 name : github-pages
2893 url : ${{ steps.deployment.outputs.page_url }}
0 commit comments