This commit is contained in:
dongmei
2026-06-10 17:14:20 +08:00
parent 91b87ac37c
commit e2afa61519

View File

@@ -4,7 +4,7 @@ on:
workflow_dispatch: workflow_dispatch:
inputs: inputs:
repo_url: repo_url:
description: '要构建的仓库地址(如:xc-workflows/engine-demo' description: '要构建的仓库地址(支持相对路径如xc-workflows/engine-demo或完整 URL 如https://dev.modelhub.org.cn/xc-workflows/engine-demo'
required: true required: true
type: string type: string
ref: ref:
@@ -35,8 +35,21 @@ jobs:
- name: Clone target repository - name: Clone target repository
run: | run: |
# 拼接完整的 clone URLgitea.server_url 已包含协议) REPO_URL="${{ github.event.inputs.repo_url }}"
CLONE_URL="${{ gitea.server_url }}/${{ github.event.inputs.repo_url }}.git"
# 判断是否完整 URL
if [[ "$REPO_URL" == http://* || "$REPO_URL" == https://* ]]; then
CLONE_URL="$REPO_URL"
# 如果没有 .git 后缀,加上
[[ "$CLONE_URL" != *.git ]] && CLONE_URL="${CLONE_URL}.git"
# 提取路径部分用于生成镜像名
REPO_PATH="$(echo "$REPO_URL" | sed 's|https\?://[^/]*/||' | sed 's|\.git$||')"
else
# 拼接完整的 clone URLgitea.server_url 已包含协议)
CLONE_URL="${{ gitea.server_url }}/$REPO_URL.git"
REPO_PATH="$REPO_URL"
fi
echo "正在克隆: $CLONE_URL" echo "正在克隆: $CLONE_URL"
git clone "$CLONE_URL" target_repo git clone "$CLONE_URL" target_repo
@@ -45,7 +58,8 @@ jobs:
# 保存仓库信息供后续步骤使用 # 保存仓库信息供后续步骤使用
echo "TARGET_REPO_PATH=$(pwd)" >> "$GITEA_ENV" echo "TARGET_REPO_PATH=$(pwd)" >> "$GITEA_ENV"
echo "TARGET_REPO_NAME=$(basename ${{ github.event.inputs.repo_url }})" >> "$GITEA_ENV" echo "TARGET_REPO_NAME=$(basename "$REPO_PATH")" >> "$GITEA_ENV"
echo "REPO_PATH=$REPO_PATH" >> "$GITEA_ENV"
echo "克隆完成,当前目录: $(pwd)" echo "克隆完成,当前目录: $(pwd)"
- name: Set image metadata - name: Set image metadata
@@ -53,12 +67,13 @@ jobs:
cd target_repo cd target_repo
# 生成镜像名称(将仓库路径中的 / 替换为 - # 生成镜像名称(将仓库路径中的 / 替换为 -
IMAGE_NAME="$(echo "${{ github.event.inputs.repo_url }}" | tr '[:upper:]' '[:lower:]' | tr '/' '-')" IMAGE_NAME="$(echo "$REPO_PATH" | tr '[:upper:]' '[:lower:]' | tr '/' '-')"
SAFE_TAG=$(echo "${{ github.event.inputs.ref }}" | sed 's/\//-/g') SAFE_TAG=$(echo "${{ github.event.inputs.ref }}" | sed 's/\//-/g')
IMAGE="${DOCKER_REGISTRY}/${DOCKER_USERNAME}/${IMAGE_NAME}:${SAFE_TAG}" IMAGE="${DOCKER_REGISTRY}/${DOCKER_USERNAME}/${IMAGE_NAME}:${SAFE_TAG}"
echo "IMAGE_NAME=${IMAGE_NAME}" >> "$GITEA_ENV" echo "IMAGE_NAME=${IMAGE_NAME}" >> "$GITEA_ENV"
echo "IMAGE=${IMAGE}" >> "$GITEA_ENV" echo "IMAGE=${IMAGE}" >> "$GITEA_ENV"
echo "SAFE_TAG=${SAFE_TAG}" >> "$GITEA_ENV"
echo "镜像名称: ${IMAGE}" echo "镜像名称: ${IMAGE}"
- name: Check Dockerfile exists - name: Check Dockerfile exists