From 9bb1545a18744d3a4baa08e9b82bc2b4fc5edfd8 Mon Sep 17 00:00:00 2001 From: mark Date: Thu, 16 Feb 2023 10:12:35 +0000 Subject: [PATCH 1/6] Adding code to generate attachments post-meeting --- create_attachments.py | 60 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 create_attachments.py diff --git a/create_attachments.py b/create_attachments.py new file mode 100644 index 0000000..9f5f026 --- /dev/null +++ b/create_attachments.py @@ -0,0 +1,60 @@ +from io import BytesIO +from pathlib import Path +import logging +import zipfile + +# For ETSI portal attachments, a single zip archive is created which +# contains: +# - All files in the top-level spec directory +# - A zipfile for each subdirectory, which contains all the files in that subdirectory +# This second step is recursive, so each zip file contains only files and other zipfiles, never subdirectories +# For an explanation as to *why* this is the case, speak to your ETSI technical officer. +# +# Example: Assuming the files for the portal attachment are of the following form: +# +# (contents of directory) +# - top_level_file.ext +# - subdirectory_1 +# - subdirectory_1_file.ext +# - subdirectory_2 +# - subdirectory_2_file.ext +# - TS 102 232-1 +# +# ...then the correct form for ETSI portal attachments is as follows +# +# ts_xxxxxx_vxxyyzzp0.zip +# which contains: +# - top_level_file.ext +# - subdirectory_1.zip +# (which contains) +# - subdirectory_1_file.ext +# - subdirectory_2.zip +# (which contains) +# - subdirectory_2_file.ext + + +def recursively_zip_directory(directory: Path, zipname: str, recursion=0): + logging.info( + f"{'':{recursion * 4}}Packaging contents of {directory} into {zipname}" + ) + buffer = BytesIO() + zip = zipfile.ZipFile(buffer, "a") + for f in directory.iterdir(): + if f.is_file(): + logging.info(f"{'':{recursion * 4}}Adding file: {f}") + zip.write(f, f.name) + elif f.is_dir(): + zipname = f.with_suffix(".zip").name + logging.info(f"{'':{recursion * 4}}Adding archive: {f}") + recurse_buffer = recursively_zip_directory(f, zipname, recursion + 1) + zip.writestr(zipname, recurse_buffer.getvalue()) + return buffer + + +if __name__ == "__main__": + logging.info("Creating attachments...") + for directory in Path(".").glob("1*"): + zip_name = f"ts_{directory.name}vXXYYZZp0.zip" + zip_buffer = recursively_zip_directory(directory, zip_name) + with open(zip_name, "wb") as f: + f.write(zip_buffer.getvalue()) -- GitLab From 596c2fb0aff64a40e80f387a3e8d92cbde676e13 Mon Sep 17 00:00:00 2001 From: mark Date: Thu, 16 Feb 2023 10:57:53 +0000 Subject: [PATCH 2/6] Modifying CI/CD to generate attachments --- .gitlab-ci.yml | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index a8ec525..f175a8a 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,3 +1,6 @@ +variables: + meeting_pattern: '/meeting.*/' + workflow: rules: - if: $CI_PIPELINE_SOURCE == "merge_request_event" @@ -39,6 +42,7 @@ generate_artefacts: interruptible: true rules: - if: $CI_PIPELINE_SOURCE == 'merge_request_event' + - if: $CI_MERGE_REQUEST_SOURCE_BRANCH_NAME !~ $meeting_pattern script: - echo $CI_PROJECT_ID - echo $CI_PROJECT_NAME @@ -55,3 +59,26 @@ generate_artefacts: - "*.docx" name: $CI_MERGE_REQUEST_TITLE expire_in: 30 days + +generate_attachments: + image: "forge.etsi.org:5050/li/schemas-definitions/forgelib" + stage: build + interruptible: true + rules: + - if: $CI_PIPELINE_SOURCE == 'merge_request_event' + - if: $CI_MERGE_REQUEST_SOURCE_BRANCH_NAME =~ $meeting_pattern + script: + - echo $CI_PROJECT_ID + - echo $CI_PROJECT_NAME + - echo $CI_PROJECT_PATH + - echo $CI_PIPELINE_SOURCE + - echo $CI_OPEN_MERGE_REQUESTS + - echo $CI_MERGE_REQUEST_IID + - echo $CI_MERGE_REQUEST_SOURCE_BRANCH_NAME + - echo $ARTEFACT_NAME + - python create_attachments.py + artifacts: + untracked: true + paths: + - "*.zip" + expire_in: 30 days -- GitLab From f6e48b3c4640f213b733913786ea7ef6fe809dc2 Mon Sep 17 00:00:00 2001 From: mark Date: Thu, 16 Feb 2023 11:07:52 +0000 Subject: [PATCH 3/6] Correcting CI/CD yaml --- .gitlab-ci.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index f175a8a..f673c09 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -41,8 +41,7 @@ generate_artefacts: stage: build interruptible: true rules: - - if: $CI_PIPELINE_SOURCE == 'merge_request_event' - - if: $CI_MERGE_REQUEST_SOURCE_BRANCH_NAME !~ $meeting_pattern + - if: $CI_PIPELINE_SOURCE == 'merge_request_event' && $CI_MERGE_REQUEST_SOURCE_BRANCH_NAME !~ $meeting_pattern script: - echo $CI_PROJECT_ID - echo $CI_PROJECT_NAME -- GitLab From 6c05cb5c38554ea4cdf31ca86ff2ff6fceeac3a4 Mon Sep 17 00:00:00 2001 From: mark Date: Thu, 16 Feb 2023 11:08:30 +0000 Subject: [PATCH 4/6] Removing f-strings --- create_attachments.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/create_attachments.py b/create_attachments.py index 9f5f026..4beaaa0 100644 --- a/create_attachments.py +++ b/create_attachments.py @@ -1,6 +1,5 @@ from io import BytesIO from pathlib import Path -import logging import zipfile # For ETSI portal attachments, a single zip archive is created which @@ -34,25 +33,19 @@ import zipfile def recursively_zip_directory(directory: Path, zipname: str, recursion=0): - logging.info( - f"{'':{recursion * 4}}Packaging contents of {directory} into {zipname}" - ) buffer = BytesIO() zip = zipfile.ZipFile(buffer, "a") for f in directory.iterdir(): if f.is_file(): - logging.info(f"{'':{recursion * 4}}Adding file: {f}") zip.write(f, f.name) elif f.is_dir(): zipname = f.with_suffix(".zip").name - logging.info(f"{'':{recursion * 4}}Adding archive: {f}") recurse_buffer = recursively_zip_directory(f, zipname, recursion + 1) zip.writestr(zipname, recurse_buffer.getvalue()) return buffer if __name__ == "__main__": - logging.info("Creating attachments...") for directory in Path(".").glob("1*"): zip_name = f"ts_{directory.name}vXXYYZZp0.zip" zip_buffer = recursively_zip_directory(directory, zip_name) -- GitLab From 3bb244d63039bd4d4d72e1fe88e120686a01c9a9 Mon Sep 17 00:00:00 2001 From: mark Date: Thu, 16 Feb 2023 11:14:17 +0000 Subject: [PATCH 5/6] Attempting to expose attachments on MR page --- .gitlab-ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index f673c09..f548766 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -78,6 +78,7 @@ generate_attachments: - python create_attachments.py artifacts: untracked: true + expose_as: 'Zip attachments' paths: - "*.zip" expire_in: 30 days -- GitLab From 51ea975386df349354ef1737689aa9060b114a62 Mon Sep 17 00:00:00 2001 From: mark Date: Thu, 16 Feb 2023 11:21:19 +0000 Subject: [PATCH 6/6] That didn't work --- .gitlab-ci.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index f548766..f673c09 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -78,7 +78,6 @@ generate_attachments: - python create_attachments.py artifacts: untracked: true - expose_as: 'Zip attachments' paths: - "*.zip" expire_in: 30 days -- GitLab