diff --git a/.github/workflows/pr-preview.yml b/.github/workflows/pr-preview.yml new file mode 100644 index 0000000..bfd2897 --- /dev/null +++ b/.github/workflows/pr-preview.yml @@ -0,0 +1,69 @@ +name: PR Preview (same-repository branches) + +on: + pull_request: + types: [opened, reopened, synchronize, closed] + +permissions: {} + +concurrency: + group: pr-preview-${{ github.event.pull_request.number }} + cancel-in-progress: true + +jobs: + explain-fork-limit: + name: Explain fork preview limitation + if: github.event.pull_request.head.repo.full_name != github.repository + permissions: + contents: read + runs-on: ubuntu-latest + steps: + - name: Record why deployment is skipped + run: echo "Fork preview deployment is intentionally disabled because pull_request workflows cannot safely grant write credentials to untrusted fork code." + + deploy-preview: + name: Deploy same-repository web preview + if: github.event.pull_request.head.repo.full_name == github.repository + permissions: + contents: write + deployments: read + pull-requests: write + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + ref: ${{ github.event.action == 'closed' && github.event.pull_request.base.sha || github.event.pull_request.head.sha }} + + - name: Set up Node.js + if: github.event.action != 'closed' + uses: actions/setup-node@v4 + with: + node-version: 20.20.2 + cache: npm + cache-dependency-path: frontend/package-lock.json + + - name: Install frontend dependencies + if: github.event.action != 'closed' + working-directory: frontend + run: npm ci + + - name: Export interactive web preview + if: github.event.action != 'closed' + working-directory: frontend + env: + EXPO_PUBLIC_USE_FAKE_WS: 'true' + EXPO_PUBLIC_WS_URL: '' + TIMEFLOW_PREVIEW_BASE_URL: /${{ github.event.repository.name }}/pr-preview/pr-${{ github.event.number }} + run: npx expo export --platform web --dev --output-dir dist + + - name: Deploy preview and comment on PR + uses: rossjrw/pr-preview-action@ffa7509e91a3ec8dfc2e5536c4d5c1acdf7a6de9 # v1.8.1 + with: + source-dir: frontend/dist + preview-branch: gh-pages + umbrella-dir: pr-preview + action: auto + wait-for-pages-deployment: true + comment: true + qr-code: true diff --git a/README.md b/README.md index c6c9ff9..aafa9c8 100644 --- a/README.md +++ b/README.md @@ -1,10 +1 @@ # TimeFlow - -## Frontend map setup - -Copy `frontend/.env.example` to `frontend/.env` and set -`EXPO_PUBLIC_BAIDU_MAP_AK` to a Baidu Maps browser-side AK. Enable JavaScript -API v4 for that AK in the Baidu Maps console and add the development and -production web origins to its Referer whitelist. Native builds render the -same JavaScript API in a WebView, so its configured `baseUrl` -(`https://timeflow.local/`) must also be allowed by the AK configuration. diff --git a/frontend/.env.example b/frontend/.env.example index 29e7b6f..9ecc315 100644 --- a/frontend/.env.example +++ b/frontend/.env.example @@ -10,7 +10,7 @@ EXPO_PUBLIC_BAIDU_MAP_AK=your-baidu-map-browser-ak # Emulator example: ws://10.0.2.2:8000/ws/v1 # Production example: wss://api.example.com/ws # Release builds require wss://. Plain ws:// is accepted only in development. -# Leave empty to use the in-process fake transport in development. + EXPO_PUBLIC_WS_URL= # Force the fake WebSocket even if EXPO_PUBLIC_WS_URL is set (dev only). diff --git a/frontend/app.config.js b/frontend/app.config.js new file mode 100644 index 0000000..6336807 --- /dev/null +++ b/frontend/app.config.js @@ -0,0 +1,13 @@ +module.exports = ({ config }) => { + const previewBaseUrl = process.env.TIMEFLOW_PREVIEW_BASE_URL?.trim(); + + if (!previewBaseUrl) return config; + + return { + ...config, + experiments: { + ...config.experiments, + baseUrl: previewBaseUrl, + }, + }; +};