@fabrika/installation-init 0.9.0-dev.17 → 0.9.0-dev.19

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fabrika/installation-init",
3
- "version": "0.9.0-dev.17",
3
+ "version": "0.9.0-dev.19",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",
@@ -28,10 +28,10 @@
28
28
  },
29
29
  "dependencies": {
30
30
  "zod": "^3.25.76",
31
- "@fabrika/app": "0.9.0-dev.17",
32
- "@fabrika/auth-core": "0.9.0-dev.17",
33
- "@fabrika/email": "0.9.0-dev.17",
34
- "@fabrika/iam-contract": "0.9.0-dev.17",
35
- "@fabrika/proxy-core": "0.9.0-dev.17"
31
+ "@fabrika/app": "0.9.0-dev.19",
32
+ "@fabrika/auth-core": "0.9.0-dev.19",
33
+ "@fabrika/email": "0.9.0-dev.19",
34
+ "@fabrika/iam-contract": "0.9.0-dev.19",
35
+ "@fabrika/proxy-core": "0.9.0-dev.19"
36
36
  }
37
37
  }
@@ -59,6 +59,12 @@ export async function configureEnvironment(
59
59
  const protection = await createEnvironment(repo, environment, effects.attempt)
60
60
  config.onProtection?.(protection)
61
61
 
62
+ // Variables first, in the caller's order: a workflow run that starts before init finishes, or a run of init that
63
+ // stops halfway, never sees an Environment whose credentials are set and whose configuration is not.
64
+ for (const [name, value] of Object.entries(vars)) {
65
+ await effects.run({ command: 'gh', args: ['variable', 'set', name, '--repo', repo, '--env', environment, '--body', value], cwd: ANCHOR })
66
+ ok(`variable ${name} set`)
67
+ }
62
68
  for (const [name, value] of Object.entries(secrets)) {
63
69
  if (value === '') {
64
70
  warn(`Skipping secret ${name} — no value (the workflow will fail without it; set it manually).`)
@@ -67,13 +73,35 @@ export async function configureEnvironment(
67
73
  await effects.run({ command: 'gh', args: ['secret', 'set', name, '--repo', repo, '--env', environment], cwd: ANCHOR, stdin: value })
68
74
  ok(`secret ${name} set`)
69
75
  }
70
- for (const [name, value] of Object.entries(vars)) {
71
- await effects.run({ command: 'gh', args: ['variable', 'set', name, '--repo', repo, '--env', environment, '--body', value], cwd: ANCHOR })
72
- ok(`variable ${name} set`)
73
- }
74
76
  detail(`Recommended hardening — require your own approval before a deploy: ${environmentReviewerCommand(repo, environment)}`)
75
77
  }
76
78
 
79
+ const variableLineSchema = z.object({ name: z.string(), value: z.string() })
80
+
81
+ /**
82
+ * The variables an Environment already holds, or null when the repository or the Environment does not exist. Any other
83
+ * failure throws: a caller decides from the answer whether an installation already exists, and must not guess.
84
+ */
85
+ export async function environmentVariables(
86
+ repo: string,
87
+ environment: string,
88
+ gh: GhAttempt = attempt,
89
+ ): Promise<Readonly<Record<string, string>> | null> {
90
+ const path = `repos/${repo}/environments/${environment}/variables`
91
+ const result = await gh({ command: 'gh', args: ['api', '--paginate', path, '--jq', '.variables[] | {name, value}'], cwd: ANCHOR })
92
+ if (result.exitCode !== 0) {
93
+ if (ghHttpStatus(result) === 404) return null
94
+ throw new Error(`\`gh api ${path}\` failed (${unavailableReason(result)}).`)
95
+ }
96
+ const variables: Record<string, string> = {}
97
+ for (const line of result.stdout.split('\n')) {
98
+ if (line.trim() === '') continue
99
+ const variable = variableLineSchema.parse(JSON.parse(line))
100
+ variables[variable.name] = variable.value
101
+ }
102
+ return variables
103
+ }
104
+
77
105
  /**
78
106
  * Idempotent create, carrying the deployment-branch policy MERGED over whatever protection rules the
79
107
  * environment already has — a PUT replaces the whole object, so a reviewer or wait timer the operator
package/src/index.ts CHANGED
@@ -29,6 +29,7 @@ export {
29
29
  configureEnvironment,
30
30
  type EnvironmentConfig,
31
31
  type EnvironmentEffects,
32
+ environmentVariables,
32
33
  type ExistingEnvironmentProtection,
33
34
  existingEnvironmentProtection,
34
35
  triggerPlatformWorkflow,
@@ -29,6 +29,11 @@ export interface EnvironmentEffects {
29
29
  }
30
30
  /** Create the GitHub Environment and populate its secrets + variables. */
31
31
  export declare function configureEnvironment(config: EnvironmentConfig, effects?: EnvironmentEffects): Promise<void>;
32
+ /**
33
+ * The variables an Environment already holds, or null when the repository or the Environment does not exist. Any other
34
+ * failure throws: a caller decides from the answer whether an installation already exists, and must not guess.
35
+ */
36
+ export declare function environmentVariables(repo: string, environment: string, gh?: GhAttempt): Promise<Readonly<Record<string, string>> | null>;
32
37
  /** One reviewer in a PUT body: GitHub's GET nests the id under `reviewer`, its PUT wants it flat. */
33
38
  interface EnvironmentReviewer {
34
39
  readonly type: string;
@@ -3,7 +3,7 @@ export { AUTH_METHODS_FLAG, type AuthMethods, checkedOidcIssuer, OIDC_CLIENT_ID_
3
3
  export { CHECKOUT_FLAG, sidecarCheckoutDir } from './checkout';
4
4
  export { type Confirmations, confirmations, UNATTENDED_FLAG } from './confirmations';
5
5
  export { EMAIL_FLAGS, type InstallationEmail, readInstallationEmail } from './email';
6
- export { configureEnvironment, type EnvironmentConfig, type EnvironmentEffects, type ExistingEnvironmentProtection, existingEnvironmentProtection, triggerPlatformWorkflow, } from './environment';
6
+ export { configureEnvironment, type EnvironmentConfig, type EnvironmentEffects, environmentVariables, type ExistingEnvironmentProtection, existingEnvironmentProtection, triggerPlatformWorkflow, } from './environment';
7
7
  export { ghRepoExists, hasGhCli } from './gh';
8
8
  export { action, detail, fail, info, ok, step, url, warn } from './log';
9
9
  export { type IamOAuthConfig, type McpClient, parseMcpClientsJson, platformIamOAuthConfig } from './mcp';