docman 0.0.14 → 0.0.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0fb73f66842f33cfed8718d90967ff300c9003df
4
- data.tar.gz: 1a7ab11302d11b040020666a2cdcf03764c24937
3
+ metadata.gz: d138ff74ad5837f8460e69faec2e19fcf97ee0a5
4
+ data.tar.gz: ef1848962b219e8780fde2f4ffdc4e3a283ea539
5
5
  SHA512:
6
- metadata.gz: f195b9bcca8313fac8986eaa236e7125263740178b7a59779c2fe9c028ccb309ca652f75e3474ea1bdf059346df78a75596699d93f6bcf55429fd99c35e4a4ec
7
- data.tar.gz: 6d219e4d86dfb1f2afd051e9951607a4ee98cc8fbd66737aa9d3bb7d1c9cbb00dc63443cdee35b20bb6066aed98b9e135b24296cf2269034de302b3d3b86f6d7
6
+ metadata.gz: 0fd814d827b2a89666f19bf9b9cc320482f214fdecf205d22678de82258744378f335159881b22e40e9b0b1f3a63fb3a01d5720c153c15ddc92118c18c772058
7
+ data.tar.gz: d62645d7718be612acff746ea478bf2af4715a350cf94c1c12f89441a2f49c5af7567a6a4f88ed4740761172a49c9f37e2740bb297b5935f02a3264a80a864b3
data/bin/bump-version.sh CHANGED
@@ -29,6 +29,7 @@ if [ -f VERSION ]; then
29
29
  fi
30
30
  echo "Will set new version to be $INPUT_STRING"
31
31
  echo $INPUT_STRING > VERSION
32
+ TAG=${INPUT_STRING}
32
33
  echo "Version $INPUT_STRING:" > tmpfile
33
34
  git log --pretty=format:" - %s" "$BASE_STRING"...HEAD >> tmpfile
34
35
  echo "" >> tmpfile
@@ -60,5 +61,21 @@ else
60
61
  git push origin --tags
61
62
  git push
62
63
  fi
63
-
64
+ TAG="0.1.0"
65
+ fi
66
+
67
+ if [ -n "$1" ]; then
68
+ BRANCH="state_$1"
69
+ git show-ref --verify --quiet "refs/heads/${BRANCH}"
70
+ if [ $? == 0 ]; then
71
+ git checkout ${BRANCH}
72
+ else
73
+ git checkout -b ${BRANCH}
74
+ fi
75
+ echo "type: tag" > info.yaml
76
+ echo "version: $TAG" >> info.yaml
77
+ git add -A
78
+ git commit -m "Changed tag to: $TAG" & git push origin ${BRANCH}
79
+ git checkout -
80
+ echo ${TAG}
64
81
  fi
data/lib/application.rb CHANGED
@@ -25,6 +25,9 @@ require 'docman/commands/create_symlink_cmd'
25
25
  require 'docman/commands/execute_script_cmd'
26
26
  require 'docman/commands/clean_changed_cmd'
27
27
  require 'docman/commands/git_commit_cmd'
28
+ require 'docman/taggers/tagger'
29
+ require 'docman/taggers/incremental_tagger'
30
+ require 'docman/taggers/option_tagger'
28
31
 
29
32
  module Docman
30
33
  class Application < Docman::Command
@@ -51,7 +54,7 @@ module Docman
51
54
  @deploy_target = @config['deploy_targets'][deploy_target_name]
52
55
  @deploy_target['name'] = deploy_target_name
53
56
  @docroot_config = DocrootConfig.new(@workspace_dir, deploy_target)
54
- execute('build', state)
57
+ execute('build', state, nil, options['tag'])
55
58
  end
56
59
 
57
60
  def deploy(deploy_target_name, name, type, version, options = false)
@@ -65,14 +68,24 @@ module Docman
65
68
  end
66
69
  end
67
70
 
68
- def execute(action, state, name = nil)
71
+ def execute(action, state, name = nil, tag = nil)
69
72
  params = Marshal.load(Marshal.dump(@deploy_target))
