sakamomo554101 / YouyakuAI

日本語用の要約を行うデモサービス
0 stars 0 forks source link

PRに対して、自動テストを行うように対応する #18

Closed sakamomo554101 closed 2 years ago

sakamomo554101 commented 3 years ago

対応内容

手段

やること整理

sakamomo554101 commented 2 years ago

https://stackoverflow.com/questions/64364989/github-actions-how-to-run-test-inside-container うーむ、VolumeをホストとContainerで共有してると面倒かもしれんぞ・・

sakamomo554101 commented 2 years ago

https://faun.pub/building-a-ci-cd-pipeline-with-github-actions-and-docker-part-1-a9d8709c31fb 勉強になりそう(Github Acrtions でのテスト)

sakamomo554101 commented 2 years ago

あと、センシティブな情報(gcpのcredentials)とか渡せるのかしら・・。 完全にprivateで使ってくれる分には問題ないが。

sakamomo554101 commented 2 years ago

https://github.com/google-github-actions/get-gke-credentials#via-google-github-actionsauth 参考になりそうだが、いまいち分からん。

sakamomo554101 commented 2 years ago

https://zenn.dev/vvakame/articles/gha-and-gcp-workload-identity お、まさにこれだ。

なるほど、普通やる場合は、githubのsecretsに持たせるのができる感じか。 それとは別にgithub actionsを用いるやり方もありそう。

sakamomo554101 commented 2 years ago

これは以下で分けたほうがいいな。(思ったより面倒)

sakamomo554101 commented 2 years ago

https://zenn.dev/naonao70/articles/67d61979886553 github actionsを使うパターン

sakamomo554101 commented 2 years ago

github actionsを使う方法で検討する。(publicリポジトリなら無料だし)

sakamomo554101 commented 2 years ago

https://helve-blog.com/posts/git/github-actions-python/

ふーむ、pythonスクリプトを実行する環境にして、build_and_deploy_image.pyをproductionでbuild_onlyで動かすようにするのが良いかなー。 (良いというより、楽、が正しいな)

sakamomo554101 commented 2 years ago

いやー、しかし、都度docker image をビルドする感じだと、時間かかりそうだなぁ・・。

sakamomo554101 commented 2 years ago

ついでにlintも入れよ。

で良いかな。

sakamomo554101 commented 2 years ago

terraform入れたら、terraformのチェックも入れたいよね。

sakamomo554101 commented 2 years ago

https://github.com/terraform-linters/tflint

tflintを使えばよさそう。

sakamomo554101 commented 2 years ago

やること整理

sakamomo554101 commented 2 years ago

https://github.com/marketplace?type=actions

上記でactionのテンプレート的なのがあるっぽい。

sakamomo554101 commented 2 years ago

https://qiita.com/yokawasa/items/e8d2552b4dffebdc3328

上記のような感じで、複数jobを構成可能。

sakamomo554101 commented 2 years ago
on:
  pull_request:
    types: ['opened', 'edited', 'reopened', 'synchronize']

pull requestに対して、チェックするパターン

sakamomo554101 commented 2 years ago

actionsのusesのパターンがよくわからん。

sakamomo554101 commented 2 years ago

https://dev.classmethod.jp/articles/mapping-secrets-github-token/

GITHUB_TOKENってなんぞ?と思ってみたら、権限周りの設定っぽい。 secrets.GITHUB_TOKENは一番権限が狭い代わりに使いやすい。

sakamomo554101 commented 2 years ago

https://qiita.com/masato_makino/items/93c4429cdb4d54c007c7

上記に遭遇した。 Githubの秘密鍵を使って、アクセスする必要がありそう。

sakamomo554101 commented 2 years ago

https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python

sakamomo554101 commented 2 years ago

57 試しにマージして、動作するかをみてみる。

sakamomo554101 commented 2 years ago

お、なんかactionsが動いて、下記エラーが発生してる。

