77 lines
2.5 KiB
YAML
77 lines
2.5 KiB
YAML
name: 自动部署
|
||
|
||
on:
|
||
push:
|
||
branches:
|
||
- master
|
||
workflow_dispatch:
|
||
|
||
env:
|
||
TZ: Asia/Shanghai
|
||
|
||
jobs:
|
||
deploy:
|
||
# 确保你的 runner config.yaml 中定义了此标签
|
||
runs-on: ubuntu-latest
|
||
steps:
|
||
- name: 检查分支
|
||
uses: actions/checkout@v4
|
||
with:
|
||
fetch-depth: 1
|
||
# 重要:在 1.25+ 版本中,禁用默认凭据以避免与 SSH 密钥冲突
|
||
persist-credentials: false
|
||
|
||
- name: 缓存项目 npm 包
|
||
id: cache-node-modules
|
||
uses: actions/cache@v4
|
||
with:
|
||
path: node_modules
|
||
key: ${{ runner.os }}-nodeModules-${{ hashFiles('package-lock.json') }}
|
||
|
||
- name: 安装 Node.js
|
||
uses: actions/setup-node@v4
|
||
with:
|
||
node-version: "22"
|
||
|
||
- name: 安装依赖与构建
|
||
run: |
|
||
npm install -g hexo-cli
|
||
npm install
|
||
npm run clean
|
||
npm run build
|
||
|
||
- name: 强制调试部署
|
||
env:
|
||
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
|
||
run: |
|
||
# 1. 验证私钥是否加载成功
|
||
if [ -z "$SSH_PRIVATE_KEY" ]; then
|
||
echo "错误: 仓库 Secrets 中的 SSH_PRIVATE_KEY 是空的!"
|
||
exit 1
|
||
fi
|
||
|
||
mkdir -p ~/.ssh
|
||
echo "$SSH_PRIVATE_KEY" > ~/.ssh/id_ed25519
|
||
chmod 600 ~/.ssh/id_ed25519
|
||
|
||
# 2. 详细测试 SSH 连接 (不使用 quiet,强制显示结果)
|
||
ssh-keyscan -p 22 git.biss.click >> ~/.ssh/known_hosts
|
||
ssh -vT -i ~/.ssh/id_ed25519 git@git.biss.click || true
|
||
|
||
# 3. 部署并移除 --quiet,打印所有 Git 原始报错
|
||
cd ./public
|
||
git init
|
||
git config user.name "${{ github.actor }}"
|
||
git config user.email "${{ github.actor }}@noreply.gitea.com"
|
||
git add .
|
||
git commit -m "Debug Deploy: $(date)"
|
||
|
||
# 开启环境变量调试输出
|
||
export GIT_SSH_COMMAND="ssh -v -i ~/.ssh/id_ed25519 -o StrictHostKeyChecking=no"
|
||
|
||
# 推送时删除 --quiet
|
||
git push --force -v "git@git.biss.click:biss/blog.git" master:pages
|
||
|
||
- name: 通知服务器 Hook
|
||
run: |
|
||
curl -k -X POST "https://45.145.229.95:40606/hook?access_key=1XJG8IvYTSZVvD5dpm86GYIpQxgxBcucULnX1MFskZSKayXU" |