Skip to content

Commit b6fca3c

Browse files
committed
build: 1
1 parent ce0c84e commit b6fca3c

File tree

1 file changed

+38
-1
lines changed

1 file changed

+38
-1
lines changed

.github/workflows/sync-releases.yml

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ jobs:
2121
env:
2222
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2323
run: |
24+
# 设置日期阈值 (Jul 21, 2017)
25+
threshold_date="2017-07-21T00:00:00Z"
26+
threshold_timestamp=$(date -d "$threshold_date" +%s)
27+
2428
# 获取所有现有的releases
2529
echo "Fetching existing releases..."
2630
curl -s -H "Authorization: token $GITHUB_TOKEN" \
@@ -62,8 +66,39 @@ jobs:
6266
6367
# 获取tag的创建时间
6468
tag_date=$(git log -1 --format=%aI "$tag")
69+
tag_timestamp=$(date -d "$tag_date" +%s)
6570
echo "Tag date: $tag_date"
6671
72+
# 检查tag日期是否早于2017年7月21日
73+
if [ "$tag_timestamp" -lt "$threshold_timestamp" ]; then
74+
echo "Tag $tag is earlier than Jul 21, 2017. Checking for existing release to delete..."
75+
76+
# 检查是否已存在该tag的release
77+
existing_release_id=$(jq -r --arg tag "$tag" '.[] | select(.tag_name == $tag) | .id' existing_releases.json)
78+
79+
if [ -n "$existing_release_id" ] && [ "$existing_release_id" != "null" ]; then
80+
echo "Found existing release (ID: $existing_release_id) for $tag. Deleting it first..."
81+
82+
delete_response=$(curl -s -w "%{http_code}" -o delete_response.json \
83+
-X DELETE \
84+
-H "Authorization: token $GITHUB_TOKEN" \
85+
-H "Accept: application/vnd.github.v3+json" \
86+
"https://api.github.com/repos/$GITHUB_REPOSITORY/releases/$existing_release_id")
87+
88+
delete_http_code=$(echo "$delete_response" | tail -c 4)
89+
90+
if [ "$delete_http_code" = "204" ]; then
91+
echo "? Successfully deleted existing release for $tag"
92+
else
93+
echo "? Failed to delete existing release for $tag (HTTP $delete_http_code)"
94+
cat delete_response.json
95+
continue
96+
fi
97+
else
98+
echo "No existing release found for $tag to delete."
99+
fi
100+
fi
101+
67102
# 获取tag的完整注释信息
68103
tag_message=$(git tag -l --format='%(contents)' "$tag")
69104
@@ -96,7 +131,9 @@ jobs:
96131
prerelease: false,
97132
created_at: $created_at,
98133
published_at: $published_at
99-
}') echo "Creating release for $tag..."
134+
}')
135+
136+
echo "Creating release for $tag..."
100137
response=$(curl -s -w "%{http_code}" -o response.json \
101138
-X POST \
102139
-H "Authorization: token $GITHUB_TOKEN" \

0 commit comments

Comments
 (0)