Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-docs.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAchilleas Pipinellis <axil@gitlab.com>2022-07-27 10:10:40 +0300
committerAsh McKenzie <amckenzie@gitlab.com>2022-08-25 09:06:38 +0300
commit2d0daaaa361cc224e2c4676929d839cdf861865a (patch)
tree2495c711e01347793c18b164b2fd0540b7a7a4d0 /lib/tasks/build_site.rake
parentac45ff8515cffb0c8601a67d1087255bab32c958 (diff)
Split Rake tasks to their own files
Diffstat (limited to 'lib/tasks/build_site.rake')
-rw-r--r--lib/tasks/build_site.rake71
1 files changed, 71 insertions, 0 deletions
diff --git a/lib/tasks/build_site.rake b/lib/tasks/build_site.rake
new file mode 100644
index 00000000..af235dbe
--- /dev/null
+++ b/lib/tasks/build_site.rake
@@ -0,0 +1,71 @@
+# frozen_string_literal: true
+
+require './lib/tasks/task_helpers'
+require 'fileutils'
+require 'pathname'
+
+task_helpers = TaskHelpers.new
+
+task default: [:clone_repositories, :generate_feature_flags]
+
+task :setup_git do
+ puts "\n#{COLOR_CODE_GREEN}INFO: Setting up dummy user and email in Git..#{COLOR_CODE_RESET}"
+
+ `git config --global user.name "Sidney Jones"`
+ `git config --global user.email "sidneyjones@example.com"`
+end
+
+desc 'Clone Git repositories of documentation projects, keeping only the most recent commit'
+task :clone_repositories do
+ task_helpers.products.each_value do |product|
+ branch = task_helpers.retrieve_branch(product['slug'])
+
+ # Limit the pipeline to pull only the repo where the MR is, not all 4, to save time/space.
+ # First we check if the branch on the docs repo is other than the default branch and
+ # then we skip if the remote branch variable is the default branch name. Finally,
+ # check if the pipeline was triggered via the API (multi-project pipeline)
+ # to exclude the case where we create a branch right off the gitlab-docs
+ # project.
+ next if ENV["CI_COMMIT_REF_NAME"] != ENV['CI_DEFAULT_BRANCH'] \
+ && branch == ENV['CI_DEFAULT_BRANCH'] \
+ && ENV["CI_PIPELINE_SOURCE"] == 'pipeline'
+
+ puts "\n#{COLOR_CODE_GREEN}INFO: Cloning #{product['repo']}..#{COLOR_CODE_RESET}"
+
+ `git clone --branch #{branch} --single-branch #{product['repo']} --depth 1 #{product['project_dir']}`
+
+ # Print the latest commit from each project so that we can see which commit we're building from.
+ puts "\n#{COLOR_CODE_GREEN}INFO: Latest commit: #{`git -C #{product['project_dir']} log --oneline -n 1`}#{COLOR_CODE_RESET}"
+ end
+end
+
+desc 'Generate feature flags data file'
+task :generate_feature_flags do
+ feature_flags_dir = Pathname.new('..').join('gitlab', 'config', 'feature_flags').expand_path
+ feature_flags_ee_dir = Pathname.new('..').join('gitlab', 'ee', 'config', 'feature_flags').expand_path
+
+ abort("\n#{COLOR_CODE_RED}ERROR: The feature flags directory #{feature_flags_dir} does not exist.#{COLOR_CODE_RESET}") unless feature_flags_dir.exist?
+ abort("\n#{COLOR_CODE_RED}ERROR: The feature flags EE directory #{feature_flags_ee_dir} does not exist.#{COLOR_CODE_RESET}") unless feature_flags_ee_dir.exist?
+
+ paths = {
+ 'GitLab Community Edition and Enterprise Edition' => feature_flags_dir.join('**', '*.yml'),
+ 'GitLab Enterprise Edition only' => feature_flags_ee_dir.join('**', '*.yml')
+ }
+
+ feature_flags = {
+ products: {}
+ }
+
+ paths.each do |key, path|
+ feature_flags[:products][key] = []
+
+ Dir.glob(path).each do |feature_flag_yaml|
+ feature_flags[:products][key] << YAML.safe_load(File.read(feature_flag_yaml))
+ end
+ end
+
+ feature_flags_yaml = File.join('content', '_data', 'feature_flags.yaml')
+
+ puts "\n#{COLOR_CODE_GREEN}INFO: Generating #{feature_flags_yaml}..#{COLOR_CODE_RESET}"
+ File.write(feature_flags_yaml, feature_flags.to_yaml)
+end