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
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 35 additions & 37 deletions .github/workflows/check-pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.

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

uses: ./.github/workflows/wc-changes.yml

skip-comment:
runs-on: ubuntu-22.04
needs: changes
if: ${{ needs.changes.outputs.any == 'false' }}
permissions:
pull-requests: write
outputs:
gen: ${{ steps.filter.outputs.gen }}
lint: ${{ steps.filter.outputs.lint }}
markdown: ${{ steps.filter.outputs.markdown }}
src: ${{ steps.filter.outputs.src }}
runs-on: ubuntu-22.04
timeout-minutes: 5

steps:
- uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3.0.2
id: filter
with:
filters: |
gen:
- "**.dart"
- "**.yaml"
- "**/pubspec.lock"
lint:
- "**.dart"
- "**.yaml"
- "**/pubspec.lock"
- "scripts/report-custom-lint-ci.sh"
markdown:
- "**.md"
src:
- "**.dart"
- "**.yaml"
- "**/pubspec.lock"
- "scripts/**"

# https://github.com/peter-evans/create-or-update-comment
- name: Comment
if: ${{ steps.filter.outputs.changes == '[]' }}
uses: peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043 # v4.0.0
with:
issue-number: ${{ github.event.pull_request.number }}
body: |
チェック対象ファイルの変更がなかったため、checkジョブをスキップしました

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
Comment on lines +31 to +43
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:
needs: pre-check
if: ${{ needs.pre-check.outputs.src == 'true' }}
needs:
- changes
- cache-dependencies
if: ${{ needs.changes.outputs.src == 'true' }}
runs-on: ubuntu-22.04
timeout-minutes: 20

Expand Down Expand Up @@ -98,8 +92,10 @@ jobs:

# custom_lintが時間かかるのでcheckと並列させる
lint:
needs: pre-check
if: ${{ needs.pre-check.outputs.lint == 'true' }}
needs:
- changes
- cache-dependencies
if: ${{ needs.changes.outputs.lint == 'true' }}
runs-on: ubuntu-22.04
timeout-minutes: 20

Expand All @@ -123,13 +119,15 @@ jobs:

diff-gen:
uses: ./.github/workflows/wc-check-diff.yaml
needs: pre-check
if: ${{ needs.pre-check.outputs.gen == 'true' }}
needs:
- changes
- cache-dependencies
if: ${{ needs.changes.outputs.gen == 'true' }}

markdown:
uses: ./.github/workflows/wc-check-markdown.yaml
needs: pre-check
if: ${{ needs.pre-check.outputs.markdown == 'true' }}
needs: changes
if: ${{ needs.changes.outputs.markdown == 'true' }}

status-check:
runs-on: ubuntu-22.04
Expand Down
74 changes: 74 additions & 0 deletions .github/workflows/wc-changes.yml
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 イベントなど他のものでも使いやすいようになったかなと思います

Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: "Check for changes in paths"

on:
workflow_call:
outputs:
gen:
value: ${{ jobs.changes.outputs.gen }}
lint:
value: ${{ jobs.changes.outputs.lint }}
any:
value: ${{ jobs.changes.outputs.any }}
markdown:
value: ${{ jobs.changes.outputs.markdown }}
src:
value: ${{ jobs.changes.outputs.src }}
dependencies:
value: ${{ jobs.changes.outputs.dependencies }}

permissions:
contents: read
pull-requests: read

jobs:
changes:
runs-on: ubuntu-22.04
outputs:
any: ${{ steps.filter.outputs.changes != '[]' }}
gen: ${{ steps.filter.outputs.gen }}
lint: ${{ steps.filter.outputs.lint }}
markdown: ${{ steps.filter.outputs.markdown }}
src: ${{ steps.filter.outputs.src }}
dependencies: ${{ steps.needs.outputs.dependencies }}
steps:
# https://github.com/marketplace/actions/checkout
- name: Checkout
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6

# https://github.com/marketplace/actions/paths-changes-filter
- name: Paths Changes Filter
uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3.0.2
id: filter
with:
filters: |
gen:
- "**.dart"
- "**.yaml"
- "**/pubspec.lock"
lint:
- "**.dart"
- "**.yaml"
- "**/pubspec.lock"
- "scripts/report-custom-lint-ci.sh"
markdown:
- "**.md"
src:
- "**.dart"
- "**.yaml"
- "**/pubspec.lock"
- "scripts/**"

- name: Check for dependencies changes
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
id: needs
with:
script: |
const changes = ${{ steps.filter.outputs.changes }};

// 依存関係の解決が必要な変更箇所
const dependencies = [
'gen',
'lint',
'src',
];
core.setOutput('dependencies', changes.some(value => dependencies.includes(value)));
Loading