@@ -24,42 +24,14 @@ jobs:
2424 sudo apt-get install jq
2525 jq . plugins.json > /dev/null
2626
27- - name : Check only changed repository URLs
27+ - name : Check repository URLs
2828 run : |
29- # 获取前一个版本的 plugins.json 文件
30- if [ "${{ github.event_name }}" == "pull_request" ]; then
31- # 对于 PR,比较目标分支与当前分支
32- git show "origin/${{ github.base_ref }}:plugins.json" > previous_plugins.json || echo "[]" > previous_plugins.json
33- else
34- # 对于推送,比较前一个提交
35- git show HEAD~1:plugins.json > previous_plugins.json || echo "[]" > previous_plugins.json
36- fi
37-
38- # 提取当前版本的所有 repo
39- current_repos=$(jq -r '.. | objects | .repo? // empty' plugins.json)
40- # 提取前一个版本的所有 repo
41- previous_repos=$(jq -r '.. | objects | .repo? // empty' previous_plugins.json)
42-
43- # 找出新增或修改的 repo
44- changed_repos=()
45- for repo in $current_repos; do
46- if ! echo "$previous_repos" | grep -q "^$repo$"; then
47- changed_repos+=("$repo")
48- fi
49- done
50-
51- # 如果没有变化的 repo,输出消息并退出
52- if [ ${#changed_repos[@]} -eq 0 ]; then
53- echo "No repository URLs were added or modified. Skipping checks."
54- exit 0
55- fi
56-
57- echo "Checking ${#changed_repos[@]} changed or new repositories..."
58-
59- # 检查变化的 repo 的可访问性
29+ # 提取 plugins.json 中的 repo 字段并检查可访问性
30+ repos=$(jq -r '.. | objects | .repo? // empty' plugins.json)
6031 unreachable_urls=() # 初始化一个数组用于记录不可访问的 URL
61-
62- for repo in "${changed_repos[@]}"; do
32+
33+ for repo in $repos; do
34+ if curl --output /dev/null --silent --head --fail "$repo"; then
6335 sleep 1
6436 if curl --output /dev/null --silent --head --fail --retry 3 "$repo"; then
6537 echo "Repository $repo is accessible."
6840 unreachable_urls+=("$repo") # 将不可访问的 URL 添加到数组
6941 fi
7042 done
71-
43+
7244 # 检查是否有不可访问的 URL
7345 if [ ${#unreachable_urls[@]} -ne 0 ]; then
7446 echo "The following repositories are NOT accessible:"
7749 done
7850 exit 1 # 结束运行并标记失败状态
7951 else
80- echo "All changed repositories are accessible."
52+ echo "All repositories are accessible."
8153 fi
0 commit comments