Skip to content

Commit 468cbee

Browse files
committed
chore: 添加 GitHub Actions 工作流用于构建和部署
1 parent 573b050 commit 468cbee

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

.github/workflows/build.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: Build And Deploy
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
workflow_dispatch:
8+
9+
env:
10+
COREPACK_NPM_REGISTRY: https://registry.npmmirror.com
11+
12+
jobs:
13+
build-and-deploy:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout Code
17+
uses: actions/checkout@v5
18+
19+
- name: Setup pnpm
20+
uses: pnpm/action-setup@v4
21+
with:
22+
version: 10
23+
24+
- name: Setup Node.js
25+
uses: actions/setup-node@v6
26+
with:
27+
node-version: 24
28+
cache: pnpm
29+
30+
- name: Install Dependencies
31+
run: pnpm install --frozen-lockfile --registry $COREPACK_NPM_REGISTRY
32+
33+
- name: Build Project
34+
run: pnpm build
35+
36+
- name: Set up SSH key
37+
run: |
38+
mkdir -p ~/.ssh
39+
echo "${{ secrets.DEPLOY_SSH_PRIVATE_KEY }}" > ~/.ssh/id_ed25519
40+
chmod 600 ~/.ssh/id_ed25519
41+
echo -e "LogLevel ERROR\nHost *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config
42+
43+
- name: Deploy to Server
44+
run: |
45+
server="${{ secrets.DEPLOY_SERVER_IP }}"
46+
deployed_dir="/opt/1panel/www/sites/zmusic.zhenxin.me/index"
47+
echo "🚀 部署到 $server"
48+
echo "📁 创建远程目录..."
49+
ssh root@$server "mkdir -p ${deployed_dir}"
50+
echo "📦 上传产物到服务器..."
51+
scp -r docs/.vuepress/dist root@$server:${deployed_dir}/index-new
52+
ssh root@$server "rm -rf ${deployed_dir}/index"
53+
ssh root@$server "cd ${deployed_dir} && mv index-new index"
54+
echo "✅ 部署完成!"

0 commit comments

Comments
 (0)