Skip to content

build: 调整build逻辑->处理二进制打包问题 #46

build: 调整build逻辑->处理二进制打包问题

build: 调整build逻辑->处理二进制打包问题 #46

Workflow file for this run

name: Docker CI (release)
on:
push:
tags: [ 'v*.*.*' ]
branches: [ main ]
jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
# 过滤掉 beta 标签,只处理正式版本
if: ${{ !contains(github.ref, 'beta') }}
steps:
- name: Checkout
uses: actions/checkout@v4
- 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 GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: 📝 获取版本信息
id: get_version
run: |
if [[ $GITHUB_REF == refs/tags/* ]]; then
# Tag触发,从tag获取版本
TAG_VERSION=${GITHUB_REF#refs/tags/v}
VERSION=$TAG_VERSION
echo "🏷️ Tag触发,版本: $VERSION"
else
# 非tag触发,使用package.json版本
VERSION=$(node -p "require('./package.json').version")
echo "📦 非tag触发,使用package.json版本: $VERSION"
fi
REPO_LC=$(echo "${{ github.repository }}" | tr '[:upper:]' '[:lower:]')
echo "VERSION=$VERSION" >> $GITHUB_ENV
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "is_release=${{ startsWith(github.ref, 'refs/tags/') }}" >> $GITHUB_OUTPUT
echo "is_main=${{ github.ref == 'refs/heads/main' }}" >> $GITHUB_OUTPUT
echo "repo_name=$REPO_LC" >> $GITHUB_OUTPUT
echo "📦 最终版本: $VERSION"
- name: 📋 提取镜像元数据
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ steps.get_version.outputs.repo_name }}
tags: |
type=raw,value=latest,enable=${{ steps.get_version.outputs.is_release == 'true' || steps.get_version.outputs.is_main == 'true' }}
type=raw,value=${{ steps.get_version.outputs.version }}
type=raw,value=dev,enable=${{ steps.get_version.outputs.is_main == 'true' && steps.get_version.outputs.is_release == 'false' }}
- name: 🏗️ 构建和推送 Docker 镜像 (release)
uses: docker/build-push-action@v5
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: |
org.opencontainers.image.version=${{ steps.get_version.outputs.version }}
org.opencontainers.image.revision=${{ github.sha }}
org.opencontainers.image.title=${{ steps.get_version.outputs.repo_name }}
build-args: |
BUILDKIT_INLINE_CACHE=1
VERSION=${{ steps.get_version.outputs.version }}
platforms: linux/amd64,linux/arm64
# cache-from: |
# type=gha,scope=release-buildcache
# cache-to: |
# type=gha,mode=max,scope=release-buildcache
- name: 📢 输出版本信息
run: |
echo "🏷️ 版本: ${{ steps.get_version.outputs.version }}"
echo "📦 镜像标签:"
echo "${{ steps.meta.outputs.tags }}" | tr '\n' '\n '
echo "🏗️ 构建架构: ${{ startsWith(github.ref, 'refs/tags/') && 'linux/amd64,linux/arm64' || 'linux/amd64' }}"