Skip to content

Scheduling infrastructure for absolutely everyone.

chore: Delete cache-build cache entries on PR close (#26312)

Keith Williams798573268391
diff --git a/.github/actions/cache-build-key/action.yml b/.github/actions/cache-build-key/action.yml
new file mode 100644
index 00000000000..847989e46a7
--- /dev/null
+++ b/.github/actions/cache-build-key/action.yml
@@ -0,0 +1,23 @@
+name: Generate cache-build key
+description: "Generate the cache key for production build caching"
+inputs:
+ branch_key:
+ required: true
+ description: "Branch key for cache scoping (e.g., github.head_ref for PRs)"
+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: prod-build
+ BRANCH_KEY: ${{ inputs.branch_key }}
+ LOCKFILE_HASH: ${{ hashFiles('yarn.lock') }}
+ 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/**') }}
+ run: |
+ echo "key=${CACHE_NAME}-${BRANCH_KEY}-${LOCKFILE_HASH}-${SOURCE_HASH}" >> $GITHUB_OUTPUT
diff --git a/.github/actions/cache-build/action.yml b/.github/actions/cache-build/action.yml
index d3445a489ac..2197e923705 100644
--- a/.github/actions/cache-build/action.yml
+++ b/.github/actions/cache-build/action.yml
@@ -1,31 +1,23 @@
name: Cache production build binaries
description: "Cache or restore if necessary"
-inputs:
- node_version:
- required: false
- default: v18.x
runs:
using: "composite"
steps:
+ - name: Generate cache key
+ id: cache-key
+ uses: ./.github/actions/cache-build-key
+ with:
+ branch_key: ${{ github.head_ref || github.ref_name }}
- 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 }}
+ key: ${{ steps.cache-key.outputs.key }}
- run: |
export NODE_OPTIONS="--max_old_space_size=8192"
yarn build
diff --git a/.github/workflows/delete-blacksmith-cache.yml b/.github/workflows/delete-blacksmith-cache.yml
index aad432deb0b..26addc991fe 100644
--- a/.github/workflows/delete-blacksmith-cache.yml
+++ b/.github/workflows/delete-blacksmith-cache.yml
@@ -1,4 +1,4 @@
-name: Manually Delete Blacksmith Cache
+name: Delete Blacksmith Cache
on:
workflow_dispatch:
inputs:
@@ -6,12 +6,28 @@ on:
description: "Blacksmith Cache Key to Delete"
required: true
type: string
+ pull_request:
+ types: [closed]
+
jobs:
manually-delete-blacksmith-cache:
+ if: github.event_name == 'workflow_dispatch'
runs-on: blacksmith-2vcpu-ubuntu-2404
steps:
- name: Checkout
uses: actions/checkout@v4
- uses: useblacksmith/cache-delete@v1
with:
- cache_key: ${{ inputs.cache_key }}
+ key: ${{ inputs.cache_key }}
+
+ delete-cache-build-on-pr-close:
+ if: github.event_name == 'pull_request' && github.event.action == 'closed'
+ runs-on: blacksmith-2vcpu-ubuntu-2404
+ env:
+ CACHE_NAME: prod-build
+ steps:
+ - name: Delete cache-build cache
+ uses: useblacksmith/cache-delete@v1
+ with:
+ key: ${{ env.CACHE_NAME }}-${{ github.event.pull_request.head.ref }}
+ prefix: "true"