roku_builder 3.3.4 → 3.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c7a3925b7a80b6bf4d42aac1f30e5389150a6ce1
4
- data.tar.gz: 8437573af545cf9e151e70dbc4345824460761ea
3
+ metadata.gz: 7a9d534271fdbd6b97dd36575bfd13e248af80d8
4
+ data.tar.gz: 1d250755fb3a741fd8887f9756c70f52648225c0
5
5
  SHA512:
6
- metadata.gz: 063192d4dfd2193affd30539e270f9d7a64cc7d87d217a4c7822a91c998f46d4a18b46bb549f3fe5627f6d6b83e7a98b2b7f1034cfa225f1965520cd67e7e944
7
- data.tar.gz: 8caf8c49315738d1e150e36589f24940f5e5049a5631a61a82301681ade6f3fb50f9cfe527dc1ffa2042b333aa1cc09e605e910e6b52ef5a57e9c1177713ad12
6
+ metadata.gz: 7460a08f88a3cc134bac6a47c29ae76bfb8810110a667d7498b9274db8a86b2d5b6cb4370206d55716fb31c5d822952d0f8d952aef8ccbb07b5ed5a7b20c1ffd
7
+ data.tar.gz: dfcb56377c93de06217de2cd359877ccdecd496de1c2b6cbc2014c95b6adc0e778e973767961c082fdde9d8dcb576887cd8fef7807cf9e317471733e35cfe5f2
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- roku_builder (3.3.4)
4
+ roku_builder (3.4.0)
5
5
  faraday (~> 0.9)
6
6
  faraday-digestauth (~> 0.2)
7
7
  git (~> 1.3)
@@ -11,8 +11,8 @@ PATH
11
11
  GEM
12
12
  remote: https://rubygems.org/
13
13
  specs:
14
- byebug (8.2.2)
15
- coderay (1.1.0)
14
+ byebug (8.2.4)
15
+ coderay (1.1.1)
16
16
  coveralls (0.8.13)
17
17
  json (~> 1.8)
18
18
  simplecov (~> 0.11.0)
@@ -23,7 +23,7 @@ GEM
23
23
  em-websocket (0.5.1)
24
24
  eventmachine (>= 0.12.9)
25
25
  http_parser.rb (~> 0.6.0)
26
- eventmachine (1.0.9.1)
26
+ eventmachine (1.2.0.1)
27
27
  faraday (0.9.2)
28
28
  multipart-post (>= 1.2, < 3)
29
29
  faraday-digestauth (0.2.1)
@@ -71,7 +71,7 @@ GEM
71
71
  coderay (~> 1.1.0)
72
72
  method_source (~> 0.8.1)
73
73
  slop (~> 3.4)
74
- rake (11.1.1)
74
+ rake (11.1.2)
75
75
  rb-fsevent (0.9.7)
76
76
  rb-inotify (0.9.7)
77
77
  ffi (>= 0.5.0)
data/README.md CHANGED
@@ -273,6 +273,8 @@ directory:
273
273
 
274
274
  ## Improvements
275
275
 
276
+ * Pull build number from correct stage
277
+ * Don't require a device for non device tasks
276
278
  * Account for missing folders or files
277
279
  * Increase testing
278
280
  * Config Unit Tests
data/config.json.example CHANGED
@@ -14,6 +14,7 @@
14
14
  "folders": ["resources","source"],
15
15
  "files": ["manifest"],
16
16
  "app_name": "<app name>",
