Skip to content

Commit 071237a

Browse files
authored
Merge pull request #789 from liangliangyy/dev
增加自动部署
2 parents 7a0c5d3 + e1bd010 commit 071237a

File tree

2 files changed

+24
-49
lines changed

2 files changed

+24
-49
lines changed

.dockerignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ settings_production.py
88
*.md
99
docs/
1010
logs/
11-
static/
11+
static/
12+
.github/

.github/workflows/deploy-master.yml

Lines changed: 22 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -144,64 +144,38 @@ jobs:
144144
- name: 发送部署通知
145145
if: always()
146146
run: |
147+
# 设置通知内容
147148
if [ "${{ job.status }}" = "success" ]; then
148149
TITLE="✅ DjangoBlog部署成功"
149150
STATUS="成功"
150-
COLOR="🟢"
151151
else
152152
TITLE="❌ DjangoBlog部署失败"
153153
STATUS="失败"
154-
COLOR="🔴"
155154
fi
156155
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 }}"
169164

170-
# 发送到Server酱
165+
# 发送Server酱通知
171166
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" \
186175
--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
197178

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 "📱 部署通知已发送"
207181
fi

0 commit comments

Comments
 (0)