@stacksjs/buddy 0.75.632 → 0.75.634

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- import{existsSync,readFileSync}from"node:fs";import{join}from"node:path";import{projectWorkflowClient}from"../workflow-client";import{loadWorkflowConfig,runWorkflowStep,writeProjectWorkflow,writeWorkflowReleaseState}from"../workflow-project";export function workflow(buddy){buddy.command("workflow:setup","Generate the normal Stacks workflow from config/workflows.ts").option("--force","Replace a reviewed existing custom workflow",{default:false}).option("--check","Verify committed workflow bytes without changing them",{default:false}).action(async(options)=>{const root=process.cwd();const config=await loadWorkflowConfig(root);if(options.check){const{renderReviewOsWorkflow}=await import("../workflow-template");const file=join(root,".reviewos/workflows/ci.yml");if(!existsSync(file)||readFileSync(file,"utf8")!==renderReviewOsWorkflow(config))throw new Error("Regenerate the workflow with buddy workflow:setup")}else console.log(writeProjectWorkflow(root,config,options.force))});buddy.command("workflow:step <step>","Run one declared application step through Stacks").action(async(step)=>{await runWorkflowStep(process.cwd(),step)});buddy.command("workflow:release-state","Verify the committed release identity and set its upload output").action(async()=>{await writeWorkflowReleaseState(process.cwd())});buddy.command("workflow:runs [file]","Read the exact-source workflow run history").option("--sha <sha>","Filter by the full source commit").action(async(file,options)=>{const config=await loadWorkflowConfig(process.cwd());console.log(JSON.stringify(await projectWorkflowClient(config).runs(file??"ci.yml",{branch:config.branch??"main",sha:options.sha})))});buddy.command("workflow:show <number>","Read actual workflow job and step execution").action(async(number)=>{console.log(JSON.stringify(await projectWorkflowClient(await loadWorkflowConfig(process.cwd())).run(Number(number))))});buddy.command("workflow:run [file]","Start a configured workflow using its normal API").option("--ref <ref>","Source branch or revision").option("--inputs <json>","Workflow input values as JSON, without credentials").action(async(file,options)=>{const config=await loadWorkflowConfig(process.cwd());const inputs=options.inputs?JSON.parse(options.inputs):{};console.log(JSON.stringify(await projectWorkflowClient(config).dispatch(file??"ci.yml",options.ref??config.branch??"main",inputs)))});buddy.command("workflow:artifacts <number>","Read retained artifact identities and digests").action(async(number)=>{console.log(JSON.stringify(await projectWorkflowClient(await loadWorkflowConfig(process.cwd())).artifacts(Number(number))))})}
1
+ import{print}from"@stacksjs/cli/output";import{existsSync,readFileSync}from"node:fs";import{join}from"node:path";import{projectWorkflowClient}from"../workflow-client";import{checkNativeWorkflowCredentials,loadWorkflowConfig,runWorkflowStep,writeProjectWorkflow,writeWorkflowReleaseState}from"../workflow-project";export function workflow(buddy){buddy.command("workflow:setup","Generate the normal Stacks workflow from config/workflows.ts").option("--force","Replace a reviewed existing custom workflow",{default:false}).option("--check","Verify committed workflow bytes without changing them",{default:false}).action(async(options)=>{const root=process.cwd();const config=await loadWorkflowConfig(root);if(options.check){const{renderReviewOsWorkflow}=await import("../workflow-template");const file=join(root,".reviewos/workflows/ci.yml");if(!existsSync(file)||readFileSync(file,"utf8")!==renderReviewOsWorkflow(config))throw new Error("Regenerate the workflow with buddy workflow:setup")}else console.log(writeProjectWorkflow(root,config,options.force))});buddy.command("workflow:step <step>","Run one declared application step through Stacks").action(async(step)=>{await runWorkflowStep(process.cwd(),step)});buddy.command("workflow:check-credentials <phase>","Check native-accept or native-release inputs without printing credentials").action(async(phase)=>{await checkNativeWorkflowCredentials(process.cwd(),phase);print(`Workflow ${phase} credentials are configured.`)});buddy.command("workflow:release-state","Verify the committed release identity and set its upload output").action(async()=>{await writeWorkflowReleaseState(process.cwd())});buddy.command("workflow:runs [file]","Read the exact-source workflow run history").option("--sha <sha>","Filter by the full source commit").action(async(file,options)=>{const config=await loadWorkflowConfig(process.cwd());console.log(JSON.stringify(await projectWorkflowClient(config).runs(file??"ci.yml",{branch:config.branch??"main",sha:options.sha})))});buddy.command("workflow:show <number>","Read actual workflow job and step execution").action(async(number)=>{console.log(JSON.stringify(await projectWorkflowClient(await loadWorkflowConfig(process.cwd())).run(Number(number))))});buddy.command("workflow:run [file]","Start a configured workflow using its normal API").option("--ref <ref>","Source branch or revision").option("--inputs <json>","Workflow input values as JSON, without credentials").action(async(file,options)=>{const config=await loadWorkflowConfig(process.cwd());const inputs=options.inputs?JSON.parse(options.inputs):{};console.log(JSON.stringify(await projectWorkflowClient(config).dispatch(file??"ci.yml",options.ref??config.branch??"main",inputs)))});buddy.command("workflow:artifacts <number>","Read retained artifact identities and digests").action(async(number)=>{console.log(JSON.stringify(await projectWorkflowClient(await loadWorkflowConfig(process.cwd())).artifacts(Number(number))))})}
@@ -1,5 +1,7 @@
1
1
  import type { WorkflowConfig, WorkflowStep } from '@stacksjs/types';
