Files
lobehub__lobehub/scripts/workerDeployAnnotations.ts
Innei 011f947cf7 👷 ci(share,workbench): upload PR previews to sibling -preview Workers (#19103)
* 👷 ci(share,workbench): upload PR previews to sibling -preview Workers

Cloudflare rolls back only to the 100 most recently uploaded versions of a
script, and PR preview uploads landed on the production scripts, so a busy
day pushed every real deployment out of the rollback window. Previews now
go to lobehub-share-preview and lobehub-workbench-preview; the preview
aliases move with them (pr<N>-lobehub-share-preview...).

Claude-Session: https://claude.ai/code/session_01BKMAksDxdePWPW4kgr9KpM

* 📝 docs(split-micro-app): previews upload to a sibling -preview Worker

Claude-Session: https://claude.ai/code/session_01BKMAksDxdePWPW4kgr9KpM

* 👷 ci(share,workbench): stamp actor, commit and run on every Worker version

Cloudflare records only the API token's owner as a version's author, so a
deploy from CI or a laptop was unattributable. wrangler deploy and PR preview
uploads now carry --tag <sha7> and --message "<actor> <repo>@<sha7> run <id>"
(local deploys: "<git email> local@<sha7>"), which 鳥居番's Deploys page
already shows per version.

Claude-Session: https://claude.ai/code/session_01BKMAksDxdePWPW4kgr9KpM

* 📝 docs(split-micro-app): 鳥居番 Deploys page has Releases and Previews tabs

Claude-Session: https://claude.ai/code/session_01BKMAksDxdePWPW4kgr9KpM

* 📝 docs(split-micro-app): releases and previews live on the target's Worker card

Claude-Session: https://claude.ai/code/session_01BKMAksDxdePWPW4kgr9KpM

* 📝 docs(split-micro-app): Set override writes the staging config directly

Claude-Session: https://claude.ai/code/session_01BKMAksDxdePWPW4kgr9KpM
2026-09-04 02:53:34 +08:00

41 lines
1.2 KiB
TypeScript

import { execSync } from 'node:child_process';
export interface LocalOperator {
email: string;
sha: string;
}
// Cloudflare stamps every version with the API token's owner, never with the person or
// pipeline behind it, so the operator has to travel in the version's own annotations.
export const workerDeployAnnotationArgs = (
env: NodeJS.ProcessEnv,
local: LocalOperator | undefined,
): string[] => {
if (env.GITHUB_ACTIONS === 'true' && env.GITHUB_SHA) {
const sha = env.GITHUB_SHA.slice(0, 7);
return [
'--tag',
sha,
'--message',
`${env.GITHUB_ACTOR ?? 'actions'} ${env.GITHUB_REPOSITORY ?? ''}@${sha} run ${env.GITHUB_RUN_ID ?? ''}`,
];
}
if (!local) return [];
const sha = local.sha.slice(0, 7);
return ['--tag', sha, '--message', `${local.email} local@${sha}`];
};
const git = (cwd: string, args: string): string | undefined => {
try {
return execSync(`git ${args}`, { cwd, stdio: ['ignore', 'pipe', 'ignore'] }).toString().trim() || undefined;
} catch {
return undefined;
}
};
export const localOperator = (cwd: string): LocalOperator | undefined => {
const email = git(cwd, 'config user.email');
const sha = git(cwd, 'rev-parse HEAD');
return email && sha ? { email, sha } : undefined;
};