/
Fastfile
131 lines (118 loc) · 4.74 KB
/
Fastfile
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
lane :test do
Dir.chdir("..") do
build_site
ensure_filenames
ensure_redirects
ensure_headers
ensure_image_assets
ensure_assets_location
ensure_tool_name_formatting
end
end
lane :post_slack_deploy_message do
slack(message: "Deployed a new version of [docs.fastlane.tools](https://docs.fastlane.tools)",
channel: "#new-docs",
default_payloads: [])
end
lane :update_available_plugins do
Fastlane::PluginFetcher.update_md_file!(output_path: "../docs/plugins/AvailablePlugins.md")
end
private_lane :build_site do
UI.message "🕗 Building page..."
sh "mkdocs build --clean --strict" # to make sure building is successful
UI.success "✅ Build successful"
end
private_lane :ensure_filenames do
UI.message "🕗 Making sure file names are all lowercase..."
Dir["docs/**/*.md"].each do |current_file|
if current_file =~ /[A-Z]/
UI.user_error!(".md files must not be upper case, use dash instead (file '#{current_file}')")
end
end
UI.success "✅ All doc files are properly named to not be camel case"
end
private_lane :ensure_redirects do
UI.message "🕗 Making sure the forwards are set up properly..."
require_relative "scripts/ci/available_redirects"
docs_redirects.each do |from, to|
UI.user_error!("redirects must not include an extension") if (from + to).include?(".")
full_to_path = File.join("docs", "#{to.chomp('/')}.md")
unless File.exist?(full_to_path)
UI.user_error!("Couldn't find file that is being redirected to '#{full_to_path}' from '#{from}'")
end
end
UI.success "✅ All forwards are cool"
end
private_lane :ensure_headers do
UI.message "🕗 Investigating all docs files and their headers..."
exceptions = ["docs/index.md"]
errors = []
Dir["docs/**/*.md"].each do |current_file|
next if exceptions.include?(current_file)
errors << "File '#{current_file}' doesn't start with #" unless File.read(current_file).start_with?("#")
end
errors.each { |e| UI.error(e) }
UI.user_error!("At least one file doesn't start with header one (#), the first line must always be # title") unless errors.empty?
UI.success "✅ All doc files start with a header"
end
private_lane :ensure_image_assets do
UI.message "🕗 Checking docs for dead image references..."
errors = []
Dir["docs/**/*.md"].each do |current_file|
content = File.read(current_file)
matches = []
["png", "jpg", "gif"].each do |extension|
matches += content.scan(/\!\[.*\]\((.*\.#{extension})\)/) # markdown matches
matches += content.scan(/\<img.*src="(.*\.#{extension})/) # HTML matches
end
matches.each do |match|
# We support both relative and absolute file paths
if match.first.start_with?("/")
path = File.join(Dir.pwd, "docs", match.first)
else
path = File.join(File.expand_path("..", current_file), match.first)
end
if File.exist?(path)
UI.message("- ✔ Verified image named '#{File.basename(match.first)}'")
next
end
errors << "Image file referenced in file '#{current_file}', but can't find it locally: '#{match.first}'"
end
end
errors.each { |e| UI.error(e) }
UI.user_error!("At least one image file was not found, check out error above") unless errors.empty?
UI.success "✅ All image files were found"
end
# This will verify that no non-md files are inside each of the sub-directories
# All images must be stored in the correct sub-dir
private_lane :ensure_assets_location do
UI.message "🕗 Ensuring asset locations..."
error = false
Dir["docs/**/*"].each do |path|
next if File.directory?(path)
next if ['docs/css', 'docs/img'].any? { |dir| path.start_with?(dir) }
next if File.dirname(path) == "docs" # root level
next if File.extname(path) == ".md"
error = true
UI.error("File '#{path}' shouldn't be in this directory, only `.md` files are allowed")
end
UI.user_error!("Found some files in a wrong directory") if error
UI.success "✅ All assets are in the correct subfolder"
end
private_lane :ensure_tool_name_formatting do
UI.message "🕗 Verifying tool name formatting..."
require 'fastlane/tools'
errors = []
Dir["docs/**/*.md"].each do |path|
content = File.read(path)
Fastlane::TOOLS.each do |tool|
errors << "Use _#{tool}_ instead of `#{tool}` to mention a tool in the docs in '#{path}'" if content.include?("`#{tool}`")
if content.include?("_#{tool.to_s.capitalize}_") || content.include?("`#{tool.to_s.capitalize}`")
errors << "fastlane tools have to be formatted in lower case: #{tool} in '#{path}'"
end
end
end
errors.each { |a| UI.error(a) }
UI.user_error!("Invalid formatting of one of the fastlane tools") unless errors.empty?
UI.success "✅ fastlane formatting is correct"
end