|
21 | 21 | env: |
22 | 22 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
23 | 23 | run: | |
| 24 | + # 设置日期阈值 (Jul 21, 2017) |
| 25 | + threshold_date="2017-07-21T00:00:00Z" |
| 26 | + threshold_timestamp=$(date -d "$threshold_date" +%s) |
| 27 | +
|
24 | 28 | # 获取所有现有的releases |
25 | 29 | echo "Fetching existing releases..." |
26 | 30 | curl -s -H "Authorization: token $GITHUB_TOKEN" \ |
|
62 | 66 |
|
63 | 67 | # 获取tag的创建时间 |
64 | 68 | tag_date=$(git log -1 --format=%aI "$tag") |
| 69 | + tag_timestamp=$(date -d "$tag_date" +%s) |
65 | 70 | echo "Tag date: $tag_date" |
66 | 71 |
|
| 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 | +
|
67 | 102 | # 获取tag的完整注释信息 |
68 | 103 | tag_message=$(git tag -l --format='%(contents)' "$tag") |
69 | 104 |
|
|
96 | 131 | prerelease: false, |
97 | 132 | created_at: $created_at, |
98 | 133 | published_at: $published_at |
99 | | - }') echo "Creating release for $tag..." |
| 134 | + }') |
| 135 | +
|
| 136 | + echo "Creating release for $tag..." |
100 | 137 | response=$(curl -s -w "%{http_code}" -o response.json \ |
101 | 138 | -X POST \ |
102 | 139 | -H "Authorization: token $GITHUB_TOKEN" \ |
|
0 commit comments