|
| 1 | +# Simple workflow for deploying static content to GitHub Pages |
| 2 | +name: Deploy static content to Pages |
| 3 | + |
| 4 | +on: |
| 5 | + push: |
| 6 | + branches: ["main", "demo_app_v1", "demo_app_v2", "demo_app_v3", "demo_app_v4", "demo_app_v5"] |
| 7 | + |
| 8 | + # Allows you to run this workflow manually from the Actions tab |
| 9 | + workflow_dispatch: |
| 10 | + |
| 11 | +# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages |
| 12 | +permissions: |
| 13 | + contents: read |
| 14 | + pages: write |
| 15 | + id-token: write |
| 16 | + |
| 17 | +# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. |
| 18 | +# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete. |
| 19 | +concurrency: |
| 20 | + group: "pages" |
| 21 | + cancel-in-progress: false |
| 22 | + |
| 23 | +jobs: |
| 24 | + # Single deploy job since we're just deploying |
| 25 | + deploy: |
| 26 | + environment: |
| 27 | + name: github-pages |
| 28 | + url: ${{ steps.deployment.outputs.page_url }} |
| 29 | + runs-on: ubuntu-latest |
| 30 | + steps: |
| 31 | + - name: Checkout |
| 32 | + 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 | +
|
| 78 | + - name: Setup Pages |
| 79 | + uses: actions/configure-pages@v5 |
| 80 | + |
| 81 | + - name: Upload build artifact |
| 82 | + uses: actions/upload-pages-artifact@v3 |
| 83 | + with: |
| 84 | + path: ./build |
| 85 | + |
| 86 | + - name: Deploy to GitHub Pages |
| 87 | + id: deployment |
| 88 | + uses: actions/deploy-pages@v4 |
0 commit comments