Make docker builds and desktop releases depend on the shared test workflow to avoid duplicate runs and ensure only tested revisions ship.
71 lines
2.4 KiB
YAML
71 lines
2.4 KiB
YAML
name: Docker Build and Push
|
|
|
|
on:
|
|
workflow_run:
|
|
workflows: [ test ]
|
|
types: [ completed ]
|
|
workflow_dispatch:
|
|
|
|
env:
|
|
# Docker Hub 配置
|
|
DOCKERHUB_REGISTRY: docker.io
|
|
DOCKERHUB_IMAGE_NAME: linshen/prompt-optimizer
|
|
|
|
# 阿里云容器镜像服务配置
|
|
ALIYUN_REGISTRY: registry.cn-guangzhou.aliyuncs.com
|
|
ALIYUN_IMAGE_NAME: prompt-optimizer/prompt-optimizer
|
|
|
|
jobs:
|
|
build:
|
|
if: ${{ github.event_name == 'workflow_dispatch' || (github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.event == 'push' && (github.event.workflow_run.head_branch == 'main' || github.event.workflow_run.head_branch == 'master')) }}
|
|
runs-on: ubuntu-latest
|
|
permissions:
|
|
contents: read
|
|
packages: write
|
|
|
|
steps:
|
|
- name: 检出代码
|
|
uses: actions/checkout@v4
|
|
with:
|
|
ref: ${{ github.event.workflow_run.head_sha || github.sha }}
|
|
|
|
- name: 获取package.json版本号
|
|
id: version
|
|
run: |
|
|
VERSION=$(grep -m1 '"version":' package.json | cut -d'"' -f4)
|
|
echo "version=$VERSION" >> $GITHUB_OUTPUT
|
|
echo "Version from package.json: $VERSION"
|
|
|
|
- name: 登录到Docker Hub
|
|
uses: docker/login-action@v3
|
|
with:
|
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
|
|
|
- name: 登录到阿里云容器镜像服务
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: ${{ env.ALIYUN_REGISTRY }}
|
|
username: ${{ secrets.ALIYUN_USERNAME }}
|
|
password: ${{ secrets.ALIYUN_PASSWORD }}
|
|
|
|
- name: Set up QEMU
|
|
uses: docker/setup-qemu-action@v3
|
|
|
|
- name: 设置Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
- name: 构建并推送Docker镜像
|
|
uses: docker/build-push-action@v6
|
|
with:
|
|
context: .
|
|
platforms: linux/amd64,linux/arm64
|
|
push: ${{ github.event_name != 'pull_request' }}
|
|
tags: |
|
|
${{ env.DOCKERHUB_REGISTRY }}/${{ env.DOCKERHUB_IMAGE_NAME }}:${{ steps.version.outputs.version }}
|
|
${{ env.DOCKERHUB_REGISTRY }}/${{ env.DOCKERHUB_IMAGE_NAME }}:latest
|
|
${{ env.ALIYUN_REGISTRY }}/${{ env.ALIYUN_IMAGE_NAME }}:${{ steps.version.outputs.version }}
|
|
${{ env.ALIYUN_REGISTRY }}/${{ env.ALIYUN_IMAGE_NAME }}:latest
|
|
cache-from: type=gha
|
|
cache-to: type=gha,mode=max
|