mirror of
https://github.com/GuDong2003/xianyu-auto-reply-fix.git
synced 2026-08-28 17:40:45 +08:00
b1e6ef3ce9
- Replace manual tag bash logic with docker/metadata-action@v5: * Releases (v1.2.3) auto-expand to :1.2.3, :1.2, :1, :latest * Push to main → :latest + :sha-<short> (rollback handle) * workflow_dispatch input → custom tag * Conditional Docker Hub image included only on auth success - Add OCI labels via meta.outputs.labels - Add concurrency: cancel old push runs but never cancel release builds (release artifacts are persistent and must complete)
90 lines
2.6 KiB
YAML
90 lines
2.6 KiB
YAML
name: Build and Push Docker Image
|
|
|
|
on:
|
|
push:
|
|
branches: [main]
|
|
paths-ignore:
|
|
- '**.md'
|
|
- 'docs/**'
|
|
workflow_dispatch:
|
|
inputs:
|
|
tag:
|
|
description: 'Image tag (e.g., v1.0.0)'
|
|
required: true
|
|
default: 'latest'
|
|
release:
|
|
types:
|
|
- published
|
|
|
|
concurrency:
|
|
group: ${{ github.workflow }}-${{ github.ref }}
|
|
cancel-in-progress: ${{ github.event_name == 'push' }}
|
|
|
|
jobs:
|
|
build-and-push:
|
|
permissions:
|
|
contents: read
|
|
packages: write
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
- name: Login to GHCR
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: ghcr.io
|
|
username: ${{ github.repository_owner }}
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: Login to Docker Hub
|
|
id: docker_hub_login
|
|
uses: docker/login-action@v3
|
|
with:
|
|
username: ${{ secrets.DOCKER_USERNAME }}
|
|
password: ${{ secrets.DOCKER_PASSWORD }}
|
|
continue-on-error: true
|
|
|
|
- name: Compose image list
|
|
id: images
|
|
run: |
|
|
REPO_LOWER=$(echo "${{ github.repository }}" | tr '[:upper:]' '[:lower:]')
|
|
{
|
|
echo "list<<EOF"
|
|
echo "ghcr.io/${REPO_LOWER}"
|
|
if [ "${{ steps.docker_hub_login.outcome }}" = "success" ]; then
|
|
REPO_NAME=$(echo "${{ github.event.repository.name }}" | tr '[:upper:]' '[:lower:]')
|
|
echo "docker.io/${{ secrets.DOCKER_USERNAME }}/${REPO_NAME}"
|
|
fi
|
|
echo "EOF"
|
|
} >> "$GITHUB_OUTPUT"
|
|
|
|
- name: Extract metadata
|
|
id: meta
|
|
uses: docker/metadata-action@v5
|
|
with:
|
|
images: ${{ steps.images.outputs.list }}
|
|
tags: |
|
|
type=semver,pattern={{version}}
|
|
type=semver,pattern={{major}}.{{minor}}
|
|
type=semver,pattern={{major}}
|
|
type=raw,value=latest,enable={{is_default_branch}}
|
|
type=raw,value=${{ github.event.inputs.tag }},enable=${{ github.event_name == 'workflow_dispatch' }}
|
|
type=sha,enable=${{ github.event_name == 'push' }},format=short
|
|
|
|
- name: Build and push multi-arch images
|
|
uses: docker/build-push-action@v5
|
|
with:
|
|
context: .
|
|
file: ./Dockerfile
|
|
push: true
|
|
tags: ${{ steps.meta.outputs.tags }}
|
|
labels: ${{ steps.meta.outputs.labels }}
|
|
platforms: linux/amd64,linux/arm64
|
|
cache-from: type=gha
|
|
cache-to: type=gha,mode=max
|