@@ -144,64 +144,38 @@ jobs:
144
144
- name : 发送部署通知
145
145
if : always()
146
146
run : |
147
+ # 设置通知内容
147
148
if [ "${{ job.status }}" = "success" ]; then
148
149
TITLE="✅ DjangoBlog部署成功"
149
150
STATUS="成功"
150
- COLOR="🟢"
151
151
else
152
152
TITLE="❌ DjangoBlog部署失败"
153
153
STATUS="失败"
154
- COLOR="🔴"
155
154
fi
156
155
157
- MESSAGE="${COLOR} **DjangoBlog部署通知**
158
-
159
- **部署状态**: ${STATUS}
160
- **触发方式**: ${{ steps.deploy-params.outputs.trigger_type }}
161
- **部署环境**: ${{ steps.deploy-params.outputs.environment }}
162
- **镜像标签**: ${{ steps.deploy-params.outputs.image_tag }}
163
- **提交信息**: ${{ github.event.head_commit.message || '手动触发部署' }}
164
- **提交者**: ${{ github.actor }}
165
- **分支**: ${{ github.ref_name }}
166
- **时间**: $(date '+%Y-%m-%d %H:%M:%S')
167
-
168
- **查看详情**: [GitHub Actions](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})"
156
+ MESSAGE="部署状态: ${STATUS}
157
+ 触发方式 : ${{ steps.deploy-params.outputs.trigger_type }}
158
+ 部署环境 : ${{ steps.deploy-params.outputs.environment }}
159
+ 镜像标签 : ${{ steps.deploy-params.outputs.image_tag }}
160
+ 提交者 : ${{ github.actor }}
161
+ 时间 : $(date '+%Y-%m-%d %H:%M:%S')
162
+
163
+ 查看详情 : https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
169
164
170
- # 发送到Server酱
165
+ # 发送Server酱通知
171
166
if [ -n "${{ secrets.SERVERCHAN_KEY }}" ]; then
172
- echo "📱 准备发送Server酱通知..."
173
-
174
- # 转义特殊字符以确保JSON格式正确
175
- ESCAPED_TITLE=$(echo "${TITLE}" | sed 's/"/\\"/g' | sed 's/\\/\\\\/g')
176
- ESCAPED_MESSAGE=$(echo "${MESSAGE}" | sed 's/"/\\"/g' | sed 's/\\/\\\\/g')
177
-
178
- # 创建JSON payload
179
- JSON_PAYLOAD="{\"title\": \"${ESCAPED_TITLE}\", \"desp\": \"${ESCAPED_MESSAGE}\"}"
180
-
181
- echo "🔗 发送到: https://sctapi.ftqq.com/${{ secrets.SERVERCHAN_KEY }}.send"
182
- echo "📝 标题: ${TITLE}"
183
-
184
- # 发送请求并捕获响应
185
- RESPONSE=$(curl --location "https://sctapi.ftqq.com/${{ secrets.SERVERCHAN_KEY }}.send" \
167
+ cat > /tmp/serverchan.json << EOF
168
+ {
169
+ " title " : " ${TITLE}" ,
170
+ " desp " : " ${MESSAGE}"
171
+ }
172
+ EOF
173
+
174
+ curl --location "https://sctapi.ftqq.com/${{ secrets.SERVERCHAN_KEY }}.send" \
186
175
--header "Content-Type : application/json" \
187
- --data "${JSON_PAYLOAD}" \
188
- --write-out "HTTPSTATUS:%{http_code}" \
189
- --silent)
190
-
191
- # 分离HTTP状态码和响应体
192
- HTTP_STATUS=$(echo $RESPONSE | tr -d '\n' | sed -e 's/.*HTTPSTATUS://')
193
- RESPONSE_BODY=$(echo $RESPONSE | sed -e 's/HTTPSTATUS:.*//g')
194
-
195
- echo "📊 HTTP状态码: ${HTTP_STATUS}"
196
- echo "📄 响应内容: ${RESPONSE_BODY}"
176
+ --data @/tmp/serverchan.json \
177
+ --silent > /dev/null
197
178
198
- if [ "${HTTP_STATUS}" -eq 200 ]; then
199
- echo "✅ Server酱通知发送成功"
200
- else
201
- echo "❌ Server酱通知发送失败 (HTTP ${HTTP_STATUS})"
202
- echo "🔍 错误详情: ${RESPONSE_BODY}"
203
- fi
204
- else
205
- echo "⚠️ 未配置Server酱密钥,跳过通知"
206
- echo "💡 提示: 请在GitHub Secrets中添加 SERVERCHAN_KEY"
179
+ rm -f /tmp/serverchan.json
180
+ echo "📱 部署通知已发送"
207
181
fi
0 commit comments