-
Notifications
You must be signed in to change notification settings - Fork 4
87 lines (80 loc) · 3.24 KB
/
Copy pathimage-zh-mock.yml
File metadata and controls
87 lines (80 loc) · 3.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# 构建并发布 Mock 模式的 Docker 镜像
# Mock 模式用于测试环境,基于正式镜像构建
name: 发布 Docker Chinese Mock 镜像
on:
# 支持手动触发,需要提供标签名称
workflow_dispatch:
inputs:
tag:
description: 'Tag 名称 (例如: n8n@2.0.3)'
required: true
jobs:
build-and-push:
runs-on: ubuntu-latest
environment: test
# 只有当前一个工作流成功时才运行(针对 workflow_run 触发)
if: ${{ github.event_name == 'workflow_dispatch' || github.event.workflow_run.conclusion == 'success' }}
steps:
# 检出 main 分支的最新代码(包含 Dockerfile.zhmock)
- name: 检出 Mock Dockerfile 代码
uses: actions/checkout@v4
with:
# 始终使用 main 分支的最新代码(包含 Dockerfile.zhmock)
ref: main
fetch-depth: 0
# 设置 Docker Buildx 以支持多架构构建
- name: 设置 Docker Buildx
uses: docker/setup-buildx-action@v3
# 登录到 DockerHub
- name: 登录 DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
# 提取版本号并判断构建模式
- name: 提取版本号
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
# 手动触发:使用输入的版本号
RAW_TAG="${{ github.event.inputs.tag }}"
VERSION=${RAW_TAG#n8n@}
echo "RELEASE_VERSION=$VERSION" >> $GITHUB_ENV
echo "BUILD_LATEST_ONLY=false" >> $GITHUB_ENV
echo "✅ 手动触发 - 版本号: $VERSION"
else
# workflow_run 触发:获取最新标签版本
RAW_TAG=$(git tag --sort=-version:refname | head -n 1)
if [ -z "$RAW_TAG" ]; then
echo "⚠️ 警告:无法获取标签,使用 latest"
echo "BUILD_LATEST_ONLY=true" >> $GITHUB_ENV
echo "RELEASE_VERSION=latest" >> $GITHUB_ENV
else
VERSION=${RAW_TAG#n8n@}
echo "RELEASE_VERSION=$VERSION" >> $GITHUB_ENV
echo "BUILD_LATEST_ONLY=false" >> $GITHUB_ENV
echo "✅ 自动触发 - 使用最新标签: $VERSION"
fi
fi
# 构建并推送带版本号的多架构镜像(手动触发时)
- name: 构建并推送 Mock 镜像(带版本)
if: env.BUILD_LATEST_ONLY == 'false'
run: |
docker buildx build \
--platform linux/amd64,linux/arm64 \
--build-arg VERSION=$RELEASE_VERSION \
-f Dockerfile.zhmock \
-t funcodingdev/n8n-chinese-mock:$RELEASE_VERSION \
-t funcodingdev/n8n-chinese-mock:latest \
--push \
.
# 仅构建并推送 latest 标签的多架构镜像(自动触发时)
- name: 构建并推送 Mock 镜像(仅 latest)
if: env.BUILD_LATEST_ONLY == 'true'
run: |
docker buildx build \
--platform linux/amd64,linux/arm64 \
--build-arg VERSION=latest \
-f Dockerfile.zhmock \
-t funcodingdev/n8n-chinese-mock:latest \
--push \
.