Skip to content

Commit

Permalink
ci: only keep the latest release (#398)
Browse files Browse the repository at this point in the history
  • Loading branch information
uubulb authored Jul 28, 2024
1 parent fe234f4 commit 100600d
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions .github/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,40 @@ def get_github_latest_release():
print("No releases found.")


def delete_gitee_releases(latest_id, client, uri, token):
get_data = {
'access_token': token
}

release_info = []
release_response = client.get(uri, json=get_data)
if release_response.status_code == 200:
release_info = release_response.json()
else:
print(
f"Request failed with status code {release_response.status_code}")

release_ids = []
for block in release_info:
if 'id' in block:
release_ids.append(block['id'])

print(f'Current release ids: {release_ids}')
release_ids.remove(latest_id)

for id in release_ids:
release_uri = f"{uri}/{id}"
delete_data = {
'access_token': access_token
}
delete_response = client.delete(release_uri, json=delete_data)
if delete_response.status_code == 204:
print(f'Successfully deleted release #{id}.')
else:
raise ValueError(
f"Request failed with status code {release_api_response.status_code}")


def sync_to_gitee(tag: str, body: str, files: slice):
release_id = ""
owner = "naibahq"
Expand Down Expand Up @@ -78,6 +112,13 @@ def sync_to_gitee(tag: str, body: str, files: slice):
print(
f"Request failed with status code {asset_api_response.status_code}")

# 仅保留最新 Release 以防超出 Gitee 仓库配额
try:
delete_gitee_releases(release_id, api_client,
release_api_uri, access_token)
except ValueError as e:
print(e)

api_client.close()
print("Sync is completed!")

Expand Down

0 comments on commit 100600d

Please sign in to comment.