Create go.yml
This commit is contained in:
54
.github/workflows/go.yml
vendored
Normal file
54
.github/workflows/go.yml
vendored
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
# This workflow will build a golang project
|
||||||
|
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go
|
||||||
|
|
||||||
|
name: Go
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- 'v*'
|
||||||
|
env:
|
||||||
|
TAG_NAME: ${{ github.ref_name }} # 直接获取简化后的 ref 名称
|
||||||
|
jobs:
|
||||||
|
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- name: 缓存Go依赖
|
||||||
|
id: go-cache
|
||||||
|
uses: actions/cache@v3
|
||||||
|
with:
|
||||||
|
path: ~/go/pkg/mod # Go模块缓存路径
|
||||||
|
key: ${{ runner.os }}-go-${{ hashFiles('**/go.mod') }}
|
||||||
|
restore-keys: |
|
||||||
|
${{ runner.os }}-go-
|
||||||
|
- name: Get Tag Name
|
||||||
|
id: tag_name
|
||||||
|
run: |
|
||||||
|
echo "TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
|
||||||
|
- name: Set up Go
|
||||||
|
uses: actions/setup-go@v4
|
||||||
|
with:
|
||||||
|
go-version: '1.20'
|
||||||
|
|
||||||
|
|
||||||
|
- name: Build logic
|
||||||
|
run: go build -o ./public/logic_${{ env.TAG }} -v ./logic
|
||||||
|
|
||||||
|
- name: Upload Build Artifact
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: logic_${{ env.TAG }}
|
||||||
|
path: ./public/logic_${{ env.TAG }}
|
||||||
|
- name: Deploy to Server # 步骤3:部
|
||||||
|
uses: easingthemes/ssh-deploy@main # 第三方SSH部署插件
|
||||||
|
env:
|
||||||
|
SSH_PRIVATE_KEY: ${{ secrets.BLAZING }} # 从仓库密钥读取私钥
|
||||||
|
REMOTE_HOST: "82.23.177.97" # 服务器公网IP或域名
|
||||||
|
REMOTE_USER: "root" # 步骤1创建的用户
|
||||||
|
SOURCE: "public/" # 本地构建输出目录
|
||||||
|
TARGET: "/home/" # 服务器目标目录
|
||||||
|
ARGS: "-avz --chown=git:git" # rsync参数:归档模式/压缩/删除多余文件
|
||||||
|
|
||||||
Reference in New Issue
Block a user