Skip to content

feat(library): add private spatial viewer experiment #1477

feat(library): add private spatial viewer experiment

feat(library): add private spatial viewer experiment #1477

name: Deploy PR Preview
on:
pull_request:
types: [opened, synchronize, reopened]
permissions:
contents: write
pull-requests: write
# Per-PR group so preview runs never cancel the production deploy (pages-production).
concurrency:
group: pages-preview-${{ github.event.pull_request.number }}
cancel-in-progress: true
jobs:
deploy-preview:
if: github.event.pull_request.head.repo.full_name == github.repository
runs-on: ubuntu-latest
# Native deployment record: GitHub renders a "View deployment" button on
# the PR. Inactive pr-<N> environments linger in the Environments tab after
# close (GITHUB_TOKEN cannot delete environments); that's cosmetic.
environment:
name: pr-${{ github.event.pull_request.number }}
url: https://xnet.fyi/pr/${{ github.event.pull_request.number }}/app/
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
- uses: ./.github/actions/setup
- name: Build packages
run: pnpm build
- name: Build web app preview
run: pnpm --filter xnet-web build
env:
VITE_BASE_PATH: /pr/${{ github.event.pull_request.number }}/app/
VITE_USE_HASH_ROUTER: 'true'
# Previews share production's origin; scope IndexedDB names so a
# preview build can never open production databases.
VITE_STORAGE_SCOPE: pr-${{ github.event.pull_request.number }}
- name: Build demos app preview
run: pnpm --filter xnet-demos build
env:
VITE_BASE_PATH: /pr/${{ github.event.pull_request.number }}/play/
- name: Prepare preview tree
run: |
rm -rf /tmp/xnet-pr-preview
mkdir -p /tmp/xnet-pr-preview
cp -R apps/web/dist/. /tmp/xnet-pr-preview/
cp /tmp/xnet-pr-preview/index.html /tmp/xnet-pr-preview/404.html
rm -rf /tmp/xnet-pr-preview-play
mkdir -p /tmp/xnet-pr-preview-play
cp -R apps/demos/dist/. /tmp/xnet-pr-preview-play/
- name: Publish preview to gh-pages
uses: ./.github/actions/publish-gh-pages
with:
source: /tmp/xnet-pr-preview
target: pr/${{ github.event.pull_request.number }}/app
commit-message: 'deploy(preview): publish PR #${{ github.event.pull_request.number }} preview'
- name: Publish demos preview to gh-pages
uses: ./.github/actions/publish-gh-pages
with:
source: /tmp/xnet-pr-preview-play
target: pr/${{ github.event.pull_request.number }}/play
commit-message: 'deploy(preview): publish PR #${{ github.event.pull_request.number }} demos preview'
- name: Comment preview link
uses: actions/github-script@v7
with:
script: |
const body = [
'<!-- xnet-pr-preview -->',
`Preview: https://xnet.fyi/pr/${context.payload.pull_request.number}/app/`,
`Demos: https://xnet.fyi/pr/${context.payload.pull_request.number}/play/`
].join('\n')
const comments = await github.paginate(github.rest.issues.listComments, {
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.pull_request.number
})
const existing = comments.find((comment) =>
comment.user?.login === 'github-actions[bot]' &&
comment.body?.includes('<!-- xnet-pr-preview -->')
)
if (existing) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existing.id,
body
})
return
}
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.pull_request.number,
body
})