test #9
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: CI/CD Pipeline | |
on: | |
push: | |
branches: | |
- main # 当代码推送到 main 分支时触发 | |
jobs: | |
# 前端部署 | |
deploy_frontend: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Set up Node.js | |
uses: actions/setup-node@v2 | |
with: | |
node-version: '16' # 确保与前端项目的 Node 版本一致 | |
- name: Install dependencies (Frontend) | |
run: | | |
cd front_end | |
npm install | |
- name: Build frontend project | |
run: | | |
cd front_end | |
npm run build | |
- name: Deploy frontend | |
run: | | |
scp -o StrictHostKeyChecking=no -r front_end/dist ubuntu@119.91.193.117:/var/www/html/my-app/front_end | |
env: | |
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }} | |
SERVER_IP: ${{ secrets.SERVER_IP }} | |
# 后端部署 | |
deploy_backend: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Set up Node.js | |
uses: actions/setup-node@v2 | |
with: | |
node-version: '16' # 确保与后端项目的 Node 版本一致 | |
- name: Install dependencies (Backend) | |
run: | | |
cd back_end | |
npm install | |
- name: Deploy backend | |
run: | | |
scp -o StrictHostKeyChecking=no -r back_end ubuntu@119.91.193.117:/home/user/my-app-backend/back_end | |
ssh -o StrictHostKeyChecking=no ubuntu@119.91.193.117 "cd /home/user/my-app-backend/back_end && npm run start" | |
env: | |
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }} | |
SERVER_IP: ${{ secrets.SERVER_IP }} | |