From e2afa61519a8504d14cb68b4199fb6f8e50cc881 Mon Sep 17 00:00:00 2001 From: dongmei Date: Wed, 10 Jun 2026 17:14:20 +0800 Subject: [PATCH] fix --- .gitea/workflows/common-trigger.yml | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/.gitea/workflows/common-trigger.yml b/.gitea/workflows/common-trigger.yml index eafaa82..3df4b24 100644 --- a/.gitea/workflows/common-trigger.yml +++ b/.gitea/workflows/common-trigger.yml @@ -4,7 +4,7 @@ on: workflow_dispatch: inputs: repo_url: - description: '要构建的仓库地址(如:xc-workflows/engine-demo)' + description: '要构建的仓库地址(支持相对路径如:xc-workflows/engine-demo,或完整 URL 如:https://dev.modelhub.org.cn/xc-workflows/engine-demo)' required: true type: string ref: @@ -35,8 +35,21 @@ jobs: - name: Clone target repository run: | - # 拼接完整的 clone URL(gitea.server_url 已包含协议) - CLONE_URL="${{ gitea.server_url }}/${{ github.event.inputs.repo_url }}.git" + REPO_URL="${{ github.event.inputs.repo_url }}" + + # 判断是否完整 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 URL(gitea.server_url 已包含协议) + CLONE_URL="${{ gitea.server_url }}/$REPO_URL.git" + REPO_PATH="$REPO_URL" + fi + echo "正在克隆: $CLONE_URL" git clone "$CLONE_URL" target_repo @@ -45,7 +58,8 @@ jobs: # 保存仓库信息供后续步骤使用 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)" - name: Set image metadata @@ -53,12 +67,13 @@ jobs: 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') IMAGE="${DOCKER_REGISTRY}/${DOCKER_USERNAME}/${IMAGE_NAME}:${SAFE_TAG}" echo "IMAGE_NAME=${IMAGE_NAME}" >> "$GITEA_ENV" echo "IMAGE=${IMAGE}" >> "$GITEA_ENV" + echo "SAFE_TAG=${SAFE_TAG}" >> "$GITEA_ENV" echo "镜像名称: ${IMAGE}" - name: Check Dockerfile exists