Module: Dapp::Dapp::OptionTags

Included in:
Dapp::Dapp
Defined in:
lib/dapp/dapp/option_tags.rb

Instance Method Summary collapse

Instance Method Details

#branch_tagsObject

Raises:



20
21
22
23
24
# File 'lib/dapp/dapp/option_tags.rb', line 20

def branch_tags
  return [] unless options[:tag_branch]
  raise Error::Dapp, code: :git_branch_without_name if (branch = git_local_repo.branch) == 'HEAD'
  [branch]
end

#build_tagsObject



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/dapp/dapp/option_tags.rb', line 32

def build_tags
  return [] unless options[:tag_build_id]

  if ENV['GITLAB_CI']
    build_id = ENV['CI_BUILD_ID']
  elsif ENV['TRAVIS']
    build_id = ENV['TRAVIS_BUILD_NUMBER']
  else
    raise Error::Dapp, code: :ci_environment_required
  end

  [build_id]
end

#ci_tagsObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/dapp/dapp/option_tags.rb', line 46

def ci_tags
  return [] unless options[:tag_ci]

  if ENV['GITLAB_CI']
    branch = ENV['CI_BUILD_REF_NAME']
    tag = ENV['CI_BUILD_TAG']
  elsif ENV['TRAVIS']
    branch = ENV['TRAVIS_BRANCH']
    tag = ENV['TRAVIS_TAG']
  else
    raise Error::Dapp, code: :ci_environment_required
  end

  [branch, tag].compact
end

#commit_tagsObject



26
27
28
29
30
# File 'lib/dapp/dapp/option_tags.rb', line 26

def commit_tags
  return [] unless options[:tag_commit]
  commit = git_local_repo.latest_commit
  [commit]
end

#git_local_repoObject



4
5
6
# File 'lib/dapp/dapp/option_tags.rb', line 4

def git_local_repo
  @git_repo ||= ::Dapp::Dimg::GitRepo::Own.new(self)
end

#option_tagsObject



8
9
10
11
12
13
14
# File 'lib/dapp/dapp/option_tags.rb', line 8

def option_tags
  @tags ||= begin
    tags = simple_tags + branch_tags + commit_tags + build_tags + ci_tags
    tags << :latest if tags.empty?
    tags
  end
end

#simple_tagsObject



16
17
18
# File 'lib/dapp/dapp/option_tags.rb', line 16

def simple_tags
  options[:tag]
end