Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci 🤖: pr preview url handling #357

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
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
13 changes: 6 additions & 7 deletions .github/workflows/pr-preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ on:
- 'index.html'
- 'vite.config.js'


concurrency: preview-${{ github.ref }}

jobs:
Expand All @@ -38,33 +37,33 @@ jobs:
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

deploy-preview:
runs-on: ubuntu-latest
needs: check_access
if: needs.check_access.outputs.level == 'write' || needs.check_access.outputs.level == 'admin'

strategy:
matrix:
node-version: [18]

steps:
- name: ⏬ Checkout
uses: actions/checkout@v3

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
registry-url: 'https://registry.npmjs.org'
cache: 'npm'

- name: ⚙️ Install and Build
run: |
export GH_BASE_URL="/teia-ui/previews/pr-${{ github.event.pull_request.number }}/"
npm ci
npm run build

- name: Deploy preview
uses: rossjrw/pr-preview-action@v1
with:
Expand Down
11 changes: 9 additions & 2 deletions src/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import { Terms } from '@pages/terms'
import ReactDOM from 'react-dom/client'
import {
createBrowserRouter,
createHashRouter,
createRoutesFromElements,
Route,
RouterProvider,
Expand All @@ -73,7 +74,10 @@ const display_routes = (
)

//TODO(mel): Check/Update site map / robot.txt
const router = createBrowserRouter(

const routerCreator =
import.meta.env.BASE_URL === '/' ? createBrowserRouter : createHashRouter
const router = routerCreator(
createRoutesFromElements(
<Route path="*" errorElement={<RootErrorBoundary />} element={<App />}>
<Route path="/*" index element={<Home />} />
Expand Down Expand Up @@ -146,7 +150,10 @@ const router = createBrowserRouter(
{display_routes}
</Route>
</Route>
)
),
{
basename: import.meta.env.BASE_URL,
}
)

ReactDOM.createRoot(document.getElementById('root')).render(
Expand Down
Loading