From 55e09223e49d5d5d3dc2aa72331cdc2c77136dc6 Mon Sep 17 00:00:00 2001 From: Shiming Zhang <wzshiming@foxmail.com> Date: Thu, 27 Jun 2024 11:16:19 +0800 Subject: [PATCH] Update image match --- .github/workflows/verify-pr.yml | 6 ++--- allows.txt | 3 --- hack/fmt-image-match.sh | 44 +++++++++++++++++++++++++++++++++ hack/verify-image-match.sh | 9 +++++++ 4 files changed, 56 insertions(+), 6 deletions(-) create mode 100755 hack/fmt-image-match.sh create mode 100755 hack/verify-image-match.sh diff --git a/.github/workflows/verify-pr.yml b/.github/workflows/verify-pr.yml index 3e18a4b..f90d7cf 100644 --- a/.github/workflows/verify-pr.yml +++ b/.github/workflows/verify-pr.yml @@ -54,9 +54,9 @@ jobs: - name: Verify allows.txt sort run: | - ./hack/verify-fmt.sh allows.txt || { - echo "Please run './hack/fmt.sh allows.txt'" - gh pr comment "${{ github.event.pull_request.number }}" --body '请运行 `./hack/fmt.sh allows.txt` 对内容进行排序' + ./hack/verify-image-match.sh allows.txt || { + echo "Please run './hack/fmt-image-match.sh allows.txt'" + gh pr comment "${{ github.event.pull_request.number }}" --body '请运行 `./hack/fmt-image-match.sh allows.txt` 对内容进行排序' exit 1 } diff --git a/allows.txt b/allows.txt index f40ff2f..75a9922 100644 --- a/allows.txt +++ b/allows.txt @@ -287,7 +287,6 @@ docker.io/prom/** docker.io/prometheuscommunity/** docker.io/pytorch/** docker.io/qdrant/** -docker.io/qdrant/qdrant docker.io/rancher/** docker.io/rclone/** docker.io/redislabs/** @@ -306,8 +305,6 @@ docker.io/sonobuoy/** docker.io/soulter/astrbot docker.io/squidfunk/** docker.io/starrocks/** -docker.io/starrocks/dev-env-centos7 -docker.io/starrocks/dev-env-ubuntu docker.io/tailscale/** docker.io/talebook/talebook docker.io/tdengine/** diff --git a/hack/fmt-image-match.sh b/hack/fmt-image-match.sh new file mode 100755 index 0000000..9ef89de --- /dev/null +++ b/hack/fmt-image-match.sh @@ -0,0 +1,44 @@ +#!/usr/bin/env bash + +function check_match() { + local image=$1 + local lines=$2 + for line in ${lines}; do + if [[ "${line}" == *"**" ]]; then + if [[ "${image}" == "${line%\*\*}"* ]]; then + return + fi + elif [[ "${line}" == *"*" ]]; then + if [[ "${image}" == "${line%\*}"* ]]; then + if [[ "${image#"${line%\*}"}" != *"/"* ]]; then + return + fi + fi + fi + done + + echo "${image}" +} + +function format() { + local file=$1 + local lines="$(cat "${file}")" + for line in ${lines}; do + if [[ "${line}" != *"*" ]]; then + check_match "${line}" "${lines}" + fi + done + + for line in ${lines}; do + if [[ "${line}" == *"*" ]]; then + echo ${line} + fi + done +} + +export LC_ALL=C +file=$1 + +format "${file}" | + sort -u | + grep -v '^$' >$1.tmp && mv $1.tmp $1 diff --git a/hack/verify-image-match.sh b/hack/verify-image-match.sh new file mode 100755 index 0000000..942547e --- /dev/null +++ b/hack/verify-image-match.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env bash + +export LC_ALL=C + +cp $1 $1.bak + +$(dirname "${BASH_SOURCE}")/fmt-image-match.sh $1.bak + +diff -c $1 $1.bak && rm $1.bak