Skip to content

Commit 0ee8c87

Browse files
committed
Update GitHub Actions workflow to support multiple branches and enhance build process
1 parent 5294703 commit 0ee8c87

File tree

1 file changed

+50
-5
lines changed

1 file changed

+50
-5
lines changed

.github/workflows/static.yml

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
name: Deploy static content to Pages
33

44
on:
5-
# Runs on pushes targeting the default branch
65
push:
7-
branches: ["demo_app_v2"]
6+
branches: ["main", "demo_app_v1", "demo_app_v2", "demo_app_v3", "demo_app_v4", "demo_app_v5"]
87

98
# Allows you to run this workflow manually from the Actions tab
109
workflow_dispatch:
@@ -31,13 +30,59 @@ jobs:
3130
steps:
3231
- name: Checkout
3332
uses: actions/checkout@v4
33+
34+
- name: Setup Node.js
35+
uses: actions/setup-node@v4
36+
with:
37+
node-version: '18'
38+
39+
- name: Install dependencies
40+
run: |
41+
if [ -f package-lock.json ]; then npm ci; else npm install; fi
42+
43+
- name: Determine deploy subpath
44+
id: vars
45+
run: |
46+
BRANCH=${GITHUB_REF#refs/heads/}
47+
# Default folder for main is root (no vX prefix). For demo branches map to v1..v5
48+
case "$BRANCH" in
49+
demo_app_v1) SUBPATH="v1";;
50+
demo_app_v2) SUBPATH="v2";;
51+
demo_app_v3) SUBPATH="v3";;
52+
demo_app_v4) SUBPATH="v4";;
53+
demo_app_v5) SUBPATH="v5";;
54+
main) SUBPATH="";;
55+
*) SUBPATH="";;
56+
esac
57+
echo "subpath=$SUBPATH" >> $GITHUB_OUTPUT
58+
59+
- name: Build
60+
env:
61+
BASE_PATH: ${{ steps.vars.outputs.subpath }}
62+
APP_BASE: browserstack-demo-app
63+
run: |
64+
# Compute a single deploy base that always ends with a trailing slash
65+
if [ -n "$BASE_PATH" ]; then
66+
DEPLOY_BASE="/${APP_BASE}/${BASE_PATH}/"
67+
else
68+
DEPLOY_BASE="/${APP_BASE}/"
69+
fi
70+
71+
# Export to the build-tool env names expected by the project
72+
export PUBLIC_URL="$DEPLOY_BASE"
73+
export VITE_BASE_PATH="$DEPLOY_BASE"
74+
echo "Building with DEPLOY_BASE=$DEPLOY_BASE"
75+
76+
npm run build
77+
3478
- name: Setup Pages
3579
uses: actions/configure-pages@v5
36-
- name: Upload artifact
80+
81+
- name: Upload build artifact
3782
uses: actions/upload-pages-artifact@v3
3883
with:
39-
# Upload entire repository
40-
path: '.'
84+
path: ./build
85+
4186
- name: Deploy to GitHub Pages
4287
id: deployment
4388
uses: actions/deploy-pages@v4

0 commit comments

Comments
 (0)