Files
MicroWARP/.github/workflows/docker-publish.yml
T
2026-03-23 23:20:33 +08:00

67 lines
2.1 KiB
YAML

name: Build and Publish MicroWARP
# ==========================================
# 触发条件:
# 1. 发布 Release 版本时自动构建 (打标签)
# 2. 手动点击触发按钮 (方便随时测试打包)
# ==========================================
on:
release:
types: [published]
workflow_dispatch:
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
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 the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
# 1. 如果是打 Tag 发版,生成严格的版本号标签 (如 1.0.0)
type=semver,pattern={{version}}
# 2. 【核心隔离】仅当 Push 到 main/master,或发版时,才打 latest 标签!
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master' || github.event_name == 'release' }}
# 3. 【新增分支】仅当 Push 到 dev 分支时,才打 dev 标签!(绝不污染 latest)
type=raw,value=dev,enable=${{ github.ref == 'refs/heads/dev' }}
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: true
platforms: linux/amd64,linux/arm64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max