17
+ "stage_method": "<git|script>",
17
18
  "stages":{
18
19
  "production": {
19
20
  "branch": "production",
data/lib/roku_builder.rb CHANGED
@@ -17,6 +17,7 @@ require "roku_builder/controller_commands"
17
17
  require "roku_builder/util"
18
18
  require "roku_builder/keyer"
19
19
  require "roku_builder/inspector"
20
+ require "roku_builder/stager"
20
21
  require "roku_builder/loader"
21
22
  require "roku_builder/packager"
22
23
  require "roku_builder/linker"
@@ -125,3 +126,15 @@ module RokuBuilder
125
126
  # Failed to capture screen
126
127
  FAILED_SCREENCAPTURE = 12
127
128
  end
129
+
130
+ class String
131
+ def underscore
132
+ word = self.dup
133
+ word.gsub!(/::/, '/')
134
+ word.gsub!(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
135
+ word.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
136
+ word.tr!("-", "_")
137
+ word.downcase!
138
+ word
139
+ end
140
+ end
@@ -47,6 +47,12 @@ module RokuBuilder
47
47
  config = JSON.parse(File.open(config).read, {symbolize_names: true})
48
48
  config[:devices][:default] = config[:devices][:default].to_sym
49
49
  config[:projects][:default] = config[:projects][:default].to_sym
50
+ config[:projects].each_pair do |key,value|
51
+ next if key == :default
52
+ if value[:stage_method]
53
+ value[:stage_method] = value[:stage_method].to_sym
54
+ end
55
+ end
50
56
  config
51
57
  rescue JSON::ParserError
52
58
  logger.fatal "Config file is not valid JSON"
@@ -11,7 +11,7 @@ module RokuBuilder
11
11
  # @return [Integer] Return code
12
12
  # @return [Hash] Intermeidate configs
13
13
  def self.parse_config(options:, config:, logger:)
14
- configs = {}
14
+ configs = {init_params: {}}
15
15
  #set device
16
16
  unless options[:device]
17
17
  options[:device] = config[:devices][:default]
@@ -27,14 +27,10 @@ module RokuBuilder
27
27
  project_config = setup_project_config(config: config, options: options)
28
28
  return [UNKNOWN_PROJECT, nil, nil] unless project_config
29
29
  configs[:project_config] = project_config
30
- stage = options[:stage].to_sym
31
- return [UNKNOWN_STAGE, nil, nil] unless project_config[:stages][stage]
32
- configs[:stage] = stage
33
- branch = project_config[:stages][stage][:branch]
34
- branch = options[:ref] if options[:ref]
35
- branch = nil if options[:current]
36
- branch = nil if options[:working]
37
- setup_sideload_config(configs: configs, options: options, branch: branch)
30
+ stage_config, stage = setup_stage_config(configs: configs, options: options, logger: logger)
31
+ return [UNKNOWN_STAGE, nil, nil] unless stage
32
+ configs[:stage_config] = stage_config
33
+ setup_sideload_config(configs: configs, options: options)
38
34
  setup_package_config(configs: configs, options: options, stage: stage)
39
35
  setup_simple_configs(configs: configs, options: options, logger: logger)
40
36
  return [SUCCESS, configs]
@@ -97,36 +93,65 @@ module RokuBuilder
97
93
  directory: pwd,
98
94
  folders: nil,
99
95
  files: nil,
100
- stages: { production: { branch: nil } }
96
+ stage_method: :current
101
97
  }
102
98
  else
103
99
  project_config = config[:projects][options[:project].to_sym]
100
+ project_config[:stage_method] = :working if options[:working]
104
101
  end
105
102
  project_config
106
103
  end
107
104
  private_class_method :setup_project_config
108
105
 
106
+ # Setup the project stage config
107
+ # @param configs [Hash] The loaded config hash
108
+ # @param options [Hash] The options hash
109
+ # @return [Hash] The stage config hash
110
+ def self.setup_stage_config(configs:, options:, logger:)
111
+ stage_config = {logger: logger}
112
+ stage = options[:stage].to_sym
113
+ project_config = configs[:project_config]
114
+ stage_config[:root_dir] = project_config[:directory]
115
+ stage_config[:method] = project_config[:stage_method]
116
+ stage_config[:method] ||= :git
117
+ case stage_config[:method]
118
+ when :git
119
+ if options[:ref]
120
+ stage_config[:key] = options[:ref]
121
+ else
122
+ return nil unless project_config[:stages][stage]
123
+ stage_config[:key] = project_config[:stages][stage][:branch]
124
+ end
125
+ when :script
126
+ return nil unless project_config[:stages][stage]
127
+ stage_config[:key] = project_config[:stages][stage][:script]
128
+ end
129
+ configs[:stage] = stage_config
130
+ [stage_config, stage]
131
+ end
132
+
109
133
  # Setup config hashes for sideloading
110
134
  # @param configs [Hash] The parsed configs hash
111
135
  # @param options [Hash] The options hash
112
136
  # @param branch [String] the branch to sideload
113
- def self.setup_sideload_config(configs:, options:, branch:)
137
+ def self.setup_sideload_config(configs:, options:)
114
138
  root_dir = configs[:project_config][:directory]
115
139
  # Create Sideload Config
116
140
  configs[:sideload_config] = {
117
- root_dir: root_dir,
118
- branch: branch,
141
+ stage: configs[:stage_config],
119
142
  update_manifest: options[:update_manifest],
120
143
  folders: configs[:project_config][:folders],
121
144
  files: configs[:project_config][:files]
122
145
  }
123
146
  # Create Build Config
124
147
  configs[:build_config] = {
125
- root_dir: root_dir,
126
- branch: branch,
148
+ stage: configs[:stage_config],
127
149
  folders: configs[:project_config][:folders],
128
150
  files: configs[:project_config][:files]
129
151
  }
152
+ configs[:init_params][:loader] = {
153
+ root_dir: root_dir
154
+ }
130
155
  end
131
156
  private_class_method :setup_sideload_config
132
157
 
@@ -16,6 +16,11 @@ module RokuBuilder
16
16
  PROJECT_MISSING_FILES = 14
17
17
  PROJECT_FILES_BAD = 15
18
18
  STAGE_MISSING_BRANCH = 16
19
+ STAGE_MISSING_SCRIPT = 17
20
+ PROJECT_STAGE_METHOD_BAD = 18
21
+
22
+
23
+ MISSING_STAGE_METHOD = -1
19
24
 
20
25
  # Validate Config File
21
26
  class ConfigValidator
@@ -39,6 +44,7 @@ module RokuBuilder
39
44
  validate_project(codes: codes, project: v)
40
45
  }
41
46
  end
47
+ codes.uniq!
42
48
  codes.push(0) if codes.empty?
43
49
  codes
44
50
  end
@@ -64,8 +70,11 @@ module RokuBuilder
64
70
  "A project config's folders is not an array.",
65
71
  "A project config is missing its files.",
66
72
  "A project config's files is not an array.", #15
67
- "A project stage is missing its branch."
73
+ "A project stage is missing its branch.",
74
+ "A project stage is missing its script.",
75
+ "A project as an invalid stage method.",
68
76
  #===============WARNINGS===============#
77
+ "A project is missing its stage method."
69
78
  ]
