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