diff --git a/.github/workflows/target-image-sync.yml b/.github/workflows/target-image-sync.yml
index d0cbaa7..ad5e581 100644
--- a/.github/workflows/target-image-sync.yml
+++ b/.github/workflows/target-image-sync.yml
@@ -22,22 +22,17 @@ jobs:
MESSAGE: "${{ github.event.issue.body }}"
run: |
ORIGIN_IMAGE=$(echo "${MESSAGE}" | grep SYNC | awk '{print $2}' | head -n 1 | sed "s/\r//g")
- if [[ -z "${ORIGIN_IMAGE}" ]]; then
- gh issue comment ${{ github.event.issue.number }} -b "找不到镜像呢"
- gh issue edit ${{ github.event.issue.number }} --title "FAILED SYNC IMAGE"
- gh issue close ${{ github.event.issue.number }} --reason "not planned"
+ CORRECT_IMAGE="$(./hack/correct-image.sh "${ORIGIN_IMAGE}")"
+ if [[ "${CORRECT_IMAGE}" == "" ]]; then
+ gh issue comment ${{ github.event.issue.number }} -b "镜像 '${ORIGIN_IMAGE}' 不是一个镜像"
exit 1
fi
- if [[ "${ORIGIN_IMAGE}" != *":"* ]]; then
- gh issue comment ${{ github.event.issue.number }} -b "镜像 ${ORIGIN_IMAGE} 不存在呢, 请指定 tag, 如: ${ORIGIN_IMAGE}:latest"
- gh issue edit ${{ github.event.issue.number }} --title "FAILED SYNC IMAGE"
- gh issue close ${{ github.event.issue.number }} --reason "not planned"
- exit 1
- fi
- if [[ "${ORIGIN_IMAGE%%/*}" != *"."* ]] || [[ "${ORIGIN_IMAGE}" != *"/"* ]]; then
- gh issue comment ${{ github.event.issue.number }} -b "镜像 ${ORIGIN_IMAGE} 不存在呢, 请指定域名, 如: docker.io/${ORIGIN_IMAGE}"
- gh issue edit ${{ github.event.issue.number }} --title "FAILED SYNC IMAGE"
- gh issue close ${{ github.event.issue.number }} --reason "not planned"
+ if [[ "${CORRECT_IMAGE}" != "${ORIGIN_IMAGE}" ]]; then
+ if ! ./hack/verify-allows.sh ./allows.txt "${CORRECT_IMAGE}"; then
+ gh issue comment ${{ github.event.issue.number }} -b "镜像 '${ORIGIN_IMAGE}' 不存在呢, 也许应该是 '${CORRECT_IMAGE}', 并且不在白名单列表里, 不支持同步和访问
可以将其添加到[白名单](https://github.com/${{ github.repository }}/issues/2328)"
+ else
+ gh issue comment ${{ github.event.issue.number }} -b "镜像 '${ORIGIN_IMAGE}' 不存在呢, 也许应该是 '${CORRECT_IMAGE}'"
+ fi
exit 1
fi
if ! ./hack/verify-allows.sh ./allows.txt "${ORIGIN_IMAGE}"; then
diff --git a/.github/workflows/target-sync-image.yml b/.github/workflows/target-sync-image.yml
index eb48069..763aef0 100644
--- a/.github/workflows/target-sync-image.yml
+++ b/.github/workflows/target-sync-image.yml
@@ -23,22 +23,19 @@ jobs:
IMAGE: "${{ github.event.issue.title }}"
run: |
ORIGIN_IMAGE="${IMAGE}"
- if [[ "${ORIGIN_IMAGE}" == *"//"* ]] || [[ "${ORIGIN_IMAGE}" == *" "* ]]; then
+ CORRECT_IMAGE="$(./hack/correct-image.sh "${ORIGIN_IMAGE}")"
+ if [[ "${CORRECT_IMAGE}" == "" ]]; then
gh issue comment ${{ github.event.issue.number }} -b "镜像 '${ORIGIN_IMAGE}' 不是一个镜像"
exit 1
fi
- if [[ "${ORIGIN_IMAGE%%/*}" != *"."* ]] || [[ "${ORIGIN_IMAGE}" != *"/"* ]]; then
- if [[ "${ORIGIN_IMAGE}" != *":"* ]]; then
- gh issue comment ${{ github.event.issue.number }} -b "镜像 '${ORIGIN_IMAGE}' 不存在呢, 请指定 域名 和 tag, 如: docker.io/${ORIGIN_IMAGE}:latest"
+ if [[ "${CORRECT_IMAGE}" != "${ORIGIN_IMAGE}" ]]; then
+ if ! ./hack/verify-allows.sh ./allows.txt "${CORRECT_IMAGE}"; then
+ gh issue comment ${{ github.event.issue.number }} -b "镜像 '${ORIGIN_IMAGE}' 不存在呢, 也许应该是 '${CORRECT_IMAGE}', 并且不在白名单列表里, 不支持同步和访问
可以将其添加到[白名单](https://github.com/${{ github.repository }}/issues/2328)"
else
- gh issue comment ${{ github.event.issue.number }} -b "镜像 '${ORIGIN_IMAGE}' 不存在呢, 请指定域名, 如: docker.io/${ORIGIN_IMAGE}"
+ gh issue comment ${{ github.event.issue.number }} -b "镜像 '${ORIGIN_IMAGE}' 不存在呢, 也许应该是 '${CORRECT_IMAGE}'"
fi
exit 1
fi
- if [[ "${ORIGIN_IMAGE}" != *":"* ]]; then
- gh issue comment ${{ github.event.issue.number }} -b "镜像 '${ORIGIN_IMAGE}' 不存在呢, 请指定 tag, 如: ${ORIGIN_IMAGE}:latest"
- exit 1
- fi
if ! ./hack/verify-allows.sh ./allows.txt "${ORIGIN_IMAGE}"; then
gh issue comment ${{ github.event.issue.number }} -b "镜像 ${ORIGIN_IMAGE} 不在白名单列表里, 不支持同步和访问
可以将其添加到[白名单](https://github.com/${{ github.repository }}/issues/2328)"
exit 1
diff --git a/hack/correct-image.sh b/hack/correct-image.sh
new file mode 100755
index 0000000..5d85a91
--- /dev/null
+++ b/hack/correct-image.sh
@@ -0,0 +1,32 @@
+#!/usr/bin/env bash
+
+function guess_image() {
+ local image="${1}"
+
+ image="${image# }"
+ image="${image% }"
+
+ if [[ -z "${image}" ]]; then
+ return
+ fi
+
+ if [[ "${image}" == *"registry.docker.com/r"* ]]; then
+ image="docker.io/${image##*registry.hub.docker.com\/r\/}"
+ fi
+ if [[ "${image}" == *"hub.docker.com/r"* ]]; then
+ image="docker.io/${image##*hub.docker.com\/r\/}"
+ fi
+ if [[ "${image%%/*}" != *"."* ]] || [[ "${image}" != *"/"* ]]; then
+ image="docker.io/${image}"
+ fi
+ if [[ "${image}" != *":"* ]]; then
+ image="${image}:latest"
+ fi
+ if [[ "${image}" == *"//"* ]] || [[ "${image}" == *" "* ]]; then
+ return
+ fi
+
+ echo "${image}"
+}
+
+guess_image "${1}"