添加手动触发功能,支持选择测试/正式环境
This commit is contained in:
+40
-1
@@ -4,6 +4,16 @@ on:
|
|||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- main
|
- main
|
||||||
|
workflow_dispatch:
|
||||||
|
inputs:
|
||||||
|
environment:
|
||||||
|
type: choice
|
||||||
|
description: 选择部署环境
|
||||||
|
required: true
|
||||||
|
default: test
|
||||||
|
options:
|
||||||
|
- test
|
||||||
|
- prod
|
||||||
|
|
||||||
env:
|
env:
|
||||||
DEPLOY_HOST: micecola.top
|
DEPLOY_HOST: micecola.top
|
||||||
@@ -12,9 +22,10 @@ env:
|
|||||||
PROD_DIR: /www/wwwroot/kb-web/zhangqing
|
PROD_DIR: /www/wwwroot/kb-web/zhangqing
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
# ==================== 测试环境部署(自动) ====================
|
# ==================== 测试环境部署 ====================
|
||||||
deploy-test:
|
deploy-test:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
if: github.event_name == 'push' || github.inputs.environment == 'test'
|
||||||
steps:
|
steps:
|
||||||
- name: Deploy to test environment
|
- name: Deploy to test environment
|
||||||
uses: appleboy/ssh-action@v1
|
uses: appleboy/ssh-action@v1
|
||||||
@@ -38,3 +49,31 @@ jobs:
|
|||||||
|
|
||||||
- name: Notify
|
- name: Notify
|
||||||
run: echo "✅ 测试环境: http://${{ env.DEPLOY_HOST }}:8081"
|
run: echo "✅ 测试环境: http://${{ env.DEPLOY_HOST }}:8081"
|
||||||
|
|
||||||
|
# ==================== 正式环境部署(手动) ====================
|
||||||
|
deploy-prod:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
if: github.inputs.environment == 'prod'
|
||||||
|
steps:
|
||||||
|
- name: Deploy to production
|
||||||
|
uses: appleboy/ssh-action@v1
|
||||||
|
with:
|
||||||
|
host: ${{ env.DEPLOY_HOST }}
|
||||||
|
username: ${{ env.DEPLOY_USER }}
|
||||||
|
key: ${{ secrets.DEPLOY_KEY }}
|
||||||
|
script: |
|
||||||
|
# 直接部署 - 不备份
|
||||||
|
rm -rf ${{ env.PROD_DIR }}
|
||||||
|
git clone --depth 1 -b main ssh://gitea-external/starmen1265/knowledge-base.git ${{ env.PROD_DIR }}
|
||||||
|
|
||||||
|
# 删除 .git 目录
|
||||||
|
rm -rf ${{ env.PROD_DIR }}/.git
|
||||||
|
|
||||||
|
# 设置权限
|
||||||
|
chown -R www:www ${{ env.PROD_DIR }}
|
||||||
|
|
||||||
|
echo "✅ 正式环境知识库部署完成"
|
||||||
|
echo "文件数: $(find ${{ env.PROD_DIR }} -type f | wc -l)"
|
||||||
|
|
||||||
|
- name: Notify
|
||||||
|
run: echo "✅ 正式环境: http://${{ env.DEPLOY_HOST }}"
|
||||||
|
|||||||
Reference in New Issue
Block a user