73
+ failed_filepath = File.join(@workspace_dir, 'failed')
74
+ if File.file?(failed_filepath)
75
+ log 'Last operation failed, forced rebuild mode'
76
+ FileUtils.rm_f failed_filepath
77
+ @force = true
78
+ end
70
79
  params['state'] = state
71
80
  params['action'] = action
72
81
  params['name'] = name
82
+ params['tag'] = tag
73
83
  params['environment'] = @config['environments'][@deploy_target['states'][state]]
74
84
  params['environment_name'] = @deploy_target['states'][state]
75
85
  Docman::Deployers::Deployer.create(params, nil, self).perform
86
+ rescue Exception => e
87
+ log "Operation failed: #{e.message}", 'error'
88
+ File.open(failed_filepath, 'w') {|f| f.write('Failed!') }
76
89
  end
77
90
 
78
91
  def force?
@@ -22,6 +22,7 @@ module Docman
22
22
 
23
23
  def config
24
24
  super
25
+ @version = nil
25
26
  add_action('before_execute', {'type' => :clean_changed}, @context)
26
27
  end
27
28
 
@@ -30,6 +31,10 @@ module Docman
30
31
  raise "Context should be of type 'Info'" unless @context.is_a? Docman::Info
31
32
  end
32
33
 
34
+ def version
35
+ @version
36
+ end
37
+
33
38
  before_execute do
34
39
  if @context.need_rebuild?
35
40
  @context.build_mode = :rebuild
@@ -16,6 +16,10 @@ module Docman
16
16
  @context['build_path']
17
17
  end
18
18
 
19
+ def version
20
+ @context['build_path']
21
+ end
22
+
19
23
  end
20
24
  end
21
25
  end
@@ -18,6 +18,10 @@ module Docman
18
18
  @context.version
19
19
  end
20
20
 
21
+ def version
22
+ @context.version
23
+ end
24
+
21
25
  end
22
26
  end
23
27
  end
@@ -7,15 +7,15 @@ module Docman
7
7
  def execute
8
8
  execute_result = GitUtil.get(@context['repo'], @context['full_build_path'], @context.version_type, @context.version)
9
9
  # No commit hash for 'root' as it will be changed later
10
- result = @context['type'] == 'root' ? @context['build_path'] : execute_result
11
- GitUtil.repo_changed?(@context['full_build_path']) ? result : false
10
+ @version = @context['type'] == 'root' ? @context['build_path'] : execute_result
11
+ GitUtil.repo_changed?(@context['full_build_path']) ? @version : false
12
12
  end
13
13
 
14
14
  def changed?
15
15
  stored_version = @context.stored_version['result']
16
16
  # No commit hash for 'root' as it will be changed later
17
- repo_version = @context['type'] == 'root' ? @context['build_path'] : GitUtil.get(@context['repo'], @context['full_build_path'], @context.version_type, @context.version, true)
18
- stored_version != repo_version
17
+ @version = @context['type'] == 'root' ? @context['build_path'] : GitUtil.get(@context['repo'], @context['full_build_path'], @context.version_type, @context.version)
18
+ stored_version != @version
19
19
  end
20
20
 
21
21
  end
@@ -7,17 +7,17 @@ module Docman
7
7
  def execute
8
8
  FileUtils.rm_r(@context['full_build_path']) if File.directory? @context['full_build_path']
9
9
  # FileUtils.rm_r @context['temp_path'] if @context.need_rebuild? and File.directory? @context['temp_path']
10
- result = GitUtil.get(@context['repo'], @context['temp_path'], @context.version_type, @context.version)
10
+ @version = GitUtil.get(@context['repo'], @context['temp_path'], @context.version_type, @context.version)
11
11
  FileUtils.mkdir_p(@context['full_build_path'])
12
12
  FileUtils.cp_r(Dir["#{@context['temp_path']}/."], @context['full_build_path'])
13
13
  FileUtils.rm_r(File.join(@context['full_build_path'], '.git')) if File.directory?(File.join(@context['full_build_path'], '.git'))
14
- GitUtil.repo_changed?(@context['full_build_path']) ? result : false
14
+ GitUtil.repo_changed?(@context['full_build_path']) ? @version : false
15
15
  end
