Pipeline Release: Use Add-On Bundle to Update Add-Ons #269

Merged
Showing only changes of commit 0dee093251 - Show all commits

View File

@ -26,7 +26,7 @@ ZIP_NAME = "blender_studio_add-ons_latest"
def main():
get_api_token()
latest_release = get_latest_release()
latest_release = get_release()
temp_dir = Path(tempfile.mkdtemp(prefix=ZIP_NAME + "_"))
release_files = create_latest_addons_zip(ZIP_NAME, temp_dir)
remove_existing_release_assets(latest_release["id"])
@ -49,13 +49,8 @@ def remove_existing_release_assets(release_id: int) -> None:
all_assets = send_get_request(RELEASE_PATH + f"/{release_id}/assets").json()
for asset in all_assets:
if asset["name"] == ZIP_NAME + ".zip" or asset["name"] == ZIP_NAME + ".zip.sha256":
response = requests.delete(
RELEASE_PATH + f"/{release_id}/assets/{asset['id']}?token={API_TOKEN}"
)
if response.status_code != 204:
print(f"Failed to delete {asset['name']}")
else:
print(f"Deleted {asset['name']} created on: {asset['created_at']}")
send_delete_request(RELEASE_PATH + f"/{release_id}/assets/{asset['id']}")
print(f"Deleted {asset['name']} created on: {asset['created_at']}")
def upload_asset_to_release(release_id: int, file: str) -> None:
@ -88,25 +83,21 @@ def upload_asset_to_release(release_id: int, file: str) -> None:
print(f"Completed")
def get_latest_release() -> dict:
"""Get the latest release matching the release title and version.
def get_release() -> dict:
"""Gets the latest release matching the configured title and version.
Checks if the latest release matches the expected title and version. If not,
loops through all releases to find the latest matching one. If none found,
creates a new release.
Removes any existing release with the same title and version first before
returning the latest release to ensure it represents the current commit.
Returns:
dict: The release object for the latest matching release.
"""
latest_release = send_get_request(RELEASE_PATH + "/latest").json()
if latest_release["name"] == RELEASE_TITLE and latest_release["tag_name"] == RELEASE_VERSION:
return latest_release
all_releases = send_get_request(RELEASE_PATH)
for release in all_releases.json(): # List is sorted by latest first
# Remove Previous Release so Release is always based on Current Commit
for release in send_get_request(RELEASE_PATH).json():
if release["name"] == RELEASE_TITLE and release["tag_name"] == RELEASE_VERSION:
return release
send_delete_request(RELEASE_PATH + f"/{release['id']}")
send_delete_request(TAG_PATH + f"/{release['tag_name']}")
return create_new_release()
@ -237,6 +228,14 @@ def generate_checksum(archive_path: Path) -> str:
return digest.hexdigest()
def send_delete_request(url) -> Response:
response = requests.delete(url=f"{url}?token={API_TOKEN}")
if response.status_code != 204:
print(f"Error: {response.status_code}: '{response.reason}'")
sys.exit(1)
return response
def send_get_request(url: str) -> Response:
response = requests.get(url=f"{url}?token={API_TOKEN}")
if not (response.status_code == 200 or response.status_code == 404):