发布 Docker Chinese Mock 镜像 #10
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 构建并发布 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 \ | |
| . |