Class: PlatformosCheck::Releaser

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

Defined Under Namespace

Classes: VersionError

Constant Summary collapse

ROOT =
File.expand_path('../..', __dir__)
LIB =
File.join(ROOT, 'lib')

Instance Method Summary collapse

Instance Method Details

#release(version) ⇒ Object

Raises:



12
13
14
15
16
17
18
19
# File 'lib/platformos_check/releaser.rb', line 12

def release(version)
  raise VersionError, "Missing version argument." if version.nil?
  raise VersionError, "Version should be a string." unless version.is_a?(String)
  raise VersionError, "Version should be a valid semver version." unless /^\d+\.\d+.\d+$/.match?(version)

  update_docs(version)
  update_version(version)
end

#update_docs(version) ⇒ Object



32
33
34
35
36
37
38
39
40
41
# File 'lib/platformos_check/releaser.rb', line 32

def update_docs(version)
  Dir[ROOT + '/docs/checks/*.md'].each do |filename|
    doc_content = File.read(filename)
    updated_doc_content = doc_content.gsub('PLATFORMOS_CHECK_VERSION', version)
    next if updated_doc_content == doc_content

    puts "Replacing `PLATFORMOS_CHECK_VERSION` with #{version} in #{Pathname.new(filename).relative_path_from(ROOT)}"
    File.write(filename, updated_doc_content)
  end
end

#update_version(version) ⇒ Object



21
22
23
24
25
26
27
28
29
30
# File 'lib/platformos_check/releaser.rb', line 21

def update_version(version)
  version_file_path = File.join(LIB, 'platformos_check/version.rb')
  version_file = File.read(version_file_path)
  updated_version_file = version_file.gsub(PlatformosCheck::VERSION, version)

  return if updated_version_file == version_file

  puts "Updating version to #{version} in #{version_file_path}."
  File.write(version_file_path, updated_version_file)
end