fix:NodeJS安装版本写错咯 #3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Deploy to Server | |
on: | |
push: | |
branches: | |
- master # 只在 main 分支推送时触发 | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
# 检出代码 | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
# 设置 Node.js 环境 | |
- name: Set up Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version: '20' # 使用的 Node.js 版本,可以根据你的需求调整 | |
# 安装 pnpm | |
- name: Install pnpm | |
run: npm install -g pnpm | |
# 安装依赖并构建 | |
- name: Install dependencies and build | |
run: | | |
pnpm install | |
pnpm build | |
# 使用 rsync 通过 SSH 将构建后的文件传输到指定服务器,并排除 . 开头的文件 | |
- name: Deploy to server using rsync over SSH | |
env: | |
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }} | |
SERVER_USER: ${{ secrets.SERVER_USER }} | |
SERVER_IP: ${{ secrets.SERVER_IP }} | |
REMOTE_PATH: /www/wwwroot/RSDaily/Site/www # 服务器上的目标目录 | |
run: | | |
# 安装 rsync 和 SSH 客户端 | |
sudo apt-get install -y openssh-client rsync | |
# 配置 SSH 密钥以便可以无密码登录 | |
mkdir -p ~/.ssh | |
echo "$SSH_PRIVATE_KEY" > ~/.ssh/id_rsa | |
chmod 600 ~/.ssh/id_rsa | |
# 使用 rsync 通过 SSH 将构建结果(排除 . 开头的文件)复制到服务器 | |
rsync -avz -e "ssh -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa" --exclude '.*' ./dist/ $SERVER_USER@$SERVER_IP:$REMOTE_PATH |