-
Notifications
You must be signed in to change notification settings - Fork 5.6k
/
test_sample_code.rb
120 lines (102 loc) 路 3.95 KB
/
test_sample_code.rb
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
module Fastlane
module Actions
class TestSampleCodeAction < Action
def self.run(params)
content = params[:content] || File.read(params[:path])
fill_in_env_variables
errors = []
content.scan(/```ruby\n(((.|\n)(?!```))*)\n```/).each do |current_match|
current_match = current_match.first # we only expect one match
next if current_match.include?("sh(") # we don't want to run any shell scripts
UI.verbose("parsing: #{current_match}")
begin
begin
# rubocop:disable Security/Eval
eval(current_match)
# rubocop:enable Security/Eval
rescue SyntaxError => ex
UI.user_error!("Syntax error in code sample:\n#{current_match}\n#{ex}")
rescue => ex
UI.user_error!("Error found in code sample:\n#{current_match}\n#{ex}")
end
rescue => ex
errors << ex
end
end
UI.error("Found errors in the documentation, more information below") unless errors.empty?
errors.each do |ex|
UI.error(ex)
end
ENV.delete("CI")
UI.user_error!("Found #{errors.count} errors in the documentation") unless errors.empty?
end
# Is used to look if the method is implemented as an action
def self.method_missing(method_sym, *arguments, &_block)
return if denylist.include?(method_sym)
class_ref = self.runner.class_reference_from_action_name(method_sym)
unless class_ref
alias_found = self.runner.find_alias(method_sym.to_s)
if alias_found
class_ref = self.runner.class_reference_from_action_name(alias_found.to_sym)
end
end
UI.user_error!("Could not find method or action named '#{method_sym}'") if class_ref.nil?
available_options = class_ref.available_options
if available_options.kind_of?(Array) && available_options.first && available_options.first.kind_of?(FastlaneCore::ConfigItem)
parameters = arguments.shift || []
parameters.each do |current_argument, value|
UI.verbose("Verifying '#{value}' for option '#{current_argument}' for action '#{method_sym}'")
config_item = available_options.find { |a| a.key == current_argument }
UI.user_error!("Unknown parameter '#{current_argument}' for action '#{method_sym}'") if config_item.nil?
if value.nil? && config_item.optional
next
end
if config_item.data_type == Fastlane::Boolean
config_item.ensure_boolean_type_passes_validation(value)
elsif config_item.data_type == Array
config_item.ensure_array_type_passes_validation(value)
else
config_item.ensure_generic_type_passes_validation(value)
end
end
else
UI.verbose("Legacy parameter technique for action '#{method_sym}'")
end
return class_ref.sample_return_value # optional value that can be set by the action to make code samples work
end
# If the action name is x, don't run the verification
# This will still verify the syntax though
# The actions listed here are still legacy actions, so
# they don't use the fastlane configuration system
def self.denylist
[
:import,
:xcode_select,
:frameit,
:refresh_dsyms,
:lane,
:before_all,
:verify_xcode,
:error
]
end
# Metadata
def self.available_options
[
FastlaneCore::ConfigItem.new(key: :path),
FastlaneCore::ConfigItem.new(key: :content)
]
end
def self.authors
["KrauseFx"]
end
def self.is_supported?(platform)
true
end
def self.fill_in_env_variables
ENV["CI"] = 1.to_s
ENV["GITHUB_TOKEN"] = "123"
end
end
end
end