Skip to content

refactor!: Sync repository #4

refactor!: Sync repository

refactor!: Sync repository #4

name: PR Preview Deployment
on:
pull_request:
types: [opened, synchronize, reopened]
branches:
- master
permissions:
contents: write
pull-requests: write
pages: write
id-token: write
jobs:
build-and-deploy-preview:
name: Build and Deploy PR Preview
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Build app
run: npm run build:app
- name: Deploy preview to GitHub Pages
uses: rossjrw/pr-preview-action@v1
with:
source-dir: ./dist/apps/demo-app
preview-branch: gh-pages-preview
umbrella-dir: pr-previews
action: auto
- name: Comment preview URL
uses: actions/github-script@v7
with:
script: |
const prNumber = context.payload.pull_request.number;
const previewUrl = `https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/pr-previews/pr-${prNumber}/`;
const comment = `## 🚀 Preview Deployment
Your preview deployment is ready!
🔗 **Preview URL**: ${previewUrl}
This preview will be updated automatically when you push new commits to this PR.
---
*Preview deployments are powered by GitHub Pages*`;
// Find existing preview comment
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber
});
const existingComment = comments.find(comment =>
comment.body.includes('## 🚀 Preview Deployment')
);
if (existingComment) {
// Update existing comment
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existingComment.id,
body: comment
});
} else {
// Create new comment
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
body: comment
});
}