forked from Homebrew/formulae.brew.sh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakefile
131 lines (107 loc) Β· 3.43 KB
/
Rakefile
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
require "rake"
require "rake/clean"
require "json"
require "date"
task default: :formula_and_analytics
desc "Dump formulae data"
task :formulae do
ENV["HOMEBREW_FORCE_HOMEBREW_ON_LINUX"] = "1"
sh "brew", "ruby", "script/generate.rb"
end
desc "Dump cask data"
task :cask do
ENV["HOMEBREW_FORCE_HOMEBREW_ON_LINUX"] = "1"
sh "brew", "ruby", "script/generate-cask.rb"
end
def generate_analytics?
return false if ENV["HOMEBREW_NO_ANALYTICS"]
json_file = "_data/analytics/build-error/30d.json"
return true unless File.exist?(json_file)
json = JSON.parse(IO.read(json_file))
end_date = Date.parse(json["end_date"])
end_date < Date.today
end
def setup_analytics_credentials
ga_credentials = ".homebrew_analytics.json"
return unless File.exist?(ga_credentials)
ga_credentials_home = File.expand_path("~/#{ga_credentials}")
return if File.exist?(ga_credentials_home)
FileUtils.cp ga_credentials, ga_credentials_home
end
def setup_formula_analytics_cmd
ENV["HOMEBREW_NO_AUTO_UPDATE"] = "1"
unless `brew tap`.include?("homebrew/formula-analytics")
sh "brew", "tap", "Homebrew/formula-analytics"
end
sh "brew", "formula-analytics", "--setup"
end
def setup_analytics
setup_analytics_credentials
setup_formula_analytics_cmd
end
desc "Dump analytics data"
task :analytics do
next unless generate_analytics?
setup_analytics
%w[build-error install cask-install install-on-request os-version
core-build-error core-install core-install-on-request].each do |category|
case category
when "core-build-error"
category = "all-core-formulae-json --build-error"
category_name = "build-error/homebrew-core"
when "core-install"
category = "all-core-formulae-json --install"
category_name = "install/homebrew-core"
when "core-install-on-request"
category = "all-core-formulae-json --install-on-request"
category_name = "install-on-request/homebrew-core"
else
category_name = category
end
FileUtils.mkdir_p "_data/analytics/#{category_name}"
%w[30 90 365].each do |days|
next if days != "30" && category_name == "build-error/homebrew-core"
sh "brew formula-analytics --days-ago=#{days} --json --#{category} " \
"> _data/analytics/#{category_name}/#{days}d.json"
end
end
end
desc "Dump formulae and analytics data"
task formula_and_analytics: %i[formulae analytics]
desc "Build the site"
task build: [:formula_and_analytics, :cask] do
sh "bundle", "exec", "jekyll", "build"
end
desc "Run html proofer to validate the HTML output."
task html_proofer: :build do
require "html-proofer"
HTMLProofer.check_directory(
"./_site",
parallel: { in_threads: 4 },
favicon: true,
http_status_ignore: [0],
assume_extension: true,
check_external_hash: true,
check_favicon: true,
check_opengraph: true,
check_img_http: true,
disable_external: true,
url_ignore: ["http://formulae.brew.sh"]
).run
end
desc "Run JSON Lint to validate the JSON output."
task jsonlint: :build do
require "jsonlint"
files_to_check = Rake::FileList.new(["./_site/**/*.json"])
puts "Running JSON Lint on #{files_to_check.flatten.length} files..."
linter = JsonLint::Linter.new
linter.check_all(files_to_check)
if linter.errors?
linter.display_errors
abort "JSON Lint found #{linter.errors_count} errors!"
else
puts "JSON Lint finished successfully."
end
end
task test: %i[html_proofer jsonlint]
CLEAN.include FileList["_site"]