From c1b939fea87377705bead671721f68234dac74c1 Mon Sep 17 00:00:00 2001
From: Tim Jaacks <tim.jaacks@garz-fricke.com>
Date: Tue, 21 Jun 2022 15:59:11 +0200
Subject: [PATCH] Use CI variables in build template directly

The job generation script implicitly passes the OS environment to the
template, so that the template has access to all GitLab CI variables.
Hence there is no need to explicitly pass any of them as command line
arguments.

This change makes the "generate-build-jobs" job more generic, so that
it can be shared with the ci-test pipeline in the future.
---
 build-jobs.jinja2 | 48 +++++++++++++++++++++++------------------------
 manifest.yml      | 11 +++--------
 2 files changed, 27 insertions(+), 32 deletions(-)

diff --git a/build-jobs.jinja2 b/build-jobs.jinja2
index e3638a3..8d8cbc4 100644
--- a/build-jobs.jinja2
+++ b/build-jobs.jinja2
@@ -7,18 +7,18 @@
 # with checked out repository, we need to get the includes
 # directly from gitlab
 include:
-  - project: '{{ ci_project_root_namespace }}/yocto/infrastructure/gitlab-ci'
-    ref: {{ gitlab_ci_current_rev }}
+  - project: '{{ CI_PROJECT_ROOT_NAMESPACE }}/yocto/infrastructure/gitlab-ci'
+    ref: {{ GITLAB_CI_CURRENT_REV }}
     file: 'common.yml'
-  - project: '{{ ci_project_root_namespace }}/yocto/infrastructure/gitlab-ci'
-    ref: {{ gitlab_ci_current_rev }}
+  - project: '{{ CI_PROJECT_ROOT_NAMESPACE }}/yocto/infrastructure/gitlab-ci'
+    ref: {{ GITLAB_CI_CURRENT_REV }}
     file: 'manifest-build.yml'
-  - project: '{{ ci_project_root_namespace }}/yocto/infrastructure/gitlab-ci'
-    ref: {{ gitlab_ci_current_rev }}
+  - project: '{{ CI_PROJECT_ROOT_NAMESPACE }}/yocto/infrastructure/gitlab-ci'
+    ref: {{ GITLAB_CI_CURRENT_REV }}
     file: 'manifest-package.yml'
 
 variables:
-  MASTER_BRANCH_MANIFEST: {{ master_branch_manifest }}
+  MASTER_BRANCH_MANIFEST: {{ MASTER_BRANCH_MANIFEST }}
 
 workflow:
   rules:
@@ -41,7 +41,7 @@ changelog:
   extends: .infrastructure
   script: .gitlab-ci/scripts/changelog_generator.py
               --token=${GITBOT_TOKEN}
-              --branch {{ master_branch_manifest }}
+              --branch=${MASTER_BRANCH_MANIFEST}
               > changelog.md
   artifacts:
     expire_in: 4 weeks
@@ -52,18 +52,18 @@ changelog:
 # Generated build jobs
 # --------------------------------------------------------------------------------------
 
-{% if distro is not defined %}
-{% set distro = "guf-wayland" %}
+{% if CI_PARAM_DISTRO is not defined %}
+{% set CI_PARAM_DISTRO = "guf-wayland" %}
 {% endif %}
-{% if distro_fng is not defined %}
-{% set distro_fng = "guf-fngsystem" %}
+{% if CI_PARAM_DISTRO_FNG is not defined %}
+{% set CI_PARAM_DISTRO_FNG = "guf-fngsystem" %}
 {% endif %}
 
-{% if optional_arguments is defined %}
+{% if CI_PARAM_MACHINES is defined %}
 
-{% for machine in optional_arguments %}
+{% for machine in CI_PARAM_MACHINES.split(' ') %}
 
-{% if yocto_image %}
+{% if CI_PARAM_IMAGE %}
 
 # Build jobs for the normal yocto image
 build-{{ machine }}:
