Class: GitPivotalTrackerIntegration::Command::Release

Inherits:
Base
  • Object
show all
Defined in:
lib/git-pivotal-tracker-integration/command/release.rb

Overview

The class that encapsulates releasing a Pivotal Tracker Story

Constant Summary collapse

CANDIDATE_STATES =
%w(delivered unstarted).freeze
CANDIDATE_TYPES =
%w(bug chore feature release)

Instance Method Summary collapse

Methods inherited from Base

#check_version, #create_backlog_bug_story, #create_backlog_feature_story, #create_icebox_bug_story, #create_icebox_feature_story, #create_story, #estimated_seconds, #initialize, #logger_filename, #seconds_spent, #start_logging

Constructor Details

This class inherits a constructor from GitPivotalTrackerIntegration::Command::Base

Instance Method Details

#run(filter) ⇒ void

This method returns an undefined value.

Releases a Pivotal Tracker story by doing the following steps:

  • Update the version to the release version

  • Create a tag for the release version

  • Update the version to the new development version

  • Push tag and changes to remote

Parameters:

  • filter (String, nil)

    a filter for selecting the release to start. This filter can be either:

    • a story id

    • nil



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/git-pivotal-tracker-integration/command/release.rb', line 36

def run(filter)

  $LOG.debug("#{self.class} in project:#{@project.name} pwd:#{pwd} branch:#{Util::Git.branch_name}")
  story = Util::Story.select_release(@project, filter.nil? ? 'v' : filter)

  # commenting the 2 lines below before we find an acceptable solution for story sorting
  #place_version_release story
  #pull_out_rejected_stories story
  Util::Story.pretty_print story
  $LOG.debug("story:#{story.name}")

  current_branch = Util::Git.branch_name

  # checkout QA branch
  # Update QA from origin
  puts Util::Shell.exec "git checkout QA"
  Util::Shell.exec "git reset --hard origin/QA"
  puts Util::Shell.exec "git fetch"
  Util::Shell.exec "git merge -s recursive --strategy-option theirs origin/QA"


  # checkout master branch
  # Merge QA into master
  puts Util::Shell.exec "git checkout master"
  puts Util::Shell.exec "git pull"
  if (Util::Shell.exec "git merge -s recursive --strategy-option theirs QA")
    puts "Merged 'QA' in to 'master'"
  else
    abort "FAILED to merge 'QA' in to 'master'"
  end

  # Update version and build numbers
  version_number    = story.name.dup
  version_number[0] = ""
  working_directory = pwd

  puts "Story Name:         #{story.name}"
  puts "Version Number:     #{version_number}"
  puts "Working Directory:  #{working_directory}*"
  puts ""

  if (OS.mac? && @platform.downcase == "ios")
    project_directory = @configuration.xcode_project_path
    project_directory ||= ((Util::Shell.exec 'find . -name "*.xcodeproj" 2>/dev/null').split /\/(?=[^\/]*$)/)[0]

    # cd to the project_directory
    Dir.chdir(project_directory)

    # set project number in project file
    pwd
    puts Util::Shell.exec "xcrun agvtool new-marketing-version #{version_number}"

    # cd back to the working_directory
    Dir.chdir(working_directory)
    # Change spec version
    change_spec_version(version_number) if has_spec_path?
  elsif @platform.downcase == 'android'
    updater = VersionUpdate::Gradle.new(@repository_root)
    updater.update_uat_version(version_number)
    updater.update_prod_version(version_number)
  elsif @platform.downcase == 'ruby-gem'
    file = Dir["#{Util::Git.repository_root}/*.gemspec"].first
    if file
      file_text = File.read(file)
      File.open(file, "w") {|gemspec| gemspec.puts file_text.gsub(/(?<!_)version(.*)=(.*)['|"]/, "version     = '#{version_number}'")}
    end
  end

  # Create a new build commit, push to QA
  puts Util::Git.create_commit( "Update version number to #{version_number} for release to UAT", story)
  puts Util::Shell.exec "git push"

  # Create release tag
  #create_release_tag(version_number)

  #Created tag should be pushed to private Podspec repo
  if has_spec_path? && @platform == "ios"
    puts Util::Shell.exec "git checkout #{version_number}"
    puts Util::Shell.exec "pod repo push V2PodSpecs #{@configuration.pconfig["spec"]["spec-path"]}"
    puts Util::Shell.exec "git checkout develop"
  end

  #checkout develop branch
  puts Util::Shell.exec "git checkout #{current_branch}"

  #add story name as one of the labels for the story
  story.add_label(story.name)

  i_stories = included_stories @project, story
  add_version_tag_to_stories i_stories, story

end