Skip to content
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

Merged
merged 39 commits into from
Dec 23, 2024

Conversation

otegami
Copy link
Contributor

@otegami otegami commented Dec 12, 2024

GitHub: GH-43

In this PR, we set up how release flow is triggered from webhook
requests.

@otegami otegami force-pushed the release-run-async-task branch 3 times, most recently from a82b318 to e4f8727 Compare December 19, 2024 02:58
@otegami otegami changed the title draf relase: run asyn task release: trigger release processes when release workflow succeeded Dec 19, 2024
@otegami otegami marked this pull request as ready for review December 19, 2024 05:57
@otegami
Copy link
Contributor Author

otegami commented Dec 19, 2024

I'm thinking I will add the test at the following PRs because this PR has already had a lots of changes.

@otegami otegami force-pushed the release-run-async-task branch from e4f8727 to ff9fcc0 Compare December 19, 2024 08:27

payload = parse_payload(request.body.read, response)
if payload.nil?
response.set(:bad_request, "invalid JSON format: <#{$!.message}>")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$! はここでも使えるんですか?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ここでは使えないので直してあげる必要がありそうです 🙏🏾

Copy link
Member

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parse_payload って ペイロードをパースする、という意味で合ってますか?
ペイロードをパースして出来上がるものは、payload ではない気がしたので、payload に代入しているのが気になりました。

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bodyをparseするので、parse_bodyにしました。

@komainu8 komainu8 force-pushed the release-run-async-task branch from 5cae964 to c1d9868 Compare December 20, 2024 03:25
@komainu8
Copy link
Member

一通り頂いた指摘に対応しました。

ansible/files/home/deployer/webhook/lib/deployer/app.rb Outdated Show resolved Hide resolved
release_tasks = Proc.new do
# TODO: call rake tasks for sign packages.
end
response.set_finish_proc(release_tasks)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

引数で response をもらわないとだめっぽい。

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

デプロイ処理の結果をレスポンスとしては返せないよ。
どのくらい時間がかかるかわからないから。
こいつが返せるのはデプロイ処理を開始できたかどうかまでだよ。
デプロイ処理のエラーはレスポンスじゃなくてログに吐くとかして確認しないとダメだよ。
(あと、エラー情報に秘匿情報が含まれたらイヤだからそういう観点でもレスポンスとして返したくない。)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix: 0be9ff2, 2f40dc8
レスポンス自体はすぐに返す想定です。
リリースに必要な作業は、スレッドを利用して非同期で対応しようと思います。
リリース作業で実行するRakeタスクに関するエラーに関しては、ログファイルに出力する予定です。

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

デプロイ処理の結果をレスポンスに使わないならset_finish_procしなくていいんじゃないかな。

Copy link
Contributor Author

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)
Copy link
Contributor

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 ではない感じがします。

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

deploy?

Copy link
Member

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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

例外を上げるようにするならvalidじゃなくてverifyとかじゃないかな。

Copy link
Member

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)
Copy link
Member

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_errore.messageでいいと思うけど。

Copy link
Contributor Author

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}$/)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mroongaで動かなそう。
(MroongaはXX.YY。)

Copy link
Contributor Author

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の形式だけにマッチするように修正してみました。

Comment on lines 27 to 29
def [](key)
key.split(".").inject(@data) do |current_data, current_key|
if current_data
current_data[current_key]
else
nil
end
end
end
Copy link
Member

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("."))にするか。

Copy link
Contributor Author

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
RELEASE_WORKFLOWS= ["Package"].map(&:freeze).freeze
RELEASE_WORKFLOWS = ["Package"].map(&:freeze).freeze

そんなにfreezeしなくてもいい気はするけど。。。
Rubyを使っているのにそんなに信じられない?というか。。。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix: be34927 そんなにfreezeしなくても良いと思うので、修正しました。

@otegami
Copy link
Contributor Author

otegami commented Dec 23, 2024

上からレビュー対応をしていきます。

otegami and others added 3 commits December 23, 2024 12:03
@otegami otegami force-pushed the release-run-async-task branch from 774dee2 to 1481c70 Compare December 23, 2024 03:03
class Error < StandardError
end

class RequestError < Error
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

よくわかってなくて初歩的な質問ですみません。
Error をはさむときと RequestError < StandardError するときとどういう違いがあるのですか?

Copy link
Contributor Author

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
Copy link
Contributor

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を考慮する必要あり?

Copy link
Member

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で一気に全部アップロードするようにしてあります。

@otegami otegami force-pushed the release-run-async-task branch from 907e74f to 45a44ab Compare December 23, 2024 03:50
Because we can just use Thread to call release tasks.
@otegami otegami force-pushed the release-run-async-task branch from 45a44ab to 89dc83f Compare December 23, 2024 03:50
@otegami
Copy link
Contributor Author

otegami commented Dec 23, 2024

ここまで頂いたレビューコメントの対応を行いました 🙏🏾


module Deployer
class Payload
RELEASE_WORKFLOWS= ["Package"].freeze
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Windows用バイナリでも実行したいから CMake も追加するとよさげ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

必要ですね!追加します。

Copy link
Contributor Author

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
RELEASE_WORKFLOWS= ["Package"].freeze
RELEASE_WORKFLOWS = ["Package"].freeze

Copy link
Contributor Author

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}$/)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
branch.match?(/^v\d+(\.\d+){1,2}$/)
branch.match?(/\Av\d+(\.\d+){1,2}\z/)

https://www.clear-code.com/blog/2015/3/25.html

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix: bceac4f

@otegami
Copy link
Contributor Author

otegami commented Dec 23, 2024

ここまで頂いたレビューコメントの対応を行いました 🙏🏾

@abetomo abetomo merged commit 491c627 into groonga:main Dec 23, 2024
@otegami otegami deleted the release-run-async-task branch December 23, 2024 05:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants