@@ -3,10 +3,10 @@ name: Validate plugin.json
33on :
44 push :
55 paths :
6- - ' plugins.json'
6+ - " plugins.json"
77 pull_request :
88 paths :
9- - ' plugins.json'
9+ - " plugins.json"
1010 workflow_dispatch : # 支持手动触发
1111
1212jobs :
@@ -16,19 +16,50 @@ jobs:
1616 steps :
1717 - name : Checkout code
1818 uses : actions/checkout@v2
19+ with :
20+ fetch-depth : 0 # 获取完整历史记录以便比较文件
1921
2022 - name : Validate plugins.json format
2123 run : |
2224 sudo apt-get install jq
2325 jq . plugins.json > /dev/null
2426
25- - name : Check repository URLs
27+ - name : Check only changed repository URLs
2628 run : |
27- # 提取 plugins.json 中的 repo 字段并检查可访问性
28- repos=$(jq -r '.. | objects | .repo? // empty' plugins.json)
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 的可访问性
2960 unreachable_urls=() # 初始化一个数组用于记录不可访问的 URL
30-
31- for repo in $repos ; do
61+
62+ for repo in "${changed_repos[@]}" ; do
3263 sleep 1
3364 if curl --output /dev/null --silent --head --fail --retry 3 "$repo"; then
3465 echo "Repository $repo is accessible."
3768 unreachable_urls+=("$repo") # 将不可访问的 URL 添加到数组
3869 fi
3970 done
40-
71+
4172 # 检查是否有不可访问的 URL
4273 if [ ${#unreachable_urls[@]} -ne 0 ]; then
4374 echo "The following repositories are NOT accessible:"
4677 done
4778 exit 1 # 结束运行并标记失败状态
4879 else
49- echo "All repositories are accessible."
80+ echo "All changed repositories are accessible."
5081 fi
51-
0 commit comments