16
16
 
17
17
  def changed?
18
18
  stored_version = @context.stored_version['result']
19
- repo_version = GitUtil.get(@context['repo'], @context['temp_path'], @context.version_type, @context.version)
20
- stored_version != repo_version
19
+ @version = GitUtil.get(@context['repo'], @context['temp_path'], @context.version_type, @context.version)
20
+ stored_version != @version
21
21
  end
22
22
 
23
23
  end
data/lib/docman/cli.rb CHANGED
@@ -38,6 +38,7 @@ module Docman
38
38
 
39
39
  desc 'build NAME', 'init to NAME'
40
40
  method_option :force, :aliases => '-f', :desc => 'Force full rebuild'
41
+ option :tag
41
42
  def build(deploy_target, state)
42
43
  config_dir?
43
44
  if options[:force]
@@ -15,7 +15,7 @@ module Docman
15
15
  end
16
16
 
17
17
  def execute
18
- message = "name: #{@context['name']} updated, state: #{@context['state']}"
18
+ message = "name: #{@context['name']} updated, state: #{@context.state_name}"
19
19
  with_logging(message) do
20
20
  GitUtil.commit(@context['root']['full_build_path'], @context['full_build_path'], message)
21
21
  end
@@ -3,6 +3,7 @@ require 'net/sftp'
3
3
  module Docman
4
4
 
5
5
  class SSHTargetChecker < Docman::TargetChecker
6
+
6
7
  register_checker :ssh
7
8
 
8
9
  def execute
@@ -12,7 +12,6 @@ module Docman
12
12
 
13
13
  @@deployers = {}
14
14
 
15
- #todo: prod ssh settings deploy target
16
15
  #todo: docroot config in separate repos for projects
17
16
 
18
17
  def self.create(params, context = nil, caller = nil)
@@ -33,7 +32,7 @@ module Docman
33
32
  @docroot_config = caller.docroot_config
34
33
  @builded = []
35
34
  @build_results = {}
36
- @environments = Docman::Application.instance.config['envoronments']
35
+ @versions = {}
37
36
  end
38
37
 
39
38
  def config
@@ -41,6 +40,8 @@ module Docman
41
40
  @docroot_config.chain(@docroot_config.info_by(self['name'])).values.each do |info|
42
41
  add_actions(info, info)
43
42
  end
43
+ else
44
+ # add_actions()
44
45
  end
45
46
 
46
47
  path = @docroot_config.root['full_build_path']
@@ -121,6 +122,7 @@ module Docman
121
122
  to_write['random'] = version
122
123
  to_write['config_hash'] = @config_hash
123
124
  to_write['docroot_config_hash'] = @docroot_config_hash
125
+ to_write.deep_merge! @versions
124
126
  File.open(path, 'w') {|f| f.write to_write.to_yaml}
125
127
  end
126
128
 
@@ -138,7 +140,7 @@ module Docman
138
140
 
139
141
  def build_dir_chain(info)
140
142
  @docroot_config.chain(info).values.each do |item|
141
- item.state = self['state']
143
+ item.state_name = self['state']
142
144
  if item.need_rebuild?
143
145
  build_recursive(item)
144
146
  return
@@ -150,11 +152,13 @@ module Docman
150
152
 
151
153
  def build_dir(info)
152
154
  return if @builded.include? info['name']
153
- info.state = self['state']
154
- build_result = Docman::Builders::Builder.create(self['builders'][info['type']], info, self).perform
155
+ info.state_name = self['state']
156
+ builder = Docman::Builders::Builder.create(self['builders'][info['type']], info, self)
157
+ build_result = builder.perform
155
158
  logger.info '-------------------------------------------------------'
156
159
  @changed = true if build_result
157
- @build_results[info['name']] = build_result
160
+ @build_results[info['name']] = build_result ? build_result : 'Not builded'
161
+ @versions[info['name']] = builder.version
158
162
  @builded << info['name']
159
163
  end
160
164
 
@@ -167,6 +171,7 @@ module Docman
167
171
  end
168
172
  end
169
173
 
