【发布时间】:2023-04-04 19:45:01
【问题描述】:
我正在寻找一个不错的 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
【问题讨论】:
标签: ruby git capistrano