70
79
  end
71
80
 
@@ -116,8 +125,11 @@ module RokuBuilder
116
125
  codes.push(PROJECT_FOLDERS_BAD) if project[:folders] and not project[:folders].is_a?(Array)
117
126
  codes.push(PROJECT_MISSING_FILES) if not project[:files]
118
127
  codes.push(PROJECT_FILES_BAD) if project[:files] and not project[:files].is_a?(Array)
128
+ codes.push(MISSING_STAGE_METHOD) unless project[:stage_method]
129
+ codes.push(PROJECT_STAGE_METHOD_BAD) unless [:git, :script, nil].include?(project[:stage_method])
119
130
  project[:stages].each {|_stage,value|
120
- codes.push(STAGE_MISSING_BRANCH) if not value[:branch]
131
+ codes.push(STAGE_MISSING_BRANCH) if not value[:branch] and project[:stage_method] == :git
132
+ codes.push(STAGE_MISSING_SCRIPT) if not value[:script] and project[:stage_method] == :script
121
133
  }
122
134
  end
123
135
  private_class_method :validate_project
@@ -99,7 +99,12 @@ module RokuBuilder
99
99
  # @param failure [Integer] failure code to return on failure if not nil
100
100
  # @return [Integer] Success of failure code
101
101
  def self.simple_command(klass:, method:, config_key: nil, configs:, failure: nil)
102
- instance = klass.new(**configs[:device_config])
102
+ config = configs[:device_config].dup
103
+ key = klass.to_s.split("::")[-1].underscore.to_sym
104
+ if configs[:init_params][key]
105
+ config[:init_params] = configs[:init_params][key]
106
+ end
107
+ instance = klass.new(**config)
103
108
  if config_key
104
109
  success = instance.send(method, configs[config_key])
105
110
  else
@@ -3,26 +3,31 @@ module RokuBuilder
3
3
  # Load/Unload/Build roku applications
4
4
  class Loader < Util
5
5
 
6
+
7
+ # Set the root directory
8
+ def init(root_dir: nil)
9
+ @root_dir = root_dir
10
+ end
11
+
6
12
  # Sideload an app onto a roku device
7
13
  # @param root_dir [String] Path to the root directory of the roku app
8
- # @param branch [String] Branch of the git repository to sideload. Pass nil to use working directory. Default: nil
14
+ # @param stage [Hash] stage to use for sideloading.
9
15
  # @param update_manifest [Boolean] Flag to update the manifest file before sideloading. Default: false
10
16
  # @param folders [Array<String>] Array of folders to be sideloaded. Pass nil to send all folders. Default: nil
11
17
  # @param files [Array<String>] Array of files to be sideloaded. Pass nil to send all files. Default: nil
12
18
  # @return [String] Build version on success, nil otherwise
13
- def sideload(root_dir:, branch: nil, update_manifest: false, folders: nil, files: nil)
14
- @root_dir = root_dir
19
+ def sideload(stage:, update_manifest: false, folders: nil, files: nil)
15
20
  result = nil
16
- begin
17
- git_switch_to(branch: branch)
21
+ stager = Stager.new(**stage)
22
+ if stager.stage
18
23
  # Update manifest
19
24
  build_version = ""
20
25
  if update_manifest
21
- build_version = ManifestManager.update_build(root_dir: root_dir)
26
+ build_version = ManifestManager.update_build(root_dir: @root_dir)
22
27
  else
23
- build_version = ManifestManager.build_version(root_dir: root_dir)
28
+ build_version = ManifestManager.build_version(root_dir: @root_dir)
24
29
  end
25
- outfile = build(root_dir: root_dir, branch: branch, build_version: build_version, folders: folders, files: files)
30
+ outfile = build(stage: stage, build_version: build_version, folders: folders, files: files)
26
31
  path = "/plugin_install"
27
32
  # Connect to roku and upload file
28
33
  conn = multipart_connection
@@ -34,35 +39,29 @@ module RokuBuilder
34
39
  # Cleanup
35
40
  File.delete(outfile)
36
41
  result = build_version if response.status==200 and response.body=~/Install Success/
37
- git_switch_from(branch: branch)
38
- rescue Git::GitExecuteError
39
- git_rescue
40
- ensure
41
- @current_dir ||= Dir.pwd
42
- Dir.chdir(@current_dir) unless @current_dir == Dir.pwd
43
42
  end
43
+ stager.unstage
44
44
  result
45
45
  end
