From 897ba05909d14939c1e044de8f71b95f0074534f Mon Sep 17 00:00:00 2001
From: Tim Jaacks <tim.jaacks@seco.com>
Date: Mon, 9 Jan 2023 10:50:26 +0100
Subject: [PATCH] Manifest integration: remove dynamic job generation

The dynamic job was only necessary because GitLab did not expand
variables in the "trigger:project" keyword:
https://gitlab.com/gitlab-org/gitlab/-/issues/347469

This has been fixed in GitLab 15.3, so we don't need it anymore:
https://gitlab.com/gitlab-org/gitlab/-/merge_requests/92346
---
 ...ml.jinja2 => manifest-integration-jobs.yml | 11 ++---
 manifest-integration-pipelines.yml.jinja2     | 47 ++-----------------
 2 files changed, 6 insertions(+), 52 deletions(-)
 rename manifest-integration-jobs.yml.jinja2 => manifest-integration-jobs.yml (85%)

diff --git a/manifest-integration-jobs.yml.jinja2 b/manifest-integration-jobs.yml
similarity index 85%
rename from manifest-integration-jobs.yml.jinja2
rename to manifest-integration-jobs.yml
index 1553845d..fe049d0d 100644
--- a/manifest-integration-jobs.yml.jinja2
+++ b/manifest-integration-jobs.yml
@@ -3,11 +3,8 @@
 # Global
 # --------------------------------------------------------------------------------------
 include:
-  # FIXME: see FIXME comments in manifest-integration-pipelines.yml.jinja2
-  # - project: '${CI_PROJECT_ROOT_NAMESPACE}/yocto/infrastructure/gitlab-ci'
-  #   ref: ${GITLAB_CI_REVISION}
-  - project: {{ CI_PROJECT_ROOT_NAMESPACE }}/yocto/infrastructure/gitlab-ci
-    ref: {{ GITLAB_CI_REVISION }}
+  - project: '${CI_PROJECT_ROOT_NAMESPACE}/yocto/infrastructure/gitlab-ci'
+    ref: ${GITLAB_CI_REVISION}
     file: common.yml
 
 workflow:
@@ -57,9 +54,7 @@ build:
       when: never
     - if: $CI_MERGE_REQUEST_IID
   trigger:
-    # FIXME: see FIXME comments in manifest-integration-pipelines.yml.jinja2
-    # project: $TARGET_PROJECT
-    project: {{ TARGET_PROJECT }}
+    project: $TARGET_PROJECT
     branch: "integrate/${CI_PROJECT_NAME}/${CI_COMMIT_REF_NAME}/into/${TARGET_BRANCH}"
     strategy: depend
 
diff --git a/manifest-integration-pipelines.yml.jinja2 b/manifest-integration-pipelines.yml.jinja2
index 6eb9ee66..cf637459 100644
--- a/manifest-integration-pipelines.yml.jinja2
+++ b/manifest-integration-pipelines.yml.jinja2
@@ -14,42 +14,6 @@ workflow:
 stages:
   - manifest-integration-pipelines
 
-# --------------------------------------------------------------------------------------
-# Generate job
-# --------------------------------------------------------------------------------------
-# Use one single job to generate multiple yaml files for the downstream pipelines.
-# FIXME: This is only necessary due to a GitLab limitation:
-# https://gitlab.com/gitlab-org/gitlab/-/issues/347469
-# We work around this by generating manifest-integration-jobs.yml from a Jinja2 template
-# and insert the trigger project via a Jinja2 variable.
-# The issue is already fixed and will be released in GitLab 15.3:
-# https://gitlab.com/gitlab-org/gitlab/-/merge_requests/92346
-# As soon as we update to this version, we can get rid of the generate job and convert
-# the Jinja2 template to a simple YAML file.
-generate:
-  extends:
-    - .infrastructure
-  stage: manifest-integration-pipelines
-  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.
-{% for integration in INTEGRATION.split('\n') %}
-{% set SOURCE_BRANCH, TARGET_PROJECT, TARGET_BRANCH = integration.split(':') %}
-{% if (CI_MERGE_REQUEST_TARGET_BRANCH_NAME is defined
-      and SOURCE_BRANCH == CI_MERGE_REQUEST_TARGET_BRANCH_NAME)
-      or SOURCE_BRANCH == CI_COMMIT_REF_NAME %}
-    - TARGET_PROJECT={{ TARGET_PROJECT }}
-        .gitlab-ci/scripts/generate_job_from_template.py
-        --template=.gitlab-ci/manifest-integration-jobs.yml.jinja2
-        > manifest-integration-jobs-{{ loop.index }}.yml
-{% endif %}
-{% endfor %}
-  artifacts:
-    expire_in: 4 weeks
-    paths:
-      - manifest-integration-jobs-*.yml
-
 # --------------------------------------------------------------------------------------
 # Trigger jobs
 # --------------------------------------------------------------------------------------
@@ -61,8 +25,6 @@ generate:
 
 {{ TARGET_PROJECT }}:{{ TARGET_BRANCH }}:
   stage: manifest-integration-pipelines
-  needs:
-    - generate
   variables:
     SOURCE_BRANCH: {{ SOURCE_BRANCH }}
     TARGET_PROJECT: {{ TARGET_PROJECT }}
@@ -72,12 +34,9 @@ generate:
     BB_RECIPE_NAME: {{ BB_RECIPE_NAME }}
   trigger:
     include:
-      # FIXME: Use these settings after switching from jinja2 to yaml (see above)
-      # project: '${CI_PROJECT_ROOT_NAMESPACE}/yocto/infrastructure/gitlab-ci'
-      # ref: ${GITLAB_CI_REVISION}
-      # file: manifest-integration-jobs.yml
-      artifact: manifest-integration-jobs-{{ loop.index }}.yml
-      job: generate
+      project: '${CI_PROJECT_ROOT_NAMESPACE}/yocto/infrastructure/gitlab-ci'
+      ref: ${GITLAB_CI_REVISION}
+      file: manifest-integration-jobs.yml
     strategy: depend
 
 {% endif %}
-- 
GitLab