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:



48
49
50
51
52
# File 'lib/dapp/dapp/option_tags.rb', line 48

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

#build_tagsObject



59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/dapp/dapp/option_tags.rb', line 59

def build_tags
  return {} unless options[:tag_build_id]

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

  { ci: [build_id] }
end

#ci_tagsObject



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

def ci_tags
  return {} unless options[:tag_ci]

  {}.tap do |tags_by_scheme|
    if ENV['GITLAB_CI']
      if ENV['CI_BUILD_TAG'] || ENV['CI_COMMIT_TAG']
        tags_by_scheme[:git_tag] = [ENV['CI_BUILD_TAG'] || ENV['CI_COMMIT_TAG']]
      elsif ENV['CI_BUILD_REF_NAME'] || ENV['CI_COMMIT_REF_NAME']
        tags_by_scheme[:git_branch] = [ENV['CI_BUILD_REF_NAME'] || ENV['CI_COMMIT_REF_NAME']]
      end
    elsif ENV['TRAVIS']
      if ENV['TRAVIS_TAG']
        tags_by_scheme[:git_tag]    = [ENV['TRAVIS_TAG']]
      elsif ENV['TRAVIS_BRANCH']
        tags_by_scheme[:git_branch] = [ENV['TRAVIS_BRANCH']]
      end
    else
      raise Error::Dapp, code: :ci_environment_required
    end

    tags_by_scheme.delete_if { |_, tags| tags.first.nil? }
  end
end

#commit_tagsObject



54
55
56
57
# File 'lib/dapp/dapp/option_tags.rb', line 54

def commit_tags
  return {} unless options[:tag_commit]
  { git_commit: [git_own_repo.head_commit] }
end

#option_tagsObject



36
37
38
# File 'lib/dapp/dapp/option_tags.rb', line 36

def option_tags
  tags_by_scheme.values.flatten
end

#plain_tagsObject



44
45
46
# File 'lib/dapp/dapp/option_tags.rb', line 44

def plain_tags
  { custom: options[:tag_plain] }
end

#slug_tagsObject



40
41
42
# File 'lib/dapp/dapp/option_tags.rb', line 40

def slug_tags
  { custom: [*options[:tag], *options[:tag_slug]]}
end

#tagging_schemesObject



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

def tagging_schemes
  %w(git_tag git_branch git_commit custom ci)
end

#tags_by_schemeObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/dapp/dapp/option_tags.rb', line 8

def tags_by_scheme
  @tags_by_scheme_name ||= begin
    if slug_tags[:custom].any?
      if settings.fetch("sentry", {}).fetch("detect-push-tag-usage", false)
        sentry_message("--tag or --tag-slug usage detected", extra: {"slug_tags" => slug_tags})
      end
    end

    {}.tap do |tags_by_scheme|
      [slug_tags, branch_tags, ci_tags].each do |_tags_by_scheme|
        _tags_by_scheme.each do |scheme, tags|
          tags_by_scheme[scheme] ||= []
          tags_by_scheme[scheme] += tags.map(&method(:consistent_uniq_slugify))
        end
      end

      [plain_tags, commit_tags, build_tags].each do |_tags_by_scheme|
        _tags_by_scheme.each do |scheme, tags|
          tags_by_scheme[scheme] ||= []
          tags_by_scheme[scheme] += tags
        end
      end

      tags_by_scheme[:custom] = [:latest] if tags_by_scheme.values.flatten.empty?
    end
  end
end