Class: Release

Inherits:
Object
  • Object
show all
Includes:
ReleaseManager::Logger
Defined in:
lib/release_manager/release.rb

Direct Known Subclasses

RemoteRelease

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ReleaseManager::Logger

#color, #log_level, #logger

Constructor Details

#initialize(path = Dir.getwd, options = {}) ⇒ Release

Returns a new instance of Release.



8
9
10
11
# File 'lib/release_manager/release.rb', line 8

def initialize(path = Dir.getwd, options = {})
  @path = path || Dir.getwd    
  @options = options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



5
6
7
# File 'lib/release_manager/release.rb', line 5

def options
  @options
end

#pathObject (readonly)

Returns the value of attribute path.



5
6
7
# File 'lib/release_manager/release.rb', line 5

def path
  @path
end

Instance Method Details

#add_upstream_remoteObject



132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/release_manager/release.rb', line 132

def add_upstream_remote
  if auto_release?
    puppet_module.add_upstream_remote
    return
  end
  answer = nil
  while answer !~ /y|n/
    print "Ok to change your upstream remote from #{puppet_module.upstream}\n to #{puppet_module.source}? (y/n): "
    answer = gets.downcase.chomp
  end
  puppet_module.add_upstream_remote if answer == 'y'
end

#auto_release?Boolean

Returns:

  • (Boolean)


71
72
73
# File 'lib/release_manager/release.rb', line 71

def auto_release?
  options[:auto] || ENV['AUTO_RELEASE'] == 'true'
end

#bumpObject

Raises:



38
39
40
41
42
43
44
45
46
47
# File 'lib/release_manager/release.rb', line 38

def bump
  if dry_run?
    logger.info "Would have just bumped the version to #{version}"
    return
  end
  raise TagExists.new("Tag v#{version} already exists") if puppet_module.tag_exists?("v#{next_version}", options[:remote])
  version = puppet_module.bump_patch_version unless options[:bump]
  # save the update version to the metadata file, then commit
  puppet_module.(options[:remote])
end

#bump_logString

Returns - sha of the commit.

Returns:

  • (String)
    • sha of the commit



50
51
52
53
54
55
56
57
# File 'lib/release_manager/release.rb', line 50

def bump_log
  if dry_run?
    logger.info "Would have just bumped the CHANGELOG to version #{version}"
    return
  end
  log = Changelog.new(puppet_module.path, version, {:commit => true})
  log.run(options[:remote], puppet_module.src_branch)
end

#check_requirementsObject



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/release_manager/release.rb', line 75

def check_requirements
  @loop_count = @loop_count.to_i + 1
  begin
    PuppetModule.check_requirements(puppet_module.path)
    raise AlreadyReleased.new("No new changes, skipping release") if puppet_module.already_latest?
    Changelog.check_requirements(puppet_module.path)
  rescue NoUnreleasedLine
    logger.fatal "No Unreleased line in the CHANGELOG.md file, please add a Unreleased line and retry"
    return false
  rescue UpstreamSourceMatch
    logger.warn "The upstream remote url does not match the source url in the metadata.json source"
    add_upstream_remote
    return false if @loop_count > 2
    check_requirements
  rescue InvalidMetadataSource
    logger.fatal "The puppet module's metadata.json source field must be a git url: ie. [email protected]:devops/module.git"
    return false
  rescue NoChangeLogFile
    logger.fatal "CHANGELOG.md does not exist, please create one"
    return false
  end
end

#dry_run?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'lib/release_manager/release.rb', line 67

def dry_run?
  options[:dry_run] == true
end

#next_versionObject



26
27
28
# File 'lib/release_manager/release.rb', line 26

def next_version
  puppet_module.version.next
end

#puppet_moduleObject



13
14
15
# File 'lib/release_manager/release.rb', line 13

def puppet_module
  @puppet_module ||= PuppetModule.new(path, upstream_repo)
end

#pushObject



59
60
61
62
63
64
65
# File 'lib/release_manager/release.rb', line 59

def push
  if dry_run?
    logger.info "Would have just pushed the code and tag to #{puppet_module.source}"
    return
  end
  puppet_module.push_to_upstream
end

#releaseObject

runs all the required steps to release the software currently this must be done manually by a release manager



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/release_manager/release.rb', line 101

def release
  unless auto_release?
    print "Have you merged your code?  Did you fetch and rebase against the upstream?  Want to continue (y/n)?: ".yellow
    answer = gets.downcase.chomp
    if answer == 'n'
      return false
    end
  end

  # updates the metadata.json file to the next version
  bump
  # updates the changelog to the next version based on the metadata file
  id = bump_log
  # tags the r10k-module with the version found in the metadata.json file
  tag(id)
  # pushes the updated code and tags to the upstream repo
  if auto_release? 
   push
   return
  end
  print "Ready to release version #{version} to #{puppet_module.source}\n and forever change history(y/n)?: ".yellow
  answer = gets.downcase.chomp
  if answer == 'y'
    push
    $?.success?
  else
    puts "Nah, forget it, this release wasn't that cool anyways.".yellow
    false 
  end 
end

#runObject



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
175
176
177
178
179
180
# File 'lib/release_manager/release.rb', line 149

def run
  begin
    exit -1 unless check_requirements
    puppet_module.create_dev_branch
    value = release
    unless value
     exit 1
    end
    logger.info "Releasing Version #{version} to #{puppet_module.source}"
    logger.info "Version #{version} has been released successfully"
    puts "This was a dry run so nothing actually happen".green if dry_run?
    exit 0
  rescue Gitlab::Error::Forbidden => e
    logger.fatal(e.message)
    logger.fatal("You don't have access to modify the repository")
    exit -1
  rescue TagExists => e
    logger.fatal(e.message)
    exit -1
  rescue GitError => e
    logger.fatal "There was an issue when running a git command\n #{e.message}"
  rescue InvalidMetadataSource
    logger.fatal "The puppet module's metadata.json source field must be a git url: ie. [email protected]:devops/module.git"
    exit -1
  rescue AlreadyReleased => e
    logger.warn(e.message)
    exit 0
  rescue ModNotFoundException
    logger.fatal "Invalid module path for #{path}"
    exit -1
  end
end

#tag(id) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/release_manager/release.rb', line 30

def tag(id)
  if dry_run?
    logger.info "Would have just tagged the module to #{version}"
    return
  end
  puppet_module.tag_module(options[:remote], id)
end

#upstream_repoObject



17
18
19
# File 'lib/release_manager/release.rb', line 17

def upstream_repo 
  options[:repo] || ENV['UPSTREAM_REPO']  
end

#verbose?Boolean

Returns:

  • (Boolean)


145
146
147
# File 'lib/release_manager/release.rb', line 145

def verbose?
  options[:verbose]
end

#versionObject



22
23
24
# File 'lib/release_manager/release.rb', line 22

def version
   dry_run? ? next_version : puppet_module.version
end