cicd
This commit is contained in:
27
.github/workflows/logic_CI.yml
vendored
27
.github/workflows/logic_CI.yml
vendored
@@ -15,14 +15,13 @@ jobs:
|
|||||||
build_version: ${{ steps.set-hash-version.outputs.version }}
|
build_version: ${{ steps.set-hash-version.outputs.version }}
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4 # 需要拉取代码才能获取commit hash
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Set commit hash as version
|
- name: Set commit hash as version
|
||||||
id: set-hash-version
|
id: set-hash-version
|
||||||
run: |
|
run: |
|
||||||
# 取前8位commit hash作为版本核心标识
|
|
||||||
COMMIT_HASH=$(git rev-parse --short=8 HEAD)
|
COMMIT_HASH=$(git rev-parse --short=8 HEAD)
|
||||||
echo "version=v$COMMIT_HASH" >> $GITHUB_OUTPUT # 格式:vabc12345
|
echo "version=v$COMMIT_HASH" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
build:
|
build:
|
||||||
needs: prepare-version
|
needs: prepare-version
|
||||||
@@ -45,13 +44,15 @@ jobs:
|
|||||||
go-version: '1.20'
|
go-version: '1.20'
|
||||||
|
|
||||||
- name: 编译logic服务
|
- name: 编译logic服务
|
||||||
run: go build -o ./public/logic_${{ needs.prepare-version.outputs.build_version }} -v ./logic
|
run: go build -o ./logic_${{ needs.prepare-version.outputs.build_version }} -v ./logic
|
||||||
|
# 移除了public目录,直接在当前目录生成可执行文件
|
||||||
|
|
||||||
- name: Upload Build Artifact
|
- name: Upload Build Artifact
|
||||||
uses: actions/upload-artifact@v4
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: logic_${{ needs.prepare-version.outputs.build_version }}
|
name: logic_${{ needs.prepare-version.outputs.build_version }}
|
||||||
path: ./public/logic_${{ needs.prepare-version.outputs.build_version }}
|
path: ./logic_${{ needs.prepare-version.outputs.build_version }}
|
||||||
|
# 直接上传可执行文件
|
||||||
|
|
||||||
- name: 推送到服务器并通过screen启动服务
|
- name: 推送到服务器并通过screen启动服务
|
||||||
uses: easingthemes/ssh-deploy@main
|
uses: easingthemes/ssh-deploy@main
|
||||||
@@ -60,9 +61,9 @@ jobs:
|
|||||||
REMOTE_HOST: "122.10.117.123"
|
REMOTE_HOST: "122.10.117.123"
|
||||||
REMOTE_PORT: 41967
|
REMOTE_PORT: 41967
|
||||||
REMOTE_USER: "root"
|
REMOTE_USER: "root"
|
||||||
SOURCE: "public/"
|
SOURCE: "logic_${{ needs.prepare-version.outputs.build_version }}" # 只指定可执行文件作为源
|
||||||
TARGET: "/home/"
|
TARGET: "/home/"
|
||||||
ARGS: "-avz --chown=git:git"
|
ARGS: "-avz --chown=git:git" # 保持权限参数
|
||||||
SCRIPT_AFTER: |
|
SCRIPT_AFTER: |
|
||||||
SCREEN_NAME="logic-${{ needs.prepare-version.outputs.build_version }}"
|
SCREEN_NAME="logic-${{ needs.prepare-version.outputs.build_version }}"
|
||||||
screen -S $SCREEN_NAME -X quit 2>/dev/null || true
|
screen -S $SCREEN_NAME -X quit 2>/dev/null || true
|
||||||
@@ -71,7 +72,7 @@ jobs:
|
|||||||
echo "服务启动成功!"
|
echo "服务启动成功!"
|
||||||
echo "Screen会话名:$SCREEN_NAME"
|
echo "Screen会话名:$SCREEN_NAME"
|
||||||
echo "服务端口:${{ github.event.inputs.servicePort }}"
|
echo "服务端口:${{ github.event.inputs.servicePort }}"
|
||||||
echo "对应Commit:${{ github.sha }}" # 显示完整哈希
|
echo "对应Commit:${{ github.sha }}"
|
||||||
echo "管理命令:"
|
echo "管理命令:"
|
||||||
echo " - 进入会话:screen -r $SCREEN_NAME"
|
echo " - 进入会话:screen -r $SCREEN_NAME"
|
||||||
echo " - 查看所有会话:screen -ls"
|
echo " - 查看所有会话:screen -ls"
|
||||||
@@ -85,11 +86,13 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Download build artifact
|
- uses: actions/checkout@v4 # 需要重新拉取代码以获取编译产物
|
||||||
|
|
||||||
|
- name: 下载构建产物
|
||||||
uses: actions/download-artifact@v4
|
uses: actions/download-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: logic_${{ needs.prepare-version.outputs.build_version }}
|
name: logic_${{ needs.prepare-version.outputs.build_version }}
|
||||||
path: ./public
|
path: . # 下载到当前目录
|
||||||
|
|
||||||
- name: Create GitHub Release
|
- name: Create GitHub Release
|
||||||
uses: softprops/action-gh-release@v1
|
uses: softprops/action-gh-release@v1
|
||||||
@@ -102,9 +105,9 @@ jobs:
|
|||||||
- 触发方式: 手动触发
|
- 触发方式: 手动触发
|
||||||
- 服务端口: ${{ github.event.inputs.servicePort }}
|
- 服务端口: ${{ github.event.inputs.servicePort }}
|
||||||
- Screen会话名: logic-${{ needs.prepare-version.outputs.build_version }}
|
- Screen会话名: logic-${{ needs.prepare-version.outputs.build_version }}
|
||||||
- 对应Commit: ${{ github.sha }} # 关联完整commit hash
|
- 对应Commit: ${{ github.sha }}
|
||||||
- 可执行文件: logic_${{ needs.prepare-version.outputs.build_version }}
|
- 可执行文件: logic_${{ needs.prepare-version.outputs.build_version }}
|
||||||
- 启动命令: ./logic_${{ needs.prepare-version.outputs.build_version }} -port=${{ github.event.inputs.servicePort }}
|
- 启动命令: ./logic_${{ needs.prepare-version.outputs.build_version }} -port=${{ github.event.inputs.servicePort }}
|
||||||
files: ./public/logic_${{ needs.prepare-version.outputs.build_version }}
|
files: logic_${{ needs.prepare-version.outputs.build_version }} # 只上传可执行文件
|
||||||
draft: false
|
draft: false
|
||||||
prerelease: false
|
prerelease: false
|
||||||
|
|||||||
Reference in New Issue
Block a user