Files
NeoBot/.github/workflows/main.yml
2026-01-24 17:06:53 +08:00

58 lines
2.0 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
name: Auto Deploy NeoBot (Full Env Secrets)
# 触发条件推送到main分支 或 手动触发
on:
push:
branches: [ main ]
workflow_dispatch:
jobs:
deploy-to-server:
# 关联你的仓库环境ENV
environment: ENV
runs-on: ubuntu-latest
steps:
- name: 检查环境密钥配置
run: |
echo "✅ 已关联环境: ${{ github.environment }}"
echo "✅ API_URL 密钥是否存在: ${{ secrets.API_URL != '' }}"
echo "✅ API_TOKEN 密钥是否存在: ${{ secrets.NEOBOT_DEPLOY_TOKEN != '' }}"
- name: 调用部署API
env:
# 从环境密钥中读取API地址和Token均为密文
API_URL: ${{ secrets.API_URL }}
API_TOKEN: ${{ secrets.NEOBOT_DEPLOY_TOKEN }}
run: |
# 安装jq用于解析JSON
sudo apt-get update && sudo apt-get install -y jq
# 打印关键信息(脱敏,仅验证是否读取到值)
echo "📌 调用的API地址脱敏: $(echo $API_URL | sed 's/http:\/\///; s/\/deploy//')"
# 发送POST请求到部署API所有配置均来自密钥
RESPONSE=$(curl -s -X POST \
$API_URL \
-H "Content-Type: application/json" \
-H "X-API-Token: $API_TOKEN" \
-d '{"script_name":"deploy.sh"}')
# 打印完整响应(便于调试)
echo "📝 API响应详情"
echo $RESPONSE | jq .
# 解析status字段判断部署结果
STATUS=$(echo $RESPONSE | jq -r '.status')
if [ "$STATUS" = "success" ]; then
echo "✅ 部署成功!"
exit 0
else
echo "❌ 部署失败!错误信息:$(echo $RESPONSE | jq -r '.message')"
exit 1
fi
- name: 部署失败通知(可选)
if: failure()
run: |
echo "⚠️ 部署失败,可在此添加通知逻辑"