-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
release: trigger release processes when release workflow succeeded #47
Conversation
a82b318
to
e4f8727
Compare
I'm thinking I will add the test at the following PRs because this PR has already had a lots of changes. |
e4f8727
to
ff9fcc0
Compare
|
||
payload = parse_payload(request.body.read, response) | ||
if payload.nil? | ||
response.set(:bad_request, "invalid JSON format: <#{$!.message}>") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$!
はここでも使えるんですか?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ここでは使えないので直してあげる必要がありそうです 🙏🏾
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
例外を上げるようにしたので、$!
は使わないようになりました。
unless valid_signature?(request) | ||
response.set(:unauthorized, "Authorization failed") | ||
return | ||
end | ||
|
||
payload = parse_payload(request.body.read, response) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
parse_payload
って ペイロードをパースする、という意味で合ってますか?
ペイロードをパースして出来上がるものは、payload
ではない気がしたので、payload
に代入しているのが気になりました。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bodyをparseするので、parse_body
にしました。
5cae964
to
c1d9868
Compare
一通り頂いた指摘に対応しました。 |
release_tasks = Proc.new do | ||
# TODO: call rake tasks for sign packages. | ||
end | ||
response.set_finish_proc(release_tasks) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
引数で response
をもらわないとだめっぽい。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
デプロイ処理の結果をレスポンスとしては返せないよ。
どのくらい時間がかかるかわからないから。
こいつが返せるのはデプロイ処理を開始できたかどうかまでだよ。
デプロイ処理のエラーはレスポンスじゃなくてログに吐くとかして確認しないとダメだよ。
(あと、エラー情報に秘匿情報が含まれたらイヤだからそういう観点でもレスポンスとして返したくない。)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
デプロイ処理の結果をレスポンスに使わないならset_finish_proc
しなくていいんじゃないかな。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
たしかに必要ないですね。そのまま普通にThreadで動かしてあげればよいだけですね。
end | ||
end | ||
|
||
def process_release(payload) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
メソッド名は改善できそう。kick_release_task
とかを考えましたが、それも違うか…。
process_release
ではない感じがします。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
deploy
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
deploy
にしました。
end | ||
end | ||
|
||
def valid_signature?(request) | ||
def valid_signature!(request) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
例外を上げるようにするならvalid
じゃなくてverify
とかじゃないかな。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
verify_signature!
にしました。
payload = parse_body(request, response) | ||
process_payload(payload) | ||
rescue => e | ||
response.set(:bad_request, e.message) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
全部:bad_request
は乱暴じゃない?
raise RequestError.new(:unauthorized, "Authorization failure")
とかするようにして、エラーメッセージだけじゃなくステータスも渡せるようにしたら?
RequestError
じゃない例外があがったら:internal_server_error
とe.message
でいいと思うけど。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fix: 1481c70 予期できるエラーに関しては、RequestError
でハンドリングするようにして、予期しないものに関してはサーバー側のエラーとして統一して返すようにしました。
|
||
def workflow_tag? | ||
return false unless branch | ||
branch.match?(/^v\d+(\.\d+){2}$/) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mroongaで動かなそう。
(MroongaはXX.YY
。)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fix: a39c792 vX.Y.Z
or vX.Y
の形式だけにマッチするように修正してみました。
def [](key) | ||
key.split(".").inject(@data) do |current_data, current_key| | ||
if current_data | ||
current_data[current_key] | ||
else | ||
nil | ||
end | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
最近のRubyにはHash#dig
があるから、今ならこれを作らなくてもいいかもね。
あるいは、@data.dig(*key.split("."))
にするか。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fix: 15cd16d Hash#dig
を利用したほうが、シンプルにかけるので修正しました。
|
||
module Deployer | ||
class Payload | ||
RELEASE_WORKFLOWS= ["Package"].map(&:freeze).freeze |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RELEASE_WORKFLOWS= ["Package"].map(&:freeze).freeze | |
RELEASE_WORKFLOWS = ["Package"].map(&:freeze).freeze |
そんなにfreeze
しなくてもいい気はするけど。。。
Rubyを使っているのにそんなに信じられない?というか。。。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fix: be34927 そんなにfreezeしなくても良いと思うので、修正しました。
上からレビュー対応をしていきます。 |
GitHub: groongaGH-43 In this PR, we set up how release flow is triggered from webhook requests.
774dee2
to
1481c70
Compare
class Error < StandardError | ||
end | ||
|
||
class RequestError < Error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
よくわかってなくて初歩的な質問ですみません。
Error
をはさむときと RequestError < StandardError
するときとどういう違いがあるのですか?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rubyは継承できるクラスが一つなので、今後拡張しやすいようにErrorのベースクラスは別で置いて置きたくて、このようにしてみました。(ただ、今回はまだ拡張予定が直近ではないのでなくても問題ないです。)
|
||
module Deployer | ||
class Payload | ||
RELEASE_WORKFLOWS= ["Package"].freeze |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
workflow_tag?
はMroongaに対応してましたが、RELEASE_WORKFLOWS
もMroongaを考慮する必要あり?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
あぁ、Mroongaの方は"workflow_run"じゃなくて"release"のwebhookでやるので気にしなくてよくなりました。
https://github.com/mroonga/mroonga/blob/main/.github/workflows/release.yml
Mroongaの方はgh run watch
で待って、gr release create
で一気に全部アップロードするようにしてあります。
907e74f
to
45a44ab
Compare
Because we can just use Thread to call release tasks.
45a44ab
to
89dc83f
Compare
ここまで頂いたレビューコメントの対応を行いました 🙏🏾 |
|
||
module Deployer | ||
class Payload | ||
RELEASE_WORKFLOWS= ["Package"].freeze |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Windows用バイナリでも実行したいから CMake
も追加するとよさげ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
必要ですね!追加します。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fix: e0b7514
|
||
module Deployer | ||
class Payload | ||
RELEASE_WORKFLOWS= ["Package"].freeze |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RELEASE_WORKFLOWS= ["Package"].freeze | |
RELEASE_WORKFLOWS = ["Package"].freeze |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fix: d94d95d
|
||
def workflow_tag? | ||
return false unless branch | ||
branch.match?(/^v\d+(\.\d+){1,2}$/) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
branch.match?(/^v\d+(\.\d+){1,2}$/) | |
branch.match?(/\Av\d+(\.\d+){1,2}\z/) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fix: bceac4f
ここまで頂いたレビューコメントの対応を行いました 🙏🏾 |
GitHub: GH-43
In this PR, we set up how release flow is triggered from webhook
requests.