46
46
 
47
47
 
48
48
  # Build an app to sideload later
49
49
  # @param root_dir [String] Path to the root directory of the roku app
50
- # @param branch [String] Branch of the git repository to sideload. Pass nil to use working directory. Default: nil
50
+ # @param stage [Hash] stage to use for sideloading.
51
51
  # @param build_version [String] Version to assigne to the build. If nil will pull the build version form the manifest. Default: nil
52
52
  # @param outfile [String] Path for the output file. If nil will create a file in /tmp. Default: nil
53
53
  # @param folders [Array<String>] Array of folders to be sideloaded. Pass nil to send all folders. Default: nil
54
54
  # @param files [Array<String>] Array of files to be sideloaded. Pass nil to send all files. Default: nil
55
55
  # @return [String] Path of the build
56
- def build(root_dir:, branch: nil, build_version: nil, outfile: nil, folders: nil, files: nil)
57
- @root_dir = root_dir
58
- begin
59
- git_switch_to(branch: branch)
60
- build_version = ManifestManager.build_version(root_dir: root_dir, logger: @logger) unless build_version
56
+ def build(stage:, build_version: nil, outfile: nil, folders: nil, files: nil)
57
+ stager = Stager.new(**stage)
58
+ if stager.stage
59
+ build_version = ManifestManager.build_version(root_dir: @root_dir, logger: @logger) unless build_version
61
60
  unless folders
62
- folders = Dir.entries(root_dir).select {|entry| File.directory? File.join(root_dir, entry) and !(entry =='.' || entry == '..') }
61
+ folders = Dir.entries(@root_dir).select {|entry| File.directory? File.join(@root_dir, entry) and !(entry =='.' || entry == '..') }
63
62
  end
64
63
  unless files
65
- files = Dir.entries(root_dir).select {|entry| File.file? File.join(root_dir, entry)}
64
+ files = Dir.entries(@root_dir).select {|entry| File.file? File.join(@root_dir, entry)}
66
65
  end
67
66
  outfile = "/tmp/build_#{build_version}.zip" unless outfile
68
67
  File.delete(outfile) if File.exist?(outfile)
@@ -78,13 +77,8 @@ module RokuBuilder
78
77
  # Add file to zip
79
78
  writeEntries(@root_dir, files, "", io)
80
79
  io.close()
81
- git_switch_from(branch: branch)
82
- rescue Git::GitExecuteError
83
- git_rescue
84
- ensure
85
- @current_dir ||= Dir.pwd
86
- Dir.chdir(@current_dir) unless @current_dir == Dir.pwd
87
80
  end
81
+ stager.unstage
88
82
  outfile
89
83
  end
90
84
 
@@ -125,37 +119,5 @@ module RokuBuilder
125
119
  end
126
120
  }
127
121
  end
128
-
129
- # Switch to the correct branch
130
- def git_switch_to(branch:)
131
- if branch
132
- @current_dir = Dir.pwd
133
- @git ||= Git.open(@root_dir)
134
- if branch != @git.current_branch
135
- Dir.chdir(@root_dir)
136
- @current_branch = @git.current_branch
137
- @stash = @git.branch.stashes.save("roku-builder-temp-stash")
138
- @git.checkout(branch)
139
- end
140
- end
141
- end
142
-
143
- # Switch back to the previous branch
144
- def git_switch_from(branch:)
145
- if branch
146
- @git ||= Git.open(@root_dir)
147
- if @git and @current_branch
148
- @git.checkout(@current_branch)
149
- @git.branch.stashes.apply if @stash
150
- end
151
- end
152
- end
153
-
154
- # Called if resuce from git exception
155
- def git_rescue
156
- @logger.error "Branch or ref does not exist"
157
- @logger.error e.message
158
- @logger.error e.backtrace
159
- end
160
122
  end
161
123
  end
@@ -58,5 +58,53 @@ module RokuBuilder
58
58
  end
59
59
  build_version
60
60
  end
61
+
62
+ # Update attributes in the app manifest
63
+ # It will add missing attributes but not remove them
64
+ # @param root_dir [String] The app root directory
65
+ # @param attributes [Hash] The new attributes for the app manifest
66
+ def self.update_manifest(root_dir:, attributes:)
67
+ temp_file = Tempfile.new('manifest')
68
+ path = File.join(root_dir, 'manifest')
69
+ new_params = attributes.dup
70
+ begin
71
+ if File.exist?(path)
72
+ File.open(path, 'r') do |file|
73
+ file.each_line do |line|
74
+ key = line.split("=")[0]
75
+ if new_params.include?(key.to_sym)
76
+ temp_file.puts("#{key}=#{new_params[key.to_sym]}")
77
+ new_params.delete(key)
78
+ else
79
+ temp_file.puts(line)
80
+ end
81
+ end
82
+ end
83
+ else
84
+ new_params = self.default_params().merge(new_params)
85
+ end
86
+ new_params.each_pair do |key, value|
87
+ temp_file.puts("#{key}=#{value}")
88
+ end
89
+ temp_file.rewind
90
+ FileUtils.cp(temp_file.path, path)
91
+ ensure
92
+ temp_file.close
93
+ temp_file.unlink
94
+ end
95
+ end
96
+
97
+ # Returns the default manafest values
98
+ # @return [Hash] default manifest values
99
+ def self.default_params
100
+ {
101
+ title: "Default Title",
102
+ major_version: 1,
103
+ minor_version: 0,
104
+ build_version: "010101.0001",
105
+ mm_icon_focus_hd: "<insert hd focus icon url>",
106
+ mm_icon_focus_sd: "<insert sd focus icon url>"
107
+ }
108
+ end
61
109
  end
