Skip to content

Commit 23f0d16

Browse files
gursewak1997jlebon
authored andcommitted
cmd-cloud-prune: Fix indent-level for json and compare only builds data
For consistency, keep the json indent level to 4 and also, only compare the respective json's build data instead of the whole file since we do update the timestamp in the builds.json in save_builds_json. Also double-check the size of builds array is the same after modifying
1 parent 77118ab commit 23f0d16

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/cmd-cloud-prune

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ def get_json_from_s3(s3, bucket, key):
203203
def save_builds_json(builds_json_data, location):
204204
builds_json_data["timestamp"] = datetime.datetime.now(pytz.utc).strftime("%Y-%m-%dT%H:%M:%SZ")
205205
with open(location, "w") as json_file:
206-
json.dump(builds_json_data, json_file, indent=2)
206+
json.dump(builds_json_data, json_file, indent=4)
207207

208208

209209
def handle_upload_builds_json(s3_client, bucket, prefix, dry_run, acl):
@@ -217,7 +217,7 @@ def handle_upload_builds_json(s3_client, bucket, prefix, dry_run, acl):
217217

218218
# If there are no changes to the local builds/builds.json we won't need to upload
219219
# anything to the s3 bucket. Will return in this scenario.
220-
if builds_json_source_data == current_builds_json:
220+
if builds_json_source_data.get('builds') == current_builds_json.get('builds'):
221221
print("There are no changes to the local builds/builds.json. No upload needed")
222222
return
223223

@@ -233,11 +233,16 @@ def handle_upload_builds_json(s3_client, bucket, prefix, dry_run, acl):
233233

234234
# Print the updated builds.json before the s3 update
235235
with open(BUILDFILES['list'], 'r') as file:
236-
data = json.load(file)
236+
updated_builds_json = json.load(file)
237237
print("----")
238-
print(json.dumps(data, indent=4))
238+
print(json.dumps(updated_builds_json, indent=4))
239239
print("----")
240240

241+
with open(BUILDFILES['sourcedata'], 'r') as file:
242+
builds_json_source_data = json.load(file)
243+
# Make sure the size of the builds array is the same in the original and our modified builds.json
244+
assert len(builds_json_source_data.get('builds')) == len(updated_builds_json.get('builds'))
245+
241246
# Before uploading builds.json, copy the updated tmp/builds-source.json as builds.json.bak as a backup
242247
s3_copy(s3_client, BUILDFILES['sourcedata'], bucket, f'{prefix}/builds.json.bak', CACHE_MAX_AGE_METADATA, acl, extra_args={}, dry_run=dry_run)
243248

0 commit comments

Comments
 (0)