[flake8_py3](https://github.com/sakamomo554101/YouyakuAI/runs/5269213819?check_suite_focus=true)
Version 3.9.6 with arch x64 not found Available versions: 2.7.18 (x64) 3.10.2 (x64) 3.6.15 (x64) 3.7.12 (x64) 3.8.12 (x64) 3.9.10 (x64)
sakamomo554101 commented 2 years ago

うーん、、実行されん・・(PR作ったときに実行してほしんだけど・・)

sakamomo554101 commented 2 years ago

https://qiita.com/nacam403/items/3e2a5df5e88ba20aa76a

なるほど、pathsに引っ掛かるファイルの修正がないと、lint動かん感じになってる。 一旦pathsを外す。

sakamomo554101 commented 2 years ago

うーむ、、flake8が動いた形跡がないな・・。

flake8 .
  shell: /usr/bin/bash -e {0}
  env:
    pythonLocation: /opt/hostedtoolcache/Python/[3](https://github.com/sakamomo554101/YouyakuAI/runs/5269273269?check_suite_focus=true#step:4:3).10.2/x6[4](https://github.com/sakamomo554101/YouyakuAI/runs/5269273269?check_suite_focus=true#step:4:4)
sakamomo554101 commented 2 years ago

お、ちゃんとflake8の指摘が出たぞ〜。(多すぎ、、直そ)

./src/summarizer/serve.py:[8](https://github.com/sakamomo554101/YouyakuAI/runs/5269321653?check_suite_focus=true#step:5:8):1: E402 module level import not at top of file
./src/summarizer/serve.py:11:1: E402 module level import not at top of file
./src/summarizer/summarizer_model.py:63:80: E501 line too long (84 > 7[9](https://github.com/sakamomo554101/YouyakuAI/runs/5269321653?check_suite_focus=true#step:5:9) characters)
./src/summarizer/summarizer_model.py:66:80: E501 line too long (87 > 79 characters)
./src/queue_api/kafka_client.py:12:1: F401 'kafka_helper.exist_kafka_topic' imported but unused
./src/queue_api/kafka_client.py:12:1: F401 'kafka_helper.get_kafka_topics' imported but unused
./src/queue_api/kafka_client.py:22:1: E402 module level import not at top of file
./src/queue_api/queue_factory.py:17:1: E402 module level import not at top of file
./src/queue_api/queue_client.py:7:1: E402 module level import not at top of file
./src/queue_api/queue_client.py:38:9: F841 local variable '__metadata__' is assigned to but never used
./src/queue_api/queue_client.py:53:9: F841 local variable '__metadata__' is assigned to but never used
./src/queue_api/kafka_helper.py:[10](https://github.com/sakamomo554101/YouyakuAI/runs/5269321653?check_suite_focus=true#step:5:10):1: E402 module level import not at top of file
./src/queue_api/test/test_queue_client.py:8:1: E402 module level import not at top of file
./src/queue_api/test/test_queue_client.py:9:1: E402 module level import not at top of file
./src/queue_api/test/test_queue_client.py:10:1: E402 module level import not at top of file
./src/queue_api/test/test_queue_client.py:13:1: E402 module level import not at top of file
./src/queue_api/test/test_queue_client.py:71:13: F841 local variable 'id' is assigned to but never used
./src/summarizer_processor/internal_api_client.py:53:80: E501 line too long (84 > 79 characters)
./src/summarizer_processor/internal_api_client.py:59:80: E501 line too long (83 > 79 characters)
./src/summarizer_processor/summarizer_process.py:20:1: E402 module level import not at top of file
./src/summarizer_processor/summarizer_process.py:23:1: E402 module level import not at top of file
./src/summarizer_processor/summarizer_process.py:24:1: E402 module level import not at top of file
./src/summarizer_processor/summarizer_process.py:27:1: E402 module level import not at top of file
./src/summarizer_processor/summarizer_process.py:48:80: E501 line too long (82 > 79 characters)
./src/summarizer_processor/summarizer_process.py:155:80: E501 line too long (131 > 79 characters)
./src/summarizer_processor/summarizer_util.py:5:1: E402 module level import not at top of file
./src/summarizer_processor/summarizer_util.py:6:1: E402 module level import not at top of file
./src/summarizer_processor/summarizer_util.py:9:1: E402 module level import not at top of file
./src/summarizer_processor/summarizer_util.py:12:1: E402 module level import not at top of file
./src/summarizer_processor/test/test_summarizer.py:10:1: E402 module level import not at top of file
./src/summarizer_processor/test/test_summarizer.py:[11](https://github.com/sakamomo554101/YouyakuAI/runs/5269321653?check_suite_focus=true#step:5:11):1: E402 module level import not at top of file
./src/summarizer_processor/test/test_summarizer.py:17:1: E402 module level import not at top of file
./src/summarizer_processor/test/test_summarizer.py:26:1: E402 module level import not at top of file
./src/summarizer_processor/test/test_summarizer.py:29:1: E402 module level import not at top of file
./src/api_gateway/queue_helper.py:7:1: E402 module level import not at top of file
./src/api_gateway/api.py:[12](https://github.com/sakamomo554101/YouyakuAI/runs/5269321653?check_suite_focus=true#step:5:12):1: E402 module level import not at top of file
./src/api_gateway/api.py:15:1: F401 'db_wrapper.SummarizeJobInfo' imported but unused
./src/api_gateway/api.py:15:1: E402 module level import not at top of file
./src/api_gateway/api.py:18:1: E402 module level import not at top of file
./src/api_gateway/api.py:23:80: E501 line too long (105 > 79 characters)
./src/api_gateway/api.py:27:80: E501 line too long ([13](https://github.com/sakamomo554101/YouyakuAI/runs/5269321653?check_suite_focus=true#step:5:13)8 > 79 characters)
./src/api_gateway/api.py:51:80: E501 line too long (80 > 79 characters)
./src/api_gateway/api.py:52:80: E501 line too long (82 > 79 characters)
./src/api_gateway/api.py:71:80: E501 line too long (98 > 79 characters)
./src/api_gateway/api.py:182:80: E501 line too long (83 > 79 characters)
./src/api_gateway/main.py:6:1: E402 module level import not at top of file
./src/api_gateway/main.py:7:1: E402 module level import not at top of file
./src/api_gateway/main.py:28:1: E302 expected 2 blank lines, found 1
./src/api_gateway/main.py:43:1: E302 expected 2 blank lines, found 1
./src/api_gateway/api_gateway_util.py:5:1: E402 module level import not at top of file
./src/api_gateway/api_gateway_util.py:6:1: E402 module level import not at top of file
./src/api_gateway/api_gateway_util.py:9:1: E402 module level import not at top of file
./src/api_gateway/api_gateway_util.py:12:1: E402 module level import not at top of file
./src/api_gateway/test/test_api.py:5:1: F401 'datetime.datetime' imported but unused
./src/api_gateway/test/test_api.py:11:1: E402 module level import not at top of file
./src/api_gateway/test/test_api.py:18:1: E402 module level import not at top of file
./src/api_gateway/test/test_api.py:29:1: E402 module level import not at top of file
./src/api_gateway/test/test_api.py:32:1: E402 module level import not at top of file
./src/api_gateway/test/test_api.py:80:9: E266 too many leading '#' for block comment
./src/api_gateway/test/test_api.py:84:9: E266 too many leading '#' for block comment
./src/db/db_wrapper.py:7:1: F401 'sqlalchemy.ForeignKey' imported but unused
./src/db/db_wrapper.py:11:1: F401 'sqlalchemy.orm.relationship' imported but unused
./src/db/db_wrapper.py:18:1: F401 'sqlalchemy_utils' imported but unused
./src/db/db_wrapper.py:25:1: F401 'sqlalchemy_utils.functions.orm.table_name' imported but unused
./src/db/db_wrapper.py:28:1: E402 module level import not at top of file
./src/db/db_wrapper.py:30:1: E402 module level import not at top of file
./src/db/db_wrapper.py:31:1: E402 module level import not at top of file
./src/db/db_wrapper.py:32:1: E402 module level import not at top of file
./src/db/db_wrapper.py:48:13: F811 redefinition of unused 'table_name' from line 25
./src/db/db_wrapper.py:79:80: E501 line too long (81 > 79 characters)
./src/db/db_wrapper.py:430:80: E501 line too long (82 > 79 characters)
./src/db/db_wrapper.py:449:80: E501 line too long (82 > 79 characters)
./src/db/db_wrapper.py:518:80: E501 line too long (86 > 79 characters)
./src/db/db_wrapper.py:533:80: E501 line too long (82 > 79 characters)
./src/db/db_wrapper.py:564:13: F402 import 'table_name' from line 25 shadowed by loop variable
./src/db/db_wrapper.py:576:13: F402 import 'table_name' from line 25 shadowed by loop variable
./src/db/db_wrapper.py:660:80: E501 line too long (84 > 79 characters)
./src/db/db_wrapper.py:825:80: E501 line too long (82 > 79 characters)
./src/db/db_wrapper.py:858:37: F811 redefinition of unused 'table_name' from line 25
./src/db/bigquery_util.py:85:5: E741 ambiguous variable name 'l'
./src/db/debug_db.py:4:1: F401 'sqlalchemy.String' imported but unused
./src/db/debug_db.py:5:1: F401 'sqlalchemy' imported but unused
./src/db/debug_db.py:6:1: F401 'sqlalchemy.ext.declarative.declarative_base' imported but unused
./src/db/debug_db.py:9:1: F401 'sqlalchemy.desc' imported but unused
./src/db/debug_db.py:16:1: E402 module level import not at top of file
./src/db/debug_db.py:17:1: E402 module level import not at top of file
./src/db/test/test_db_wrapper.py:9:1: E402 module level import not at top of file
./src/db/test/test_db_wrapper.py:17:1: E402 module level import not at top of file
./src/db/test/test_db_wrapper.py:51:9: F841 local variable 'ids' is assigned to but never used
./src/db/test/test_db_wrapper.py:92:9: F841 local variable 'result_ids' is assigned to but never used
./src/db/test/test_db_wrapper.py:[15](https://github.com/sakamomo554101/YouyakuAI/runs/5269321653?check_suite_focus=true#step:5:15)7:9: F841 local variable 'ids' is assigned to but never used
./src/db/test/test_bq_db_wrapper.py:8:1: F401 'db_wrapper.DBUtil' imported but unused
./src/db/test/test_bq_db_wrapper.py:8:1: E402 module level import not at top of file
./src/db/test/test_bq_db_wrapper.py:[17](https://github.com/sakamomo554101/YouyakuAI/runs/5269321653?check_suite_focus=true#step:5:17):1: E402 module level import not at top of file
./src/db/test/test_bq_db_wrapper.py:[18](https://github.com/sakamomo554101/YouyakuAI/runs/5269321653?check_suite_focus=true#step:5:18):1: E402 module level import not at top of file
./src/db/test/test_bq_db_wrapper.py:[19](https://github.com/sakamomo554101/YouyakuAI/runs/5269321653?check_suite_focus=true#step:5:19):1: E402 module level import not at top of file
./src/db/test/test_bq_db_wrapper.py:157:80: E501 line too long (176 > 79 characters)
./src/db/test/test_bq_db_wrapper.py:195:9: E741 ambiguous variable name 'l'
./src/dashboard/app.py:56:80: E501 line too long (81 > 79 characters)
./src/dashboard/app.py:1[21](https://github.com/sakamomo554101/YouyakuAI/runs/5269321653?check_suite_focus=true#step:5:21):9: F811 redefinition of unused 'execute_summarize' from line 98
./src/dashboard/dashboard_util.py:5:1: E402 module level import not at top of file
./src/dashboard/dashboard_util.py:8:1: E402 module level import not at top of file
./src/dashboard/api_client.py:28:80: E501 line too long (84 > 79 characters)
./src/dashboard/api_client.py:34:80: E501 line too long (83 > 79 characters)
./src/dashboard/api_client.py:51:80: E501 line too long (84 > 79 characters)
./src/dashboard/api_client.py:57:80: E501 line too long (83 > 79 characters)
./src/dashboard/api_client.py:63:9: F841 local variable 'url' is assigned to but never used
./src/log/custom_log.py:2:18: E401 multiple imports on one line
./model_pipeline/pipeline.py:473:80: E501 line too long (96 > 79 characters)
./model_pipeline/pipeline.py:506:80: E501 line too long (92 > 79 characters)
./model_pipeline/pipeline.py:553:80: E501 line too long (90 > 79 characters)
./model_pipeline/pipeline.py:569:13: F401 'google.protobuf.field_mask_pb2.FieldMask' imported but unused
./model_pipeline/pipeline.py:574:80: E501 line too long (106 > 79 characters)
./model_pipeline/pipeline.py:604:80: E501 line too long (95 > 79 characters)
./model_pipeline/pipeline.py:609:80: E501 line too long (89 > 79 characters)
./model_pipeline/pipeline.py:6[27](https://github.com/sakamomo554101/YouyakuAI/runs/5269321653?check_suite_focus=true#step:5:27):80: E501 line too long (83 > 79 characters)
./model_pipeline/pipeline.py:660:80: E501 line too long (97 > 79 characters)
./model_pipeline/pipeline.py:691:80: E501 line too long (80 > 79 characters)
./model_pipeline/pipeline.py:801:80: E501 line too long (85 > 79 characters)
./model_pipeline/components/trainer/src/trainer_component.py:17:9: F841 local variable '__metadata__' is assigned to but never used
./model_pipeline/components/trainer/src/trainer.py:15:1: E[30](https://github.com/sakamomo554101/YouyakuAI/runs/5269321653?check_suite_focus=true#step:5:30)2 expected 2 blank lines, found 1
./model_pipeline/components/trainer/src/dataset.py:2:1: F[40](https://github.com/sakamomo554101/YouyakuAI/runs/5269321653?check_suite_focus=true#step:5:40)1 'os' imported but unused
./model_pipeline/components/trainer/src/dataset.py:18:80: E[50](https://github.com/sakamomo554101/YouyakuAI/runs/5269321653?check_suite_focus=true#step:5:50)1 line too long (88 > [79](https://github.com/sakamomo554101/YouyakuAI/runs/5269321653?check_suite_focus=true#step:5:79) characters)
./model_pipeline/components/trainer/src/dataset.py:106:[80](https://github.com/sakamomo554101/YouyakuAI/runs/5269321653?check_suite_focus=true#step:5:80): E501 line too long ([88](https://github.com/sakamomo554101/YouyakuAI/runs/5269321653?check_suite_focus=true#step:5:88) > 79 characters)
./model_pipeline/components/trainer/tests/test_main.py:3:1: F401 'pandas.core.base' imported but unused
./sample/sample_kfp.py:4:1: F401 'kfp.v2.dsl.InputPath' imported but unused
sakamomo554101 commented 2 years ago

とりあえず、文字長い問題は一旦除外する。 E501かな。下記のような感じで除外可能。

あと、import問題は後で直すので、一旦除外。 E402だな。

flake8 --ignore=E1,E23,W503 sample.py
sakamomo554101 commented 2 years ago

あれ、直したのに、反映されん。 チェックアウト対象がおかしい?

sakamomo554101 commented 2 years ago

試しにmake build-componentの処理をgithub actions経由で実行したら、下記のエラーが起きるんだが・・。。

ModuleNotFoundError: No module named 'yaml'
sakamomo554101 commented 2 years ago

https://stackoverflow.com/questions/59572174/no-module-named-dotenv-python-3-8 上記も起きた

sakamomo554101 commented 2 years ago

ダッシュボードのPORT指定がおかしそう(エラーになって欲しいが、、エラーになってないなぁ・・)

Step 14/35 : EXPOSE ${port}
Invalid containerPort: None
sakamomo554101 commented 2 years ago

envにDASHBOARD_PORTが入っていなかったのが問題だな。

次にtflintを試す。 https://github.com/marketplace/actions/setup-tflint

sakamomo554101 commented 2 years ago

https://future-architect.github.io/articles/20211223a/

tflintをGCPで使う際の参考になりそう。 tflint --initでインストールすべきpluginを整理する必要がある。

sakamomo554101 commented 2 years ago

https://github.com/terraform-linters/tflint-ruleset-google 上記を入れる。

sakamomo554101 commented 2 years ago

うーむ、、あまりtflintがちゃんと動いてないように見える・・。 tflint --initがちゃんと正常じゃない?

ただ、tflint --versionで、下記が出てるから、pluginは入ってそうなんだよなあぁ・・。

TFLint version 0.34.1
+ ruleset.google (0.15.0)
sakamomo554101 commented 2 years ago

とりあえず、一通り対応できたので、コミット整理して、マージする。

sakamomo554101 commented 2 years ago

58 で対応済み。