Skip to content

docs(explorations): add web and mobile devtool strategy #73

docs(explorations): add web and mobile devtool strategy

docs(explorations): add web and mobile devtool strategy #73

name: Deploy PR Preview
on:
pull_request:
types: [opened, synchronize, reopened]
permissions:
contents: write
pull-requests: write
concurrency:
group: pages-branch
cancel-in-progress: true
jobs:
deploy-preview:
if: github.event.pull_request.head.repo.full_name == github.repository
runs-on: ubuntu-latest
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'
- 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
- name: Publish preview to gh-pages
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
rm -rf /tmp/xnet-gh-pages
git fetch origin gh-pages || true
if git ls-remote --exit-code --heads origin gh-pages >/dev/null 2>&1; then
git worktree add -B gh-pages /tmp/xnet-gh-pages origin/gh-pages
else
git worktree add -B gh-pages /tmp/xnet-gh-pages HEAD
find /tmp/xnet-gh-pages -mindepth 1 -maxdepth 1 ! -name '.git' -exec rm -rf {} +
cp site/public/CNAME /tmp/xnet-gh-pages/CNAME
touch /tmp/xnet-gh-pages/.nojekyll
fi
preview_dir="/tmp/xnet-gh-pages/pr/${{ github.event.pull_request.number }}/app"
mkdir -p "$preview_dir"
rsync -a --delete /tmp/xnet-pr-preview/ "$preview_dir/"
cd /tmp/xnet-gh-pages
git add -A
if git diff --cached --quiet; then
echo "No preview changes to publish."
exit 0
fi
git commit -m "deploy(preview): publish PR #${{ github.event.pull_request.number }} preview"
git push origin HEAD:gh-pages
- 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/`
].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
})