Skip to content

fix(version):修复版获取相关问题 #8

fix(version):修复版获取相关问题

fix(version):修复版获取相关问题 #8

Workflow file for this run

name: Build and Release Multi-Platform
on:
push:
tags:
- 'v*'
permissions:
contents: write
packages: write
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.24.3'
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install pnpm
uses: pnpm/action-setup@v3
with:
version: 8
run_install: false
- name: Get pnpm store directory
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
- name: Setup pnpm cache
uses: actions/cache@v3
with:
path: ${{ env.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Install frontend dependencies
run: |
cd webs
pnpm install
- name: Build frontend
run: |
cd webs
pnpm run build
- name: Copy frontend to static
run: |
rm -rf static
mkdir -p static
# 复制前端构建产物到 static 目录
cp -r webs/dist/* static/
- name: Write version to VERSION file
run: |
TAG_NAME=${GITHUB_REF#refs/tags/}
echo "$TAG_NAME" > VERSION
echo "Written version $TAG_NAME to VERSION file"
- name: Build Go binaries
run: |
# 创建构建目录
mkdir -p build
# 构建不同平台的可执行文件,添加 -tags=prod 参数嵌入前端文件
GOOS=linux GOARCH=amd64 go build -tags=prod -ldflags="-s -w" -o build/sublinkPro-linux-amd64 .
GOOS=linux GOARCH=arm64 go build -tags=prod -ldflags="-s -w" -o build/sublinkPro-linux-arm64 .
GOOS=windows GOARCH=amd64 go build -tags=prod -ldflags="-s -w" -o build/sublinkPro-windows-amd64.exe .
GOOS=darwin GOARCH=amd64 go build -tags=prod -ldflags="-s -w" -o build/sublinkPro-darwin-amd64 .
GOOS=darwin GOARCH=arm64 go build -tags=prod -ldflags="-s -w" -o build/sublinkPro-darwin-arm64 .
- name: Generate changelog
id: changelog
run: |
# 获取当前tag
CURRENT_TAG=${GITHUB_REF#refs/tags/}
# 获取上一个tag
PREVIOUS_TAG=$(git describe --tags --abbrev=0 HEAD~1 2>/dev/null || echo "")
echo "current_tag=$CURRENT_TAG" >> $GITHUB_OUTPUT
# 生成changelog
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: 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: |
TAG=${GITHUB_REF#refs/tags/}
docker buildx build --no-cache --pull --platform linux/amd64,linux/arm64 \
-t zerodeng/sublink-pro:${TAG} \
-t zerodeng/sublink-pro:latest \
--push .
- 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 }}