Skip to content

Commit

Permalink
cleanup, fix order logic, really delete files
Browse files Browse the repository at this point in the history
  • Loading branch information
gsanchietti committed Feb 5, 2024
1 parent 766356f commit c714df7
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions builder/cleanup/cleanup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ def owrt_version(release):
raise ValueError(f"Invalid OpenWrt release format: {release}")

def ns_version(version):
# convert from 0.0.1-beta1-3-g4c5b89a to 0.0.1-beta1.3
# to correctly sort build part
if version.count('-') > 1:
parts = version.split('-')
version = parts[0] + '-' + parts[1] + '.' + parts[2]
try:
return semver.VersionInfo.parse(version)
except ValueError:
Expand All @@ -46,17 +51,20 @@ def ns_version(version):
# Sort by OpenWrt release
owrt_sorted = sorted(unordered_versions, key=lambda x: owrt_version(x))
# Sort by NethSecurity release
sorted_dev = sorted(owrt_sorted, key=lambda v: ns_version(v))
sorted_dev = sorted(owrt_sorted, key=lambda v: ns_version(v[13:]), reverse=True)
to_delete = []
keep = 0
for version in sorted_dev:
sversion = ns_version(version[13:])
# keep at least max_versions of each sub release like 8-23.05.2-ns.0.0.1-beta1-3-g4c5b89a
if '-' in sversion.prerelease and len(to_delete) < max_versions:
to_delete.append(version)
if sversion.prerelease and '.' in sversion.prerelease:
keep += 1
if keep > max_versions:
to_delete.append(version)

for d in to_delete:
print(f"Deleting {d} ...")
objects_to_delete = s3_client.list_objects(Bucket=bucket_name, Prefix=f"{prefix}/{d}/")
delete_keys = {'Objects' : []}
delete_keys['Objects'] = [{'Key' : k} for k in [obj['Key'] for obj in objects_to_delete.get('Contents', [])] ]
#s3_client.delete_objects(Bucket=bucket_name, Delete=delete_keys)
s3_client.delete_objects(Bucket=bucket_name, Delete=delete_keys)

0 comments on commit c714df7

Please sign in to comment.