forked from bevry/staticsitegenerators-list
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
117 lines (104 loc) · 2.35 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
require 'yaml'
require 'curb'
task default: %w[test]
task :test do
# Load all entries
entries = YAML.load_file('list.yaml')
puts "#{entries.length} entries, syntax probably OK"
# Check every entry
entries.each do |entry|
# Check name
if entry['name'] then
puts "Checking #{entry['name']}..."
else
raise 'Missing required "name" field.'
end
# Check github
check_uri('https://github.com/' + entry['github'], 1) if entry['github']
# Check website
if entry['website'] != "" then
check_uri(entry['website'], 1) if entry['website']
end
# Check license
check_license(entry['license']) if entry['license']
# Check language
check_language(entry['language']) if entry['language']
end
end
# Check that the URI returns a 200
def check_uri(uri, attempt)
curl = Curl::Easy.new(uri)
curl.ssl_verify_peer = false
curl.follow_location = true
curl.headers['User-Agent'] = 'static-site-generator-comparison-0.1.0.0'
curl.headers['Accept'] = 'text/html,application/xhtml+xml,application/xml'
begin
curl.perform
rescue Exception => e
puts "#{uri}: failed to curl"
if attempt >= 3
puts "#{uri}: tried #{attempt} times, giving up"
raise e
else
puts "#{uri}: tried #{attempt} times, trying again"
check_uri(uri, attempt + 1)
end
end
unless curl.response_code == 200
raise "#{uri}: #{curl.response_code} response"
end
end
# Check license
def check_license(license)
known_licenses = [
"MIT", "BSD", "GPL", "Public", "MS-PL", "SimPL", "Apache", "Ruby", "Perl",
"EPL", "CC", "Beer-ware", "Commercial", "ISC", false
]
unless known_licenses.include? license
raise "Unknown license: #{license}"
end
end
# Check language
def check_language(language)
known_languages = [
"App",
"Awk",
"Batch",
"C#",
"C++",
"Clojure",
"CoffeeScript",
"Common Lisp",
"Dart",
"Elixir",
"Emacs Lisp",
"Erlang",
"F#",
"Fortran",
"Go",
"Groovy",
"Haskell",
"Java",
"JavaScript",
"Lisp",
"Lua",
"Make",
"newLISP",
"Nimrod",
"OCaml",
"Objective-C",
"PHP",
"Perl",
"Python",
"Racket",
"Ruby",
"Rust",
"Scala",
"Shell",
"Tcl",
"Web"
]
unless known_languages.include? language
raise "Unknown language: #{language}"
end
end