-
Notifications
You must be signed in to change notification settings - Fork 1
186 lines (171 loc) · 7.63 KB
/
deploy-multipost.yml
File metadata and controls
186 lines (171 loc) · 7.63 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
name: Deploy MultiPost
on:
repository_dispatch:
types: [deploy-multipost]
jobs:
build-and-deploy:
runs-on: ubuntu-latest
outputs:
pr_number: ${{ steps.set-ref.outputs.pr_number }}
is_deployable: ${{ steps.set-ref.outputs.is_deployable }}
steps:
- name: Validate and set ref
id: set-ref
run: |
REF="${{ github.event.client_payload.ref }}"
if [ -z "$REF" ]; then
echo "ref=main" >> $GITHUB_OUTPUT
echo "pr_number=" >> $GITHUB_OUTPUT
echo "is_deployable=true" >> $GITHUB_OUTPUT
echo "使用默认分支: main (ref 为空)"
elif [[ "$REF" == "main" ]] || [[ "$REF" == "refs/heads/main" ]]; then
echo "ref=$REF" >> $GITHUB_OUTPUT
echo "pr_number=" >> $GITHUB_OUTPUT
echo "is_deployable=true" >> $GITHUB_OUTPUT
echo "使用 main 分支: $REF"
elif [[ "$REF" =~ ^([0-9]+)/merge ]]; then
# 提取 PR 号,使用 PR 的 merge ref
PR_NUMBER="${BASH_REMATCH[1]}"
echo "ref=refs/pull/${PR_NUMBER}/merge" >> $GITHUB_OUTPUT
echo "pr_number=${PR_NUMBER}" >> $GITHUB_OUTPUT
echo "is_deployable=false" >> $GITHUB_OUTPUT
echo "检测到 PR merge ref,使用 PR #${PR_NUMBER} 的 merge ref"
elif [[ "$REF" == *"/merge"* ]]; then
# 其他 merge 格式,尝试提取 PR 号
PR_NUMBER=$(echo "$REF" | grep -oE '[0-9]+' | head -1)
if [ -n "$PR_NUMBER" ]; then
echo "ref=refs/pull/${PR_NUMBER}/merge" >> $GITHUB_OUTPUT
echo "pr_number=${PR_NUMBER}" >> $GITHUB_OUTPUT
echo "is_deployable=false" >> $GITHUB_OUTPUT
echo "检测到 merge ref,使用 PR #${PR_NUMBER} 的 merge ref"
else
echo "ref=main" >> $GITHUB_OUTPUT
echo "pr_number=" >> $GITHUB_OUTPUT
echo "is_deployable=true" >> $GITHUB_OUTPUT
echo "无法提取 PR 号,使用默认分支: main (原始 ref: $REF)"
fi
elif [[ "$REF" =~ ^v[0-9]+\.[0-9]+\.[0-9]+ ]] || [[ "$REF" =~ ^refs/tags/ ]]; then
# Tag 格式,标记为需要部署
echo "ref=$REF" >> $GITHUB_OUTPUT
echo "pr_number=" >> $GITHUB_OUTPUT
echo "is_deployable=true" >> $GITHUB_OUTPUT
echo "检测到 tag: $REF,将执行部署"
else
echo "ref=$REF" >> $GITHUB_OUTPUT
echo "pr_number=" >> $GITHUB_OUTPUT
echo "is_deployable=false" >> $GITHUB_OUTPUT
echo "使用指定 ref: $REF"
fi
- name: Checkout code
uses: actions/checkout@v4
with:
token: ${{ secrets.ACCESS_TOKEN }}
repository: leaperone/MultiPost
ref: ${{ steps.set-ref.outputs.ref }}
- name: Check Skip CI
run: |
if grep -q "noci" <<< "${{ github.event.client_payload.message || '' }}"; then
echo "跳过构建: commit message 包含 'noci'"
exit 78
fi
- name: Setup docker-compose
uses: KengoTODA/actions-setup-docker-compose@v1
with:
version: '2.14.2'
- name: Build Docker images
env:
POSTHOG_API_KEY: ${{ secrets.POSTHOG_API_KEY }}
POSTHOG_MULTIPOST_ENV_ID: ${{ secrets.POSTHOG_MULTIPOST_ENV_ID }}
NEXT_PUBLIC_POSTHOG_HOST: https://us.posthog.com
run: docker compose -f ./docker/docker-compose-build.yml build
- name: Login to Aliyun Docker Registry
if: steps.set-ref.outputs.is_deployable == 'true'
uses: docker/login-action@v3
with:
registry: registry.cn-hongkong.aliyuncs.com
username: ${{ secrets.ALIYUN_DOCKER_USERNAME }}
password: ${{ secrets.ALIYUN_DOCKER_PASSWORD }}
- name: Tag and Push Docker images
if: steps.set-ref.outputs.is_deployable == 'true'
run: |
docker push registry.cn-hongkong.aliyuncs.com/leaperone/multipost:latest
docker push registry.cn-hongkong.aliyuncs.com/leaperone/multipost:backend-latest
docker push registry.cn-hongkong.aliyuncs.com/leaperone/multipost:video-stt-worker-latest
- name: Run Database Migrations
if: steps.set-ref.outputs.is_deployable == 'true'
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Execute Migrations
if: steps.set-ref.outputs.is_deployable == 'true'
run: |
npm install -g prisma@6.19.0
export MULTIPOST_DATABASE_URL="${{ secrets.MULTIPOST_DATABASE_URL }}"
sh prisma/migrate_deploy.sh
- name: Deploy to Production
if: steps.set-ref.outputs.is_deployable == 'true'
uses: appleboy/ssh-action@v1.0.0
with:
host: ${{ secrets.ALIYUN_HK_HOST }}
username: ${{ secrets.ALIYUN_CN_USERNAME }}
port: ${{ secrets.ALIYUN_CN_PORT }}
key: ${{ secrets.ALIYUN_CN_SSH_PRIVATE_KEY }}
script: ${{ secrets.DEPLOY_MULTIPOST_SCRIPT }}
# Temporarily disabled: Deploy to Production (Service)
# - name: Deploy to Production (Service)
# if: steps.set-ref.outputs.is_deployable == 'true'
# uses: appleboy/ssh-action@v1.0.0
# with:
# host: ${{ secrets.ALIYUN_HK_HOST }}
# username: ${{ secrets.SERVICE_SERVER_USERNAME }}
# port: ${{ secrets.SERVICE_SERVER_PORT }}
# key: ${{ secrets.ALIYUN_CN_SSH_PRIVATE_KEY }}
# script: ${{ secrets.SERVICE_DEPLOY_MULTIPOST_SCRIPT }}
pr-comment:
needs: build-and-deploy
if: always() && needs.build-and-deploy.outputs.pr_number != ''
uses: leaperone/leaperone-releases/.github/workflows/pr-comment.yml@main
with:
status: ${{ needs.build-and-deploy.result }}
ref: leaperone/MultiPost@${{ github.event.client_payload.ref }}
run_number: ${{ github.run_number }}
message: ${{ github.event.client_payload.message }}
author: ${{ github.event.client_payload.author }}
run_id: ${{ github.run_id }}
pr_number: ${{ needs.build-and-deploy.outputs.pr_number }}
repository: leaperone/MultiPost
secrets:
ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }}
notify:
needs: build-and-deploy
if: always()
uses: leaperone/leaperone-releases/.github/workflows/feishu-notification.yml@main
with:
status: ${{ needs.build-and-deploy.result }}
ref: leaperone/MultiPost@${{ github.event.client_payload.ref }}
run_number: ${{ github.run_number }}
message: ${{ github.event.client_payload.message }}
author: ${{ github.event.client_payload.author }}
run_id: ${{ github.run_id }}
repository: leaperone/MultiPost
pr_number: ${{ needs.build-and-deploy.outputs.pr_number }}
secrets:
FEISHU_WEBHOOK_URL: ${{ secrets.FEISHU_WEBHOOK_URL }}
# Disabled: notifications now handled by Leo webhook handler
# notify-telegram:
# needs: build-and-deploy
# if: always()
# uses: leaperone/leaperone-releases/.github/workflows/telegram-notification.yml@main
# with:
# status: ${{ needs.build-and-deploy.result }}
# ref: leaperone/MultiPost@${{ github.event.client_payload.ref }}
# run_number: ${{ github.run_number }}
# message: ${{ github.event.client_payload.message }}
# author: ${{ github.event.client_payload.author }}
# run_id: ${{ github.run_id }}
# repository: leaperone/MultiPost
# pr_number: ${{ needs.build-and-deploy.outputs.pr_number }}
# secrets:
# TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }}
# TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_CHAT_ID }}
# ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }}