name: Build and Deploy Server on: push: branches: - main paths: - "server/**" - ".gitea/workflows/server-deploy.yml" jobs: build: # 专属运行器:docker://golang:1.22-bookworm(注册于 doc79) runs-on: lunar-ci steps: - uses: https://gitea.neatcn.com/gouki/action-checkout@v4 with: fetch-depth: 20 - name: Verify Go runtime run: go version - name: Install dependencies working-directory: server run: go mod download - name: Run tests working-directory: server run: go test ./... - name: Build application working-directory: server env: GITEA_SHA: ${{ gitea.sha }} GITEA_RUN_NUMBER: ${{ gitea.run_number }} run: | mkdir -p bin # 生成版本号(使用构建编号) VERSION="1.0.${GITEA_RUN_NUMBER}" BUILD_TIME="$(date -u +%Y-%m-%dT%H:%M:%SZ)" COMMIT_SHORT="${GITEA_SHA:0:7}" echo "Building server version: $VERSION" echo "Build time: $BUILD_TIME" echo "Commit SHA: $COMMIT_SHORT" # 使用 ldflags 注入版本信息 go build -ldflags "\ -X main.Version=$VERSION \ -X main.BuildTime=$BUILD_TIME \ -X main.CommitSha=$COMMIT_SHORT" \ -o bin/server cmd/main.go # 同时保存版本信息到文件(用于部署时读取) cat > bin/version.env <