forked from travis-ci/travis-deploy
/
config.rb
65 lines (52 loc) · 1.33 KB
/
config.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
require 'shellwords'
require 'yaml'
module Travis
class Cli
class Config
include Helper
attr_reader :shell, :remote, :options
def initialize(shell, remote, options)
@remote = remote
@options = options
@shell = shell
end
def invoke
store
push
end
protected
def app
@app ||= begin
app = File.basename(Dir.pwd).gsub('travis-', '')
app = 'web' if app == 'ci'
app
end
end
def config
@config ||= keychain.fetch
end
def keychain
@keychain ||= Keychain.new(app, shell)
end
def store
backup if backup?
File.open(filename, 'w+') { |f| f.write(config) }
end
def push
say 'Configuring the app ...'
config = Shellwords.escape(YAML.dump(YAML.load(self.config)[remote]))
run "heroku config:add travis_config=#{config} -r #{remote}", :echo => "heroku config:add travis_config=... -r #{app}"
end
def backup
say 'Backing up the old config file ...'
run "cp #{filename} #{filename}.backup"
end
def backup?
!!options['backup']
end
def filename
"config/travis.yml"
end
end
end
end