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

[GH-224] GitHub Actions でキャッシュを利用するよう改善 #239

Merged
merged 6 commits into from
Jun 6, 2024

Conversation

tatsutakein
Copy link
Member

@tatsutakein tatsutakein commented Jun 5, 2024

概要

GitHub Actions でキャッシュを利用するよう改善します.

  • キャッシュ用のジョブ ( cache-dependencies ) を挟むことで他のジョブ ( check, lint, diff-gen ) は高速化されていますが,トータルでみると少し遅くなったように感じます
    • 今後他にも並列で走らせたいものが増える場合や,コード量が増える場合はこの構成が有効そうです
    • 逆に今の規模からコード量が増えないのであればあまり効果がないように思えます

レビュー観点

  • コードに違和感がないか
  • CI が流れる状態となっているか(デグレしていないか)

レビューレベル

  • Lv1: ぱっとみて違和感がないかチェックして Approve する
  • Lv2: 仕様レベルまで理解して、仕様通りに動くかある程度検証して Approve する
  • Lv3: 実際に環境で動作確認したうえで Approve する

レビュー優先度

  • すぐに見てもらいたい ( hotfix など ) 🚀
  • 今日中に見てもらいたい 🚗
  • 今日〜明日中で見てもらいたい 🚶
  • 数日以内で見てもらいたい 🐢

画像 / 動画

改善前

https://github.com/yumemi-inc/flutter-mobile-project-template/actions/runs/9378775404
CleanShot 2024-06-05 at 14 45 57

改善後

CleanShot 2024-06-05 at 18 56 13

独自で actions/cache を併用した場合

改善後( cache-dependencies で初回キャッシュ有り)

https://github.com/yumemi-inc/flutter-mobile-project-template/actions/runs/9378814404/attempts/1
CleanShot 2024-06-05 at 14 46 24

改善後( cache-dependencies でキャッシュ復元)

https://github.com/yumemi-inc/flutter-mobile-project-template/actions/runs/9378814404
CleanShot 2024-06-05 at 14 56 51

動作確認手順

備考

Copy link

github-actions bot commented Jun 5, 2024

Visit the preview URL for this PR (updated for commit 96db918):

https://flutter-mobile-project-template-catalog--pr239-feature-es9trved.web.app

(expires Wed, 12 Jun 2024 10:04:29 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

Sign: 9ea56735a63d07a7cfe62eb204b0528284c37c23

Copy link
Member Author

Choose a reason for hiding this comment

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

変更箇所の検出で check-pr が肥大化しそうだったので workflow_call で分割しています.(この内容だったら job を並列で走らせたりしていないので action でも良かったかもです…)

今後 push イベントなど他のものでも使いやすいようになったかなと思います

Comment on lines +31 to +43
cache-dependencies:
runs-on: ubuntu-22.04
needs: changes
if: ${{ needs.changes.outputs.dependencies == 'true' }}
timeout-minutes: 10

steps:
# https://github.com/marketplace/actions/checkout
- name: Checkout
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6

- name: Setup Application Runtime
uses: ./.github/actions/setup-application-runtime
Copy link
Member Author

Choose a reason for hiding this comment

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

キャッシュがない場合を考慮して,一旦ここで一通りのセットアップ処理を実行します.
これにより,後続の処理では必ずキャッシュが復元されて高速化されます.

@@ -8,51 +8,45 @@ concurrency:
cancel-in-progress: true

jobs:
pre-check:
changes:
Copy link
Member Author

Choose a reason for hiding this comment

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

わかりやすそうな名前に変更しています

Comment on lines 20 to 38
# https://github.com/actions/cache
- name: cache pub
id: cache
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
env:
cache-name: pub
with:
# pub-cache files are stored in `~/.pub-cache` on Linux/macOS
path: ~/.pub-cache
key: ${{ runner.os }}-${{ env.cache-name }}-${{ hashFiles('**/pubspec.lock') }}
restore-keys: |
${{ runner.os }}-${{ env.cache-name }}-${{ hashFiles('**/pubspec.lock') }}
${{ runner.os }}-${{ env.cache-name }}-
${{ runner.os }}-

- name: Path pub-cache
shell: bash
run: echo "$HOME/.pub-cache/bin" >> "$GITHUB_PATH"

Copy link
Member Author

Choose a reason for hiding this comment

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

subosito/flutter-action が同等のキャッシュをしていることに気づいたため,独自のキャッシュ処理を削除しています.

https://github.com/subosito/flutter-action/blob/44ac965b96f18d999802d4b807e3256d5a3f9fa1/action.yaml#L103-L111

ワークフロー実行時のログ
https://github.com/yumemi-inc/flutter-mobile-project-template/actions/runs/9378814404/job/25822833262#step:3:70

@tatsutakein tatsutakein marked this pull request as ready for review June 5, 2024 06:19
@yumemi-team-review-requester yumemi-team-review-requester bot requested review from a team, morikann and K9i-0 and removed request for a team June 5, 2024 06:20
Copy link

github-actions bot commented Jun 5, 2024

Ready for review 🚀

@tatsutakein tatsutakein marked this pull request as draft June 5, 2024 08:13
auto-merge was automatically disabled June 5, 2024 08:13

Pull request was converted to draft

Comment on lines 19 to 33
# https://github.com/actions/cache
- name: Cache build runner
id: cache-build-runner
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
env:
cache-name: build-runner
with:
path: |
**/.dart_tool/build
key: ${{ runner.os }}-${{ env.cache-name }}-${{ hashFiles('**/asset_graph.json') }}-${{ hashFiles('**/pubspec.lock') }}
restore-keys: |
${{ runner.os }}-${{ env.cache-name }}-${{ hashFiles('**/asset_graph.json') }}-${{ hashFiles('**/pubspec.lock') }}
${{ runner.os }}-${{ env.cache-name }}-${{ hashFiles('**/pubspec.lock') }}
${{ runner.os }}-${{ env.cache-name }}-
${{ runner.os }}-
Copy link
Member Author

Choose a reason for hiding this comment

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

#240 の内容を近しい場所で記載しています

@tatsutakein tatsutakein marked this pull request as ready for review June 5, 2024 09:57
Copy link

github-actions bot commented Jun 5, 2024

Ready for review 🚀

Copy link
Contributor

@K9i-0 K9i-0 left a comment

Choose a reason for hiding this comment

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

LGTM
コード生成のところちょっと不安だったので失敗する場合を試しましたが、大丈夫そうでした 👍
https://github.com/yumemi-inc/flutter-mobile-project-template/actions/runs/9393478411

@tatsutakein tatsutakein merged commit e93bb39 into main Jun 6, 2024
10 checks passed
@tatsutakein tatsutakein deleted the feature/GH-224 branch June 6, 2024 01:15
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.

GitHub Actions でpubのキャッシュを利用
2 participants