fix
This commit is contained in:
@@ -20,6 +20,29 @@ on:
|
|||||||
options:
|
options:
|
||||||
- 'true'
|
- 'true'
|
||||||
- 'false'
|
- 'false'
|
||||||
|
job_id:
|
||||||
|
description: '任务ID'
|
||||||
|
required: true
|
||||||
|
type: string
|
||||||
|
submission_id:
|
||||||
|
description: '提交ID'
|
||||||
|
required: true
|
||||||
|
type: string
|
||||||
|
callback_url:
|
||||||
|
description: '回调地址'
|
||||||
|
required: false
|
||||||
|
default: ''
|
||||||
|
type: string
|
||||||
|
callback_token:
|
||||||
|
description: '回调Token'
|
||||||
|
required: false
|
||||||
|
default: ''
|
||||||
|
type: string
|
||||||
|
startup_params:
|
||||||
|
description: '启动参数(JSON格式)'
|
||||||
|
required: false
|
||||||
|
default: '{}'
|
||||||
|
type: string
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
@@ -32,6 +55,10 @@ jobs:
|
|||||||
echo "Repo URL input: ${{ github.event.inputs.repo_url }}"
|
echo "Repo URL input: ${{ github.event.inputs.repo_url }}"
|
||||||
echo "Ref: ${{ github.event.inputs.ref }}"
|
echo "Ref: ${{ github.event.inputs.ref }}"
|
||||||
echo "Dry run: ${{ github.event.inputs.dry_run }}"
|
echo "Dry run: ${{ github.event.inputs.dry_run }}"
|
||||||
|
echo "Job ID: ${{ github.event.inputs.job_id }}"
|
||||||
|
echo "Submission ID: ${{ github.event.inputs.submission_id }}"
|
||||||
|
echo "Callback URL: ${{ github.event.inputs.callback_url }}"
|
||||||
|
echo "Startup Params: ${{ github.event.inputs.startup_params }}"
|
||||||
|
|
||||||
- name: Clone target repository
|
- name: Clone target repository
|
||||||
run: |
|
run: |
|
||||||
@@ -56,10 +83,16 @@ jobs:
|
|||||||
cd target_repo
|
cd target_repo
|
||||||
git checkout "${{ github.event.inputs.ref }}"
|
git checkout "${{ github.event.inputs.ref }}"
|
||||||
|
|
||||||
|
# 打 tag
|
||||||
|
TAG_NAME="build-${{ github.event.inputs.submission_id }}-${{ github.event.inputs.job_id }}"
|
||||||
|
git tag "$TAG_NAME"
|
||||||
|
echo "已打 tag: $TAG_NAME"
|
||||||
|
|
||||||
# 保存仓库信息供后续步骤使用
|
# 保存仓库信息供后续步骤使用
|
||||||
echo "TARGET_REPO_PATH=$(pwd)" >> "$GITEA_ENV"
|
echo "TARGET_REPO_PATH=$(pwd)" >> "$GITEA_ENV"
|
||||||
echo "TARGET_REPO_NAME=$(basename "$REPO_PATH")" >> "$GITEA_ENV"
|
echo "TARGET_REPO_NAME=$(basename "$REPO_PATH")" >> "$GITEA_ENV"
|
||||||
echo "REPO_PATH=$REPO_PATH" >> "$GITEA_ENV"
|
echo "REPO_PATH=$REPO_PATH" >> "$GITEA_ENV"
|
||||||
|
echo "TAG_NAME=$TAG_NAME" >> "$GITEA_ENV"
|
||||||
echo "克隆完成,当前目录: $(pwd)"
|
echo "克隆完成,当前目录: $(pwd)"
|
||||||
|
|
||||||
- name: Set image metadata
|
- name: Set image metadata
|
||||||
@@ -68,7 +101,7 @@ jobs:
|
|||||||
|
|
||||||
# 生成镜像名称(将仓库路径中的 / 替换为 -)
|
# 生成镜像名称(将仓库路径中的 / 替换为 -)
|
||||||
IMAGE_NAME="$(echo "$REPO_PATH" | 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="${TAG_NAME}"
|
||||||
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"
|
||||||
@@ -132,7 +165,7 @@ jobs:
|
|||||||
echo "✅ 仅构建模式完成(未推送)"
|
echo "✅ 仅构建模式完成(未推送)"
|
||||||
echo "=========================================="
|
echo "=========================================="
|
||||||
echo "源仓库: ${{ github.event.inputs.repo_url }}"
|
echo "源仓库: ${{ github.event.inputs.repo_url }}"
|
||||||
echo "分支/Tag: ${{ github.event.inputs.ref }}"
|
echo "分支: ${{ github.event.inputs.ref }}"
|
||||||
echo "镜像名称: ${IMAGE}"
|
echo "镜像名称: ${IMAGE}"
|
||||||
echo "镜像标签: ${SAFE_TAG}"
|
echo "镜像标签: ${SAFE_TAG}"
|
||||||
echo "=========================================="
|
echo "=========================================="
|
||||||
@@ -145,7 +178,42 @@ jobs:
|
|||||||
echo "✅ 完整构建完成(已推送)"
|
echo "✅ 完整构建完成(已推送)"
|
||||||
echo "=========================================="
|
echo "=========================================="
|
||||||
echo "源仓库: ${{ github.event.inputs.repo_url }}"
|
echo "源仓库: ${{ github.event.inputs.repo_url }}"
|
||||||
echo "分支/Tag: ${{ github.event.inputs.ref }}"
|
echo "分支: ${{ github.event.inputs.ref }}"
|
||||||
echo "镜像名称: ${IMAGE}"
|
echo "镜像名称: ${IMAGE}"
|
||||||
echo "镜像标签: ${SAFE_TAG}"
|
echo "镜像标签: ${SAFE_TAG}"
|
||||||
echo "=========================================="
|
echo "=========================================="
|
||||||
|
|
||||||
|
- name: Callback notification
|
||||||
|
if: github.event.inputs.callback_url != ''
|
||||||
|
run: |
|
||||||
|
echo "正在发送回调通知..."
|
||||||
|
|
||||||
|
# 构造回调请求体
|
||||||
|
CALLBACK_URL="${{ github.event.inputs.callback_url }}"
|
||||||
|
CALLBACK_TOKEN="${{ github.event.inputs.callback_token }}"
|
||||||
|
JOB_ID="${{ github.event.inputs.job_id }}"
|
||||||
|
STARTUP_PARAMS='${{ github.event.inputs.startup_params }}'
|
||||||
|
|
||||||
|
# 使用 jq 构造 JSON 请求体
|
||||||
|
BODY=$(jq -n \
|
||||||
|
--arg jobId "$JOB_ID" \
|
||||||
|
--arg imageUrl "$IMAGE" \
|
||||||
|
--argjson startupParams "$STARTUP_PARAMS" \
|
||||||
|
'{jobId: $jobId, imageUrl: $imageUrl, startupParams: $startupParams}')
|
||||||
|
|
||||||
|
echo "回调请求体: $BODY"
|
||||||
|
|
||||||
|
# 发送 POST 请求
|
||||||
|
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" \
|
||||||
|
-X POST \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-H "X-Callback-Token: $CALLBACK_TOKEN" \
|
||||||
|
-d "$BODY" \
|
||||||
|
"$CALLBACK_URL")
|
||||||
|
|
||||||
|
if [ "$HTTP_CODE" -ge 200 ] && [ "$HTTP_CODE" -lt 300 ]; then
|
||||||
|
echo "✅ 回调通知发送成功,HTTP 状态码: $HTTP_CODE"
|
||||||
|
else
|
||||||
|
echo "❌ 回调通知发送失败,HTTP 状态码: $HTTP_CODE"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user