62
110
  end
@@ -0,0 +1,86 @@
1
+ module RokuBuilder
2
+
3
+ # Change stage of roku application
4
+ class Stager
5
+
6
+ def initialize(key: nil, method:, root_dir:, logger:)
7
+ @method = method
8
+ @key = key
9
+ @root_dir = root_dir
10
+ @logger = logger
11
+ @stage_success = true
12
+ @orginal_directory = Dir.pwd
13
+ end
14
+
15
+ def stage
16
+ Dir.chdir(@root_dir) unless @root_dir == @orginal_directory
17
+ case @method
18
+ when :current
19
+ # Do Nothing
20
+ when :working
21
+ # Do Nothing
22
+ when :git
23
+ begin
24
+ git_switch_to(branch: @key)
25
+ rescue Git::GitExecuteError
26
+ git_rescue
27
+ @stage_success = false
28
+ end
29
+ when :script
30
+ Controller.system(command: @key[:stage])
31
+ end
32
+ @stage_success
33
+ end
34
+
35
+ def unstage
36
+ unstage_success = true
37
+ case @method
38
+ when :current
39
+ # Do Nothing
40
+ when :working
41
+ # Do Nothing
42
+ when :git
43
+ begin
44
+ git_switch_from(branch: @key, checkout: @stage_success)
45
+ rescue Git::GitExecuteError
46
+ git_rescue
47
+ unstage_success = false
48
+ end
49
+ when :script
50
+ Controller.system(command: @key[:unstage])
51
+ end
52
+ Dir.chdir(@orginal_directory) unless @root_dir == @orginal_directory
53
+ unstage_success
54
+ end
55
+
56
+ private
57
+
58
+ # Switch to the correct branch
59
+ def git_switch_to(branch:)
60
+ if branch
61
+ @git ||= Git.open(@root_dir)
62
+ if branch != @git.current_branch
63
+ @current_branch = @git.current_branch
64
+ @stash = @git.branch.stashes.save("roku-builder-temp-stash")
65
+ @git.checkout(branch)
66
+ end
67
+ end
68
+ end
69
+
70
+ # Switch back to the previous branch
71
+ def git_switch_from(branch:, checkout: true)
72
+ if branch
73
+ @git ||= Git.open(@root_dir)
74
+ if @git and @current_branch
75
+ @git.checkout(@current_branch) if checkout
76
+ @git.branch.stashes.apply if @stash
77
+ end
78
+ end
79
+ end
80
+
81
+ # Called if resuce from git exception
82
+ def git_rescue
83
+ @logger.error "Branch or ref does not exist"
84
+ end
85
+ end
86
+ end
@@ -9,7 +9,7 @@ module RokuBuilder
9
9
  # @param ip [String] IP address of roku device
10
10
  # @param user [String] Username for roku device
11
11
  # @param password [String] Password for roku device
