From 16f6099e46ef92530e7561fbcdc8287f2df489dd Mon Sep 17 00:00:00 2001 From: Keith Williams Date: Wed, 31 Dec 2025 11:17:31 -0300 Subject: [PATCH] ci: simplify DB cache key and skip yarn-install on cache hit (#26344) * ci: skip yarn-install in setup-db when DB cache exists Co-Authored-By: keith@cal.com * ci: skip entire setup-db job when DB cache exists This saves ~35-40s per workflow run by: 1. Adding DB cache lookup to prepare job (lookup-only mode) 2. Skipping the entire setup-db job when cache exists (avoids postgres container startup) 3. Keeping the yarn-install skip in setup-db.yml as a fallback Co-Authored-By: keith@cal.com * ci: simplify DB cache key and skip yarn-install on cache hit - Remove commit SHA and PR number from cache key for better reuse - Cache key now only depends on prisma schema/migrations hash - Skip yarn-install in setup-db when DB cache exists (saves ~17s) - Revert changes to pr.yml required job logic Co-Authored-By: keith@cal.com * ci: move DB cache lookup to prepare step and skip cache-db on hit - Move cache lookup to pr.yml prepare step for early detection - Pass db-cache-hit output to setup-db.yml as input - Skip yarn-install and cache-db action when cache exists - setup-db job still runs and reports success (no required job changes) Co-Authored-By: keith@cal.com * ci: skip container initialization when DB cache exists - Rename setup-db to setup-db-seed (only runs on cache miss) - Add lightweight setup-db wrapper job that always returns success - When cache exists: setup-db-seed is skipped, setup-db returns success - When cache miss: setup-db-seed runs with postgres, setup-db checks result - This avoids postgres container startup (~17-20s) when cache exists Co-Authored-By: keith@cal.com * ci: add cache-db-key action for consistent cache key generation - Create cache-db-key action to generate DB cache key in one place - Update cache-db action to use cache-db-key for consistency - Update pr.yml prepare step to use cache-db-key for lookup - This ensures the lookup key always matches the actual cache key Co-Authored-By: keith@cal.com * ci: remove runner.os from cache-db-key Co-Authored-By: keith@cal.com * ci: simplify setup-db by removing wrapper job - Remove setup-db wrapper job and rename setup-db-seed back to setup-db - setup-db is now skipped when cache exists (no container startup) - Update required check to allow skipped for setup-db when cache hit Co-Authored-By: keith@cal.com * ci: revert to two-job pattern for setup-db - setup-db-seed: only runs on cache miss (has postgres container) - setup-db: wrapper that always runs and reports success - This ensures downstream jobs (Tests, Production builds) are not skipped - Reverts required check to simple setup-db.result != 'success' Co-Authored-By: keith@cal.com * ci: single setup-db job with conditional steps on cache hit - Removed two-job pattern (setup-db-seed + wrapper) - Single setup-db job calls setup-db.yml reusable workflow - Pass DB_CACHE_HIT input from prepare job's db-cache-hit output - Skip yarn-install and cache-db steps when cache hit (~17s savings) - Container still starts (will optimize in follow-up) Co-Authored-By: keith@cal.com --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- .github/actions/cache-db-key/action.yml | 23 +++++++++++++++++++++++ .github/actions/cache-db/action.yml | 15 ++++++--------- .github/workflows/pr.yml | 13 ++++++++++++- .github/workflows/setup-db.yml | 10 +++++----- 4 files changed, 46 insertions(+), 15 deletions(-) create mode 100644 .github/actions/cache-db-key/action.yml diff --git a/.github/actions/cache-db-key/action.yml b/.github/actions/cache-db-key/action.yml new file mode 100644 index 0000000000..f8bd9211bc --- /dev/null +++ b/.github/actions/cache-db-key/action.yml @@ -0,0 +1,23 @@ +name: Generate cache-db key +description: "Generate the cache key for database caching" +inputs: + path: + required: false + default: "backups/backup.sql" + description: "Path to the backup file" +outputs: + key: + description: "The generated cache key" + value: ${{ steps.generate-key.outputs.key }} +runs: + using: "composite" + steps: + - name: Generate cache key + id: generate-key + shell: bash + env: + CACHE_NAME: cache-db + PATH_KEY: ${{ inputs.path }} + PRISMA_HASH: ${{ hashFiles('packages/prisma/schema.prisma', 'packages/prisma/migrations/**/**.sql', 'packages/prisma/*.ts') }} + run: | + echo "key=${CACHE_NAME}-${PATH_KEY}-${PRISMA_HASH}" >> $GITHUB_OUTPUT diff --git a/.github/actions/cache-db/action.yml b/.github/actions/cache-db/action.yml index 876bebd2a1..ec5738e426 100644 --- a/.github/actions/cache-db/action.yml +++ b/.github/actions/cache-db/action.yml @@ -7,21 +7,18 @@ inputs: path: required: false default: "backups/backup.sql" - COMMIT_SHA: - required: false - default: "" - description: "Commit SHA to include in cache key (passed from workflow)" runs: using: "composite" steps: + - name: Generate cache key + id: cache-key + uses: ./.github/actions/cache-db-key + with: + path: ${{ inputs.path }} - name: Cache database id: cache-db uses: actions/cache@v4 env: - cache-name: cache-db - key-1: ${{ hashFiles('packages/prisma/schema.prisma', 'packages/prisma/migrations/**/**.sql', 'packages/prisma/*.ts') }} - key-2: ${{ github.event.pull_request.number || github.ref }} - key-3: ${{ inputs.COMMIT_SHA || github.event.pull_request.head.sha || github.sha }} DATABASE_URL: ${{ inputs.DATABASE_URL }} DATABASE_DIRECT_URL: ${{ inputs.DATABASE_URL }} E2E_TEST_CALCOM_QA_EMAIL: ${{ inputs.E2E_TEST_CALCOM_QA_EMAIL }} @@ -29,7 +26,7 @@ runs: E2E_TEST_CALCOM_QA_GCAL_CREDENTIALS: ${{ inputs.E2E_TEST_CALCOM_QA_GCAL_CREDENTIALS }} with: path: ${{ inputs.path }} - key: ${{ runner.os }}-${{ env.cache-name }}-${{ inputs.path }}-${{ env.key-1 }}-${{ env.key-2 }}-${{ env.key-3 }} + key: ${{ steps.cache-key.outputs.key }} - run: yarn db-seed if: steps.cache-db.outputs.cache-hit != 'true' shell: bash diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index d15fcc6c45..d0df09ea1a 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -161,9 +161,20 @@ jobs: has_companion: ${{ steps.filter.outputs.has_companion }} commit-sha: ${{ steps.get_sha.outputs.commit-sha }} run-e2e: ${{ steps.check-if-pr-has-label.outputs.run-e2e == 'true' }} + db-cache-hit: ${{ steps.cache-db-check.outputs.cache-hit }} steps: - uses: actions/checkout@v4 - uses: ./.github/actions/dangerous-git-checkout + - name: Generate DB cache key + id: cache-db-key + uses: ./.github/actions/cache-db-key + - name: Check DB cache (lookup-only) + id: cache-db-check + uses: actions/cache/restore@v4 + with: + path: backups/backup.sql + key: ${{ steps.cache-db-key.outputs.key }} + lookup-only: true - uses: dorny/paths-filter@v3 id: filter with: @@ -288,7 +299,7 @@ jobs: if: ${{ needs.prepare.outputs.run-e2e == 'true' && needs.prepare.outputs.has-files-requiring-all-checks == 'true' }} uses: ./.github/workflows/setup-db.yml with: - COMMIT_SHA: ${{ needs.prepare.outputs.commit-sha }} + DB_CACHE_HIT: ${{ needs.prepare.outputs.db-cache-hit }} secrets: inherit build-api-v1: diff --git a/.github/workflows/setup-db.yml b/.github/workflows/setup-db.yml index 468dbbabbd..a4618d1fb9 100644 --- a/.github/workflows/setup-db.yml +++ b/.github/workflows/setup-db.yml @@ -3,11 +3,11 @@ name: Setup Database on: workflow_call: inputs: - COMMIT_SHA: + DB_CACHE_HIT: required: false type: string - default: "" - description: "Commit SHA to include in cache key" + default: "false" + description: "Whether the DB cache was hit (skip yarn-install and cache-db if true)" permissions: contents: read @@ -49,6 +49,6 @@ jobs: - uses: actions/checkout@v4 - uses: ./.github/actions/dangerous-git-checkout - uses: ./.github/actions/yarn-install + if: inputs.DB_CACHE_HIT != 'true' - uses: ./.github/actions/cache-db - with: - COMMIT_SHA: ${{ inputs.COMMIT_SHA || github.sha }} + if: inputs.DB_CACHE_HIT != 'true'