feat: implement git checkout caching to speed up CI workflows (#26636)

* feat: implement git checkout caching to speed up CI workflows

- Create cache-checkout action to save/restore git working directory
- Update prepare job in pr.yml to cache checkout after dangerous-git-checkout
- Update all downstream workflows to restore from cache instead of checkout
- Pass commit-sha to all workflow calls for cache key consistency

This reduces the number of full git checkouts from 20+ per workflow run to just 1,
significantly improving CI performance especially for large repos.

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* refactor: use actions/cache/restore directly instead of custom action

Remove sparse-checkout and use actions/cache/restore@v4 directly in all
downstream workflows. This eliminates the need for any git fetch operation
before restoring from cache, making the optimization more effective.

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* refactor: use github.event.pull_request.head.sha for cache key

- Remove commit-sha input from all downstream workflows
- Update cache-checkout action to use github.event.pull_request.head.sha directly
- Remove commit-sha output from prepare job
- Remove commit-sha from all workflow calls in pr.yml
- Keep sparse-checkout of .github to access the cache-checkout action

This eliminates the need to pass commit-sha around while still using
a reusable action for the cache restore logic.

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* fix: update cache key to include branch name and add cache cleanup

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* fix: use github.head_ref and github.sha for cache key

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* fix: add prefix delete before saving cache to clear previous caches

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* perf: add sparse-checkout to exclude example-apps and mp4 files

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* fix: restore get_sha step and commit-sha output that was accidentally removed

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* fix: add trailing dash to cache key prefix to prevent accidental deletion of other branches' caches

The prefix-based cache deletion was using 'git-checkout-{branch}' which would
accidentally match and delete caches for branches with similar prefixes.
For example, branch 'feature' would delete caches for 'feature-2', 'feature-new', etc.

Adding a trailing '-' ensures exact branch matching:
- 'git-checkout-feature-' matches 'git-checkout-feature-abc123' (intended)
- 'git-checkout-feature-' does NOT match 'git-checkout-feature-2-def456' (correct)

Fixes both the cache-checkout action and the PR close cleanup workflow.

Co-Authored-By: unknown <>

---------

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
Keith Williams
2026-01-10 21:46:21 +09:00
committed by GitHub
co-authored by unknown <> Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
parent 2d514a2a3e
commit cbb56f6a61
22 changed files with 149 additions and 18 deletions
@@ -65,7 +65,11 @@ jobs:
- 5432:5432
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/dangerous-git-checkout
with:
sparse-checkout: .github
- uses: ./.github/actions/cache-checkout
with:
mode: restore
- uses: ./.github/actions/yarn-install
- uses: ./.github/actions/cache-db
- name: Cache API v1 production build
@@ -35,7 +35,11 @@ jobs:
- 5432:5432
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/dangerous-git-checkout
with:
sparse-checkout: .github
- uses: ./.github/actions/cache-checkout
with:
mode: restore
- uses: ./.github/actions/yarn-install
- name: Generate Prisma schemas
working-directory: apps/api/v2
+5 -1
View File
@@ -12,7 +12,11 @@ jobs:
runs-on: blacksmith-4vcpu-ubuntu-2404
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/dangerous-git-checkout
with:
sparse-checkout: .github
- uses: ./.github/actions/cache-checkout
with:
mode: restore
- uses: ./.github/actions/yarn-install
- run: yarn prisma generate
- name: Run API v2 unit tests
+5 -1
View File
@@ -12,7 +12,11 @@ jobs:
timeout-minutes: 30
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/dangerous-git-checkout
with:
sparse-checkout: .github
- uses: ./.github/actions/cache-checkout
with:
mode: restore
- uses: ./.github/actions/yarn-install
- name: Cache atoms production build
uses: actions/cache@v4
@@ -34,7 +34,11 @@ jobs:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- uses: actions/checkout@v4
- uses: ./.github/actions/dangerous-git-checkout
with:
sparse-checkout: .github
- uses: ./.github/actions/cache-checkout
with:
mode: restore
- uses: ./.github/actions/yarn-install
- name: Generate Swagger
+5 -1
View File
@@ -12,7 +12,11 @@ jobs:
runs-on: blacksmith-4vcpu-ubuntu-2404
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/dangerous-git-checkout
with:
sparse-checkout: .github
- uses: ./.github/actions/cache-checkout
with:
mode: restore
- uses: ./.github/actions/yarn-install
- name: Show info
run: node -e "console.log(require('v8').getHeapStatistics())"
+5 -1
View File
@@ -17,7 +17,11 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/dangerous-git-checkout
with:
sparse-checkout: .github
- uses: ./.github/actions/cache-checkout
with:
mode: restore
- name: Setup Bun
uses: oven-sh/setup-bun@v1
@@ -31,3 +31,13 @@ jobs:
with:
key: ${{ env.CACHE_NAME }}-${{ github.event.pull_request.head.ref }}
prefix: "true"
delete-git-checkout-cache-on-pr-close:
if: github.event_name == 'pull_request' && github.event.action == 'closed'
runs-on: blacksmith-2vcpu-ubuntu-2404
steps:
- name: Delete git-checkout cache
uses: useblacksmith/cache-delete@v1
with:
key: git-checkout-${{ github.event.pull_request.head.ref }}-
prefix: "true"
+5 -1
View File
@@ -12,7 +12,11 @@ jobs:
runs-on: blacksmith-2vcpu-ubuntu-2404
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/dangerous-git-checkout
with:
sparse-checkout: .github
- uses: ./.github/actions/cache-checkout
with:
mode: restore
- name: Cache Docs build
uses: actions/cache@v4
id: cache-docs-build
+5 -1
View File
@@ -74,7 +74,11 @@ jobs:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- uses: actions/checkout@v4
- uses: ./.github/actions/dangerous-git-checkout
with:
sparse-checkout: .github
- uses: ./.github/actions/cache-checkout
with:
mode: restore
- uses: ./.github/actions/yarn-install
- uses: ./.github/actions/cache-db
- name: Build platform packages with Turbo
+5 -1
View File
@@ -81,7 +81,11 @@ jobs:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- uses: actions/checkout@v4
- uses: ./.github/actions/dangerous-git-checkout
with:
sparse-checkout: .github
- uses: ./.github/actions/cache-checkout
with:
mode: restore
- uses: ./.github/actions/yarn-install
- uses: ./.github/actions/yarn-playwright-install
- run: yarn prisma generate
+5 -1
View File
@@ -73,7 +73,11 @@ jobs:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- uses: actions/checkout@v4
- uses: ./.github/actions/dangerous-git-checkout
with:
sparse-checkout: .github
- uses: ./.github/actions/cache-checkout
with:
mode: restore
- uses: ./.github/actions/yarn-install
- uses: ./.github/actions/yarn-playwright-install
- run: yarn prisma generate
+5 -1
View File
@@ -81,7 +81,11 @@ jobs:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- uses: actions/checkout@v4
- uses: ./.github/actions/dangerous-git-checkout
with:
sparse-checkout: .github
- uses: ./.github/actions/cache-checkout
with:
mode: restore
- uses: ./.github/actions/yarn-install
- uses: ./.github/actions/yarn-playwright-install
- run: yarn prisma generate
+5 -1
View File
@@ -82,7 +82,11 @@ jobs:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- uses: actions/checkout@v4
- uses: ./.github/actions/dangerous-git-checkout
with:
sparse-checkout: .github
- uses: ./.github/actions/cache-checkout
with:
mode: restore
- uses: ./.github/actions/yarn-install
- uses: ./.github/actions/yarn-playwright-install
- run: yarn prisma generate
+5 -1
View File
@@ -79,7 +79,11 @@ jobs:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- uses: actions/checkout@v4
- uses: ./.github/actions/dangerous-git-checkout
with:
sparse-checkout: .github
- uses: ./.github/actions/cache-checkout
with:
mode: restore
- uses: ./.github/actions/yarn-install
- run: yarn prisma generate
- uses: ./.github/actions/cache-db
+5 -1
View File
@@ -10,7 +10,11 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/dangerous-git-checkout
with:
sparse-checkout: .github
- uses: ./.github/actions/cache-checkout
with:
mode: restore
- uses: ./.github/actions/yarn-install
- name: Run Lint
run: yarn lint
+4
View File
@@ -175,6 +175,10 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/dangerous-git-checkout
- name: Cache git checkout
uses: ./.github/actions/cache-checkout
with:
mode: save
- name: Generate DB cache key
id: cache-db-key
uses: ./.github/actions/cache-db-key
@@ -43,7 +43,11 @@ jobs:
timeout-minutes: 30
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/dangerous-git-checkout
with:
sparse-checkout: .github
- uses: ./.github/actions/cache-checkout
with:
mode: restore
- uses: ./.github/actions/yarn-install
- run: yarn prisma generate
- name: Generate cache key
+5 -1
View File
@@ -47,7 +47,11 @@ jobs:
- 5432:5432
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/dangerous-git-checkout
with:
sparse-checkout: .github
- uses: ./.github/actions/cache-checkout
with:
mode: restore
- uses: ./.github/actions/yarn-install
if: inputs.DB_CACHE_HIT != 'true'
- run: yarn prisma generate
+5 -1
View File
@@ -12,7 +12,11 @@ jobs:
runs-on: blacksmith-4vcpu-ubuntu-2404
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/dangerous-git-checkout
with:
sparse-checkout: .github
- uses: ./.github/actions/cache-checkout
with:
mode: restore
- uses: ./.github/actions/yarn-install
- run: yarn prisma generate
- run: yarn test -- --no-isolate