ci: only keep the latest release (#398)
This commit is contained in:
parent
fe234f4f38
commit
100600d594
41
.github/sync.py
vendored
41
.github/sync.py
vendored
@ -31,6 +31,40 @@ def get_github_latest_release():
|
|||||||
print("No releases found.")
|
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):
|
def sync_to_gitee(tag: str, body: str, files: slice):
|
||||||
release_id = ""
|
release_id = ""
|
||||||
owner = "naibahq"
|
owner = "naibahq"
|
||||||
@ -78,6 +112,13 @@ def sync_to_gitee(tag: str, body: str, files: slice):
|
|||||||
print(
|
print(
|
||||||
f"Request failed with status code {asset_api_response.status_code}")
|
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()
|
api_client.close()
|
||||||
print("Sync is completed!")
|
print("Sync is completed!")
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user