Skip to content

Commit c8290ae

Browse files
committed
feat(RELEASE-2243): add file ordering for Content Gateway publishing
Checksum files (sha256sum.txt, sha256sum.txt.gpg, sha256sum.txt.sig) are now published first, followed by the remaining files in the order they are listed in the RPA. Each file includes an "order" field in its metadata payload so CGW displays them in a consistent, deterministic sequence. Assisted-by: Cursor AI Signed-off-by: Scott Wickersham <swickers@redhat.com>
1 parent b9693c7 commit c8290ae

File tree

3 files changed

+197
-204
lines changed

3 files changed

+197
-204
lines changed

publish-to-cgw-wrapper/publish_to_cgw_wrapper.py

Lines changed: 29 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -204,51 +204,36 @@ def generate_metadata(
204204
if mirror_openshift_Push:
205205
shortURL_base = "/pub/cgw"
206206

207-
# Build file_lookup from source field (using basename of source)
208-
file_lookup = {os.path.basename(file["source"]) for file in files}
209-
metadata = []
207+
dir_contents = set(os.listdir(content_dir))
208+
209+
# Checksum files first (fixed names, fixed order), then RPA files in their original order
210+
checksum_files = [
211+
("sha256sum.txt", "Checksum"),
212+
("sha256sum.txt.gpg", "Checksum - GPG"),
213+
("sha256sum.txt.sig", "Checksum - Signature"),
214+
]
215+
216+
ordered_files = [
217+
(name, label) for name, label in checksum_files if name in dir_contents
218+
] + [
219+
(os.path.basename(f["source"]), os.path.basename(f["source"]))
220+
for f in files
221+
if os.path.basename(f["source"]) in dir_contents
222+
]
210223

211-
for file_name in os.listdir(content_dir):
212-
if file_name in file_lookup:
213-
logging.info(f"Processing file: {file_name}")
214-
metadata.append(
215-
{
216-
**default_values_per_component,
217-
"shortURL": f"{shortURL_base}/{product_code}/{version_name}/{file_name}",
218-
"productVersionId": version_id,
219-
"downloadURL": generate_download_url(content_dir, file_name),
220-
"label": file_name,
221-
}
222-
)
223-
elif file_name.startswith("sha256") or file_name.startswith(component_name):
224-
logging.info(f"Processing file: {file_name}")
225-
label = None
226-
if file_name.endswith(".gpg"):
227-
label = "Checksum - GPG"
228-
elif file_name.endswith(".sig"):
229-
label = "Checksum - Signature"
230-
elif file_name.endswith(".txt"):
231-
label = "Checksum"
232-
233-
if label:
234-
metadata.append(
235-
{
236-
**default_values_per_component,
237-
"productVersionId": version_id,
238-
"downloadURL": generate_download_url(content_dir, file_name),
239-
"shortURL": (
240-
f"{shortURL_base}/{product_code}/{version_name}/{file_name}"
241-
),
242-
"label": label,
243-
}
244-
)
245-
else:
246-
# Skip files that arent listed in files and aren't a checksum.
247-
logging.warning(
248-
f"Skipping file: {file_name} "
249-
"as it's not listed in component 'files' and not a checksum."
250-
)
251-
continue
224+
metadata = []
225+
for order, (file_name, label) in enumerate(ordered_files, start=1):
226+
logging.info(f"Processing file: {file_name} (order={order}, label={label})")
227+
metadata.append(
228+
{
229+
**default_values_per_component,
230+
"shortURL": f"{shortURL_base}/{product_code}/{version_name}/{file_name}",
231+
"productVersionId": version_id,
232+
"downloadURL": generate_download_url(content_dir, file_name),
233+
"label": label,
234+
"order": order,
235+
}
236+
)
252237

253238
return metadata
254239

0 commit comments

Comments
 (0)