From 1a6099cd6f7570fa80bb274a50eaaf828f27c3d1 Mon Sep 17 00:00:00 2001 From: weishu Date: Mon, 29 Dec 2025 09:30:53 +0800 Subject: [PATCH] ci: add GitHub Pages deployment workflow for web app Adds automated deployment to GitHub Pages with custom domain app.hapi.run, and updates vite.config.ts to support dynamic base URL via VITE_BASE_URL environment variable --- .github/workflows/webapp.yml | 48 ++++++++++++++++++++++++++++++++++++ web/vite.config.ts | 8 +++--- 2 files changed, 53 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/webapp.yml diff --git a/.github/workflows/webapp.yml b/.github/workflows/webapp.yml new file mode 100644 index 00000000..e0f118ac --- /dev/null +++ b/.github/workflows/webapp.yml @@ -0,0 +1,48 @@ +name: Deploy Web App to GitHub Pages + +on: + push: + branches: + - main + paths: + - 'web/**' + - '.github/workflows/webapp.yml' + workflow_dispatch: + +permissions: + contents: read + pages: write + id-token: write + +concurrency: + group: pages + cancel-in-progress: true + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: oven-sh/setup-bun@v2 + - run: bun install + - name: Build web app + run: bun run --cwd web build + - name: Add CNAME for custom domain + run: echo "app.hapi.run" > web/dist/CNAME + - name: Setup Pages + uses: actions/configure-pages@v5 + - name: Upload artifact + uses: actions/upload-pages-artifact@v3 + with: + path: web/dist + + deploy: + needs: build + runs-on: ubuntu-latest + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + steps: + - name: Deploy to GitHub Pages + id: deployment + uses: actions/deploy-pages@v4 diff --git a/web/vite.config.ts b/web/vite.config.ts index bca4a1ea..ef57be7e 100644 --- a/web/vite.config.ts +++ b/web/vite.config.ts @@ -3,6 +3,8 @@ import react from '@vitejs/plugin-react' import { VitePWA } from 'vite-plugin-pwa' import { resolve } from 'node:path' +const base = process.env.VITE_BASE_URL || '/' + export default defineConfig({ server: { host: true, @@ -31,8 +33,8 @@ export default defineConfig({ background_color: '#ffffff', display: 'standalone', orientation: 'portrait', - scope: '/', - start_url: '/', + scope: base, + start_url: base, icons: [ { src: 'pwa-64x64.png', @@ -126,7 +128,7 @@ export default defineConfig({ } }) ], - base: '/', + base, resolve: { alias: { '@': resolve(__dirname, 'src')