添加自动部署的workflow
Some checks failed
自动构建并部署Astro博客 / build-and-deploy (push) Failing after 1m4s

This commit is contained in:
2026-04-15 14:18:34 +08:00
parent f39c2913fa
commit ab6ff0cdae

View File

@@ -0,0 +1,41 @@
name: 自动构建并部署Astro博客
# 触发条件main分支有代码推送时执行
on:
push:
branches: [ main ]
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
# 1. 拉取仓库最新代码
- name: 检出代码
uses: actions/checkout@v4
with:
fetch-depth: 0
# 2. 安装Node.js 20Astro运行环境
- name: 安装Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'npm'
# 3. 安装依赖 + 打包Astro项目生成dist目录
- name: 安装依赖并构建
run: |
npm install
npm run build
# 4. 把打包好的dist文件同步到服务器Apache目录
- name: 同步到服务器
uses: appleboy/scp-action@master
with:
host: ${{ secrets.SERVER_IP }}
username: ${{ secrets.SERVER_USER }}
port: ${{ secrets.SERVER_PORT }}
key: ${{ secrets.SERVER_SSH_KEY }}
source: "dist/*"
target: "/var/www/blog/"
overwrite: true