PLugin versioning fixes

This commit is contained in:
IGNY8 VPS (Salman)
2026-01-09 23:36:03 +00:00
parent 4343f62140
commit 0ea3a30909
7 changed files with 441 additions and 115 deletions

View File

@@ -23,58 +23,68 @@ def auto_build_plugin_on_release(sender, instance, **kwargs):
1. ZIP file is always up-to-date with source code
2. File size and checksum are auto-calculated
3. No manual intervention needed for releases
Triggers on:
- New version created with status 'released' or 'update_ready'
- Existing version status changed to 'released' or 'update_ready'
"""
# Skip if this is a new instance (no pk yet)
if not instance.pk:
return
try:
# Get the old instance to check for status change
old_instance = PluginVersion.objects.get(pk=instance.pk)
except PluginVersion.DoesNotExist:
return
# Check if status is changing TO 'released' or 'update_ready'
release_statuses = ['released', 'update_ready']
old_status = old_instance.status
new_status = instance.status
# Only trigger build if:
# 1. Status is changing
# 2. New status is a release status
# 3. Old status was not a release status (avoid rebuilding on every save)
if old_status == new_status:
# Check if this version should have a ZIP built
should_build = False
if not instance.pk:
# New instance - build if status is a release status
if instance.status in release_statuses:
should_build = True
logger.info(f"New plugin version {instance.plugin.slug} v{instance.version} created with status '{instance.status}' - building ZIP")
else:
# Existing instance - check if status changed to a release status
try:
old_instance = PluginVersion.objects.get(pk=instance.pk)
old_status = old_instance.status
new_status = instance.status
# Build if moving to a release status from a non-release status
if new_status in release_statuses and old_status not in release_statuses:
should_build = True
logger.info(f"Building plugin ZIP for {instance.plugin.slug} v{instance.version} (status: {old_status} -> {new_status})")
elif old_status == new_status and new_status in release_statuses:
# No status change, but already released - no rebuild
return
elif old_status in release_statuses and new_status in release_statuses:
# Moving between release statuses - no rebuild
logger.info(f"Plugin {instance.plugin.slug} v{instance.version}: Status changing from {old_status} to {new_status}, no rebuild needed")
return
except PluginVersion.DoesNotExist:
return
if not should_build:
return
if new_status not in release_statuses:
return
# If moving from one release status to another, don't rebuild
if old_status in release_statuses:
logger.info(f"Plugin {instance.plugin.slug} v{instance.version}: Status changing from {old_status} to {new_status}, no rebuild needed")
return
logger.info(f"Building plugin ZIP for {instance.plugin.slug} v{instance.version} (status: {old_status} -> {new_status})")
# Build the ZIP
file_path, checksum, file_size = create_plugin_zip(
platform=instance.plugin.platform,
plugin_slug=instance.plugin.slug,
version=instance.version,
update_version=True
)
if not file_path:
logger.error(f"Failed to build ZIP for {instance.plugin.slug} v{instance.version}")
return
# Update the instance with new file info
instance.file_path = file_path
instance.checksum = checksum
instance.file_size = file_size
# Set released_at if moving to released status and not already set
if new_status in release_statuses and not instance.released_at:
instance.released_at = timezone.now()
logger.info(f"Built plugin ZIP: {file_path} ({file_size} bytes, checksum: {checksum[:16]}...)")
try:
file_path, checksum, file_size = create_plugin_zip(
platform=instance.plugin.platform,
plugin_slug=instance.plugin.slug,
version=instance.version,
update_version=True
)
if not file_path:
logger.error(f"Failed to build ZIP for {instance.plugin.slug} v{instance.version}")
return
# Update the instance with new file info
instance.file_path = file_path
instance.checksum = checksum
instance.file_size = file_size
# Set released_at if not already set
if not instance.released_at:
instance.released_at = timezone.now()
logger.info(f"Built plugin ZIP: {file_path} ({file_size} bytes, checksum: {checksum[:16]}...)")
except Exception as e:
logger.error(f"Error building ZIP for {instance.plugin.slug} v{instance.version}: {e}")