-
Notifications
You must be signed in to change notification settings - Fork 0
77 lines (64 loc) · 2.29 KB
/
Copy pathpr-preview.yml
File metadata and controls
77 lines (64 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
name: PR Preview
on:
pull_request:
types: [opened, synchronize, reopened]
branches: [main]
jobs:
deploy-preview:
runs-on: ubuntu-latest
permissions:
contents: write
pages: write
id-token: write
pull-requests: write
steps:
- uses: actions/checkout@v7
with:
fetch-depth: 0
- uses: actions/setup-node@v7
with:
node-version: 24
- run: npm ci
- name: Build for PR preview
env:
VITE_BASE_PATH: /generated-game-experiment/pr-${{ github.event.number }}/
run: npm run build
- name: Deploy to GitHub Pages (PR Preview)
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./dist
destination_dir: pr-${{ github.event.number }}
- name: Comment PR with preview URL
uses: actions/github-script@v9
with:
script: |
const prNumber = context.payload.number;
const previewUrl = `https://commjoen.github.io/generated-game-experiment/pr-${prNumber}/`;
// Check if we already commented with preview URL
const comments = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
});
const existingComment = comments.data.find(comment =>
comment.body.includes('🚀 Preview deployed') && comment.user.login === 'github-actions[bot]'
);
const commentBody = `🚀 **Preview deployed!**
Your changes are now available at: ${previewUrl}
*This preview will be automatically cleaned up when the PR is closed or merged.*`;
if (existingComment) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existingComment.id,
body: commentBody,
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
body: commentBody,
});
}