174
+ # TODO: need to refactor.
170
175
  def describe(type = 'short')
171
176
  properties_info(['handler'])
172
177
  end
@@ -6,8 +6,20 @@ module Docman
6
6
 
7
7
  def push
8
8
  root = @docroot_config.root
9
- root.state = self['state']
10
- GitUtil.commit(root['full_build_path'], root['full_build_path'], 'Updated version.yaml')
9
+ root.state_name = self['state']
10
+ tag = nil
11
+
12
+ if self['environment'].has_key?('tagger')
13
+ filepath = File.join(root['full_build_path'], 'VERSION')
14
+ prev_version = File.file?(filepath) ? File.open(filepath) : nil
15
+ params = self['environment']['tagger']
16
+ params['prev_version'] = prev_version
17
+ version = Docman::Taggers::Tagger.create(params, root, self).perform
18
+ File.open(filepath, 'w') {|f| f.write(version) }
19
+ tag = version
20
+ end
21
+
22
+ GitUtil.commit(root['full_build_path'], root['full_build_path'], 'Updated version', tag)
11
23
  GitUtil.push(root['full_build_path'], root.version)
12
24
  end
13
25
 
@@ -81,7 +81,7 @@ module Docman
81
81
  raise "There is no project with name '#{name}' exists in config" unless @names.has_key? name
82
82
 
83
83
  states = {}
84
- @names[name]['states'].each do |state, info|
84
+ @names[name].states.each do |state, info|
85
85
  states[state] = info if info['version'] == version
86
86
  end
87
87
  states
@@ -20,35 +20,38 @@ module Docman
20
20
  exec 'git clean -f -d'
21
21
  end
22
22
 
23
- def self.get(repo, path, type, version, force_return = false)
23
+ def self.get(repo, path, type, version)
24
24
  if File.directory? path and File.directory?(File.join(path, '.git'))
25
25
  Dir.chdir path
26
-
27
26
  self.reset_repo(path) #if self.repo_changed?(path)
28
-
29
27
  if type == 'branch'
28
+ exec "git fetch"
30
29
  exec "git checkout #{version}"
31
- initial_revision = self.last_revision
32
30
  exec "git pull origin #{version}"
33
31
  end
34
32
  if type == 'tag'
35
33
  exec 'git fetch --tags'
36
- initial_revision = self.last_revision
37
34
  exec "git checkout tags/#{version}"
38
35
  end
39
36
  else
40
- initial_revision = nil
41
37
  FileUtils.rm_rf path if File.directory? path
42
38
  exec "git clone #{repo} #{path}"
43
39
  Dir.chdir path
44
40
  exec "git checkout #{version}"
45
41
  end
46
- result = self.last_revision
47
- @logger.info "Commit hash: #{result}"
48
- # force_return or result != initial_revision ? result : false
42
+ result = type == 'branch' ? self.last_revision : version
49
43
  result
50
44
  end
51
45
 
46
+ def self.read_yaml_from_file(repo, path, version, filename)
47
+ self.get(repo, path, 'branch', version)
48
+ filepath = File.join(path, filename)
49
+ return YAML::load_file(filepath) if File.file? filepath
50
+ nil
51
+ rescue StandardError => e
52
+ raise "Error in info file: #{filepath}, #{e.message}"
53
+ end
54
+
52
55
  def self.last_revision
53
56
  result = `git rev-parse --short HEAD`
54
57
  result.delete!("\n")
@@ -58,12 +61,13 @@ module Docman
58
61
  pull path
59
62
  end
60
63
 
61
- def self.commit(root_path, path, message)
64
+ def self.commit(root_path, path, message, tag = nil)
62
65
  if repo_changed? path
63
66
  # puts message
64
67
  pull root_path
