Skip to content

Commit d40c566

Browse files
committed
build: 1
1 parent fe77df0 commit d40c566

File tree

1 file changed

+50
-17
lines changed

1 file changed

+50
-17
lines changed

.github/workflows/sync-releases.yml

Lines changed: 50 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,39 @@ jobs:
2525
threshold_date="2017-07-21T00:00:00Z"
2626
threshold_timestamp=$(date -d "$threshold_date" +%s)
2727
28-
# 获取所有现有的releases
28+
# 获取所有现有的releases (分页获取)
2929
echo "Fetching existing releases..."
30-
curl -s -H "Authorization: token $GITHUB_TOKEN" \
31-
"https://api.github.com/repos/$GITHUB_REPOSITORY/releases" > existing_releases.json
30+
page=1
31+
all_releases="[]"
32+
33+
while true; do
34+
echo "Fetching releases page $page..."
35+
page_releases=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \
36+
"https://api.github.com/repos/$GITHUB_REPOSITORY/releases?page=$page&per_page=100")
37+
38+
# 检查是否为空数组
39+
if [ "$(echo "$page_releases" | jq 'length')" -eq 0 ]; then
40+
echo "No more releases found. Total pages: $((page-1))"
41+
break
42+
fi
43+
44+
# 合并到总结果中
45+
all_releases=$(echo "$all_releases $page_releases" | jq -s 'add')
46+
echo "Page $page: $(echo "$page_releases" | jq 'length') releases"
47+
48+
page=$((page + 1))
49+
50+
# 防止无限循环,设置最大页数限制
51+
if [ $page -gt 20 ]; then
52+
echo "Reached maximum page limit (20), stopping..."
53+
break
54+
fi
55+
done
56+
57+
# 保存所有releases到文件
58+
echo "$all_releases" > existing_releases.json
59+
echo "Total releases fetched: $(echo "$all_releases" | jq 'length')"
60+
echo ""
3261
3362
# 提取现有release的tag名称
3463
existing_tags=$(jq -r '.[].tag_name' existing_releases.json | sort)
@@ -69,29 +98,33 @@ jobs:
6998
tag_timestamp=$(date -d "$tag_date" +%s)
7099
echo "Tag date: $tag_date"
71100
72-
# 检查tag日期是否晚于2017年7月21日
101+
# 检查tag日期是否晚于2017年7月19日
73102
if [ "$tag_timestamp" -gt "$threshold_timestamp" ]; then
74-
echo "Tag $tag is later than Jul 21, 2017. Checking for existing release to delete..."
103+
echo "Tag $tag is later than Jul 19, 2017. Checking for existing release to delete..."
75104
76105
# 检查是否已存在该tag的release
77106
existing_release_id=$(jq -r --arg tag "$tag" '.[] | select(.tag_name == $tag) | .id' existing_releases.json)
78107
79-
echo "Found existing release (ID: $existing_release_id) for $tag. Deleting it first..."
108+
if [ -n "$existing_release_id" ] && [ "$existing_release_id" != "null" ]; then
109+
echo "Found existing release (ID: $existing_release_id) for $tag. Deleting it first..."
80110
81-
delete_response=$(curl -s -w "%{http_code}" -o delete_response.json \
82-
-X DELETE \
83-
-H "Authorization: token $GITHUB_TOKEN" \
84-
-H "Accept: application/vnd.github.v3+json" \
85-
"https://api.github.com/repos/$GITHUB_REPOSITORY/releases/$existing_release_id")
111+
delete_response=$(curl -s -w "%{http_code}" -o delete_response.json \
112+
-X DELETE \
113+
-H "Authorization: token $GITHUB_TOKEN" \
114+
-H "Accept: application/vnd.github.v3+json" \
115+
"https://api.github.com/repos/$GITHUB_REPOSITORY/releases/$existing_release_id")
86116
87-
delete_http_code=$(echo "$delete_response" | tail -c 4)
117+
delete_http_code=$(echo "$delete_response" | tail -c 4)
88118
89-
if [ "$delete_http_code" = "204" ]; then
90-
echo "? Successfully deleted existing release for $tag"
119+
if [ "$delete_http_code" = "204" ]; then
120+
echo "? Successfully deleted existing release for $tag"
121+
else
122+
echo "? Failed to delete existing release for $tag (HTTP $delete_http_code)"
123+
cat delete_response.json
124+
continue
125+
fi
91126
else
92-
echo "? Failed to delete existing release for $tag (HTTP $delete_http_code)"
93-
cat delete_response.json
94-
continue
127+
echo "No existing release found for $tag to delete."
95128
fi
96129
fi
97130

0 commit comments

Comments
 (0)