diff options
Diffstat (limited to 'Rakefile')
-rw-r--r-- | Rakefile | 65 |
1 files changed, 65 insertions, 0 deletions
@@ -132,6 +132,71 @@ namespace :release do puts "\n#{COLOR_CODE_GREEN}INFO: Created new Dockerfile:#{COLOR_CODE_RESET} #{dockerfile}." puts "#{COLOR_CODE_GREEN}INFO: To push the new branch, run:#{COLOR_CODE_RESET} git push origin #{version}." end + + desc 'Creates merge requests to update the dropdowns in all online versions' + task :dropdowns do + # Check if you're on the default branch before starting. Fail if you are. + abort("\n#{COLOR_CODE_RED}ERROR: You are on the default branch. Create the current release branch and run the Rake task again.#{COLOR_CODE_RESET}") if `git branch --show-current`.tr("\n", '') == ENV['CI_DEFAULT_BRANCH'] + + # Load online versions + versions = YAML.load_file('./content/_data/versions.yaml') + + # The first online version should be the current stable one + current_version = versions['online'].first + + # The release branch name + release_branch = "release-#{current_version.tr('.', '-')}" + + # Check if a release branch has been created, if not fail and warn the user + abort("\n#{COLOR_CODE_RED}ERROR: A release branch for the latest stable version has not been created.#{COLOR_CODE_RESET}") if `git rev-parse --verify #{release_branch}`.empty? + + # Create a merge request to update the dropdowns in all online versions + versions['online'].each do |version| + # Set the commit title + mr_title = "Update #{version} dropdown to match that of #{current_version}" + mr_description = "Update version dropdown of #{version} release for the #{current_version} release." + branch_name = "update-#{version.tr('.', '-')}-for-release-#{current_version.tr('.', '-')}" + + puts "\n#{COLOR_CODE_GREEN}INFO: Fetching #{version} stable branch..#{COLOR_CODE_RESET}" + `git fetch origin #{version}` + + puts "\n#{COLOR_CODE_GREEN}INFO: Creating a new branch off of the online version..#{COLOR_CODE_RESET}" + `git checkout -b #{branch_name} origin/#{version}` + `git reset --hard origin/#{version}` + + puts "\n#{COLOR_CODE_GREEN}INFO: Copying the versions.yaml content from the release-#{current_version} branch..#{COLOR_CODE_RESET}" + `git checkout release-#{current_version.tr('.', '-')} -- content/_data/versions.yaml` + + puts "\n#{COLOR_CODE_GREEN}INFO: Committing and pushing to create a merge request..#{COLOR_CODE_RESET}" + `git commit -m "Update dropdown to #{current_version}"` + `git push --set-upstream origin #{branch_name} -o merge_request.create -o merge_request.target=#{version} -o merge_request.remove_source_branch -o merge_request.title="#{mr_title}" -o merge_request.description="#{mr_description}" -o merge_request.label="Technical Writing" -o merge_request.label="release" -o merge_request.label="Category:Docs Site" -o merge_request.label="type::maintenance"` + end + + # Create a merge request to update the dropdowns in all previous major online versions + versions['previous_majors'].each do |version| + # Set the commit title + mr_title = "Update #{version} dropdown to match that of #{current_version}" + mr_description = "Update version dropdown of #{version} release for the #{current_version} release." + branch_name = "update-#{version.tr('.', '-')}-for-release-#{current_version.tr('.', '-')}" + + puts "\n#{COLOR_CODE_GREEN}INFO: Fetching #{version} stable branch..#{COLOR_CODE_RESET}" + `git fetch origin #{version}` + + puts "\n#{COLOR_CODE_GREEN}INFO: Creating a new branch off of the online version..#{COLOR_CODE_RESET}" + `git checkout -b #{branch_name} origin/#{version}` + `git reset --hard origin/#{version}` + + puts "\n#{COLOR_CODE_GREEN}INFO: Copying the versions.yaml content from the release-#{current_version} branch..#{COLOR_CODE_RESET}" + `git checkout release-#{current_version.tr('.', '-')} -- content/_data/versions.yaml` + + puts "\n#{COLOR_CODE_GREEN}INFO: Committing and pushing to create a merge request..#{COLOR_CODE_RESET}" + `git commit -m "Update dropdown to #{current_version}"` + `git push --set-upstream origin #{branch_name} -o merge_request.create -o merge_request.target=#{version} -o merge_request.remove_source_branch -o merge_request.title="#{mr_title}" -o merge_request.description="#{mr_description}" -o merge_request.label="Technical Writing" -o merge_request.label="release" -o merge_request.label="Category:Docs Site" -o merge_request.label="type::maintenance"` + end + + # Switch back to the release branch after the dropdowns are pushed + `git checkout #{release_branch}` + end end desc 'Create the _redirects file' |