-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
update_script.rb
49 lines (47 loc) · 1.57 KB
/
update_script.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
class BuildUpdateScript
attr_accessor :header_lines, :options, :lines, :path, :root, :actions
def initialize(path)
type = path.split('.')[-1]
@actions = ScriptActions.create(type)
@path = path
@header_lines = []
@options = {}
@lines = []
@root = ''
if File.exist?(path)
f = File.open(@path, 'r')
line = f.gets.chomp
raise "Invalid Header: #{line}\nShould be: #{@actions.file_header}" unless line == @actions.file_header
while line = f.gets
variable = @actions.parse_variable(line)
break if variable.nil?
@header_lines.push(line)
@options.merge!(variable)
end
end
end
def set_header(server, project, build, build_type, root_dir, build_tag)
@header_lines = [
@actions.file_header,
@actions.variable('server', server)
]
if project.nil? && build.nil?
@header_lines.push(@actions.variable('build_type',build_type))
else
@header_lines.push(@actions.variable('project',project))
@header_lines.push(@actions.variable('build', build))
end
@header_lines.push(@actions.variable('root_dir', root_dir)) unless root_dir.nil?
@header_lines.push(@actions.variable('build_tag', build_tag)) unless build_tag.nil?
end
def update
File.open(@path, 'w') do |f|
f.puts(@header_lines)
f.puts(@actions.comment("Auto-generated by https://github.com/sillsdev/BuildUpdate."))
f.puts(@actions.comment("Do not edit this file by hand!"))
f.puts(@actions.begin_lines)
f.puts(@lines)
f.puts(@actions.end_lines)
end
end
end