Class: CiToolkit::Build

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

Overview

Provides utility for a build

Instance Method Summary collapse

Constructor Details

#initialize(git = CiToolkit::Git.new, env = CiToolkit::BitriseEnv.new) ⇒ Build

Returns a new instance of Build.



6
7
8
9
10
11
12
# File 'lib/ci_toolkit/build.rb', line 6

def initialize(
  git = CiToolkit::Git.new,
  env = CiToolkit::BitriseEnv.new
)
  @git = git
  @env = env
end

Instance Method Details

#from_cron_job?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/ci_toolkit/build.rb', line 38

def from_cron_job?
  @env.build_from_cron_job?
end

#from_develop?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/ci_toolkit/build.rb', line 26

def from_develop?
  !!(@git.branch =~ /^develop$/)
end

#from_master?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/ci_toolkit/build.rb', line 34

def from_master?
  !!(@git.branch =~ /^master$/)
end

#from_pull_request?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/ci_toolkit/build.rb', line 22

def from_pull_request?
  @env.build_from_pr?
end

#from_release?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/ci_toolkit/build.rb', line 30

def from_release?
  !!(@git.branch =~ %r{^release/.*})
end

#numberObject



18
19
20
# File 'lib/ci_toolkit/build.rb', line 18

def number
  @env.build_number || Time.now.to_i.to_s
end

#tag_name(build_number = nil) ⇒ Object



52
53
54
55
56
# File 'lib/ci_toolkit/build.rb', line 52

def tag_name(build_number = nil)
  return version.to_s if version.include?("-build.") || build_number.nil?

  "#{version}-build.#{build_number}"
end

#urlObject



14
15
16
# File 'lib/ci_toolkit/build.rb', line 14

def url
  @env.build_url
end

#versionObject

Raises:

  • (StandardError)


42
43
44
45
46
47
48
49
50
# File 'lib/ci_toolkit/build.rb', line 42

def version
  version = @git.branch.split("/").last
  return version if !version.nil? && Gem::Version.correct?(version)

  return @git.latest_tag if Gem::Version.correct?(@git.latest_tag)

  raise StandardError, "Incorrect version supplied. You need to build from a valid \
release branch with semantic versioning, eg. release/x.y.z"
end