From 9bb1545a18744d3a4baa08e9b82bc2b4fc5edfd8 Mon Sep 17 00:00:00 2001 From: mark Date: Thu, 16 Feb 2023 10:12:35 +0000 Subject: [PATCH 1/2] 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/2] 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