mirror of
https://github.com/supabase/supabase.git
synced 2026-10-08 19:05:06 +03:00
Deployment update checks now receive a timestamp from GitHub’s documented commit API instead of silently falling back to `unknown` when its website response changes. Valid deployment metadata is cached for ten minutes; development and failed lookups are uncached so they can recover. **Changed:** - Validate and normalize the committer date in the shared Next/TanStack handler, preserving the existing response shape and `unknown` fallback. - Exclude only the exact deployment-metadata endpoint from TanStack’s private API cache default; authenticated APIs and server functions retain it. - Keep the client update query unpinned and its existing toast threshold unchanged. **Added:** - Shared-handler tests through both Next and the TanStack adapter for dates, malformed payloads, upstream failures, and recovery. - Tests using the installed Vercel route compiler for root and `/dashboard` cache rules, security headers, and empty Next configuration. ## To test - On the TanStack preview, request `/dashboard/api/get-deployment-commit`; compare its SHA and UTC timestamp with the deployed commit’s GitHub committer date. - Repeat the request to check CDN caching. Vercel consumes `s-maxage`, so use cache-hit/age evidence as well as client-visible headers. - Confirm another API route and a server-function path retain `private, no-store`. - Open an existing project, reload it while clean, and inspect the untouched support form for metadata-related errors. Validation: 60 focused tests, Studio typecheck, scoped ESLint, formatting, knip, and both framework production builds passed. Live unauthenticated GitHub lookup with the configured API version returned the expected committer date. Full source lint ratchet also passed, excluding only generated build directories. Local TanStack browser checks passed for clean project/reload, general settings, untouched support form, and naturally emitted development metadata formatting; no errors or unexpected update toast appeared. The positive two-deployment toast and submitted support-version formatting were not exercised. Deployed native Next previews returned the exact commit SHA and expected UTC timestamp; repeated metadata requests produced CDN HIT responses (ages 26 and 100 seconds). Build logs establish that the staging preview also ran Next, so it does not validate TanStack edge header behavior. A separate preview-only redeployment with a deployment-scoped TanStack override was confirmed to run Vite. It returned the same correct SHA/timestamp, a repeat CDN cache HIT, and private, no-store on the neighboring UTC API. No project settings or production aliases were changed. Installed Vercel compiler tests cover the remaining root/base-path and server-function rules. No new environment variable, token, or dependency is required. Co-authored-by: Alaister Young <10985857+alaister@users.noreply.github.com>
51 lines
1.4 KiB
TypeScript
51 lines
1.4 KiB
TypeScript
import type { NextApiRequest, NextApiResponse } from 'next'
|
|
import { z } from 'zod'
|
|
|
|
const commitSchema = z.object({
|
|
committer: z.object({ date: z.string().datetime({ offset: true }) }),
|
|
})
|
|
|
|
async function getCommitTime(commitSha: string) {
|
|
try {
|
|
const response = await fetch(
|
|
`https://api.github.com/repos/supabase/supabase/git/commits/${commitSha}`,
|
|
{
|
|
headers: {
|
|
Accept: 'application/vnd.github+json',
|
|
'X-GitHub-Api-Version': '2026-03-10',
|
|
'User-Agent': 'Supabase-Studio',
|
|
},
|
|
}
|
|
)
|
|
|
|
if (!response.ok) {
|
|
throw new Error('Failed to fetch commit details')
|
|
}
|
|
|
|
const data = commitSchema.parse(await response.json())
|
|
return new Date(data.committer.date).toISOString()
|
|
} catch (error) {
|
|
console.error('Error fetching commit time:', error)
|
|
return 'unknown'
|
|
}
|
|
}
|
|
|
|
export default async function handler(
|
|
_req: NextApiRequest,
|
|
res: NextApiResponse<{ commitSha: string; commitTime: string }>
|
|
) {
|
|
const commitSha = process.env.VERCEL_GIT_COMMIT_SHA || 'development'
|
|
const commitTime = commitSha !== 'development' ? await getCommitTime(commitSha) : 'unknown'
|
|
|
|
// Valid metadata is identical for all visitors; failed lookups must remain retryable.
|
|
res.setHeader(
|
|
'Cache-Control',
|
|
commitTime === 'unknown' ? 'private, no-store' : 'public, max-age=0, s-maxage=600'
|
|
)
|
|
|
|
res.status(200).json({
|
|
commitSha,
|
|
commitTime,
|
|
})
|
|
}
|