<NME> util.rb
<BEF> module Gitlab
  class Util
    class << self
      def get_env(key)
        ENV[key]&.strip
      end

      def set_env(key, value)
        ENV[key] = value&.strip
      end

      def set_env_if_missing(key, value)
        ENV[key] ||= value&.strip
      end

      def section(name, collapsed: true)
        return yield unless ENV['CI']

        name.tr!(':', '-')

        collapsed_mark = collapsed ? '[collapsed=true]' : ''
        $stdout.puts "section_start:#{Time.now.to_i}:#{name}#{collapsed_mark}\r\e[0K#{name}"

        yield

        $stdout.puts "section_end:#{Time.now.to_i}:#{name}\r\e[0K"
      end
    end
  end
end

<MSG> Run generate-facts in .com pipeline also

So that dotenv report can be generated in those pipelines, for the
triggers to use.

Signed-off-by: Balasankar "Balu" C <250a398eb3bfb9862062144cc742cc8f9bdd8d78@gitlab.com>

<DFF> @@ -2,7 +2,9 @@ module Gitlab
   class Util
     class << self
       def get_env(key)
-        ENV[key]&.strip
+        value = ENV[key]&.strip
+
+        value unless value&.empty?
       end
 
       def set_env(key, value)

{'commit': 'diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml\nindex ba68b8542..f99e79b6a 100644\n--- a/.gitlab-ci.yml\n+++ b/.gitlab-ci.yml\n@@ -184,10 +184,12 @@ generate-facts:\n     reports:\n       dotenv: build_facts/env_vars\n   rules:\n-    # Run on dev.gitlab.org and multi-project pipelines on omnibus-gitlab-mirror\n-    - if: \'$CI_PROJECT_PATH == "gitlab/omnibus-gitlab"\'\n-    - if: \'$CI_PIPELINE_SOURCE == "pipeline" && $CI_PROJECT_PATH == "gitlab-org/build/omnibus-gitlab-mirror"\'\n-    - if: \'$CI_PIPELINE_SOURCE == "schedule" && $CI_PROJECT_PATH == "gitlab-org/build/omnibus-gitlab-mirror"\'\n+    - if: \'$DEPS_PIPELINE || $CACHE_UPDATE || $DEPENDENCY_SCANNING\'\n+      when: never\n+    - if: \'$CI_BRANCH_NAME =~ /^[0-9]+-[0-9]+-auto-deploy-[0-9]+$/ || $CI_BRANCH_NAME =~ /^deps/\'\n+      when: never\n+    - when: always\n+  needs: []\n \n include:\n   - \'/gitlab-ci-config/gitlab-com.yml\'\ndiff --git a/gitlab-ci-config/gitlab-com.yml b/gitlab-ci-config/gitlab-com.yml\nindex 015c64d57..0f4867f23 100644\n--- a/gitlab-ci-config/gitlab-com.yml\n+++ b/gitlab-ci-config/gitlab-com.yml\n@@ -27,6 +27,12 @@\n       - $DEPS_PIPELINE || $CACHE_UPDATE || $DEPENDENCY_SCANNING\n       - $CI_COMMIT_REF_NAME =~ /^[0-9]+-[0-9]+-auto-deploy-[0-9]+$/\n \n+.com-branches-except-trigger: &com-branches-except-trigger\n+  only:\n+    - branches@gitlab-org/omnibus-gitlab\n+    - branches@gitlab-org/security/omnibus-gitlab\n+  <<: *com-except-triggers\n+\n .com-trigger-only: &com-trigger-only\n   only:\n     - triggers@gitlab-org/build/omnibus-gitlab-mirror\n@@ -135,31 +141,43 @@\n   retry: 1\n \n .trigger-job:\n-  extends: .gems-cache\n-  image: "${RUBY_IMAGE}"\n   stage: trigger-package\n+  inherit:\n+    variables: false\n+  variables:\n+    ALTERNATIVE_SOURCES: \'true\'\n+    BUILDER_IMAGE_REVISION: ${BUILDER_IMAGE_REVISION}\n+    BUILDER_IMAGE_REGISTRY: ${BUILDER_IMAGE_REGISTRY}\n+    PUBLIC_BUILDER_IMAGE_REGISTRY: ${PUBLIC_BUILDER_IMAGE_REGISTRY}\n+    COMPILE_ASSETS: ${COMPILE_ASSETS}\n+    GITLAB_VERSION: ${GITLAB_VERSION}\n+    GITLAB_SHELL_VERSION: ${GITLAB_SHELL_VERSION}\n+    GITLAB_PAGES_VERSION: ${GITLAB_PAGES_VERSION}\n+    GITALY_VERSION: ${GITALY_SERVER_VERSION}\n+    GITLAB_ELASTICSEARCH_INDEXER_VERSION: ${GITLAB_ELASTICSEARCH_INDEXER_VERSION}\n+    GITLAB_KAS_VERSION: ${GITLAB_KAS_VERSION}\n+    TOP_UPSTREAM_SOURCE_PROJECT: ${TOP_UPSTREAM_SOURCE_PROJECT}\n+    TOP_UPSTREAM_SOURCE_JOB: ${TOP_UPSTREAM_SOURCE_JOB}\n+    TOP_UPSTREAM_SOURCE_SHA: ${TOP_UPSTREAM_SOURCE_SHA}\n+    TOP_UPSTREAM_SOURCE_REF: ${TOP_UPSTREAM_SOURCE_REF}\n+    QA_BRANCH: ${QA_BRANCH}\n   when: manual\n-  script:\n-    - support/wait_for_sha\n-    - bundle exec rake build:trigger\n-  only:\n-    - branches@gitlab-org/omnibus-gitlab\n-    - branches@gitlab-org/security/omnibus-gitlab\n-  except:\n-    refs:\n-      - triggers\n-      - /^deps/\n-      - /(^docs[\\/-].*|.*-docs$)/\n-    variables:\n-      - $DEPS_PIPELINE || $CACHE_UPDATE || $DEPENDENCY_SCANNING\n-      - $CI_COMMIT_REF_NAME =~ /^[0-9]+-[0-9]+-auto-deploy-[0-9]+$/\n-  needs: []\n-  timeout: 3h\n+  trigger:\n+    project: \'gitlab-org/build/omnibus-gitlab-mirror\'\n+    branch: $CI_COMMIT_REF_NAME\n+    strategy: depend\n+  <<: *com-branches-except-trigger\n+  needs:\n+    - job: generate-facts\n+      artifacts: true\n+    - job: check-for-sha-in-mirror\n+      artifacts: false\n \n .trigger-pipeline:\n   stage: trigger-qa\n   image: "${RUBY_IMAGE}"\n   when: manual\n+  allow_failure: true\n   <<: *com-trigger-only\n   needs:\n     - job: Trigger:package\n@@ -244,6 +262,16 @@ update-trigger-package-cache:\n #     Branch pipeline     #\n ###########################\n \n+check-for-sha-in-mirror:\n+  extends: .gems-cache\n+  stage: check\n+  image: "${RUBY_IMAGE}"\n+  script:\n+    - support/wait_for_sha\n+  <<: *com-branches-except-trigger\n+  timeout: 3h\n+  needs: []\n+\n Trigger:ce-package:\n   extends: .trigger-job\n \n@@ -446,7 +474,6 @@ Trigger:package:\n   image: "${BUILDER_IMAGE_REGISTRY}/ubuntu_20.04:${BUILDER_IMAGE_REVISION}"\n   stage: trigger-package\n   script:\n-    - if [ -n "$TRIGGERED_USER" ] && [ -n "$TRIGGER_SOURCE" ]; then echo "Pipeline triggered by $TRIGGERED_USER at $TRIGGER_SOURCE"; fi\n     - *build-package\n     # Renaming so we can easily generate the artifact URL\n     - mv pkg/ubuntu-focal/*.deb pkg/ubuntu-focal/gitlab.deb\n@@ -484,7 +511,6 @@ Trigger:gitlab-docker:\n     - .gems-cache\n   stage: trigger-docker\n   script:\n-    - if [ -n "$TRIGGERED_USER" ] && [ -n "$TRIGGER_SOURCE" ]; then echo "Pipeline triggered by $TRIGGERED_USER at $TRIGGER_SOURCE"; fi\n     - bundle exec rake docker:build:image\n     - bundle exec rake docker:push:triggered\n   <<: *com-trigger-only\n@@ -501,7 +527,6 @@ Trigger:qa-docker:\n     - .gems-cache\n   stage: trigger-docker\n   script:\n-    - if [ -n "$TRIGGERED_USER" ] && [ -n "$TRIGGER_SOURCE" ]; then echo "Pipeline triggered by $TRIGGERED_USER at $TRIGGER_SOURCE"; fi\n     - bundle exec rake qa:build\n     - bundle exec rake qa:push:triggered\n   <<: *com-trigger-only\n@@ -551,7 +576,6 @@ letsencrypt-test:\n   extends: .docker_job\n   stage: trigger-qa\n   script:\n-    - if [ -n "$TRIGGERED_USER" ] && [ -n "$TRIGGER_SOURCE" ]; then echo "Pipeline triggered by $TRIGGERED_USER at $TRIGGER_SOURCE"; fi\n     - echo "${CI_REGISTRY_PASSWORD}" | docker login -u $CI_REGISTRY_USER --password-stdin $CI_REGISTRY\n     - curl -L "https://github.com/docker/compose/releases/download/1.29.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose\n     - chmod +x /usr/local/bin/docker-compose\n@@ -565,6 +589,7 @@ RAT:\n   stage: trigger-qa\n   image: "${RUBY_IMAGE}"\n   when: manual\n+  allow_failure: true\n   script:\n     - bundle exec rake qa:rat:trigger\n   <<: *com-trigger-only\ndiff --git a/lib/gitlab/build/facts.rb b/lib/gitlab/build/facts.rb\nindex 9f9e06049..151928874 100644\n--- a/lib/gitlab/build/facts.rb\n+++ b/lib/gitlab/build/facts.rb\n@@ -20,16 +20,17 @@ module Build\n         env_vars = []\n         env_vars += common_vars\n         env_vars += qa_trigger_vars\n+        env_vars += omnibus_trigger_vars\n \n         File.write("build_facts/env_vars", env_vars.join("\\n"))\n       end\n \n       def common_vars\n         %W[\n-          TOP_UPSTREAM_SOURCE_PROJECT=#{Gitlab::Util.get_env(\'TOP_UPSTREAM_SOURCE_PROJECT\')}\n-          TOP_UPSTREAM_SOURCE_REF=#{Gitlab::Util.get_env(\'TOP_UPSTREAM_SOURCE_REF\')}\n-          TOP_UPSTREAM_SOURCE_JOB=#{Gitlab::Util.get_env(\'TOP_UPSTREAM_SOURCE_JOB\')}\n-          TOP_UPSTREAM_SOURCE_SHA=#{Gitlab::Util.get_env(\'TOP_UPSTREAM_SOURCE_SHA\')}\n+          TOP_UPSTREAM_SOURCE_PROJECT=#{Gitlab::Util.get_env(\'TOP_UPSTREAM_SOURCE_PROJECT\') || Gitlab::Util.get_env(\'CI_PROJECT_PATH\')}\n+          TOP_UPSTREAM_SOURCE_REF=#{Gitlab::Util.get_env(\'TOP_UPSTREAM_SOURCE_REF\') || Gitlab::Util.get_env(\'CI_COMMIT_REF_NAME\')}\n+          TOP_UPSTREAM_SOURCE_JOB=#{Gitlab::Util.get_env(\'TOP_UPSTREAM_SOURCE_JOB\') || Gitlab::Util.get_env(\'CI_JOB_URL\')}\n+          TOP_UPSTREAM_SOURCE_SHA=#{Gitlab::Util.get_env(\'TOP_UPSTREAM_SOURCE_SHA\') || Gitlab::Util.get_env(\'CI_COMMIT_SHA\')}\n           TOP_UPSTREAM_MERGE_REQUEST_PROJECT_ID=#{Gitlab::Util.get_env(\'TOP_UPSTREAM_MERGE_REQUEST_PROJECT_ID\')}\n           TOP_UPSTREAM_MERGE_REQUEST_IID=#{Gitlab::Util.get_env(\'TOP_UPSTREAM_MERGE_REQUEST_IID\')}\n         ]\n@@ -47,6 +48,16 @@ module Build\n         ]\n       end\n \n+      def omnibus_trigger_vars\n+        version_vars\n+      end\n+\n+      def version_vars\n+        Gitlab::Version::COMPONENTS_ENV_VARS.values.uniq.map do |version|\n+          "#{version}=#{Gitlab::Util.get_env(version)}"\n+        end\n+      end\n+\n       private\n \n       def generate_knapsack_report?\ndiff --git a/lib/gitlab/util.rb b/lib/gitlab/util.rb\nindex 722e30cb2..99e2bf475 100644\n--- a/lib/gitlab/util.rb\n+++ b/lib/gitlab/util.rb\n@@ -2,7 +2,9 @@ module Gitlab\n   class Util\n     class << self\n       def get_env(key)\n-        ENV[key]&.strip\n+        value = ENV[key]&.strip\n+\n+        value unless value&.empty?\n       end\n \n       def set_env(key, value)\ndiff --git a/spec/gitlab/build/facts_spec.rb b/spec/gitlab/build/facts_spec.rb\nindex 6bfc3ef5f..c5f8d25cb 100644\n--- a/spec/gitlab/build/facts_spec.rb\n+++ b/spec/gitlab/build/facts_spec.rb\n@@ -34,10 +34,11 @@ RSpec.describe Build::Facts do\n     before do\n       allow(described_class).to receive(:common_vars).and_return(%w[TOP_UPSTREAM_SOURCE_PROJECT=gitlab-org/gitlab])\n       allow(described_class).to receive(:qa_trigger_vars).and_return(%w[QA_RELEASE=foobar])\n+      allow(described_class).to receive(:version_vars).and_return(%w[GITLAB_VERSION=randombranch])\n     end\n \n     it \'writes environment variables to file\' do\n-      expect(File).to receive(:write).with(\'build_facts/env_vars\', "TOP_UPSTREAM_SOURCE_PROJECT=gitlab-org/gitlab\\nQA_RELEASE=foobar")\n+      expect(File).to receive(:write).with(\'build_facts/env_vars\', "TOP_UPSTREAM_SOURCE_PROJECT=gitlab-org/gitlab\\nQA_RELEASE=foobar\\nGITLAB_VERSION=randombranch")\n \n       described_class.generate_env_file\n     end\n', 'commit_subject': 'Run generate-facts in .com pipeline also', 'repo_name': 'gitlabhq/omnibus-gitlab', 'committer': {'name': 'DJ Mountney', 'email': '10099878e72cf7e0ee4aa0cbce77aa8d5e6825f3@gitlab.com', 'time_sec': '1646337553', 'tz_offset': '0', 'date': {'seconds': '1646337553'}}, 'commit_tree': 'f713cbb4431484f949b765b29767e9c83d8c7f90', 'commit_message': 'Run generate-facts in .com pipeline also\n\nSo that dotenv report can be generated in those pipelines, for the\ntriggers to use.\n\nSigned-off-by: Balasankar "Balu" C <250a398eb3bfb9862062144cc742cc8f9bdd8d78@gitlab.com>\n', 'language_name': 'HTML', 'license': 'apache-2.0', 'hunks': '@@ -2,7 +2,9 @@ module Gitlab\n   class Util\n     class << self\n       def get_env(key)\n-        ENV[key]&.strip\n+        value = ENV[key]&.strip\n+\n+        value unless value&.empty?\n       end\n \n       def set_env(key, value)\n', 'addition_count': 3, 'deletion_count': 1, 'src_file': 'a/lib/gitlab/util.rb', 'tgt_file': 'b/lib/gitlab/util.rb', 'file_extension': '.rb', 'before_file': 'module Gitlab\n  class Util\n    class << self\n      def get_env(key)\n        ENV[key]&.strip\n      end\n\n      def set_env(key, value)\n        ENV[key] = value&.strip\n      end\n\n      def set_env_if_missing(key, value)\n        ENV[key] ||= value&.strip\n      end\n\n      def section(name, collapsed: true)\n        return yield unless ENV[\'CI\']\n\n        name.tr!(\':\', \'-\')\n\n        collapsed_mark = collapsed ? \'[collapsed=true]\' : \'\'\n        $stdout.puts "section_start:#{Time.now.to_i}:#{name}#{collapsed_mark}\\r\\e[0K#{name}"\n\n        yield\n\n        $stdout.puts "section_end:#{Time.now.to_i}:#{name}\\r\\e[0K"\n      end\n    end\n  end\nend\n', 'message': 'Run generate-facts in .com pipeline also\n\nSo that dotenv report can be generated in those pipelines, for the\ntriggers to use.\n\nSigned-off-by: Balasankar "Balu" C <250a398eb3bfb9862062144cc742cc8f9bdd8d78@gitlab.com>\n', 'author_name': 'DJ Mountney', 'lang': 'rb'}