forked from magento/devdocs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmultirepo.rake
51 lines (44 loc) · 2.07 KB
/
multirepo.rake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# Copyright © Magento, Inc. All rights reserved.
# See COPYING.txt for license details.
# frozen_string_literal: true
namespace :multirepo do
desc 'Create a file tree for devdocs website and get all required content'
task :init do
protocol = ENV['token'] ? "https://#{ENV['token']}@github.com/" : '[email protected]:'
@content_map.each do |subrepo|
repo_url = protocol + subrepo['repository'] + '.git'
add_subrepo(subrepo['directory'], repo_url, subrepo['branch'], subrepo['filter'])
end
end
desc 'Reinitialize subrepositories. CAUTION: This will remove directories and associated git repositories listed in Docfile'
task reinit: %w[clean] do
@content_map.each do |subrepo|
if subrepo['directory']
puts "Removing #{subrepo['directory']}".yellow
sh 'rm', '-rf', subrepo['directory']
end
end
Rake::Task['init'].invoke
end
desc 'Add multirepo docs providing shell arguments "dir=<directory where to init a repo>", "repo=<SSH URL>", "branch=<branch to checkout>", "filter=<true/false>" ("true" by default) to 1) filter content if "true" or 2) add content from the entire repository if "false".'
task :add do
dir = ENV['dir']
repo = ENV['repo']
branch = ENV['branch']
filter = ENV['filter']
abort 'Provide a directory name for the multirepo docs. Example: dir=src/mftf' unless dir
abort "'#{dir}' directory already exists" if Dir.exist? dir
unless repo
abort 'Provide a repository cloning URL (SSH).Example: [email protected]:magento-devdocs/magento2-functional-testing-framework.git'
end
abort 'Provide a branch name for the multirepo docs. Example: branch=master' unless branch
add_subrepo(dir, repo, branch, filter)
end
end
def add_subrepo(dir, repo, branch, filter)
filter_text = filter ? 'some' : 'all'
puts "Checking out #{filter_text} files from #{repo} (#{branch} branch) to the #{dir} directory ...".magenta
sh('./scripts/docs-from-code.sh', dir, repo, branch, filter.to_s) do |ok, _res|
abort "Couldn't checkout files for the #{repo} project".red unless ok
end
end