-
Notifications
You must be signed in to change notification settings - Fork 2
/
Rakefile
131 lines (109 loc) · 3.75 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
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'scrape/api_definitions_job'
require 'rake/testtask'
require 'net/https'
require 'json'
require 'yaml'
namespace :scrape do
desc "Scrape API Definitions"
task :api_defs do
url = ENV.fetch('TEST_NODE', 'https://sophiatx.com')
job = Scrape::ApiDefinitionsJob.new(url: url)
count = job.perform
puts "Methods added or changed: #{count}"
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://sophiatx.com')
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']
sophiatx_rev = version['sophiatx_revision'][0..5]
fc_rev = version['fc_revision'][0..5]
puts "node: #{url}; blockchain_version: #{blockchain_version}; sophiatx_rev: #{sophiatx_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