forked from steemit/devportal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakefile
184 lines (151 loc) · 4.97 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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'scrape/api_definitions_job'
require 'scrape/tutorials_job/base'
require 'scrape/tutorials_job/javascript'
require 'scrape/tutorials_job/python'
require 'scrape/tutorials_job/ruby'
require 'rake/testtask'
require 'net/https'
require 'json'
require 'yaml'
namespace :scrape do
desc "Scrape dpayjs docs"
task :javascript do
end
desc "Scrape dpaypy docs"
task :python do
end
desc "Scrape API Definitions"
task :api_defs do
url = ENV.fetch('TEST_NODE', 'https://api.dpays.io')
job = Scrape::ApiDefinitionsJob.new(url: url)
count = job.perform
puts "Methods added or changed: #{count}"
end
desc 'Scrape all known tutorial repositories.'
task :tutorials do
puts '=' * 80
puts "JS-Tutorials:"
Rake::Task["scrape:tutorials:js"].invoke
puts '=' * 80
puts "PY-Tutorials:"
Rake::Task["scrape:tutorials:py"].invoke
puts '=' * 80
puts "RB-Tutorials:"
Rake::Task["scrape:tutorials:rb"].invoke
end
namespace :tutorials do
desc 'Scrape JS-Tutorials'
task :js, [:num, :force] do |t, args|
job = Scrape::TutorialsJob::Javascript.new(num: args[:num], force: args[:force])
count = job.perform
puts "Tutorials added or changed: #{count}"
end
desc 'Scrape PY-Tutorials'
task :py, [:num, :force] do |t, args|
job = Scrape::TutorialsJob::Python.new(num: args[:num], force: args[:force])
count = job.perform
puts "Tutorials added or changed: #{count}"
end
desc 'Scrape RB-Tutorials'
task :rb, [:num, :force] do |t, args|
job = Scrape::TutorialsJob::Ruby.new(num: args[:num], force: args[:force])
count = job.perform
puts "Tutorials added or changed: #{count}"
end
end
end
namespace :production do
task :prevent_dirty_builds do
if `git status --porcelain`.chomp.length > 0
puts '*** WARNING: You currently have uncommitted changes. ***'
fail 'Build aborted, because project directory is not clean.' unless ENV['ALLOW_DIRTY']
end
end
task :build do
sh 'bundle exec jekyll build --destination docs'
end
task :drop_previous_build do
sh 'git checkout master'
sh 'git rm -rf docs'
sh 'git commit -m "jekyll dropped previous site"'
end
desc "Deploy current master to GH Pages"
task deploy: [:prevent_dirty_builds, :drop_previous_build, :build] do
sh 'git add -A'
sh 'git commit -m "jekyll base sources"'
sh 'git push origin master'
exit(0)
end
desc "Rollback GH Pages"
task rollback: [:prevent_dirty_builds] do
sh 'git checkout master'
sh 'git reset --hard HEAD^'
sh 'git push origin master'
exit(0)
end
end
namespace :test do
KNOWN_APIS = %i(
account_by_key_api account_history_api block_api condenser_api
database_api follow_api jsonrpc market_history_api network_broadcast_api
tags_api witness_api
)
desc "Tests the curl examples of api definitions. Known APIs: #{KNOWN_APIS.join(' ')}"
task :curl, [:apis] do |t, args|
smoke = 0
url = ENV.fetch('TEST_NODE', 'https://api.dpays.io')
apis = [args[:apis].split(' ').map(&:to_sym)].flatten if !!args[:apis]
apis ||= KNOWN_APIS
version = `curl -s --data '{"jsonrpc":"2.0", "method":"condenser_api.get_version", "params":[], "id":1}' #{url}`
version = JSON[version]['result']
blockchain_version = version['blockchain_version']
dpay_rev = version['dpay_revision'][0..5]
fc_rev = version['fc_revision'][0..5]
puts "node: #{url}; blockchain_version: #{blockchain_version}; dpay_rev: #{dpay_rev}; fc_rev: #{fc_rev}"
apis.each do |api|
file_name = "_data/apidefinitions/#{api}.yml"
unless File.exist?(file_name)
puts "Does not exist: #{file_name}"
next
end
yml = YAML.load_file(file_name)
yml[0]['methods'].each do |method|
print "Testing #{method['api_method']} ... "
if method['curl_examples'].nil?
puts "no curl examples."
next
end
method['curl_examples'].each_with_index do |curl_example, index|
response = `curl -s -w \"HTTP_CODE:%{http_code}\" --data '#{curl_example}' #{url}`
response = response.split('HTTP_CODE:')
json = response[0]
code = response[1]
case code
when '200'
data = JSON[json]
if !!data['error']
expected_curl_response = if !!method['expected_curl_responses']
method['expected_curl_responses'][index]
end
if !!expected_curl_response && data['error']['message'].include?(expected_curl_response)
print '√'
else
smoke += 1
print "\n\t#{data['error']['message']}\n"
end
else
print '√'
end
else
smoke += 1
'X'
end
end
print "\n"
end
end
exit smoke
end
end