12
- def initialize(ip:, user:, password:, logger:)
12
+ def initialize(ip:, user:, password:, logger:, init_params: nil)
13
13
  @device_config = {
14
14
  ip: ip,
15
15
  user: user,
@@ -20,7 +20,11 @@ module RokuBuilder
20
20
  @dev_password = password
21
21
  @url = "http://#{@roku_ip_address}"
22
22
  @logger = logger
23
- init()
23
+ if init_params
24
+ init(**init_params)
25
+ else
26
+ init
27
+ end
24
28
  end
25
29
 
26
30
  # Second initializer to be overwriten
@@ -1,4 +1,4 @@
1
1
  module RokuBuilder
2
2
  # Version of the RokuBuilder Gem
3
- VERSION = "3.3.4"
3
+ VERSION = "3.4.0"
4
4
  end
@@ -8,14 +8,16 @@ class LoaderTest < Minitest::Test
8
8
  response = Minitest::Mock.new
9
9
 
10
10
  root_dir = File.join(File.dirname(__FILE__), "test_files", "loader_test")
11
+ logger = Logger.new("/dev/null")
11
12
  device_config = {
12
13
  ip: "111.222.333",
13
14
  user: "user",
14
15
  password: "password",
15
- logger: Logger.new("/dev/null")
16
+ logger: logger,
17
+ init_params: {root_dir: root_dir}
16
18
  }
17
19
  loader_config = {
18
- root_dir: root_dir,
20
+ stage: {method: :working, root_dir: root_dir, logger: logger},
19
21
  folders: ["source"],
20
22
  files: ["manifest"]
21
23
  }
@@ -66,14 +68,16 @@ class LoaderTest < Minitest::Test
66
68
  response = Minitest::Mock.new
67
69
 
68
70
  root_dir = File.join(File.dirname(__FILE__), "test_files", "loader_test")
71
+ logger = Logger.new("/dev/null")
69
72
  device_config = {
70
73
  ip: "111.222.333",
71
74
  user: "user",
72
75
  password: "password",
73
- logger: Logger.new("/dev/null")
76
+ logger: logger,
77
+ init_params: {root_dir: root_dir}
74
78
  }
75
79
  loader_config = {
76
- root_dir: root_dir,
80
+ stage: {method: :working, root_dir: root_dir, logger: logger},
77
81
  update_manifest: true,
78
82
  folders: ["source"],
79
83
  files: ["manifest"]
@@ -121,14 +125,16 @@ class LoaderTest < Minitest::Test
121
125
 
122
126
  def test_loader_build_defining_folder_and_files
123
127
  root_dir = File.join(File.dirname(__FILE__), "test_files", "loader_test")
128
+ logger = Logger.new("/dev/null")
124
129
  device_config = {
125
130
  ip: "111.222.333",
126
131
  user: "user",
127
132
  password: "password",
128
- logger: Logger.new("/dev/null")
133
+ logger: logger,
134
+ init_params: {root_dir: root_dir}
129
135
  }
130
136
  build_config = {
131
- root_dir: root_dir,
137
+ stage: {method: :working, root_dir: root_dir, logger: logger},
132
138
  folders: ["source"],
133
139
  files: ["manifest"]
134
140
  }
@@ -146,15 +152,15 @@ class LoaderTest < Minitest::Test
146
152
  end
147
153
  def test_loader_build_all_contents
148
154
  root_dir = File.join(File.dirname(__FILE__), "test_files", "loader_test")
155
+ logger = Logger.new("/dev/null")
149
156
  device_config = {
150
157
  ip: "111.222.333",
151
158
  user: "user",
152
159
  password: "password",
153
- logger: Logger.new("/dev/null")
154
- }
155
- build_config = {
156
- root_dir: root_dir,
160
+ logger: logger,
161
+ init_params: {root_dir: root_dir}
157
162
  }
163
+ build_config = {stage: {method: :working, root_dir: root_dir, logger: logger}}
158
164
  loader = RokuBuilder::Loader.new(**device_config)
159
165
  outfile = nil
160
166
  RokuBuilder::ManifestManager.stub(:build_version, "build_version") do
@@ -177,7 +183,8 @@ class LoaderTest < Minitest::Test
177
183
  ip: "111.222.333",
178
184
  user: "user",
179
185
  password: "password",
180
- logger: Logger.new("/dev/null")
186
+ logger: Logger.new("/dev/null"),
187
+ init_params: {root_dir: "/dev/null"}
181
188
  }
182
189
  payload = {
183
190
  mysubmit: "Delete",
@@ -219,7 +226,8 @@ class LoaderTest < Minitest::Test
219
226
  ip: "111.222.333",
220
227
  user: "user",
221
228
  password: "password",
222
- logger: Logger.new("/dev/null")
229
+ logger: Logger.new("/dev/null"),
230
+ init_params: {root_dir: "/dev/null"}
223
231
  }
224
232
  payload = {
225
233
  mysubmit: "Delete",
@@ -31,4 +31,34 @@ class ManifestManagerTest < Minitest::Test
31
31
  assert_equal "010101.1", build_version
32
32
  FileUtils.rm(File.join(root_dir, "manifest"))
33
33
  end
34
+
35
+ def test_manifest_manager_update_manifest
36
+ root_dir = File.join(File.dirname(__FILE__), "test_files", "manifest_manager_test")
37
+ FileUtils.cp(File.join(root_dir, "manifest_template"), File.join(root_dir, "manifest"))
38
+ attrs = {
39
+ title: "New Title",
40
+ major_version: 2,
41
+ minor_version: 2,
42
+ build_version: "020202.0002",
43
+ mm_icon_focus_hd: "pkg:/images/focus1.png",
44
+ mm_icon_focus_sd: "pkg:/images/focus2.png"
45
+ }
46
+ RokuBuilder::ManifestManager.update_manifest(root_dir: root_dir, attributes: attrs)
47
+ assert FileUtils.compare_file(File.join(root_dir, "manifest"), File.join(root_dir, "updated_title_manifest"))
48
+ FileUtils.rm(File.join(root_dir, "manifest"))
49
+ end
50
+ def test_manifest_manager_update_manifest
51
+ root_dir = File.join(File.dirname(__FILE__), "test_files", "manifest_manager_test")
52
+ attrs = {
53
+ title: "New Title",
54
+ major_version: 2,
55
+ minor_version: 2,
56
+ build_version: "020202.0002",
57
+ mm_icon_focus_hd: "pkg:/images/focus1.png",
58
+ mm_icon_focus_sd: "pkg:/images/focus2.png"
59
+ }
60
+ RokuBuilder::ManifestManager.update_manifest(root_dir: root_dir, attributes: attrs)
61
+ assert FileUtils.compare_file(File.join(root_dir, "manifest"), File.join(root_dir, "updated_title_manifest"))
62
+ FileUtils.rm(File.join(root_dir, "manifest"))
63
+ end
34
64
  end
@@ -0,0 +1,179 @@
1
+ require_relative "test_helper.rb"
2
+
3
+ class StagerTest < Minitest::Test
4
+ def test_stager_stage_working
5
+ root_dir = File.join(File.dirname(__FILE__), "test_files", "stager_test")
6
+ stager_config = {
7
+ method: :working,
8
+ root_dir: root_dir,
9
+ logger: nil
10
+ }
11
+ stager = RokuBuilder::Stager.new(**stager_config)
12
+ assert stager.stage
13
+ assert stager.unstage
14
+ end
15
+
16
+ def test_stager_stage_current
17
+ root_dir = File.join(File.dirname(__FILE__), "test_files", "stager_test")
18
+ stager_config = {
19
+ method: :current,
20
+ root_dir: root_dir,
21
+ logger: nil
22
+ }
23
+ stager = RokuBuilder::Stager.new(**stager_config)
24
+ assert stager.stage
25
+ assert stager.unstage
26
+ end
27
+
28
+ def test_stager_stage_git_stash
29
+ root_dir = File.join(File.dirname(__FILE__), "test_files", "stager_test")
30
+ branch_name = 'branch'
31
+ git = Minitest::Mock.new
32
+ branch = Minitest::Mock.new
33
+ stashes = Minitest::Mock.new
34
+
35
+ stager_config = {
36
+ method: :git,
37
+ root_dir: root_dir,
38
+ key: branch_name,
39
+ logger: nil
40
+ }
41
+
42
+ git.expect(:current_branch, 'other_branch')
43
+ git.expect(:current_branch, 'other_branch')
44
+ git.expect(:branch, branch)
45
+ branch.expect(:stashes, stashes)
46
+ stashes.expect(:save, true, ["roku-builder-temp-stash"])
47
+ git.expect(:checkout, nil, [branch_name])
48
+ git.expect(:checkout, nil, ['other_branch'])
49
+ git.expect(:branch, branch)
50
+ branch.expect(:stashes, stashes)
51
+ stashes.expect(:apply, nil)
52
+
53
+ Git.stub(:open, git) do
54
+ stager = RokuBuilder::Stager.new(**stager_config)
55
+ assert stager.stage
56
+ assert stager.unstage
57
+ end
58
+ git.verify
59
+ branch.verify
60
+ stashes.verify
61
+ end
62
+
63
+ def test_stager_stage_git_no_stash
64
+ root_dir = File.join(File.dirname(__FILE__), "test_files", "stager_test")
65
+ branch_name = 'branch'
66
+ git = Minitest::Mock.new
67
+ branch = Minitest::Mock.new
68
+ stashes = Minitest::Mock.new
69
+
70
+ stager_config = {
71
+ method: :git,
72
+ root_dir: root_dir,
73
+ key: branch_name,
74
+ logger: nil
75
+ }
76
+
77
+ git.expect(:current_branch, 'other_branch')
78
+ git.expect(:current_branch, 'other_branch')
79
+ git.expect(:branch, branch)
80
+ branch.expect(:stashes, stashes)
81
+ stashes.expect(:save, nil, ["roku-builder-temp-stash"])
82
+ git.expect(:checkout, nil, [branch_name])
83
+ git.expect(:checkout, nil, ['other_branch'])
84
+
85
+ Git.stub(:open, git) do
86
+ stager = RokuBuilder::Stager.new(**stager_config)
87
+ assert stager.stage
88
+ assert stager.unstage
89
+ end
90
+ git.verify
91
+ branch.verify
92
+ stashes.verify
93
+ end
94
+
95
+ def test_stager_stage_git_error_stage
96
+ root_dir = File.join(File.dirname(__FILE__), "test_files", "stager_test")
97
+ branch_name = 'branch'
98
+ git = Minitest::Mock.new
99
+ branch = Minitest::Mock.new
100
+ stashes = Minitest::Mock.new
101
+ logger = Minitest::Mock.new
102
+
103
+ stager_config = {
104
+ method: :git,
105
+ root_dir: root_dir,
106
+ key: branch_name,
107
+ logger: logger
108
+ }
109
+
110
+ def git.checkout(branch)
111
+ raise Git::GitExecuteError.new
112
+ end
113
+
114
+ git.expect(:current_branch, 'other_branch')
115
+ git.expect(:current_branch, 'other_branch')
116
+ git.expect(:branch, branch)
117
+ branch.expect(:stashes, stashes)
118
+ stashes.expect(:save, true, ["roku-builder-temp-stash"])
119
+ logger.expect(:error, nil, ["Branch or ref does not exist"])
120
+ git.expect(:branch, branch)
121
+ branch.expect(:stashes, stashes)
122
+ stashes.expect(:apply, nil)
123
+
124
+ Git.stub(:open, git) do
125
+ stager = RokuBuilder::Stager.new(**stager_config)
126
+ assert !stager.stage
127
+ assert stager.unstage
128
+ end
129
+ git.verify
130
+ branch.verify
131
+ stashes.verify
132
+ logger.verify
133
+ end
134
+
135
+ def test_stager_stage_git_error_unstage
136
+ root_dir = File.join(File.dirname(__FILE__), "test_files", "stager_test")
137
+ branch_name = 'branch'
138
+ git = Minitest::Mock.new
139
+ branch = Minitest::Mock.new
140
+ stashes = Minitest::Mock.new
141
+ logger = Minitest::Mock.new
142
+
143
+ stager_config = {
144
+ method: :git,
145
+ root_dir: root_dir,
146
+ key: branch_name,
147
+ logger: logger
148
+ }
149
+
150
+ def git.checkout(branch)
151
+ raise Git::GitExecuteError.new
152
+ end
153
+
154
+ logger.expect(:error, nil, ["Branch or ref does not exist"])
155
+
156
+ Git.stub(:open, git) do
157
+ stager = RokuBuilder::Stager.new(**stager_config)
158
+ stager.instance_variable_set(:@current_branch, "branch")
159
+ assert !stager.unstage
160
+ end
161
+ logger.verify
162
+ end
163
+
164
+ def test_stager_stage_script
165
+ root_dir = File.join(File.dirname(__FILE__), "test_files", "stager_test")
166
+ stager_config = {
167
+ method: :script,
168
+ key: {stage: "stage_script", unstage: "unstage_script"},
169
+ root_dir: root_dir,
170
+ logger: nil
171
+ }
172
+ RokuBuilder::Controller.stub(:system, nil) do
173
+ stager = RokuBuilder::Stager.new(**stager_config)
174
+ assert stager.stage
175
+ assert stager.unstage
176
+ end
177
+ end
178
+ end
179
+
@@ -1,2 +1,6 @@
1
- build_version=010101.1
2
1
  title=Test
2
+ major_version=1
3
+ minor_version=0
4
+ build_version=010101.1
5
+ mm_icon_focus_hd=pkg:/images/focus.png
6
+ mm_icon_focus_sd=pkg:/images/focus.png
@@ -1,2 +1,6 @@
1
- build_version=010101
2
1
  title=Test
2
+ major_version=1
3
+ minor_version=0
4
+ build_version=010101
5
+ mm_icon_focus_hd=pkg:/images/focus.png
6
+ mm_icon_focus_sd=pkg:/images/focus.png
@@ -0,0 +1,6 @@
1
+ title=New Title
2
+ major_version=2
3
+ minor_version=2
4
+ build_version=020202.0002
5
+ mm_icon_focus_hd=pkg:/images/focus1.png
6
+ mm_icon_focus_sd=pkg:/images/focus2.png
File without changes
@@ -29,6 +29,7 @@ def good_config
29
29
  folders: ["resources","source"],
30
30
  files: ["manifest"],
31
31
  app_name: "<app name>",
32
+ stage_method: :git,
32
33
  stages:{
33
34
  production: {
34
35
  branch: "production",
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: roku_builder
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.3.4
4
+ version: 3.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - greeneca
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-05 00:00:00.000000000 Z
11
+ date: 2016-04-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubyzip
@@ -253,6 +253,7 @@ files:
253
253
  - lib/roku_builder/monitor.rb
254
254
  - lib/roku_builder/navigator.rb
255
255
  - lib/roku_builder/packager.rb
256
+ - lib/roku_builder/stager.rb
256
257
  - lib/roku_builder/tester.rb
257
258
  - lib/roku_builder/util.rb
258
259
  - lib/roku_builder/version.rb
@@ -272,6 +273,7 @@ files:
272
273
  - tests/roku_builder/monitor_test.rb
273
274
  - tests/roku_builder/navigator_test.rb
274
275
  - tests/roku_builder/packager_test.rb
276
+ - tests/roku_builder/stager_test.rb
275
277
  - tests/roku_builder/test_files/controller_config_test/valid_config.json
276
278
  - tests/roku_builder/test_files/controller_test/load_config_test.json
277
279
  - tests/roku_builder/test_files/controller_test/valid_config.json
@@ -281,6 +283,11 @@ files:
281
283
  - tests/roku_builder/test_files/loader_test/source/c/d
282
284
  - tests/roku_builder/test_files/manifest_manager_test/manifest_template
283
285
  - tests/roku_builder/test_files/manifest_manager_test/manifest_template_2
286
+ - tests/roku_builder/test_files/manifest_manager_test/updated_title_manifest
287
+ - tests/roku_builder/test_files/stager_test/a
288
+ - tests/roku_builder/test_files/stager_test/manifest
289
+ - tests/roku_builder/test_files/stager_test/source/b
290
+ - tests/roku_builder/test_files/stager_test/source/c/d
284
291
  - tests/roku_builder/test_helper.rb
285
292
  - tests/roku_builder/tester_test.rb
286
293
  - tests/roku_builder/util_test.rb