Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions .github/workflows/pr-preview.yml
Original file line number Diff line number Diff line change
@@ -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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This condition skips the entire job whenever the PR head repository is a fork, which includes this PR. As a result, fork PRs never export, deploy, or receive a preview comment. If fork previews are intended to be supported, use a trigger/checkout design that preserves token safety while allowing the preview; otherwise this workflow should document that limitation rather than presenting itself as a general PR preview.

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
9 changes: 0 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 1 addition & 1 deletion frontend/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
13 changes: 13 additions & 0 deletions frontend/app.config.js
Original file line number Diff line number Diff line change
@@ -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,
},
};
};
Loading