Skip to content

Commit

Permalink
Merge pull request #239 from yumemi-inc/feature/GH-224
Browse files Browse the repository at this point in the history
[GH-224] GitHub Actions でキャッシュを利用するよう改善
  • Loading branch information
tatsutakein committed Jun 6, 2024
2 parents 86c957f + 96db918 commit e93bb39
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 39 deletions.
76 changes: 37 additions & 39 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:
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

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 @@ -97,9 +91,11 @@ jobs:
fail-on-error: "true"

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

Expand All @@ -123,20 +119,22 @@ 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
needs:
- check
- custom-lint
- diff-gen
- lint
- markdown
permissions: { }
if: failure()
Expand Down
74 changes: 74 additions & 0 deletions .github/workflows/wc-changes.yml
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)));
16 changes: 16 additions & 0 deletions .github/workflows/wc-check-diff.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,22 @@ jobs:
- name: Setup Application Runtime
uses: ./.github/actions/setup-application-runtime

# 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('**/pubspec.lock') }}-${{ hashFiles('**/*.dart') }}
restore-keys: |
${{ runner.os }}-${{ env.cache-name }}-${{ hashFiles('**/pubspec.lock') }}-${{ hashFiles('**/*.dart') }}
${{ runner.os }}-${{ env.cache-name }}-${{ hashFiles('**/pubspec.lock') }}
${{ runner.os }}-${{ env.cache-name }}-
${{ runner.os }}-
- name: Regenerate code
run: melos run regenerate_code --no-select

Expand Down

0 comments on commit e93bb39

Please sign in to comment.