forked from labring/fastgpt-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
118 lines (101 loc) · 3.35 KB
/
Copy pathpreview-push.yml
File metadata and controls
118 lines (101 loc) · 3.35 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
name: Preview Image — Push
on:
workflow_call:
inputs:
pr_number:
required: true
type: string
sha:
required: true
type: string
run_id:
required: true
type: string
secrets:
ALI_IMAGE_USER:
required: true
ALI_IMAGE_PSW:
required: true
ALI_IMAGE_PREFIX:
required: true
# Only one push at a time
concurrency:
group: 'preview-push'
cancel-in-progress: false
permissions:
contents: read
packages: write
attestations: write
id-token: write
pull-requests: write
actions: read
jobs:
push:
runs-on: ubuntu-24.04
steps:
- name: Download build artifact
uses: actions/download-artifact@v4
with:
name: preview-image
path: /tmp
run-id: ${{ inputs.run_id }}
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Read PR metadata
id: pr
run: |
echo "number=${{ inputs.pr_number }}" >> "$GITHUB_OUTPUT"
echo "sha=${{ inputs.sha }}" >> "$GITHUB_OUTPUT"
echo "package_changes=$(cat /tmp/package-changes.txt)" >> "$GITHUB_OUTPUT"
- name: Load Docker image
run: docker load --input /tmp/image.tar
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Aliyun Container Registry
uses: docker/login-action@v3
with:
registry: registry.cn-hangzhou.aliyuncs.com
username: ${{ secrets.ALI_IMAGE_USER }}
password: ${{ secrets.ALI_IMAGE_PSW }}
- name: Tag and push Docker image
run: |
docker tag fastgpt-plugin-pr:${{ steps.pr.outputs.sha }} \
${{ secrets.ALI_IMAGE_PREFIX }}/fastgpt-plugin-pr:${{ steps.pr.outputs.sha }}
docker push ${{ secrets.ALI_IMAGE_PREFIX }}/fastgpt-plugin-pr:${{ steps.pr.outputs.sha }}
- name: Add PR comment on success
if: success() && steps.pr.outputs.number != ''
uses: actions/github-script@v7
with:
script: |
const prNumber = parseInt('${{ steps.pr.outputs.number }}');
const marker = '<!-- fastgpt-plugin-preview -->';
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(marker)
);
const commentBody = `${marker}
✅ **Build Successful** - Preview Images for this PR:
\`\`\`
${{ secrets.ALI_IMAGE_PREFIX }}/fastgpt-plugin-pr:${{ steps.pr.outputs.sha }}
\`\`\`
**Changed packages:**
${{ steps.pr.outputs.package_changes || 'None' }}
`;
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
});
}