From b20b9daf42ed09ccf46b6da5f4265978f3843fca Mon Sep 17 00:00:00 2001 From: Shiming Zhang Date: Fri, 10 Nov 2023 17:44:41 +0800 Subject: [PATCH] Mantain mirror (#795) --- .github/workflows/verify-pr.yml | 11 ++++++++++- hack/fmt-image.sh | 25 +++++++++++++++++++++++++ hack/fmt.sh | 20 -------------------- hack/merge-mirror.sh | 33 +++++++++++++++++++++++++++++++++ hack/verify-fmt-image.sh | 9 +++++++++ 5 files changed, 77 insertions(+), 21 deletions(-) create mode 100755 hack/fmt-image.sh create mode 100755 hack/merge-mirror.sh create mode 100755 hack/verify-fmt-image.sh diff --git a/.github/workflows/verify-pr.yml b/.github/workflows/verify-pr.yml index 570a93c..7cfdc4f 100644 --- a/.github/workflows/verify-pr.yml +++ b/.github/workflows/verify-pr.yml @@ -33,7 +33,16 @@ jobs: gh pr comment "${{ github.event.pull_request.number }}" --body '请运行 `./hack/fmt.sh domain.txt` 对内容进行排序' exit 1 } - - name: Verify mirror.txt + + - name: Verify mirror.txt image + run: | + ./hack/verify-fmt-image.sh mirror.txt || { + echo "Please run './hack/fmt-image.sh mirror.txt'" + gh pr comment "${{ github.event.pull_request.number }}" --body '请运行 `./hack/fmt-image.sh mirror.txt` 对内容进行格式化' + exit 1 + } + + - name: Verify mirror.txt sort run: | ./hack/verify-fmt.sh mirror.txt || { echo "Please run './hack/fmt.sh mirror.txt'" diff --git a/hack/fmt-image.sh b/hack/fmt-image.sh new file mode 100755 index 0000000..4c8b2fd --- /dev/null +++ b/hack/fmt-image.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env bash + +function filter_docker_library() { + while read -r line; do + if [[ $line =~ ^docker\.io/[^/]*$ ]]; then + echo "docker.io/library/${line#docker.io/}" + else + echo "${line}" + fi + done +} + +function filter_k8s_old() { + while read -r line; do + if [[ $line =~ ^k8s\.gcr\.io/.*$ ]]; then + echo "registry.k8s.io/${line#k8s.gcr.io/}" + else + echo "${line}" + fi + done +} + +cat $1 | + filter_docker_library | + filter_k8s_old >$1.tmp && mv $1.tmp $1 diff --git a/hack/fmt.sh b/hack/fmt.sh index 7566a4f..a23b029 100755 --- a/hack/fmt.sh +++ b/hack/fmt.sh @@ -2,26 +2,6 @@ export LC_ALL=C -function filter_docker_library() { - while read -r line; do - if [[ $line =~ ^docker\.io/[^/]*$ ]]; then - echo "docker.io/library/${line#docker.io/}" - else - echo "${line}" - fi - done -} - -function filter_k8s_old() { - while read -r line; do - if [[ $line =~ ^k8s\.gcr\.io/.*$ ]]; then - echo "registry.k8s.io/${line#k8s.gcr.io/}" - else - echo "${line}" - fi - done -} - cat $1 | filter_docker_library | filter_k8s_old | diff --git a/hack/merge-mirror.sh b/hack/merge-mirror.sh new file mode 100755 index 0000000..bd9ad55 --- /dev/null +++ b/hack/merge-mirror.sh @@ -0,0 +1,33 @@ +#!/usr/bin/env bash + +base_list="${1}" +used_list="${2}" +used_top="${3:-100}" + +function used_top() { + cat "${used_list}" | head -n "${used_top}" +} + +function intersection_used() { + sort "${base_list}" "${used_list}" | uniq -d +} + +function fixed_docker() { + grep "^docker\.io/library/" "${base_list}" + grep "^docker\.io/library/" "${used_list}" +} + +function fixed_k8s() { + grep "^registry\.k8s\.io/" "${base_list}" + grep "^registry\.k8s\.io/" "${used_list}" +} + +function fixed_istio() { + grep "^docker\.io/istio/" "${base_list}" + grep "^docker\.io/istio/" "${used_list}" +} + +cat <(used_top) \ + <(intersection_used) \ + <(fixed_docker) \ + <(fixed_k8s) | sort | uniq -u diff --git a/hack/verify-fmt-image.sh b/hack/verify-fmt-image.sh new file mode 100755 index 0000000..297edcb --- /dev/null +++ b/hack/verify-fmt-image.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env bash + +export LC_ALL=C + +cp $1 $1.bak + +$(dirname "${BASH_SOURCE}")/fmt-image.sh $1.bak + +diff -c $1 $1.bak && rm $1.bak