Fix publish.yml

This commit is contained in:
2026-03-04 16:08:59 +08:00
parent ee05d0c71f
commit fe37cce13e

View File

@@ -1,17 +1,26 @@
name: Publish Docker to GHCR name: Publish Docker to GHCR
on: on:
workflow_dispatch: workflow_dispatch:
inputs: inputs:
environment:
description: "Target environment"
required: true
type: choice
options:
- production
- staging
tag: tag:
description: "Image tag (e.g. v1.0.0)" description: "Image tag (e.g. v1.0.0)"
required: true required: true
default: "latest"
env: env:
REGISTRY: ghcr.io REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }} IMAGE_NAME: ${{ github.repository }}
jobs: jobs:
publish: publish:
name: Build & Push to GHCR name: Build & Push to GHCR (${{ github.event.inputs.environment }})
runs-on: ubuntu-latest runs-on: ubuntu-latest
permissions: permissions:
contents: read contents: read
@@ -29,10 +38,6 @@ jobs:
- name: Checkout repository - name: Checkout repository
uses: actions/checkout@v4 uses: actions/checkout@v4
- name: Extract tag name
id: meta
run: echo "tag=${{ github.event.inputs.tag }}" >> $GITHUB_OUTPUT
- name: Set up QEMU - name: Set up QEMU
uses: docker/setup-qemu-action@v3 uses: docker/setup-qemu-action@v3
@@ -46,6 +51,15 @@ jobs:
username: ${{ github.actor }} username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }} password: ${{ secrets.GITHUB_TOKEN }}
- name: Generate image metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=${{ github.event.inputs.environment }}-${{ github.event.inputs.tag }}
type=raw,value=${{ github.event.inputs.environment }}-latest
- name: Build and push Docker image - name: Build and push Docker image
uses: docker/build-push-action@v6 uses: docker/build-push-action@v6
with: with:
@@ -53,8 +67,6 @@ jobs:
file: ./Dockerfile file: ./Dockerfile
push: true push: true
platforms: linux/amd64 platforms: linux/amd64
tags: | tags: ${{ steps.meta.outputs.tags }}
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.meta.outputs.tag }}
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
labels: ${{ steps.meta.outputs.labels }} labels: ${{ steps.meta.outputs.labels }}
no-cache: true no-cache: true