跟踪当前部署到 Heroku 服务器的 git 分支
我知道有一个我可以使用的 http 部署钩子,但不幸的是它没有提交分支名称,这是它提交的内容:
{"head"=>"7021419", "app"=>"appname", "git_log"=>"commit message", "action"=>"home", "url"=>"site url", "prev_head"=>"1d844b0", "controller"=>"account_sessions", "user"=>"[email protected]", "head_long"=>"7031429230228988d8f3312fa9e74d77b6c1bc14"}
我尝试使用 head 或 head_long 来找出分支名称:
git branch --contains SHA
哪个有效,但它不是 100% 准确,因为相同的 SHA 可能存在于多个分支中。同样可以这样说:
git reflog show --all | grep 7021419
我很确定不可能从已部署的应用程序中获取当前分支名称,因为部署到 Heroku 的分支始终是“主”分支。我希望我可以将部署回调挂钩发送到另一台服务器并将部署记录存储在某处。
I know there is a http deploy hook I can use but unfortunately it does not submit the branch name, here is what it does submit:
{"head"=>"7021419", "app"=>"appname", "git_log"=>"commit message", "action"=>"home", "url"=>"site url", "prev_head"=>"1d844b0", "controller"=>"account_sessions", "user"=>"[email protected]", "head_long"=>"7031429230228988d8f3312fa9e74d77b6c1bc14"}
I tried using the head or head_long to figure out the branch name with:
git branch --contains SHA
Which worked, but it is not 100% accurate as the same SHA could be in multiple branches. Same can be said about:
git reflog show --all | grep 7021419
I am pretty sure it is impossible to get the current branch name from within the deployed app as the branch deployed to Heroku is always the "master" branch. I was hoping I can send the deploy callback hook to another server and store the deployment record somewhere.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
1. 仅检测
如果仅检测头部,请使用
一些附加的
--format
和grep
逻辑2. 本地跟踪
最简单的方法是使用标签。
像普通分支一样推送标签:不幸的是,这只会推送标签,而不是分支...;继续阅读替代方案
(注意我不知道/使用heroku,所以我不知道命名约定,抱歉)
3.符号分支引用
如果您不介意使用一些管道,您可以将本地引用命名为部署的引用。您可以为此目的使用符号引用:
1. Detecting only
If it's just about heads, use
with a bit of
--format
andgrep
logic tacked on2. Tracking locally
The simplest way would be using a tag.
Push the tag like a normal branch:Unfortunately, that would just push the tag, not a branch... ; read on for alternative
(note I don't know/use heroku, so I don't know the naming conventions, sorry)
3. Symbolic branch reference
If you don't mind using a bit of plumbing, you can name a local ref as the one deployed. You can have a symbolic ref for the purpose:
如果相同的 SHA 位于多个分支中,则它们实际上是同一分支(至少在该时间点)。如果您确定 SHA 是分支的最后一次提交,则可以在 .git/refs/heads/* 中找到它,其中 * 是名称与分支名称对应的文件列表,内容是 SHA。
看来你可以通过不使用他们的 API 来解决这个录制问题。包装您的部署脚本(或 Heroku 的部署二进制文件,或 post-push 挂钩)应该为您提供通知不同服务进行记录保存所需的灵活性。
If the same SHA is in multiple branches, they are effectively the same branch (at least at that point in time). If you're sure that SHA is the last commit of a branch, you can find it in .git/refs/heads/* where * is a list of files whose names correspond to branch names and contents are the SHAs.
It seems like you might be able to solve this recording problem by not using their API. Wrapping your deploy script (or Heroku's deploy binary, or a post-push hook) should give you the flexibility you need to notify a different service for record keeping.