Skip to content

chore(repo): 添加.gitattributes文件配置 #174

chore(repo): 添加.gitattributes文件配置

chore(repo): 添加.gitattributes文件配置 #174

Workflow file for this run

name: Build and Release Multi-Platform
on:
push:
tags:
- 'v*'
branches:
- 'dev'
permissions:
contents: write
packages: write
jobs:
build-frontend:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '22'
# cache: 'yarn' # Disabled to prevent using system Yarn v1 which conflicts with Corepack Yarn v4
- name: Enable Corepack
run: corepack enable
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: |
cd webs
echo "dir=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT
- name: Cache dependencies
uses: actions/cache@v4
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('webs/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Install frontend dependencies
run: |
cd webs
yarn install --immutable
- name: Build frontend
run: |
cd webs
yarn run build
- name: Upload frontend artifacts
uses: actions/upload-artifact@v4
with:
name: frontend-dist
path: webs/dist/
retention-days: 1
# 使用矩阵策略并发构建不同架构的二进制文件
build-go-binaries:
needs: build-frontend
runs-on: ubuntu-latest
strategy:
fail-fast: false # 允许其他架构继续构建,即使某个失败
matrix:
include:
- goos: linux
goarch: amd64
output: sublinkPro-linux-amd64
upx: true
- goos: linux
goarch: arm64
output: sublinkPro-linux-arm64
upx: true
- goos: windows
goarch: amd64
output: sublinkPro-windows-amd64.exe
upx: false
- goos: darwin
goarch: amd64
output: sublinkPro-darwin-amd64
upx: false
- goos: darwin
goarch: arm64
output: sublinkPro-darwin-arm64
upx: false
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.25.5'
cache: true
cache-dependency-path: go.sum
- name: Download frontend artifacts
uses: actions/download-artifact@v4
with:
name: frontend-dist
path: static/
- name: Write version to VERSION file
run: |
if [[ $GITHUB_REF == refs/tags/* ]]; then
TAG_NAME=${GITHUB_REF#refs/tags/}
else
TAG_NAME=$(git rev-parse --short HEAD)
fi
echo "$TAG_NAME" > VERSION
echo "Written version $TAG_NAME to VERSION file"
- name: Build Go binary for ${{ matrix.goos }}/${{ matrix.goarch }}
run: |
mkdir -p build
echo "Building ${{ matrix.output }} for ${{ matrix.goos }}/${{ matrix.goarch }}..."
CGO_ENABLED=0 GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} \
go build -tags=prod -ldflags="-s -w" -o build/${{ matrix.output }} .
echo "Build completed. Binary size:"
ls -lh build/${{ matrix.output }}
- name: Compress binary with UPX
if: matrix.upx
run: |
# 安装 UPX
sudo apt-get update && sudo apt-get install -y upx
echo "=== Original binary size ==="
ls -lh build/${{ matrix.output }}
# 使用最佳压缩率压缩 Linux 二进制文件
upx --best --lzma build/${{ matrix.output }} || true
echo "=== Compressed binary size ==="
ls -lh build/${{ matrix.output }}
- name: Upload binary artifact
uses: actions/upload-artifact@v4
with:
name: binary-${{ matrix.goos }}-${{ matrix.goarch }}
path: build/${{ matrix.output }}
retention-days: 1
# 合并所有架构的二进制文件
merge-binaries:
needs: build-go-binaries
runs-on: ubuntu-latest
steps:
- name: Download all binary artifacts
uses: actions/download-artifact@v4
with:
pattern: binary-*
path: build/
merge-multiple: true
- name: Verify all binaries
run: |
echo "=== All binary files ==="
ls -lh build/
# 验证所有必需的二进制文件都存在
REQUIRED_FILES=(
"sublinkPro-linux-amd64"
"sublinkPro-linux-arm64"
"sublinkPro-windows-amd64.exe"
"sublinkPro-darwin-amd64"
"sublinkPro-darwin-arm64"
)
MISSING=0
for file in "${REQUIRED_FILES[@]}"; do
if [ ! -f "build/$file" ]; then
echo "ERROR: Missing required binary: $file"
MISSING=1
else
echo "OK: $file exists"
fi
done
if [ $MISSING -eq 1 ]; then
echo "ERROR: Some required binaries are missing!"
exit 1
fi
echo "=== All binaries verified successfully ==="
- name: Upload merged binaries
uses: actions/upload-artifact@v4
with:
name: go-binaries
path: build/
retention-days: 1
release:
if: startsWith(github.ref, 'refs/tags/')
needs: merge-binaries
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Download binary artifacts
uses: actions/download-artifact@v4
with:
name: go-binaries
path: build/
- name: Generate changelog
id: changelog
run: |
CURRENT_TAG=${GITHUB_REF#refs/tags/}
PREVIOUS_TAG=$(git describe --tags --abbrev=0 HEAD~1 2>/dev/null || echo "")
echo "current_tag=$CURRENT_TAG" >> $GITHUB_OUTPUT
if [ -z "$PREVIOUS_TAG" ]; then
echo "## 🎉 首次发布" > changelog.md
echo "" >> changelog.md
echo "### 📝 所有提交:" >> changelog.md
git log --pretty=format:"- %s (%h)" >> changelog.md
else
echo "## 🚀 更新内容 ($PREVIOUS_TAG -> $CURRENT_TAG)" > changelog.md
echo "" >> changelog.md
echo "### 📝 提交记录:" >> changelog.md
git log --pretty=format:"- %s (%h)" $PREVIOUS_TAG..$CURRENT_TAG >> changelog.md
fi
echo "" >> changelog.md
echo "### 📦 发布文件:" >> changelog.md
echo "- \`sublinkPro-linux-amd64\` - Linux x64" >> changelog.md
echo "- \`sublinkPro-linux-arm64\` - Linux ARM64" >> changelog.md
echo "- \`sublinkPro-windows-amd64.exe\` - Windows x64" >> changelog.md
echo "- \`sublinkPro-darwin-amd64\` - macOS x64" >> changelog.md
echo "- \`sublinkPro-darwin-arm64\` - macOS ARM64 (Apple Silicon)" >> changelog.md
- name: Create Release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ steps.changelog.outputs.current_tag }}
name: Release ${{ steps.changelog.outputs.current_tag }}
body_path: changelog.md
files: |
build/sublinkPro-linux-amd64
build/sublinkPro-linux-arm64
build/sublinkPro-windows-amd64.exe
build/sublinkPro-darwin-amd64
build/sublinkPro-darwin-arm64
draft: false
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
build-docker:
needs: [build-frontend, merge-binaries]
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Download frontend artifacts
uses: actions/download-artifact@v4
with:
name: frontend-dist
path: static/
- name: Download binary artifacts
uses: actions/download-artifact@v4
with:
name: go-binaries
path: build/
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and Push Multi-Arch Docker Image
run: |
if [[ $GITHUB_REF == refs/tags/* ]]; then
TAG=${GITHUB_REF#refs/tags/}
docker buildx build --no-cache --pull --platform linux/amd64,linux/arm64 \
-f Dockerfile.ci \
-t zerodeng/sublink-pro:${TAG} \
-t zerodeng/sublink-pro:latest \
--push .
elif [[ $GITHUB_REF == refs/heads/dev ]]; then
docker buildx build --no-cache --pull --platform linux/amd64,linux/arm64 \
-f Dockerfile.ci \
-t zerodeng/sublink-pro:dev \
--push .
fi