diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index 3ca3027..cb08897 100644 --- a/.github/workflows/static.yml +++ b/.github/workflows/static.yml @@ -21,8 +21,89 @@ concurrency: cancel-in-progress: false jobs: - # Single deploy job since we're just deploying - deploy: + # Deploy for non-main branches (no protected environment) + deploy_unprotected: + if: github.ref != 'refs/heads/main' + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: '18' + + - name: Install dependencies + run: | + # Ensure required native deps for image optimization binaries (pngquant) are present + sudo apt-get update && sudo apt-get install -y libpng-dev build-essential pkg-config || true + # Avoid installing optional native binaries that sometimes fail in CI + export npm_config_optional=false + if [ -f package-lock.json ]; then npm ci; else npm install; fi + + - name: Determine deploy subpath + id: vars + run: | + BRANCH=${GITHUB_REF#refs/heads/} + # Default folder for main is root (no vX prefix). For demo branches map to v1..v5 + case "$BRANCH" in + demo_app_v1) SUBPATH="v1";; + demo_app_v2) SUBPATH="v2";; + demo_app_v3) SUBPATH="v3";; + demo_app_v4) SUBPATH="v4";; + demo_app_v5) SUBPATH="v5";; + main) SUBPATH="";; + *) SUBPATH="";; + esac + echo "subpath=$SUBPATH" >> $GITHUB_OUTPUT + + - name: Build + env: + BASE_PATH: ${{ steps.vars.outputs.subpath }} + run: | + # Compute a single deploy base that always ends with a trailing slash + # Use repository name as base (strip organization) so site is published under the repo path + REPO_NAME=${GITHUB_REPOSITORY#*/} + if [ -n "$BASE_PATH" ]; then + DEPLOY_BASE="/${REPO_NAME}/${BASE_PATH}/" + else + DEPLOY_BASE="/${REPO_NAME}/" + fi + + # Export to the build-tool env names expected by the project + export PUBLIC_URL="$DEPLOY_BASE" + export VITE_BASE_PATH="$DEPLOY_BASE" + echo "Building with DEPLOY_BASE=$DEPLOY_BASE" + + # Print the expected GitHub Pages URL to make verification easier + OWNER=${GITHUB_REPOSITORY%%/*} + REPO=${GITHUB_REPOSITORY#*/} + # strip possible .git (unlikely in GITHUB_REPOSITORY but safe) + REPO=$(basename -s .git "$REPO") + # Construct URL without trailing slash + EXPECTED_URL="https://${OWNER}.github.io/${REPO}${DEPLOY_BASE%/}" + echo "Expected Pages URL: $EXPECTED_URL" + + npm run build + # Ensure SPA routes work on GitHub Pages by providing a 404 fallback + if [ -f dist/index.html ]; then cp dist/index.html dist/404.html || true; fi + + - name: Setup Pages + uses: actions/configure-pages@v5 + + - name: Upload build artifact + uses: actions/upload-pages-artifact@v3 + with: + path: ./dist + + - name: Deploy to GitHub Pages + id: deployment + uses: actions/deploy-pages@v4 + + # Deploy for main branch (keeps environment protections) + deploy_protected: + if: github.ref == 'refs/heads/main' environment: name: github-pages url: ${{ steps.deployment.outputs.page_url }} @@ -38,6 +119,10 @@ jobs: - name: Install dependencies run: | + # Ensure required native deps for image optimization binaries (pngquant) are present + sudo apt-get update && sudo apt-get install -y libpng-dev build-essential pkg-config || true + # Avoid installing optional native binaries that sometimes fail in CI + export npm_config_optional=false if [ -f package-lock.json ]; then npm ci; else npm install; fi - name: Determine deploy subpath @@ -59,21 +144,30 @@ jobs: - name: Build env: BASE_PATH: ${{ steps.vars.outputs.subpath }} - APP_BASE: browserstack-demo-app run: | # Compute a single deploy base that always ends with a trailing slash + # Use repository name as base (strip organization) so site is published under the repo path + REPO_NAME=${GITHUB_REPOSITORY#*/} if [ -n "$BASE_PATH" ]; then - DEPLOY_BASE="/${APP_BASE}/${BASE_PATH}/" + DEPLOY_BASE="/${REPO_NAME}/${BASE_PATH}/" else - DEPLOY_BASE="/${APP_BASE}/" + DEPLOY_BASE="/${REPO_NAME}/" fi # Export to the build-tool env names expected by the project export PUBLIC_URL="$DEPLOY_BASE" export VITE_BASE_PATH="$DEPLOY_BASE" echo "Building with DEPLOY_BASE=$DEPLOY_BASE" + # Print the expected GitHub Pages URL to make verification easier + OWNER=${GITHUB_REPOSITORY%%/*} + REPO=${GITHUB_REPOSITORY#*/} + REPO=$(basename -s .git "$REPO") + EXPECTED_URL="https://${OWNER}.github.io/${REPO}${DEPLOY_BASE%/}" + echo "Expected Pages URL: $EXPECTED_URL" npm run build + # Ensure SPA routes work on GitHub Pages by providing a 404 fallback + if [ -f dist/index.html ]; then cp dist/index.html dist/404.html || true; fi - name: Setup Pages uses: actions/configure-pages@v5 @@ -81,7 +175,7 @@ jobs: - name: Upload build artifact uses: actions/upload-pages-artifact@v3 with: - path: ./build + path: ./dist - name: Deploy to GitHub Pages id: deployment diff --git a/index.html b/index.html index 5f870f6..668abe9 100644 --- a/index.html +++ b/index.html @@ -4,14 +4,14 @@ browserstack-demo - + - - - + + + - + + diff --git a/package-lock.json b/package-lock.json index 990af7c..9ddc8d5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,11 +1,11 @@ { - "name": "browserstack-demo-app", + "name": "test-selection-demo-app-browserstack", "version": "0.0.0", "lockfileVersion": 3, "requires": true, "packages": { "": { - "name": "browserstack-demo-app", + "name": "test-selection-demo-app-browserstack", "version": "0.0.0", "dependencies": { "@hookform/resolvers": "^3.9.0", diff --git a/package.json b/package.json index 656b9ae..409c953 100644 --- a/package.json +++ b/package.json @@ -1,17 +1,14 @@ { - "name": "browserstack-demo-app", + "name": "test-selection-demo-app-browserstack", "version": "0.0.0", "type": "module", - "homepage": "https://browserstack.github.io/browserstack-demo-app", + "homepage": "https://browserstack.github.io/test-selection-demo-app-browserstack/", "scripts": { "predeploy": "npm run build", "deploy": "gh-pages -d dist", "dev": "vite", "build": "vite build", "build:dev": "vite build --mode development", - "build:v1": "cross-env VITE_BASE_PATH=/browserstack-demo-app/v1/ vite build", - "build:v2": "cross-env VITE_BASE_PATH=/browserstack-demo-app/v2/ vite build", - "build:v3": "cross-env VITE_BASE_PATH=/browserstack-demo-app/v3/ vite build", "lint": "eslint .", "preview": "vite preview" }, diff --git a/public/404.html b/public/404.html index 8f017f3..b31f5fb 100644 --- a/public/404.html +++ b/public/404.html @@ -3,24 +3,26 @@ - Loading... + Redirecting... -

Loading the application…

+

Redirecting to the app...

diff --git a/public/_redirects b/public/_redirects deleted file mode 100644 index ad37e2c..0000000 --- a/public/_redirects +++ /dev/null @@ -1 +0,0 @@ -/* /index.html 200 diff --git a/src/App.tsx b/src/App.tsx index 065c7b4..0884723 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -120,7 +120,7 @@ const App = () => ( - + diff --git a/src/data/products.ts b/src/data/products.ts index 3bbec7e..14f844f 100644 --- a/src/data/products.ts +++ b/src/data/products.ts @@ -91,15 +91,5 @@ export const products = [ description: 'Samsung Galaxy S20+ with Snapdragon 865, 6.7-inch Dynamic AMOLED, quad camera system.', image: getAssetPath('/static/products/samsung-S20+.png'), rating: { rate: 4.7, count: 160 } - }, - { - id: 10, - title: 'Samsung Galaxy S20 Ultra', - price: 999.99, - category: 'android', - os: 'android', - description: 'Samsung Galaxy S20 Ultra with Snapdragon 865, 6.9-inch Dynamic AMOLED, 108MP camera.', - image: getAssetPath('/static/products/samsung-S20Ultra.png'), - rating: { rate: 4.8, count: 175 } } ];