From 69973c951efebb5c6c950ed6854ce31e3bb8633c Mon Sep 17 00:00:00 2001 From: Tim Jaacks <tim.jaacks@seco.com> Date: Thu, 12 Oct 2023 14:36:10 +0200 Subject: [PATCH] Deploy: save deployed files in dotenv variable instead of dedicated file Previously the deployed files were stored in a dedicated text file called files.txt. Move this information to a dotenv variable called FILES, so that we don't need special handling for it in the Confluence stage. --- build-pipeline.yml | 4 +- scripts/collect_release_information.py | 58 ++++---------------------- 2 files changed, 11 insertions(+), 51 deletions(-) diff --git a/build-pipeline.yml b/build-pipeline.yml index 2611206b..9675394c 100644 --- a/build-pipeline.yml +++ b/build-pipeline.yml @@ -387,10 +387,11 @@ workflow: rules: - when: manual allow_failure: true - before_script: + after_script: # Save MACHINE for confluence stage. This variable cannot be passed directly on the # job definition level because the confluence stage is machine-independent. - echo "MACHINE=${MACHINE}" > deploy.env + - echo "FILES=\"$(cat files.txt | tr '\n' ' ')\"" >> deploy.env timeout: 60m cache: # Get the packaged artifacts from the cache @@ -400,7 +401,6 @@ workflow: - release artifacts: paths: - - files.txt - "**/md5sums.txt" # Needed for later stage, but dotenv artifacts cannot be downloaded via GitLab API - deploy.env diff --git a/scripts/collect_release_information.py b/scripts/collect_release_information.py index b9251ccb..179ead06 100755 --- a/scripts/collect_release_information.py +++ b/scripts/collect_release_information.py @@ -16,18 +16,18 @@ from get_pipeline_jobs import get_pipeline_jobs def get_job_env_variables( gitlab: Gitlab, project: Project, jobs: list[ProjectPipelineJob], env_file: str ): - """Get a list of deploy variables from the deploy.env files from the given deploy - jobs. If a variable is set to different values in different jobs, the values are + """Get a list of variables from the env_file files from the given jobs. + If a variable is set to different values in different jobs, the values are concatenated and newline-separated. Args: gitlab: Gitlab object project: Gitlab project - jobs: list of deploy jobs - glob: pattern to match deployed file names against + jobs: list of jobs + env_file: name of the GitLab dotenv file to read variables from Returns: - Dictionary of deploy variables with 'name' and 'value' fields + Dictionary of variables with 'name' and 'value' fields """ variables = {} @@ -47,7 +47,7 @@ def get_job_env_variables( for line in lines: name, value = line.partition("=")[::2] - value = value.strip("'") + value = value.strip("'").strip('"') variables[name] = ( f"{variables[name]}\n{value}" if name in variables and variables[name] != value @@ -57,47 +57,6 @@ def get_job_env_variables( return variables -def get_deployed_files( - gitlab: Gitlab, project: Project, deploy_jobs: list[ProjectPipelineJob] -): - """Get a set of deployed files matching a glob from a list of deploy jobs. - - Args: - gitlab: Gitlab object - project: Gitlab project - jobs: list of deploy jobs - glob: pattern to match deployed file names against - - Returns: - Set of deployed file paths - """ - - artifacts = set() - deploy_list_file = "files.txt" - - for job in deploy_jobs: - - with tempfile.NamedTemporaryFile() as target_file: - print( - f"Downloading file {deploy_list_file} from job {job.name}", - file=sys.stderr, - ) - download_job_artifact( - gitlab, - target_file.name, - deploy_list_file, - job.id, - project=project, - ) - - lines = [line.decode("utf-8").rstrip() for line in target_file.readlines()] - - for line in lines: - artifacts.add(line) - - return sorted(artifacts) - - def main(): parser = argparse.ArgumentParser(description=__doc__, usage="%(prog)s [OPTIONS]") @@ -151,9 +110,10 @@ def main(): variables |= get_job_env_variables(gitlab, project, successful_jobs, "deploy.env") - files = get_deployed_files(gitlab, project, successful_jobs) + files = variables["FILES"].replace("\n", " ").split(" ") + + html_files = set(fnmatch.filter(files, "*.html")) - html_files = fnmatch.filter(files, "*.html") for html_file in html_files: variables["HTML_FILES"] = ( f"{variables['HTML_FILES']}\n{html_file}" -- GitLab