-
Notifications
You must be signed in to change notification settings - Fork 1
87 lines (69 loc) · 2.47 KB
/
Copy pathdeploy-preview.yml
File metadata and controls
87 lines (69 loc) · 2.47 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
78
79
80
81
82
83
84
85
86
87
name: Preview Deployment
on:
pull_request:
branches:
- main
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Bun
uses: oven-sh/setup-bun@v2
- name: Install Deco CLI
run: bun install -g deco-cli
- name: Install dependencies
run: bun install
- name: Build
run: bun run build
- name: Deploy
id: deploy
run: |
cd server
deco deploy -y --no-promote ./dist -t ${{ secrets.DECO_DEPLOY_TOKEN }}
env:
DECO_DEPLOY_TOKEN: ${{ secrets.DECO_DEPLOY_TOKEN }}
- name: Comment PR
uses: actions/github-script@v7
if: steps.deploy.outputs.preview_url
with:
script: |
const { data: pullRequest } = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number,
});
const previewUrl = "${{ steps.deploy.outputs.preview_url }}";
const comment = `## 🚀 Preview Deployment Ready!
Your changes have been deployed to a preview environment:
**🔗 [View Preview](${previewUrl})**
This preview will be automatically updated with new commits to this PR.
---
<sub>Deployed from commit: \`${context.sha.substring(0, 7)}\`</sub>`;
// Check if we already have a preview comment
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const existingComment = comments.find(comment =>
comment.body.includes('🚀 Preview Deployment Ready!')
);
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: context.issue.number,
body: comment
});
}