2
2
  export declare function loadWorkflowConfig(root: string): Promise<WorkflowConfig>;
3
+ /** Check scoped inputs before expensive native builds, without revealing values. */
4
+ export declare function checkNativeWorkflowCredentials(root: string, phase: string, env?: Record<string, string | undefined>): Promise<void>;
3
5
  export declare function workflowReleaseIdentity(root: string, config: NonNullable<WorkflowConfig['release']>): { version: string, build: number, tag: string };
4
6
  export declare function writeProjectWorkflow(root: string, config: WorkflowConfig, force?: boolean): string;
5
7
  /** Execute argv directly; an artifact path or a title is never shell code. */
@@ -1,2 +1,2 @@
1
- import{execFileSync}from"node:child_process";import{appendFileSync,existsSync,lstatSync,mkdirSync,readFileSync,realpathSync,writeFileSync}from"node:fs";import{dirname,isAbsolute,join,relative,resolve,sep}from"node:path";import{pathToFileURL}from"node:url";import{renderReviewOsWorkflow,validateWorkflowConfig}from"./workflow-template";export async function loadWorkflowConfig(root){const file=join(root,"config/workflows.ts");if(!existsSync(file))throw new Error("Configure config/workflows.ts before running a workflow");const config=(await import(pathToFileURL(file).href)).default;validateWorkflowConfig(config);return config}function ownedFile(root,file){const path=resolve(root,file);const child=relative(realpathSync(root),realpathSync(path));if(!child||isAbsolute(child)||child===".."||child.startsWith(`..${sep}`)||lstatSync(path).isSymbolicLink()||!lstatSync(path).isFile())throw new Error("Workflow inputs must be regular files inside the project");return path}export function workflowReleaseIdentity(root,config){const manifest=JSON.parse(readFileSync(ownedFile(root,config.versionFile),"utf8"));const version=manifest[config.versionField??"version"];const build=manifest[config.buildField??"build"];if(typeof version!=="string"||!/^\d+\.\d+\.\d+$/.test(version)||!Number.isSafeInteger(build)||build<=0)throw new Error("The release manifest needs a semantic version and a positive integer build");return{version,build,tag:`v${version}-build.${build}`}}export function writeProjectWorkflow(root,config,force=false){const file=join(root,".reviewos/workflows/ci.yml");const source=renderReviewOsWorkflow(config);if(existsSync(file)&&!readFileSync(file,"utf8").startsWith("# Generated by buddy workflow:setup")&&!force)throw new Error("The workflow already exists. Review it before replacing it with --force");mkdirSync(dirname(file),{recursive:true});writeFileSync(file,source);return file}function downloadedArtifact(root,config){if(!config.native)throw new Error("Configure the native artifact before acceptance");const directory=resolve(root,config.native.downloadDirectory);const files=[...new Bun.Glob(config.native.archivePattern).scanSync({cwd:directory,absolute:true,onlyFiles:true,followSymlinks:false})];if(files.length!==1)throw new Error("Native acceptance needs exactly one downloaded application archive");return ownedFile(root,files[0])}export async function runWorkflowStep(root,step){const config=await loadWorkflowConfig(root);if(!["prepare","lint","typecheck","test","build","deploy","after-deploy","native-build","native-accept","native-sign","native-upload","native-verify","native-cleanup"].includes(step))throw new Error("Unknown workflow step");const defaults={prepare:existsSync(join(root,"pantry.lock"))?[["pantry","ci"]]:[],lint:[["./buddy","lint"]],typecheck:[["./buddy","typecheck"]],test:[["./buddy","test"]],build:[[process.execPath,"run","build"]],deploy:[["./buddy","deploy","--prod","--yes"]]};const commands=config.commands?.[step]??defaults[step];if(!commands&&!(step==="native-cleanup"&&!config.release))throw new Error(`Configure the ${step} workflow command`);for(const command of commands??[]){const argv=command.map((value)=>value==="{artifact}"?downloadedArtifact(root,config):value);const child=Bun.spawn(argv,{cwd:root,env:process.env,stdout:"inherit",stderr:"inherit",stdin:"ignore"});const code=await child.exited;if(code!==0)throw new Error(`The ${step} workflow command exited ${code}`)}}export async function writeWorkflowReleaseState(root){const config=await loadWorkflowConfig(root);const git=(...args)=>execFileSync("git",args,{cwd:root,encoding:"utf8"}).trim();const requested=process.env.WORKFLOW_UPLOAD_REQUESTED==="true";const release=git("log","-1","--format=%s").startsWith("chore(release): v");let upload=false;if(requested||release){if(!config.release)throw new Error("Configure release metadata before uploading");const identity=workflowReleaseIdentity(root,config.release);const branch=config.branch??"main";const main=process.env.GITHUB_REF?process.env.GITHUB_REF===`refs/heads/${branch}`:git("branch","--show-current")===branch;let tagged=false;try{tagged=git("rev-parse","--verify","--quiet",`${identity.tag}^{commit}`)===git("rev-parse","HEAD")}catch{}if(!main||!tagged)throw new Error("An upload needs its actual release tag on the configured main branch");if(git("status","--porcelain","--untracked-files=no"))throw new Error("An upload needs the unchanged release checkout");upload=true}if(!process.env.GITHUB_OUTPUT)throw new Error("The workflow must provide its step output file");appendFileSync(process.env.GITHUB_OUTPUT,`upload=${upload}
1
+ import{execFileSync}from"node:child_process";import{appendFileSync,existsSync,lstatSync,mkdirSync,readFileSync,realpathSync,writeFileSync}from"node:fs";import{dirname,isAbsolute,join,relative,resolve,sep}from"node:path";import{pathToFileURL}from"node:url";import{nativeReleaseSecretNames,nativeWorkflowSecretNames,renderReviewOsWorkflow,validateWorkflowConfig}from"./workflow-template";export async function loadWorkflowConfig(root){const file=join(root,"config/workflows.ts");if(!existsSync(file))throw new Error("Configure config/workflows.ts before running a workflow");const config=(await import(pathToFileURL(file).href)).default;validateWorkflowConfig(config);return config}function requireWorkflowSecrets(names,phase,env){const missing=[...new Set(names)].filter((name)=>!env[name]?.trim());if(missing.length)throw new Error(`Missing workflow credentials for ${phase}: ${missing.join(", ")}. Configure these names in the ios-testflight environment. Values are never printed.`)}export async function checkNativeWorkflowCredentials(root,phase,env=process.env){if(!["native-accept","native-release"].includes(phase))throw new Error("Choose native-accept or native-release credentials");const config=await loadWorkflowConfig(root);if(!config.native)throw new Error("Configure a native workflow before checking its credentials");if(phase==="native-release"&&!config.release)throw new Error("Configure native release metadata before checking release credentials");requireWorkflowSecrets(phase==="native-release"?nativeReleaseSecretNames(config):nativeWorkflowSecretNames(config,"native-accept"),phase,env)}function ownedFile(root,file){const path=resolve(root,file);const child=relative(realpathSync(root),realpathSync(path));if(!child||isAbsolute(child)||child===".."||child.startsWith(`..${sep}`)||lstatSync(path).isSymbolicLink()||!lstatSync(path).isFile())throw new Error("Workflow inputs must be regular files inside the project");return path}export function workflowReleaseIdentity(root,config){const manifest=JSON.parse(readFileSync(ownedFile(root,config.versionFile),"utf8"));const version=manifest[config.versionField??"version"];const build=manifest[config.buildField??"build"];if(typeof version!=="string"||!/^\d+\.\d+\.\d+$/.test(version)||!Number.isSafeInteger(build)||build<=0)throw new Error("The release manifest needs a semantic version and a positive integer build");return{version,build,tag:`v${version}-build.${build}`}}export function writeProjectWorkflow(root,config,force=false){const file=join(root,".reviewos/workflows/ci.yml");const source=renderReviewOsWorkflow(config);if(existsSync(file)&&!readFileSync(file,"utf8").startsWith("# Generated by buddy workflow:setup")&&!force)throw new Error("The workflow already exists. Review it before replacing it with --force");mkdirSync(dirname(file),{recursive:true});writeFileSync(file,source);return file}function downloadedArtifact(root,config){if(!config.native)throw new Error("Configure the native artifact before acceptance");const directory=resolve(root,config.native.downloadDirectory);const files=[...new Bun.Glob(config.native.archivePattern).scanSync({cwd:directory,absolute:true,onlyFiles:true,followSymlinks:false})];if(files.length!==1)throw new Error("Native acceptance needs exactly one downloaded application archive");return ownedFile(root,files[0])}export async function runWorkflowStep(root,step){const config=await loadWorkflowConfig(root);if(!["prepare","lint","typecheck","test","build","deploy","after-deploy","native-build","native-accept","native-sign","native-upload","native-verify","native-cleanup"].includes(step))throw new Error("Unknown workflow step");requireWorkflowSecrets(nativeWorkflowSecretNames(config,step),step,process.env);const defaults={prepare:existsSync(join(root,"pantry.lock"))?[["pantry","ci"]]:[],lint:[["./buddy","lint"]],typecheck:[["./buddy","typecheck"]],test:[["./buddy","test"]],build:[[process.execPath,"run","build"]],deploy:[["./buddy","deploy","--prod","--yes"]]};const commands=config.commands?.[step]??defaults[step];if(!commands&&!(step==="native-cleanup"&&!config.release))throw new Error(`Configure the ${step} workflow command`);for(const command of commands??[]){const argv=command.map((value)=>value==="{artifact}"?downloadedArtifact(root,config):value);const child=Bun.spawn(argv,{cwd:root,env:process.env,stdout:"inherit",stderr:"inherit",stdin:"ignore"});const code=await child.exited;if(code!==0)throw new Error(`The ${step} workflow command exited ${code}`)}}export async function writeWorkflowReleaseState(root){const config=await loadWorkflowConfig(root);const git=(...args)=>execFileSync("git",args,{cwd:root,encoding:"utf8"}).trim();const requested=process.env.WORKFLOW_UPLOAD_REQUESTED==="true";const release=git("log","-1","--format=%s").startsWith("chore(release): v");let upload=false;if(requested||release){if(!config.release)throw new Error("Configure release metadata before uploading");const identity=workflowReleaseIdentity(root,config.release);const branch=config.branch??"main";const main=process.env.GITHUB_REF?process.env.GITHUB_REF===`refs/heads/${branch}`:git("branch","--show-current")===branch;let tagged=false;try{tagged=git("rev-parse","--verify","--quiet",`${identity.tag}^{commit}`)===git("rev-parse","HEAD")}catch{}if(!main||!tagged)throw new Error("An upload needs its actual release tag on the configured main branch");if(git("status","--porcelain","--untracked-files=no"))throw new Error("An upload needs the unchanged release checkout");upload=true}if(!process.env.GITHUB_OUTPUT)throw new Error("The workflow must provide its step output file");appendFileSync(process.env.GITHUB_OUTPUT,`upload=${upload}
2
2
  `);return upload}
@@ -1,4 +1,6 @@
1
- import type { WorkflowConfig } from '@stacksjs/types';
1
+ import type { WorkflowConfig, WorkflowStep } from '@stacksjs/types';
2
+ export declare function nativeWorkflowSecretNames(config: WorkflowConfig, step: WorkflowStep): string[];
3
+ export declare function nativeReleaseSecretNames(config: WorkflowConfig): string[];
2
4
  export declare function validateWorkflowConfig(config: WorkflowConfig): void;
3
5
  /** A single ordered pipeline keeps deployment fixed for its native acceptance. */
4
6
  export declare function renderReviewOsWorkflow(config: WorkflowConfig): string;
@@ -1,4 +1,4 @@
1
- function relativePath(value){return typeof value==="string"&&!!value&&!/^[A-Za-z]:|^[\\/]|[\\\r\n\x00]/.test(value)&&!value.split("/").some((segment)=>segment==="."||segment==="..")}export function validateWorkflowConfig(config){const origin=new URL(config.origin);if(config.provider!=="reviewos"||origin.protocol!=="https:"||origin.username||origin.password||origin.pathname!=="/"||origin.search||origin.hash||!/^[\w.-]+\/[\w.-]+$/.test(config.repository)||config.repository.split("/").some((part)=>part==="."||part===".."))throw new Error("Configure a canonical ReviewOS origin and owner/repository");for(const group of["checks",...config.deploy?["deploy"]:[],...config.native?["ios"]:[]]){const labels=config.runners[group];if(!Array.isArray(labels)||!labels.includes("self-hosted")||labels.some((label)=>!/^[\w.-]+$/.test(label)))throw new Error(`Declare the owned ${group} runner labels`)}if(config.priorities!==undefined&&(!config.priorities||typeof config.priorities!=="object"||Array.isArray(config.priorities)||Object.entries(config.priorities).some(([stage,value])=>!["checks","deploy","ios"].includes(stage)||!Number.isInteger(value)||value<-1000||value>1000)))throw new Error("Workflow priorities must name checks, deploy or ios with integer values from -1000 to 1000");for(const values of Object.values(config.env??{})){if(!values||typeof values!=="object"||Array.isArray(values)||Object.entries(values).some(([name,value])=>!/^[A-Z_][A-Z0-9_]*$/.test(name)||typeof value!=="string"||value.includes("\x00")))throw new Error("Workflow environment settings must be named string values")}for(const names of Object.values(config.secrets??{})){if(!Array.isArray(names)||names.some((name)=>!/^[A-Z_][A-Z0-9_]*$/.test(name)))throw new Error("Workflow secrets must be environment variable names")}for(const[step,names]of Object.entries(config.stepSecrets??{})){if(!["native-build","native-accept","native-sign","native-upload","native-verify","native-cleanup"].includes(step)||!Array.isArray(names)||names.some((name)=>!config.secrets?.ios?.includes(name)))throw new Error("Step credentials must name declared native secrets")}if(config.native&&(!config.native.artifacts.length||![...config.native.artifacts,config.native.downloadDirectory,config.native.archivePattern,...config.native.evidence??[],...config.native.releaseArtifacts??[]].every(relativePath)))throw new Error("Native artifacts must stay inside the workspace");if(config.deploy&&!config.commands?.["after-deploy"]?.length)throw new Error("Configure deployed application verification");if(config.native&&["native-build","native-accept"].some((step)=>!config.commands?.[step]?.length))throw new Error("Configure native build and downloaded acceptance commands");if(config.release&&(!config.native||["native-sign","native-upload","native-verify","native-cleanup"].some((step)=>!config.commands?.[step]?.length)))throw new Error("Configure native signing, upload, verification and cleanup before releasing");if(config.release&&(!relativePath(config.release.versionFile)||config.release.notesDirectory!==undefined&&!relativePath(config.release.notesDirectory)||config.release.locales?.some((locale)=>!/^[a-z]{2}(?:-[A-Z]{2})?$/.test(locale))))throw new Error("Release files and locales must stay inside the workspace");for(const commands of Object.values(config.commands??{})){if(!Array.isArray(commands)||commands.some((argv)=>!Array.isArray(argv)||!argv.length||argv.some((arg)=>typeof arg!=="string"||arg.includes("\x00"))))throw new Error("Workflow commands must be nonempty argv arrays")}}export function renderReviewOsWorkflow(config){validateWorkflowConfig(config);const branch=config.branch??"main";if(!/^[\w./-]+$/.test(branch)||branch.includes(".."))throw new Error("Configure a branch name");const main=`github.ref == 'refs/heads/${branch}' && github.event_name != 'pull_request'`;const upload="steps.release.outputs.upload == 'true'";const secretEnv=(group)=>Object.fromEntries((config.secrets?.[group]??[]).map((name)=>[name,"${{ secrets."+name+" }}"]));const nativeSecrets=(step)=>{const names=config.stepSecrets?.[step]??(step==="native-sign"?config.secrets?.ios??[]:[]);return names.length?{env:Object.fromEntries(names.map((name)=>[name,"${{ secrets."+name+" }}"]))}:{}};const bootstrap=()=>[{name:"Checkout the exact source",uses:"actions/checkout@11d5960a326750d5838078e36cf38b85af677262",with:{"fetch-depth":0,"persist-credentials":false}},{name:"Set up the pinned tools",uses:"pantry-pm/pantry/packages/action@624cd6674f8c5c2d4e4204c11ece62a00d7fac0a",with:{version:config.pantry??"0.11.199",install:"false",packages:`bun.sh@${config.bun??"1.4.4"}`}},{name:"Install the frozen application dependencies",run:"bun install --frozen-lockfile"},{name:"Prepare declared application inputs",run:"./buddy workflow:step prepare"}];const jobPriority=(stage)=>{const value=config.priorities?.[stage];return value===undefined?{}:{priority:value}};const jobs={};for(const name of["lint","typecheck","test","build"])jobs[name]={"runs-on":config.runners.checks,"timeout-minutes":name==="test"?90:30,reviewos:{...jobPriority("checks"),secrets:config.secrets?.checks??[]},env:{...config.env?.checks,...secretEnv("checks")},steps:[...bootstrap(),{name:`Run ${name}`,run:`./buddy workflow:step ${name}`}]};if(config.deploy)jobs.deploy={needs:["lint","typecheck","test","build"],if:main,"runs-on":config.runners.deploy,"timeout-minutes":60,environment:"production",reviewos:{...jobPriority("deploy"),secrets:[...config.secrets?.checks??[],...config.secrets?.deploy??[]]},env:{...config.env?.checks,...config.env?.deploy,...secretEnv("checks"),...secretEnv("deploy")},steps:[...bootstrap(),{name:"Deploy the qualified source",run:"./buddy workflow:step deploy"},{name:"Verify the deployed application",run:"./buddy workflow:step after-deploy"}]};if(config.native)jobs.native={needs:config.deploy?["deploy"]:["lint","typecheck","test","build"],if:main,"runs-on":config.runners.ios,"timeout-minutes":90,environment:"ios-testflight",reviewos:{...jobPriority("ios"),secrets:[...config.secrets?.checks??[],...config.secrets?.ios??[]]},env:{...config.env?.checks,...config.env?.ios,...secretEnv("checks")},steps:[...bootstrap(),{name:"Read the committed release identity",id:"release",run:"./buddy workflow:release-state",env:{WORKFLOW_UPLOAD_REQUESTED:"${{ inputs.upload && 'true' || 'false' }}"}},{name:"Build the simulator application",run:"./buddy workflow:step native-build",...nativeSecrets("native-build")},{name:"Publish the simulator application",uses:"actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02",with:{name:"native-simulator-${{ github.run_id }}-${{ github.run_attempt }}",path:config.native.artifacts.join(`
1
+ export function nativeWorkflowSecretNames(config,step){switch(step){case"native-build":case"native-accept":case"native-sign":case"native-upload":case"native-verify":case"native-cleanup":return config.stepSecrets?.[step]??(step==="native-sign"?config.secrets?.ios??[]:[]);default:return[]}}export function nativeReleaseSecretNames(config){return[...new Set(["native-sign","native-upload","native-verify","native-cleanup"].flatMap((step)=>nativeWorkflowSecretNames(config,step)))]}function relativePath(value){return typeof value==="string"&&!!value&&!/^[A-Za-z]:|^[\\/]|[\\\r\n\x00]/.test(value)&&!value.split("/").some((segment)=>segment==="."||segment==="..")}export function validateWorkflowConfig(config){const origin=new URL(config.origin);if(config.provider!=="reviewos"||origin.protocol!=="https:"||origin.username||origin.password||origin.pathname!=="/"||origin.search||origin.hash||!/^[\w.-]+\/[\w.-]+$/.test(config.repository)||config.repository.split("/").some((part)=>part==="."||part===".."))throw new Error("Configure a canonical ReviewOS origin and owner/repository");for(const group of["checks",...config.deploy?["deploy"]:[],...config.native?["ios"]:[]]){const labels=config.runners[group];if(!Array.isArray(labels)||!labels.includes("self-hosted")||labels.some((label)=>!/^[\w.-]+$/.test(label)))throw new Error(`Declare the owned ${group} runner labels`)}if(config.priorities!==undefined&&(!config.priorities||typeof config.priorities!=="object"||Array.isArray(config.priorities)||Object.entries(config.priorities).some(([stage,value])=>!["checks","deploy","ios"].includes(stage)||!Number.isInteger(value)||value<-1000||value>1000)))throw new Error("Workflow priorities must name checks, deploy or ios with integer values from -1000 to 1000");for(const values of Object.values(config.env??{})){if(!values||typeof values!=="object"||Array.isArray(values)||Object.entries(values).some(([name,value])=>!/^[A-Z_][A-Z0-9_]*$/.test(name)||typeof value!=="string"||value.includes("\x00")))throw new Error("Workflow environment settings must be named string values")}for(const names of Object.values(config.secrets??{})){if(!Array.isArray(names)||names.some((name)=>!/^[A-Z_][A-Z0-9_]*$/.test(name)))throw new Error("Workflow secrets must be environment variable names")}for(const[step,names]of Object.entries(config.stepSecrets??{})){if(!["native-build","native-accept","native-sign","native-upload","native-verify","native-cleanup"].includes(step)||!Array.isArray(names)||names.some((name)=>!config.secrets?.ios?.includes(name)))throw new Error("Step credentials must name declared native secrets")}if(config.native&&(!config.native.artifacts.length||![...config.native.artifacts,config.native.downloadDirectory,config.native.archivePattern,...config.native.evidence??[],...config.native.releaseArtifacts??[]].every(relativePath)))throw new Error("Native artifacts must stay inside the workspace");if(config.deploy&&!config.commands?.["after-deploy"]?.length)throw new Error("Configure deployed application verification");if(config.native&&["native-build","native-accept"].some((step)=>!config.commands?.[step]?.length))throw new Error("Configure native build and downloaded acceptance commands");if(config.release&&(!config.native||["native-sign","native-upload","native-verify","native-cleanup"].some((step)=>!config.commands?.[step]?.length)))throw new Error("Configure native signing, upload, verification and cleanup before releasing");if(config.release&&(!relativePath(config.release.versionFile)||config.release.notesDirectory!==undefined&&!relativePath(config.release.notesDirectory)||config.release.locales?.some((locale)=>!/^[a-z]{2}(?:-[A-Z]{2})?$/.test(locale))))throw new Error("Release files and locales must stay inside the workspace");for(const commands of Object.values(config.commands??{})){if(!Array.isArray(commands)||commands.some((argv)=>!Array.isArray(argv)||!argv.length||argv.some((arg)=>typeof arg!=="string"||arg.includes("\x00"))))throw new Error("Workflow commands must be nonempty argv arrays")}}export function renderReviewOsWorkflow(config){validateWorkflowConfig(config);const branch=config.branch??"main";if(!/^[\w./-]+$/.test(branch)||branch.includes(".."))throw new Error("Configure a branch name");const main=`github.ref == 'refs/heads/${branch}' && github.event_name != 'pull_request'`;const upload="steps.release.outputs.upload == 'true'";const secretEnv=(group)=>Object.fromEntries((config.secrets?.[group]??[]).map((name)=>[name,"${{ secrets."+name+" }}"]));const nativeSecrets=(step)=>{const names=nativeWorkflowSecretNames(config,step);return names.length?{env:Object.fromEntries(names.map((name)=>[name,"${{ secrets."+name+" }}"]))}:{}};const bootstrap=()=>[{name:"Checkout the exact source",uses:"actions/checkout@11d5960a326750d5838078e36cf38b85af677262",with:{"fetch-depth":0,"persist-credentials":false}},{name:"Set up the pinned tools",uses:"pantry-pm/pantry/packages/action@624cd6674f8c5c2d4e4204c11ece62a00d7fac0a",with:{version:config.pantry??"0.11.199",install:"false",packages:`bun.sh@${config.bun??"1.4.4"}`}},{name:"Install the frozen application dependencies",run:"bun install --frozen-lockfile"},{name:"Prepare declared application inputs",run:"./buddy workflow:step prepare"}];const jobPriority=(stage)=>{const value=config.priorities?.[stage];return value===undefined?{}:{priority:value}};const jobs={};for(const name of["lint","typecheck","test","build"])jobs[name]={"runs-on":config.runners.checks,"timeout-minutes":name==="test"?90:30,reviewos:{...jobPriority("checks"),secrets:config.secrets?.checks??[]},env:{...config.env?.checks,...secretEnv("checks")},steps:[...bootstrap(),{name:`Run ${name}`,run:`./buddy workflow:step ${name}`}]};if(config.deploy)jobs.deploy={needs:["lint","typecheck","test","build"],if:main,"runs-on":config.runners.deploy,"timeout-minutes":60,environment:"production",reviewos:{...jobPriority("deploy"),secrets:[...config.secrets?.checks??[],...config.secrets?.deploy??[]]},env:{...config.env?.checks,...config.env?.deploy,...secretEnv("checks"),...secretEnv("deploy")},steps:[...bootstrap(),{name:"Deploy the qualified source",run:"./buddy workflow:step deploy"},{name:"Verify the deployed application",run:"./buddy workflow:step after-deploy"}]};if(config.native)jobs.native={needs:config.deploy?["deploy"]:["lint","typecheck","test","build"],if:main,"runs-on":config.runners.ios,"timeout-minutes":90,environment:"ios-testflight",reviewos:{...jobPriority("ios"),secrets:[...config.secrets?.checks??[],...config.secrets?.ios??[]]},env:{...config.env?.checks,...config.env?.ios,...secretEnv("checks")},steps:[...bootstrap(),{name:"Read the committed release identity",id:"release",run:"./buddy workflow:release-state",env:{WORKFLOW_UPLOAD_REQUESTED:"${{ inputs.upload && 'true' || 'false' }}"}},{name:"Validate native acceptance credentials",run:"./buddy workflow:check-credentials native-accept",...nativeSecrets("native-accept")},...config.release?[{name:"Validate release credentials",if:upload,run:"./buddy workflow:check-credentials native-release",...nativeReleaseSecretNames(config).length?{env:Object.fromEntries(nativeReleaseSecretNames(config).map((name)=>[name,"${{ secrets."+name+" }}"]))}:{}}]:[],{name:"Build the simulator application",run:"./buddy workflow:step native-build",...nativeSecrets("native-build")},{name:"Publish the simulator application",uses:"actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02",with:{name:"native-simulator-${{ github.run_id }}-${{ github.run_attempt }}",path:config.native.artifacts.join(`
2
2
  `),"if-no-files-found":"error","retention-days":7}},{name:"Download the published application",uses:"actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093",with:{name:"native-simulator-${{ github.run_id }}-${{ github.run_attempt }}",path:config.native.downloadDirectory}},{name:"Accept the downloaded application",run:"./buddy workflow:step native-accept",...nativeSecrets("native-accept")},{name:"Prepare temporary signing material",if:upload,run:"./buddy workflow:step native-sign",...nativeSecrets("native-sign")},{name:"Upload the accepted application",if:upload,run:"./buddy workflow:step native-upload",...nativeSecrets("native-upload")},{name:"Verify tester availability",if:upload,run:"./buddy workflow:step native-verify",...nativeSecrets("native-verify")},{name:"Remove temporary signing material",if:"always()",run:"./buddy workflow:step native-cleanup",...nativeSecrets("native-cleanup")},...[...config.native.evidence??[],...config.native.releaseArtifacts??[]].length?[{name:"Preserve acceptance and release receipts",if:"always()",uses:"actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02",with:{name:"native-evidence-${{ github.run_id }}-${{ github.run_attempt }}",path:[...config.native.evidence??[],...config.native.releaseArtifacts??[]].join(`
3
3
  `),"if-no-files-found":"warn","retention-days":7}}]:[]]};return`# Generated by buddy workflow:setup from config/workflows.ts.
4
4
  `+Bun.YAML.stringify({name:"CI",on:{push:{branches:[branch]},pull_request:{branches:[branch]},workflow_dispatch:{inputs:{upload:{type:"boolean",default:false,description:"Upload a committed release after native acceptance"}}}},concurrency:{group:"stacks-app-${{ github.ref }}","cancel-in-progress":`\${{ github.ref != 'refs/heads/${branch}' }}`},permissions:{contents:"read"},jobs},null,2)}
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@stacksjs/buddy",
3
3
  "type": "module",
4
4
  "sideEffects": false,
5
- "version": "0.75.632",
5
+ "version": "0.75.634",
6
6
  "description": "Meet Buddy. The Stacks runtime.",
7
7
  "author": "Chris Breuer",
8
8
  "contributors": [
@@ -95,71 +95,71 @@
95
95
  "prepublishOnly": "bun run build"
96
96
  },
97
97
  "dependencies": {
98
- "@stacksjs/actions": "0.75.632",
99
- "@stacksjs/docs": "0.75.632",
100
- "@stacksjs/ai": "0.75.632",
101
- "@stacksjs/alias": "0.75.632",
102
- "@stacksjs/analytics": "0.75.632",
103
- "@stacksjs/api": "0.75.632",
104
- "@stacksjs/arrays": "0.75.632",
105
- "@stacksjs/auth": "0.75.632",
106
- "@stacksjs/browser-extension": "0.75.632",
107
- "@stacksjs/build": "0.75.632",
98
+ "@stacksjs/actions": "0.75.634",
99
+ "@stacksjs/docs": "0.75.634",
100
+ "@stacksjs/ai": "0.75.634",
101
+ "@stacksjs/alias": "0.75.634",
102
+ "@stacksjs/analytics": "0.75.634",
103
+ "@stacksjs/api": "0.75.634",
104
+ "@stacksjs/arrays": "0.75.634",
105
+ "@stacksjs/auth": "0.75.634",
106
+ "@stacksjs/browser-extension": "0.75.634",
107
+ "@stacksjs/build": "0.75.634",
108
108
  "@stacksjs/bumpx": "^0.2.32",
109
- "@stacksjs/cache": "0.75.632",
110
- "@stacksjs/chat": "0.75.632",
109
+ "@stacksjs/cache": "0.75.634",
110
+ "@stacksjs/chat": "0.75.634",
111
111
  "@stacksjs/clapp": "^0.2.17",
112
- "@stacksjs/cli": "0.75.632",
113
- "@stacksjs/cloud": "0.75.632",
114
- "@stacksjs/cms": "0.75.632",
115
- "@stacksjs/collections": "0.75.632",
116
- "@stacksjs/commerce": "0.75.632",
117
- "@stacksjs/config": "0.75.632",
118
- "@stacksjs/database": "0.75.632",
119
- "@stacksjs/desktop-build": "0.75.632",
120
- "@stacksjs/dns": "0.75.632",
112
+ "@stacksjs/cli": "0.75.634",
113
+ "@stacksjs/cloud": "0.75.634",
114
+ "@stacksjs/cms": "0.75.634",
115
+ "@stacksjs/collections": "0.75.634",
116
+ "@stacksjs/commerce": "0.75.634",
117
+ "@stacksjs/config": "0.75.634",
118
+ "@stacksjs/database": "0.75.634",
119
+ "@stacksjs/desktop-build": "0.75.634",
120
+ "@stacksjs/dns": "0.75.634",
121
121
  "@stacksjs/dnsx": "^0.2.3",
122
- "@stacksjs/email": "0.75.632",
123
- "@stacksjs/enums": "0.75.632",
124
- "@stacksjs/env": "0.75.632",
125
- "@stacksjs/error-handling": "0.75.632",
126
- "@stacksjs/events": "0.75.632",
127
- "@stacksjs/features": "0.75.632",
128
- "@stacksjs/git": "0.75.632",
122
+ "@stacksjs/email": "0.75.634",
123
+ "@stacksjs/enums": "0.75.634",
124
+ "@stacksjs/env": "0.75.634",
125
+ "@stacksjs/error-handling": "0.75.634",
126
+ "@stacksjs/events": "0.75.634",
127
+ "@stacksjs/features": "0.75.634",
128
+ "@stacksjs/git": "0.75.634",
129
129
  "@stacksjs/gitit": "^0.2.5",
130
- "@stacksjs/health": "0.75.632",
131
- "@stacksjs/hq": "0.75.632",
130
+ "@stacksjs/health": "0.75.634",
131
+ "@stacksjs/hq": "0.75.634",
132
132
  "@stacksjs/httx": "^0.1.10",
133
- "@stacksjs/image": "0.75.632",
134
- "@stacksjs/lint": "0.75.632",
135
- "@stacksjs/logging": "0.75.632",
136
- "@stacksjs/notifications": "0.75.632",
137
- "@stacksjs/objects": "0.75.632",
138
- "@stacksjs/orm": "0.75.632",
139
- "@stacksjs/path": "0.75.632",
140
- "@stacksjs/payments": "0.75.632",
141
- "@stacksjs/realtime": "0.75.632",
142
- "@stacksjs/router": "0.75.632",
133
+ "@stacksjs/image": "0.75.634",
134
+ "@stacksjs/lint": "0.75.634",
135
+ "@stacksjs/logging": "0.75.634",
136
+ "@stacksjs/notifications": "0.75.634",
137
+ "@stacksjs/objects": "0.75.634",
138
+ "@stacksjs/orm": "0.75.634",
139
+ "@stacksjs/path": "0.75.634",
140
+ "@stacksjs/payments": "0.75.634",
141
+ "@stacksjs/realtime": "0.75.634",
142
+ "@stacksjs/router": "0.75.634",
143
143
  "@stacksjs/rpx": "^0.11.54",
144
- "@stacksjs/scheduler": "0.75.632",
145
- "@stacksjs/search-engine": "0.75.632",
146
- "@stacksjs/security": "0.75.632",
147
- "@stacksjs/server": "0.75.632",
148
- "@stacksjs/sites": "0.75.632",
149
- "@stacksjs/skills": "0.75.632",
150
- "@stacksjs/socials": "0.75.632",
151
- "@stacksjs/storage": "0.75.632",
152
- "@stacksjs/strings": "0.75.632",
144
+ "@stacksjs/scheduler": "0.75.634",
145
+ "@stacksjs/search-engine": "0.75.634",
146
+ "@stacksjs/security": "0.75.634",
147
+ "@stacksjs/server": "0.75.634",
148
+ "@stacksjs/sites": "0.75.634",
149
+ "@stacksjs/skills": "0.75.634",
150
+ "@stacksjs/socials": "0.75.634",
151
+ "@stacksjs/storage": "0.75.634",
152
+ "@stacksjs/strings": "0.75.634",
153
153
  "@stacksjs/stx": "^0.2.908",
154
- "@stacksjs/testing": "0.75.632",
155
- "@stacksjs/tinker": "0.75.632",
154
+ "@stacksjs/testing": "0.75.634",
155
+ "@stacksjs/tinker": "0.75.634",
156
156
  "@stacksjs/tlsx": "^0.13.19",
157
157
  "@stacksjs/ts-cloud": "^0.16.144",
158
- "@stacksjs/tunnel": "0.75.632",
159
- "@stacksjs/types": "0.75.632",
160
- "@stacksjs/ui": "0.75.632",
161
- "@stacksjs/utils": "0.75.632",
162
- "@stacksjs/validation": "0.75.632",
158
+ "@stacksjs/tunnel": "0.75.634",
159
+ "@stacksjs/types": "0.75.634",
160
+ "@stacksjs/ui": "0.75.634",
161
+ "@stacksjs/utils": "0.75.634",
162
+ "@stacksjs/validation": "0.75.634",
163
163
  "ajv": "^8.20.0",
164
164
  "ajv-formats": "^3.0.1",
165
165
  "bun-plugin-stx": "^0.2.908",