65
68
  exec %Q(git add --all #{path.slice "#{root_path}/"})
66
69
  exec %Q(git commit -m "#{message}") if repo_changed? path
70
+ self.tag(root_path, tag) if tag
67
71
  end
68
72
  end
69
73
 
@@ -88,8 +92,14 @@ module Docman
88
92
 
89
93
  def self.push(root_path, version)
90
94
  Dir.chdir root_path
91
- `git pull origin #{version}`
92
- `git push origin #{version}`
95
+ exec "git pull origin #{version}"
96
+ exec "git push origin #{version}"
97
+ end
98
+
99
+ def self.tag(root_path, tag)
100
+ Dir.chdir root_path
101
+ exec %Q(git tag -a -m "Tagged to #{tag}" "#{tag}")
102
+ exec "git push origin #{tag}"
93
103
  end
94
104
  end
95
105
 
data/lib/docman/info.rb CHANGED
@@ -5,7 +5,7 @@ module Docman
5
5
 
6
6
  include Docman::Context
7
7
 
8
- attr_accessor :need_rebuild, :build_mode
8
+ attr_accessor :need_rebuild, :build_mode, :state_name
9
9
 
10
10
  def initialize(hash = {})
11
11
  super
@@ -15,14 +15,26 @@ module Docman
15
15
  self['build_type'] = self['docroot_config'].deploy_target['builders'][self['type']]['handler']
16
16
  @need_rebuild = Hash.new
17
17
  @changed = Hash.new
18
+ @state_name = nil
19
+ if self.has_key? 'states'
20
+ self['states'].each_pair do |name, state|
21
+ if state.has_key?('source')
22
+ if state['source']['type'] == :retrieve_from_repo
23
+ repo = state['source']['repo'] == :project_repo ? self['repo'] : state['source']['repo']
24
+ external_state_info = GitUtil.read_yaml_from_file(repo, self['temp_path'], state['source']['branch'], state['source']['file'])
25
+ state.deep_merge! external_state_info
26
+ end
27
+ end
28
+ end
29
+ end
18
30
  end
19
31
 
20
32
  def version
21
- self['states'][self['state']].nil? ? nil : self['states'][self['state']]['version']
33
+ state.nil? ? nil : state['version']
22
34
  end
23
35
 
24
36
  def version_type
25
- self['states'][self['state']].nil? ? nil : self['states'][self['state']]['type']
37
+ state.nil? ? nil : state['type']
26
38
  end
27
39
 
28
40
  def describe(type = 'short')
@@ -31,7 +43,7 @@ module Docman
31
43
 
32
44
  def write_info(result)
33
45
  to_save = {}
34
- to_save['state'] = self['state']
46
+ to_save['state'] = @state_name
35
47
  to_save['version_type'] = self.version_type unless self.version_type.nil?
36
48
  to_save['version'] = self.version unless self.version.nil?
37
49
  to_save['result'] = result
@@ -44,25 +56,25 @@ module Docman
44
56
 
45
57
  def changed?
46
58
  #TODO: need refactor
47
- return @changed[self['state']] if not @changed.nil? and @changed.has_key? self['state'] and not @changed[self['state']].nil?
48
- @changed[self['state']] = false
59
+ return @changed[@state_name] if not @changed.nil? and @changed.has_key? @state_name and not @changed[@state_name].nil?
60
+ @changed[@state_name] = false
49
61
  if need_rebuild?
50
- @changed[self['state']] = true
62
+ @changed[@state_name] = true
51
63
  end
52
- @changed[self['state']]
64
+ @changed[@state_name]
53
65
  end
54
66
 
55
67
  def need_rebuild?
56
- return @need_rebuild[self['state']] if not @need_rebuild.nil? and @need_rebuild.has_key? self['state'] and not @need_rebuild[self['state']].nil?
57
- @need_rebuild[self['state']] = _need_rebuild?
58
- if @need_rebuild[self['state']]
68
+ return @need_rebuild[@state_name] if not @need_rebuild.nil? and @need_rebuild.has_key? @state_name and not @need_rebuild[@state_name].nil?
69
+ @need_rebuild[@state_name] = _need_rebuild?
70
+ if @need_rebuild[@state_name]
59
71
  set_rebuild_recursive(self, true)
60
72
  end
61
- @need_rebuild[self['state']]
73
+ @need_rebuild[@state_name]
62
74
  end
63
75
 
64
76
  def set_rebuild_recursive(obj, value)
65
- obj.need_rebuild[self['state']] = value
77
+ obj.need_rebuild[@state_name] = value
66
78
  if obj.has_key?('children')
67
79
  obj['children'].each do |info|
68
80
  set_rebuild_recursive(info, value)
@@ -78,11 +90,11 @@ module Docman
78
90
  return true if v['type'] != self['type']
79
91
  return true if v['build_type'] != self['build_type']
80
92
  # return true if (not v['version'].nil? and v['version'] != self.version)
81
- @changed[self['state']] = true if (not v['version'].nil? and v['version'] != self.version)
82
- return true if (not v['version_type'].nil? and v['version_type'] != self.version_type)
93
+ @changed[@state_name] = true if (not v['version'].nil? and v['version'] != version)
94
+ return true if (not v['version_type'].nil? and v['version_type'] != version_type)
83
95
  unless v['state'].nil?
84
- # return true if v['state'] != self['state']
85
- @changed[self['state']] = true if v['state'] != self['state']
96
+ # return true if v['state'] != @state_name
97
+ @changed[@state_name] = true if v['state'] != @state_name
86
98
  end
87
99
  false
88
100
  end
@@ -93,8 +105,12 @@ module Docman
93
105
  YAML::load_file(info_filename)
94
106
  end
95
107
 
96
- def state=(state)
97
- self['state'] = state
108
+ def state
109
+ states[@state_name]
110
+ end
111
+
112
+ def states
113
+ self['states']
98
114
  end
99
115
 
100
116
  def disabled?
@@ -112,7 +128,7 @@ module Docman
112
128
  end
113
129
 
114
130
  def environment_name
115
- self['docroot_config'].deploy_target['states'][self['state']]
131
+ self['docroot_config'].deploy_target['states'][@state_name]
116
132
  end
117
133
 
118
134
  end
@@ -0,0 +1,17 @@
1
+ require 'docman/taggers/tagger'
2
+
3
+ module Docman
4
+ class IncrementalTagger < Docman::Taggers::Tagger
5
+
6
+ register_tagger :incremental
7
+
8
+ def execute
9
+ version = self['prev_version'].nil? ? 0 : self['prev_version'].to_i
10
+ version = 0 unless version.is_a? Integer
11
+ version + 1
12
+ rescue
13
+ 1
14
+ end
15
+
16
+ end
17
+ end
@@ -0,0 +1,13 @@
1
+ require 'docman/taggers/tagger'
2
+
3
+ module Docman
4
+ class OptionTagger < Docman::Taggers::Tagger
5
+
6
+ register_tagger :option
7
+
8
+ def execute
9
+ @caller['tag']
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,28 @@
1
+ module Docman
2
+ module Taggers
3
+ class Tagger < Docman::Command
4
+
5
+ @@taggers = {}
6
+
7
+ #todo: docroot config in separate repos for projects
8
+
9
+ def self.create(params, context = nil, caller = nil)
10
+ c = @@taggers[params['handler']]
11
+ if c
12
+ c.new(params, context, caller, 'tagger')
13
+ else
14
+ raise "Bad tagger type: #{type}"
15
+ end
16
+ end
17
+
18
+ def self.register_tagger(name)
19
+ @@taggers[name] = self
20
+ end
21
+
22
+ def initialize(params, context = nil, caller = nil, type = nil)
23
+ super(params, context, caller, type)
24
+ end
25
+
26
+ end
27
+ end
28
+ end
@@ -1,3 +1,3 @@
1
1
  module Docman
2
- VERSION = "0.0.14"
2
+ VERSION = "0.0.15"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: docman
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.14
4
+ version: 0.0.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Tolstikov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-17 00:00:00.000000000 Z
11
+ date: 2014-07-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -195,6 +195,9 @@ files:
195
195
  - lib/docman/git_util.rb
196
196
  - lib/docman/info.rb
197
197
  - lib/docman/logging.rb
198
+ - lib/docman/taggers/incremental_tagger.rb
199
+ - lib/docman/taggers/option_tagger.rb
200
+ - lib/docman/taggers/tagger.rb
198
201
  - lib/docman/version.rb
199
202
  homepage: ''
200
203
  licenses: