hi-server/.github/workflows/deploy-linux.yml
EUForest 0d57e7eae3 简化为纯 Golang Linux 二进制构建工作流
- 移除复杂的部署逻辑和 Docker 支持
- 专注于构建 Linux AMD64 二进制文件
- 自动生成 SHA256 校验和
- 支持 GitHub Release 自动上传
- 提供简洁的构建摘要
2025-11-24 18:12:12 +08:00

110 lines
3.8 KiB
YAML

name: Build Linux Binary
on:
push:
branches: [ main, master ]
workflow_dispatch:
inputs:
version:
description: 'Version to build (leave empty for auto)'
required: false
type: string
release:
types: [ published ]
permissions:
contents: write
jobs:
build:
name: Build Linux Binary
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}
binary_name: ${{ steps.build.outputs.binary_name }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.23.3'
cache: true
- name: Get version information
id: version
run: |
if [ "${{ github.event_name }}" = "release" ]; then
VERSION=${GITHUB_REF#refs/tags/}
elif [ -n "${{ github.event.inputs.version }}" ]; then
VERSION="${{ github.event.inputs.version }}"
else
VERSION=$(git describe --tags --always --dirty)
fi
echo "VERSION=$VERSION" >> $GITHUB_ENV
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "BUILD_TIME=$(date -u +"%Y-%m-%d %H:%M:%S")" >> $GITHUB_ENV
echo "GIT_COMMIT=${GITHUB_SHA}" >> $GITHUB_ENV
- name: Build binary
id: build
env:
CGO_ENABLED: 0
GOOS: linux
GOARCH: amd64
run: |
BINARY_NAME_WITH_VERSION="ppanel-server-${{ env.VERSION }}-linux-amd64"
echo "binary_name=$BINARY_NAME_WITH_VERSION" >> $GITHUB_OUTPUT
go build \
-ldflags "-s -w \
-X 'github.com/perfect-panel/server/pkg/constant.Version=${{ env.VERSION }}' \
-X 'github.com/perfect-panel/server/pkg/constant.BuildTime=${{ env.BUILD_TIME }}' \
-X 'github.com/perfect-panel/server/pkg/constant.GitCommit=${{ env.GIT_COMMIT }}'" \
-o "$BINARY_NAME_WITH_VERSION" \
./ppanel.go
- name: Generate checksum
run: |
sha256sum "${{ steps.build.outputs.binary_name }}" > checksum.txt
echo "Checksum: $(cat checksum.txt)"
- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: ppanel-server-linux-amd64
path: |
${{ steps.build.outputs.binary_name }}
checksum.txt
retention-days: 30
- name: Upload to GitHub Release (if release)
if: github.event_name == 'release'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh release upload ${{ env.VERSION }} \
${{ steps.build.outputs.binary_name }} \
checksum.txt
- name: Create summary
run: |
echo "## 📦 Build Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Binary:** ${{ steps.build.outputs.binary_name }}" >> $GITHUB_STEP_SUMMARY
echo "**Version:** ${{ env.VERSION }}" >> $GITHUB_STEP_SUMMARY
echo "**Size:** $(du -h ${{ steps.build.outputs.binary_name }} | cut -f1)" >> $GITHUB_STEP_SUMMARY
echo "**Checksum:** $(cat checksum.txt)" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### 📥 Download" >> $GITHUB_STEP_SUMMARY
echo "Go to Actions → Artifacts → \`ppanel-server-linux-amd64\` to download" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### 🚀 Usage" >> $GITHUB_STEP_SUMMARY
echo "1. Download the binary" >> $GITHUB_STEP_SUMMARY
echo "2. Extract from tar.gz" >> $GITHUB_STEP_SUMMARY
echo "3. Run: chmod +x ppanel-server-* && ./ppanel-server-* run --config etc/ppanel.yaml" >> $GITHUB_STEP_SUMMARY