Class: KCommercial::KCPipeline::AutoRelease

Inherits:
Object
  • Object
show all
Defined in:
lib/KCommercialPipeline/core/version_pipeline/release_branches.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(branch_name) ⇒ AutoRelease

Returns a new instance of AutoRelease.



59
60
61
# File 'lib/KCommercialPipeline/core/version_pipeline/release_branches.rb', line 59

def initialize(branch_name)
   @branch_name = branch_name
end

Instance Attribute Details

#branch_nameObject

拉分支名



57
58
59
# File 'lib/KCommercialPipeline/core/version_pipeline/release_branches.rb', line 57

def branch_name
  @branch_name
end

#versionObject

Returns the value of attribute version.



58
59
60
# File 'lib/KCommercialPipeline/core/version_pipeline/release_branches.rb', line 58

def version
  @version
end

Instance Method Details

#change_version(version) ⇒ Object



99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/KCommercialPipeline/core/version_pipeline/release_branches.rb', line 99

def change_version(version)
   lines = File.readlines(version_file_path).map do |line|
      if line.include? 'VERSION'
         "\tVERSION = '#{version.to_s}'\n"
      else
         line
      end
   end
   File.open(version_file_path, 'w+') do |file|
      file.write lines.join('')
   end
end

#create_branchObject



84
85
86
87
# File 'lib/KCommercialPipeline/core/version_pipeline/release_branches.rb', line 84

def create_branch
   KCommercial::UI.debug("准备拉取分支#{@branch_name}")
   KCGit.git.branch(@branch_name).checkout
end

#finall!Object



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/KCommercialPipeline/core/version_pipeline/release_branches.rb', line 112

def finall!
   commit = BranchTool.last_commit_on_current_branch
   time = Time.now;
   ##### commit_id:#{commit.sha}
        msg =  <<EOF
# #{KimConfig.configs["common_cfg"]["app_name"]}<font color = red size =4 >#{branch_name}</font>分支已拉出
# 分支拉取时间:#{time.strftime("%Y-%m-%d %H:%M:%S")}
## 最后一次提交信息:
#### 作者:#{commit.author.name}
#### commit message:#{commit.message}
### commit_date:#{commit.date.to_s} 
EOF

   kim_model = KimModel.new(MessageType::Markdown,"",msg,"",KimConfig.configs["AutoRelease"]["kim"]["mentioned_list"] || [])
   robot_keys = KimConfig.configs["AutoRelease"]["kim"]["robot_key"] || ["75ec6f27-eede-46c0-8f2b-264dbc165af0"]
   if robot_keys.size > 0
      robot_keys.each do |k|
         Kim.new(k,kim_model).notifi_kim
      end
   else
      KCommercial::UI.error("请配置AutoRelease 通知机器人🤖key!!!")
      exit!(0)
   end
end

#prepareObject



70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/KCommercialPipeline/core/version_pipeline/release_branches.rb', line 70

def prepare
   unless @branch_name.nil?
      branchs =BranchTool.all_release_branchs_sorted
      if branchs.empty?
         KCommercial::UI.error("未发现合法release分支!")
         exit! 0
      end
      release_brnche = branchs[-1]
      prefix = KimConfig.configs["common_cfg"]["release_prefix"] || "release/matrix/RB_"
      @version = "#{release_brnche.major}.#{release_brnche.minor.to_i+1}.0"
      @branch_name = prefix + "#{release_brnche.major}.#{release_brnche.minor.to_i+1}"
   end
end

#push!Object



89
90
91
92
# File 'lib/KCommercialPipeline/core/version_pipeline/release_branches.rb', line 89

def push!
   KCGit.git.push(remote = 'origin', branch = @branch_name)
   KCommercial::UI.debug("已拉取分支#{@branch_name}")
end

#run!Object



63
64
65
66
67
68
# File 'lib/KCommercialPipeline/core/version_pipeline/release_branches.rb', line 63

def run!
   prepare
   create_branch
   push!
   finall!
end

#update_component_versionObject

更新podspec version 和auto version 目录



95
96
97
# File 'lib/KCommercialPipeline/core/version_pipeline/release_branches.rb', line 95

def update_component_version

end