-
Notifications
You must be signed in to change notification settings - Fork 0
68 lines (59 loc) · 2.23 KB
/
Copy pathpreview.yml
File metadata and controls
68 lines (59 loc) · 2.23 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
name: PR Preview
on:
pull_request:
branches: [master]
jobs:
preview:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "22"
cache: "npm"
cache-dependency-path: bobsgameweb/package-lock.json
- name: Install dependencies
working-directory: bobsgameweb
run: npm ci --legacy-peer-deps
- name: Build
working-directory: bobsgameweb
run: npx vite build
- name: Upload PR preview artifact
uses: actions/upload-artifact@v4
with:
name: pr-preview-${{ github.event.pull_request.number }}
path: bobsgameweb/dist/
retention-days: 3
- name: Comment PR with build status
uses: actions/github-script@v7
with:
script: |
const buildUrl = `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`;
const body = `## ✅ PR Build Successful\n\n` +
`Build artifacts are available for download from this workflow run.\n\n` +
`- **Build URL:** [View build logs](${buildUrl})\n` +
`- **Artifact:** \`pr-preview-${context.issue.number}\`\n` +
`- **Retention:** 3 days\n\n` +
`> Merge to \`master\` to deploy to production.`;
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const existing = comments.find(c => c.body?.includes('PR Build Successful'));
if (existing) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existing.id,
body: body,
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: body,
});
}