Class: Releasinator::Downstream

Inherits:
Object
  • Object
show all
Defined in:
lib/downstream.rb

Instance Method Summary collapse

Constructor Details

#initialize(releasinator_config, validator, current_release) ⇒ Downstream

Returns a new instance of Downstream.



10
11
12
13
14
# File 'lib/downstream.rb', line 10

def initialize(releasinator_config, validator, current_release)
  @releasinator_config = releasinator_config
  @validator = validator
  @current_release = current_release
end

Instance Method Details

#build(args) ⇒ Object



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/downstream.rb', line 110

def build(args)
  if @releasinator_config.has_key?(:downstream_repos)
    get_downstream_repos(args[:downstream_repo_index]).each do |downstream_repo, index|
      puts "building downstream_repo[#{index}]: #{downstream_repo.url}" if @releasinator_config[:verbose]
      Dir.chdir(DOWNSTREAM_REPOS) do
        Dir.chdir(downstream_repo.name) do
          # build any files to verify release
          if downstream_repo.options.has_key? :build_methods
            downstream_repo.options[:build_methods].each do |method|
              method.call
            end
          end
        end
      end
    end
    Printer.success("Done building downstream repos.")
  else
    Printer.success("Not building downstream repos.  None found.")
  end
end

#package(args) ⇒ Object



131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/downstream.rb', line 131

def package(args)
  if @releasinator_config.has_key?(:downstream_repos)
    get_downstream_repos(args[:downstream_repo_index]).each do |downstream_repo, index|
      puts "packaging downstream_repo[#{index}]: #{downstream_repo.url}" if @releasinator_config[:verbose]
      Dir.chdir(DOWNSTREAM_REPOS) do
        Dir.chdir(downstream_repo.name) do
          # don't tag those where new branches are created
          GitUtil.tag(@current_release.version, @current_release.changelog) unless downstream_repo.options.has_key? :new_branch_name
        end
      end
    end
    Printer.success("Done packaging downstream repos.")
  else
    Printer.success("Not packaging downstream repos.  None found.")
  end
end

#prepare(args) ⇒ Object



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
# File 'lib/downstream.rb', line 50

def prepare(args)
  if @releasinator_config.has_key?(:downstream_repos)
    get_downstream_repos(args[:downstream_repo_index]).each do |downstream_repo, index|
      puts "preparing downstream_repo[#{index}]: #{downstream_repo.url}" if @releasinator_config[:verbose]

      root_dir = Dir.pwd.strip
      copy_from_dir = root_dir + "/" + @releasinator_config.base_dir

      Dir.chdir(DOWNSTREAM_REPOS) do
        Dir.chdir(downstream_repo.name) do

          if downstream_repo.options.has_key? :new_branch_name
            new_branch_name = get_new_branch_name(downstream_repo.options[:new_branch_name], @current_release.version)
            CommandProcessor.command("git checkout -b #{new_branch_name}")
          end

          if downstream_repo.full_file_sync
            # remove old everything
            CommandProcessor.command("rm -rf *")

            # update all distribution files
            CommandProcessor.command("rsync -av --exclude='#{DOWNSTREAM_REPOS}' --exclude='.git/' #{copy_from_dir}/* .")
            CommandProcessor.command("rsync -av --exclude='#{DOWNSTREAM_REPOS}' --exclude='.git/' #{copy_from_dir}/.[!.]* .")
          end

          # copy custom files
          if downstream_repo.options.has_key? :files_to_copy
            downstream_repo.options[:files_to_copy].each do |copy_file|
              copy_the_file(root_dir, copy_file, @current_release.version)
            end
          end

          if downstream_repo.options.has_key? :post_copy_methods
            downstream_repo.options[:post_copy_methods].each do |method|
              method.call(@current_release.version)
            end
          end

          if GitUtil.is_clean_git?
            Printer.fail("Nothing changed in #{downstream_repo.name}!")
            abort()
          end
          # add everything to git and commit
          CommandProcessor.command("git add .")
          CommandProcessor.command("git add -u .")
          if downstream_repo.options.has_key? :new_branch_name
            commit_message = "Update #{@releasinator_config[:product_name]} to #{@current_release.version}"
          else
            commit_message = "Release #{@current_release.version}"
          end
          CommandProcessor.command("git commit -am \"#{commit_message}\"")
        end
      end
    end
    Printer.success("Done preparing downstream repos.")
  else
    Printer.success("Not preparing downstream repos.  None found.")
  end
end

#push(args) ⇒ Object



148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# File 'lib/downstream.rb', line 148

def push(args)
  if @releasinator_config.has_key?(:downstream_repos)
    get_downstream_repos(args[:downstream_repo_index]).each do |downstream_repo, index|
      puts "pushing downstream_repo[#{index}]: #{downstream_repo.url}" if @releasinator_config[:verbose]
      Dir.chdir(DOWNSTREAM_REPOS) do
        Dir.chdir(downstream_repo.name) do
          if downstream_repo.options.has_key? :new_branch_name
            new_branch_name = get_new_branch_name(downstream_repo.options[:new_branch_name], @current_release.version)
            CommandProcessor.command("git push -u origin #{new_branch_name}")
            # TODO - check that the branch exists
            CommandProcessor.command("sleep 5")
            Publisher.new(@releasinator_config).publish_pull_request(downstream_repo.url, @current_release, @releasinator_config[:product_name], downstream_repo.branch, new_branch_name)
          else
            GitUtil.push_branch("master")
            GitUtil.push_tag(@current_release.version)
            # TODO - check that the tag exists
            CommandProcessor.command("sleep 5")
            Publisher.new(@releasinator_config).publish(downstream_repo.url, @current_release) unless ! downstream_repo.release_to_github
          end
        end
      end
    end
    Printer.success("Done pushing downstream repos.")
  else
    Printer.success("Not pushing downstream repos.  None found.")
  end
end

#reset(args) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/downstream.rb', line 26

def reset(args)
  if @releasinator_config.has_key?(:downstream_repos)
    get_downstream_repos(args[:downstream_repo_index]).each do |downstream_repo, index|
      puts "resetting downstream_repo[#{index}]: #{downstream_repo.url}" if @releasinator_config[:verbose]
      Dir.mkdir(DOWNSTREAM_REPOS) unless File.exist?(DOWNSTREAM_REPOS)
      Dir.chdir(DOWNSTREAM_REPOS) do
        CommandProcessor.command("git clone --origin origin #{downstream_repo.url} #{downstream_repo.name}") unless File.exist?(downstream_repo.name)

        Dir.chdir(downstream_repo.name) do
          GitUtil.reset_repo(downstream_repo.branch)

          if downstream_repo.options.has_key? :new_branch_name
            new_branch_name = get_new_branch_name(downstream_repo.options[:new_branch_name], @current_release.version)
            GitUtil.delete_branch new_branch_name
          end
        end
      end
    end
    Printer.success("Done resetting downstream repos.")
  else
    Printer.success("Not resetting downstream repos.  None found.")
  end
end

#validate_github_permissions(args) ⇒ Object



16
17
18
19
20
21
22
23
24
# File 'lib/downstream.rb', line 16

def validate_github_permissions(args)
  if @releasinator_config.has_key?(:downstream_repos)
    get_downstream_repos(args[:downstream_repo_index]).each do |downstream_repo, index|
      @validator.validate_github_permissions(downstream_repo.url)
    end
  else
    Printer.success("Not validating permissions of downstream repos.  None found.")
  end
end