@@ -71,8 +71,8 @@ build-{{ machine }}:
   stage: build
   variables:
     CI_PARAM_MACHINE: {{ machine }}
-    CI_PARAM_DISTRO: {{ distro }}
-    CI_PARAM_IMAGE: {{ yocto_image }}
+    CI_PARAM_DISTRO: {{ CI_PARAM_DISTRO }}
+    CI_PARAM_IMAGE: {{ CI_PARAM_IMAGE }}
 
 # Build jobs for the sdk
 buildsdk-{{ machine }}:
@@ -80,8 +80,8 @@ buildsdk-{{ machine }}:
   stage: build
   variables:
     CI_PARAM_MACHINE: {{ machine }}
-    CI_PARAM_DISTRO: {{ distro }}
-    CI_PARAM_IMAGE: {{ yocto_image }}
+    CI_PARAM_DISTRO: {{ CI_PARAM_DISTRO }}
+    CI_PARAM_IMAGE: {{ CI_PARAM_IMAGE }}
 
 # Deploy jobs for the yocto image
 deployimage-{{ machine }}:
@@ -133,9 +133,9 @@ platformtest:{{ machine }}:
     CI_PARAM_PLATFORMS: {{ platforms }}
 {% endif %}
 
-{% endif %} # if yocto_image is defined
+{% endif %} # if CI_PARAM_IMAGE is defined
 
-{% if fngsystem_image %}
+{% if CI_PARAM_IMAGE_FNG %}
 
 # Build jobs for the fng system image
 build-{{ machine }}-fngsystem:
@@ -143,8 +143,8 @@ build-{{ machine }}-fngsystem:
   stage: build
   variables:
     CI_PARAM_MACHINE: {{ machine }}
-    CI_PARAM_DISTRO: {{ distro_fng }}
-    CI_PARAM_IMAGE: {{ fngsystem_image }}
+    CI_PARAM_DISTRO: {{ CI_PARAM_DISTRO_FNG }}
+    CI_PARAM_IMAGE: {{ CI_PARAM_IMAGE_FNG }}
 
 # Deploy jobs for the fngsystem image
 deployimage-{{ machine }}-fngsystem:
@@ -158,7 +158,7 @@ uploadftp-{{ machine }}-fngsystem:
   stage: uploadftp
   needs: [build-{{ machine }}-fngsystem, changelog]
 
-{% endif %} # if fngsystem_image is defined
+{% endif %} # if CI_PARAM_IMAGE_FNG is defined
 
 {% endfor %}
 {% endif %}
diff --git a/manifest.yml b/manifest.yml
index 5cfad0a..8485d51 100644
--- a/manifest.yml
+++ b/manifest.yml
@@ -90,16 +90,11 @@ generate-build-jobs:
   rules:
     - if: $CI_COMMIT_REF_NAME != $MASTER_BRANCH_MANIFEST || $CI_PIPELINE_SOURCE == "api"
   script:
+    # The job generation script implicitly passes the OS environment to the template, so
+    # that the template has access to all GitLab CI variables. Hence there is no need
+    # to explicitly pass any of them as command line arguments.
     - .gitlab-ci/scripts/generate_job_from_template.py
               --template=.gitlab-ci/build-jobs.jinja2
-              --distro=$CI_PARAM_DISTRO
-              --yocto_image=$CI_PARAM_IMAGE
-              --distro_fng=$CI_PARAM_DISTRO_FNG
-              --fngsystem_image=$CI_PARAM_IMAGE_FNG
-              --gitlab_ci_current_rev=$GITLAB_CI_CURRENT_REV
-              --ci_project_root_namespace=$CI_PROJECT_ROOT_NAMESPACE
-              --master_branch_manifest=$MASTER_BRANCH_MANIFEST
-              $CI_PARAM_MACHINES
               > build-jobs.yml
   artifacts:
     expire_in: 4 weeks
-- 
GitLab