-
Notifications
You must be signed in to change notification settings - Fork 20
92 lines (78 loc) · 2.81 KB
/
Copy pathpreview-deploy.yml
File metadata and controls
92 lines (78 loc) · 2.81 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
88
89
90
91
92
name: Preview Home Page — Deploy
on:
workflow_run:
workflows: ["Preview Home Page — Build"]
types: [completed]
# Only one deploy at a time; do not cancel in-progress deploys.
concurrency:
group: 'preview-deploy'
cancel-in-progress: false
permissions:
contents: read
deployments: write
pull-requests: write
actions: read
env:
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true
jobs:
deploy:
runs-on: ubuntu-24.04
# Only deploy when the build succeeded.
if: ${{ github.event.workflow_run.conclusion == 'success' }}
steps:
- name: Download build artifact
uses: actions/download-artifact@v4
with:
name: preview-build
path: ./out
run-id: ${{ github.event.workflow_run.id }}
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Read PR number
id: pr
run: |
number="$(cat ./out/pr-number.txt)"
echo "number=$number" >> "$GITHUB_OUTPUT"
echo "branch=pr-$number" >> "$GITHUB_OUTPUT"
- name: Deploy to Cloudflare Pages
id: deploy
uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ vars.CLOUDFLARE_ACCOUNT_ID }}
command: pages deploy ./out --project-name=fastgpt-home --branch=${{ steps.pr.outputs.branch }}
quiet: false
- name: Comment Preview URL on PR
uses: actions/github-script@v7
if: success() && steps.pr.outputs.number != ''
with:
script: |
const prNumber = parseInt('${{ steps.pr.outputs.number }}');
const deployUrl = '${{ steps.deploy.outputs.deployment-url }}';
const marker = '<!-- fastgpt-home-preview -->';
const body = `${marker}
🚀 **FastGPT Homepage Preview Ready!**
📱 **Preview URL:** ${deployUrl}
🔗 [👀 Click here to visit preview](${deployUrl})
---
💡 This preview will be automatically updated when you push new commits to this PR.`;
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
});
const existing = comments.find(c => c.body.includes(marker));
if (existing) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existing.id,
body,
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
body,
});
}