The*_*ist 12 ruby git capistrano
我正在寻找一个很好的小Capistrano配方来部署在Git中控制的网站版本.
除了我正在添加的其他一些内容之外,我的第一个任务是使用当前日期标记当前版本...并且当该标记已经存在时(例如,一天中有多个版本),附加一个字母.
我写了一些工作代码,我在我的production.rb中测试过它(在capistrano-ext中使用多级)...但我必须认为我可以写得更好.首先,在实际检查标签是否存在时会有一些重复.但是,无论我移动的是什么顺序,这都是产生结果的唯一配置.
有任何想法吗?提前致谢.
before 'deploy' do
# Tag name is build_YYYYMMDD
tag_name = "build_#{Time.now.strftime('%Y%m%d')}"
check_tag = `git tag -l #{tag_name}`
# If the tag exists, being appending letter suffix
if not check_tag.empty?
suffix = 'a'
check_tag = `git tag -l #{tag_name}#{suffix}`
while not check_tag.empty? do
suffix.next!
check_tag = `git tag -l #{tag_name}#{suffix}`
end
tag_name = "#{tag_name}#{suffix}"
end
# Tag with computed tag name
p "Tagging #{tag_name}" # TODO How to output via Capistrano?
system "git tag #{tag_name}"
# Push tags to origin remote
p "Pushing tag to origin" # TODO How to output via Capistrano?
system "git push origin master --tags"
end
Run Code Online (Sandbox Code Playgroud)
dun*_*289 23
我和卡皮斯特拉诺做过类似的事.最简单的方法是使用Capistrano在部署期间使用的时间戳名称标记 - 即YYYYMMDDHHMMSS,因此很难获得重复项.
例:
task :push_deploy_tag do
user = `git config --get user.name`.chomp
email = `git config --get user.email`.chomp
puts `git tag #{stage}_#{release_name} #{current_revision} -m "Deployed by #{user} <#{email}>"`
puts `git push --tags origin`
end
Run Code Online (Sandbox Code Playgroud)