Class: Gem::Tasks::SCM::Tag

Inherits:
Task
  • Object
show all
Defined in:
lib/rubygems/tasks/scm/tag.rb

Overview

The scm:tag task.

Constant Summary collapse

DEFAULT_FORMAT =

Default format for versions

'v%s'

Constants included from Printing

Printing::ANSI_BRIGHT, Printing::ANSI_CLEAR, Printing::ANSI_GREEN, Printing::ANSI_RED, Printing::ANSI_YELLOW, Printing::DEBUG_PREFIX, Printing::ERROR_PREFIX, Printing::STATUS_PREFIX

Instance Attribute Summary collapse

Attributes inherited from Task

#project

Instance Method Summary collapse

Methods inherited from Task

#bundle, #gem, #gemspec_tasks, #invoke, #namespaced_tasks, #run, #task?

Methods included from Printing

#debug, #error, #status

Constructor Details

#initialize(format: DEFAULT_FORMAT, sign: nil) {|_self| ... } ⇒ Tag

Initializes the scm:tag task.

Parameters:

  • format (String, Proc) (defaults to: DEFAULT_FORMAT)

    The format String or Proc for version tags.

  • sign (Boolean) (defaults to: nil)

    Enables PGP signing of tags.

Yields:

  • (_self)

Yield Parameters:



39
40
41
42
43
44
45
46
47
# File 'lib/rubygems/tasks/scm/tag.rb', line 39

def initialize(format: DEFAULT_FORMAT, sign: nil)
  super()

  @format = format
  @sign   = sign

  yield self if block_given?
  define
end

Instance Attribute Details

#formatString, Proc

The format for version tags.

Returns:

  • (String, Proc)

    The format String or Proc.



20
21
22
# File 'lib/rubygems/tasks/scm/tag.rb', line 20

def format
  @format
end

#sign=(value) ⇒ Object (writeonly)

Enables or disables PGP signing of tags.

Parameters:

  • value (Boolean)

    The new value.

Since:

  • 0.2.0



28
29
30
# File 'lib/rubygems/tasks/scm/tag.rb', line 28

def sign=(value)
  @sign = value
end

Instance Method Details

#defineObject

Defines the scm:tag task.



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/rubygems/tasks/scm/tag.rb', line 52

def define
  task :validate

  namespace :scm do
    task :tag, [:name] => :validate do |t,args|
      tag = (args.name || version_tag(@project.gemspec.version))

      status "Tagging #{tag} ..."

      unless tag!(tag)
        error "Could not create tag #{tag}"
      end
    end
  end
end

#sign?Boolean

Note:

If #sign= has not been set, #sign? will determine if tag signing has been enabled globally by calling the following commands:

  • Git: git config user.signingkey
  • Mercurial: hg showconfig extensions hgext gpg

Indicates whether new tags will be signed.

Returns:

  • (Boolean)

    Specifies whether new tags will be signed.

Since:

  • 0.2.0



110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/rubygems/tasks/scm/tag.rb', line 110

def sign?
  if @sign.nil?
    @sign = case @project.scm
            when :git
              !`git config user.signingkey`.chomp.empty?
            when :hg
              !`hg showconfig extensions.hgext.gpg`.empty?
            else
              false
            end
  end

  return @sign
end

#tag!(name) ⇒ Boolean

Creates a tag.

Parameters:

  • name (String)

    The name of the tag.

Returns:

  • (Boolean)

    Specifies whether the tag was successfully created.



136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'lib/rubygems/tasks/scm/tag.rb', line 136

def tag!(name)
  message = "Tagging #{name}"

  case @project.scm
  when :git then
    arguments = ['-m', message]
    arguments << '-s' if sign?
    arguments << name

    run 'git', 'tag', *arguments
  when :hg  then
    if sign?
      # sign the change-set, then tag the release
      run 'hg', 'sign', '-m', "Signing #{name}"
    end

    run 'hg', 'tag', '-m', message, name
  when :svn
    branch   = File.basename(@project.root)
    tags_dir = if branch == 'trunk'
                 # we are in trunk/
                 File.join('..','tags')
               else
                 # must be within branches/$name/
                 File.join('..','..','tags')
               end

    tag_dir = File.join(tag_dirs,name)

    run 'svn', 'mkdir', '--parents', tag_dir
    run 'svn', 'cp', '*', tag_dir
    run 'svn', 'commit', '-m', message, tag_dir
  else
    true
  end
end

#version_tag(version) ⇒ String

Formats the version into a version tag.

Parameters:

  • version (String)

    The version to be formatted.

Returns:

  • (String)

    The tag for the version.

Raises:

  • (TypeError)

    #format was not a String or a Proc.



82
83
84
85
86
87
88
89
90
91
# File 'lib/rubygems/tasks/scm/tag.rb', line 82

def version_tag(version)
  case @format
  when String
    (@format % version)
  when Proc
    @format[version]
  else
    raise(TypeError,"tag format must be a String or Proc")
  end
end