chore: restore production build cache with stable key using actions/cache (#26276)

* fix: align env vars between Production Builds and E2E workflows for turbo cache sharing

Co-Authored-By: keith@cal.com <keithwillcode@gmail.com>

* fix: move E2E-specific env vars to step-level for turbo cache alignment

Instead of adding env vars to production-build-without-database.yml (which
caused DB calls during build), move the E2E-specific env vars from workflow-level
to step-level in e2e.yml. This ensures the cache-build step has the same env
context in both workflows, enabling turbo remote cache sharing.

Env vars moved to step-level:
- DATABASE_DIRECT_URL (to cache-db and Run Tests steps)
- E2E_TEST_MAILHOG_ENABLED (to Run Tests step)
- EMAIL_SERVER_* (to Run Tests step)

Co-Authored-By: keith@cal.com <keithwillcode@gmail.com>

* fix: restore production build cache with stable key using actions/cache

- Restore artifact caching for .next, dist, and .turbo directories
- Use actions/cache@v4 (accelerated by Blacksmith on their runners)
- Design stable cache key scoped to branch:
  - Includes branch name (head_ref for PRs, ref_name for pushes)
  - Hashes yarn.lock for dependency changes
  - Hashes source files in apps/web and packages/*/src
  - Excludes generated directories (prisma/zod, kysely) that caused instability
- Add restore-keys for partial cache hits
- Only run yarn build on cache miss
- Revert e2e.yml env var changes (no longer needed with artifact caching)

Co-Authored-By: keith@cal.com <keithwillcode@gmail.com>

* fix: simplify restore-keys to single fallback

Co-Authored-By: keith@cal.com <keithwillcode@gmail.com>

* fix: remove restore-keys entirely for exact cache matching only

Co-Authored-By: keith@cal.com <keithwillcode@gmail.com>

* fix: use broader package pattern with exclusions for generated prisma files

Co-Authored-By: keith@cal.com <keithwillcode@gmail.com>

* fix: add exclusions for prisma/generated and prisma/client directories

Co-Authored-By: keith@cal.com <keithwillcode@gmail.com>

* Apply suggestion from @cubic-dev-ai[bot]

Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>

* fix: add .json and .css patterns to cache hash for config and style changes

Co-Authored-By: keith@cal.com <keithwillcode@gmail.com>

---------

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
This commit is contained in:
Keith Williams
2025-12-29 21:59:00 -03:00
committed by GitHub
co-authored by keith@cal.com <keithwillcode@gmail.com> keith@cal.com <keithwillcode@gmail.com> keith@cal.com <keithwillcode@gmail.com> keith@cal.com <keithwillcode@gmail.com> keith@cal.com <keithwillcode@gmail.com> cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com> keith@cal.com <keithwillcode@gmail.com> Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
parent 23c4e7edef
commit e4b0a1b941
+20
View File
@@ -7,7 +7,27 @@ inputs:
runs:
using: "composite"
steps:
- name: Cache production build
uses: actions/cache@v4
id: cache-build
env:
cache-name: prod-build
# Use branch name for cache scoping (head_ref for PRs, ref_name for pushes)
branch-key: ${{ github.head_ref || github.ref_name }}
# Hash yarn.lock for dependency changes
lockfile-hash: ${{ hashFiles('yarn.lock') }}
# Hash source files that affect the web build, excluding generated directories
# Excludes packages/prisma/{generated,client,zod}/* and packages/kysely/* which are generated by prisma generate
source-hash: ${{ hashFiles('apps/**/**.[jt]s', 'apps/**/**.[jt]sx', 'apps/**/*.json', 'apps/**/*.css', 'packages/**/**.[jt]s', 'packages/**/**.[jt]sx', 'packages/prisma/schema.prisma', 'packages/prisma/migrations/**/*.sql', '!**/node_modules/**', '!packages/prisma/generated/**', '!packages/prisma/client/**', '!packages/prisma/zod/**', '!packages/kysely/**') }}
with:
path: |
${{ github.workspace }}/apps/web/.next
${{ github.workspace }}/apps/web/public/embed
**/.turbo/**
**/dist/**
key: ${{ runner.os }}-${{ env.cache-name }}-${{ inputs.node_version }}-${{ env.branch-key }}-${{ env.lockfile-hash }}-${{ env.source-hash }}
- run: |
export NODE_OPTIONS="--max_old_space_size=8192"
yarn build
if: steps.cache-build.outputs.cache-hit != 'true'
shell: bash