@@ -40,11 +40,6 @@ function resetDir(dir: string) {
4040 ensureDir ( dir )
4141}
4242
43- function isPullRequestCI ( ) {
44- // biome-ignore lint/nursery/noProcessEnv: process.env.GITHUB_EVENT_NAME === "pull_request" || !!process.env.GITHUB_HEAD_REF
45- return process . env . GITHUB_EVENT_NAME === "pull_request" || ! ! process . env . GITHUB_HEAD_REF
46- }
47-
4843function repoPath ( ...segments : string [ ] ) {
4944 return path . normalize ( path . join ( ...segments . filter ( Boolean ) ) )
5045}
@@ -136,7 +131,6 @@ function installDependencies(worktreePath: string, docsWorkspace: string) {
136131 run ( `pnpm install ${ lockFlag } ` , { cwd : worktreePath , inherit : true } )
137132 }
138133
139- // Install docs workspace dependencies if different from root
140134 if ( docsWorkspace !== worktreePath ) {
141135 const hasDocsPackage = existsSync ( resolve ( docsWorkspace , "package.json" ) )
142136 const hasDocsLock = existsSync ( resolve ( docsWorkspace , "pnpm-lock.yaml" ) )
@@ -189,66 +183,17 @@ function buildCurrentWorkspace(label: string) {
189183 buildDocs ( CURRENT_WORKSPACE , outDir )
190184}
191185
192- function buildForDevelopment ( ) {
193- // biome-ignore lint/suspicious/noConsole: build logging
194- console . log ( chalk . cyan ( "[dev] Building current workspace → current" ) )
195- buildCurrentWorkspace ( "current" )
196- return [ "current" ]
197- }
198-
199- function buildForPullRequest ( versionsSpec : string ) {
200- const versions : string [ ] = [ ]
201-
202- // biome-ignore lint/suspicious/noConsole: build logging
203- console . log ( chalk . cyan ( "[pr] Building PR workspace → current" ) )
204- buildCurrentWorkspace ( "current" )
205- versions . push ( "current" )
206-
207- // Build additional version tags if requested
208- if ( versionsSpec ) {
209- const tags = resolveTagsFromSpec ( versionsSpec )
210- if ( tags . length === 0 ) {
211- throw new Error ( `No tags matched spec "${ versionsSpec } "` )
212- }
213-
214- // biome-ignore lint/suspicious/noConsole: build logging
215- console . log ( chalk . cyan ( `[pr] Building tags: ${ tags . join ( ", " ) } ` ) )
216- for ( const tag of tags ) {
217- buildFromTag ( tag )
218- }
219- versions . push ( ...tags )
220- }
221-
222- return versions
223- }
224-
225- function buildForProduction ( branch : string , versionsSpec : string ) : string [ ] {
226- // Build specific version tags
227- if ( versionsSpec ) {
228- const tags = resolveTagsFromSpec ( versionsSpec )
229- if ( tags . length === 0 ) {
230- throw new Error ( `No tags matched spec "${ versionsSpec } "` )
231- }
232-
233- // biome-ignore lint/suspicious/noConsole: build logging
234- console . log ( chalk . cyan ( `[ci] Building tags: ${ tags . join ( ", " ) } ` ) )
235- for ( const tag of tags ) {
236- buildFromTag ( tag )
237- }
238- return tags
239- }
240-
241- // Build default branch
186+ function buildMainBranchFallback ( branch : string ) {
242187 const contentPath = repoPath ( WORKSPACE_RELATIVE , CONTENT_DIR )
243188 fetchBranch ( branch )
244189
245190 const hasContent = refHasPath ( `origin/${ branch } ` , contentPath )
246191 if ( ! hasContent ) {
247- throw new Error ( `Branch 'origin/${ branch } ' has no '${ contentPath } '. Use --versions to build tags instead .` )
192+ throw new Error ( `Branch 'origin/${ branch } ' has no '${ contentPath } '. Cannot build docs .` )
248193 }
249194
250195 // biome-ignore lint/suspicious/noConsole: build logging
251- console . log ( chalk . cyan ( `[ci] Building branch '${ branch } ' → ${ branch } ` ) )
196+ console . log ( chalk . cyan ( `Building fallback: branch '${ branch } ' → ${ branch } ` ) )
252197 buildFromBranch ( branch , branch )
253198 return [ branch ]
254199}
@@ -288,15 +233,40 @@ export const versions = ${JSON.stringify(versions, null, 2)} as const
288233
289234async function main ( ) {
290235 const { branch, versions : versionsSpec } = parseCliArgs ( )
291-
292236 let builtVersions : string [ ]
293237
294238 if ( APP_ENV === "development" ) {
295- builtVersions = buildForDevelopment ( )
296- } else if ( isPullRequestCI ( ) ) {
297- builtVersions = buildForPullRequest ( versionsSpec )
239+ // Development: always build current workspace
240+ // biome-ignore lint/suspicious/noConsole: build logging
241+ console . log ( chalk . cyan ( "[dev] Building current workspace → current" ) )
242+ buildCurrentWorkspace ( "current" )
243+ builtVersions = [ "current" ]
298244 } else {
299- builtVersions = buildForProduction ( branch , versionsSpec )
245+ // Production
246+ if ( versionsSpec ) {
247+ // Try to build from version tags
248+ const tags = resolveTagsFromSpec ( versionsSpec )
249+
250+ if ( tags . length > 0 ) {
251+ // Build all matching tags
252+ // biome-ignore lint/suspicious/noConsole: build logging
253+ console . log ( chalk . cyan ( `[prod] Building tags: ${ tags . join ( ", " ) } ` ) )
254+ for ( const tag of tags ) {
255+ buildFromTag ( tag )
256+ }
257+ builtVersions = tags
258+ } else {
259+ // No tags matched → fallback to main branch
260+ // biome-ignore lint/suspicious/noConsole: build logging
261+ console . log ( chalk . yellow ( `[prod] No tags matched "${ versionsSpec } ", falling back to branch` ) )
262+ builtVersions = buildMainBranchFallback ( branch )
263+ }
264+ } else {
265+ // No versions specified → build main branch
266+ // biome-ignore lint/suspicious/noConsole: build logging
267+ console . log ( chalk . cyan ( `[prod] No versions specified, building branch '${ branch } '` ) )
268+ builtVersions = buildMainBranchFallback ( branch )
269+ }
300270 }
301271
302272 writeVersionsFile ( builtVersions )
0 commit comments