Skip to content

Commit 077c604

Browse files
committed
build: 1
1 parent ce0c84e commit 077c604

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

.github/workflows/sync-releases.yml

Lines changed: 32 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,33 @@ 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+
delete_response=$(curl -s -w "%{http_code}" -o delete_response.json \
80+
-X DELETE \
81+
-H "Authorization: token $GITHUB_TOKEN" \
82+
-H "Accept: application/vnd.github.v3+json" \
83+
"https://api.github.com/repos/$GITHUB_REPOSITORY/releases/$existing_release_id")
84+
85+
delete_http_code=$(echo "$delete_response" | tail -c 4)
86+
87+
if [ "$delete_http_code" = "204" ]; then
88+
echo "? Successfully deleted existing release for $tag"
89+
else
90+
echo "? Failed to delete existing release for $tag (HTTP $delete_http_code)"
91+
cat delete_response.json
92+
continue
93+
fi
94+
fi
95+
6796
# 获取tag的完整注释信息
6897
tag_message=$(git tag -l --format='%(contents)' "$tag")
6998
@@ -96,7 +125,9 @@ jobs:
96125
prerelease: false,
97126
created_at: $created_at,
98127
published_at: $published_at
99-
}') echo "Creating release for $tag..."
128+
}')
129+
130+
echo "Creating release for $tag..."
100131
response=$(curl -s -w "%{http_code}" -o response.json \
101132
-X POST \
102133
-H "Authorization: token $GITHUB_TOKEN" \

0 commit comments

Comments
 (0)