@smoothbricks/cli 0.11.17 → 0.11.18
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/README.md +22 -4
- package/dist/cli.js +10 -7
- package/dist/monorepo/ci-workflow.d.ts +56 -0
- package/dist/monorepo/ci-workflow.d.ts.map +1 -1
- package/dist/monorepo/ci-workflow.js +199 -2
- package/dist/monorepo/managed-files.d.ts +23 -0
- package/dist/monorepo/managed-files.d.ts.map +1 -1
- package/dist/monorepo/managed-files.js +39 -1
- package/dist/release/github-release.d.ts +10 -0
- package/dist/release/github-release.d.ts.map +1 -1
- package/dist/release/github-release.js +11 -5
- package/dist/release/index.d.ts.map +1 -1
- package/dist/release/index.js +4 -5
- package/dist/secrets/commands.d.ts +52 -13
- package/dist/secrets/commands.d.ts.map +1 -1
- package/dist/secrets/commands.js +220 -34
- package/dist/secrets/index.d.ts +21 -1
- package/dist/secrets/index.d.ts.map +1 -1
- package/dist/secrets/index.js +110 -4
- package/dist/secrets/repository.d.ts +60 -0
- package/dist/secrets/repository.d.ts.map +1 -0
- package/dist/secrets/repository.js +145 -0
- package/dist/wrangler/cloudflare.d.ts +7 -0
- package/dist/wrangler/cloudflare.d.ts.map +1 -1
- package/dist/wrangler/cloudflare.js +10 -0
- package/dist/wrangler/deploy-stage.d.ts.map +1 -1
- package/dist/wrangler/deploy-stage.js +50 -24
- package/dist/wrangler/stage-secrets.d.ts +57 -0
- package/dist/wrangler/stage-secrets.d.ts.map +1 -0
- package/dist/wrangler/stage-secrets.js +178 -0
- package/managed/raw/tooling/direnv/devenv.smoo.nix +9 -1
- package/managed/raw/tooling/git-hooks/pre-push.sh +30 -29
- package/package.json +2 -2
- package/src/cli.ts +33 -10
- package/src/monorepo/__tests__/ci-workflow.test.ts +161 -0
- package/src/monorepo/ci-workflow.ts +277 -2
- package/src/monorepo/managed-files.test.ts +27 -0
- package/src/monorepo/managed-files.ts +56 -2
- package/src/monorepo/package-policy.test.ts +1 -1
- package/src/release/__tests__/github-release.test.ts +8 -4
- package/src/release/github-release.ts +13 -5
- package/src/release/index.ts +4 -4
- package/src/secrets/commands.test.ts +28 -0
- package/src/secrets/commands.ts +237 -35
- package/src/secrets/index.test.ts +118 -1
- package/src/secrets/index.ts +108 -4
- package/src/secrets/repository.test.ts +98 -0
- package/src/secrets/repository.ts +164 -0
- package/src/wrangler/cloudflare.ts +18 -0
- package/src/wrangler/deploy-stage.test.ts +258 -11
- package/src/wrangler/deploy-stage.ts +70 -38
- package/src/wrangler/stage-secrets.ts +146 -0
package/dist/release/index.js
CHANGED
|
@@ -23,7 +23,7 @@ import { bootstrapNpmPackages, NPM_BOOTSTRAP_DIST_TAG, NPM_BOOTSTRAP_VERSION, }
|
|
|
23
23
|
import { resolveBuildInputPatterns } from './build-inputs.js';
|
|
24
24
|
import { parseReleaseProjectSelection, releaseCandidatePackages, } from './candidates.js';
|
|
25
25
|
import { classifyReleaseBranchPush, collectOwnedReleaseTagRecords, divergedReleaseBranchMessage, pendingReleaseTargets, releaseTag, releaseTagAliases, } from './core.js';
|
|
26
|
-
import { createOrUpdateGithubRelease, githubReleaseLookupExists, importWorkspaceNx, renderNxProjectChangelogContents, withNxWorkspaceRoot, } from './github-release.js';
|
|
26
|
+
import { createOrUpdateGithubRelease, DEPENDENCY_ONLY_RELEASE_NOTES, githubReleaseLookupExists, importWorkspaceNx, renderNxProjectChangelogContents, withNxWorkspaceRoot, } from './github-release.js';
|
|
27
27
|
import { publishWithAuthDiagnostics } from './npm-auth.js';
|
|
28
28
|
import { bumpStableReleaseToNext, collectRepairPlatformOutputs, completeReleaseAtHead as completeReleaseAtHeadWithShell, prepareReleaseCandidate, repairPendingTargets, runReleaseTag, runReleaseVersion, } from './orchestration.js';
|
|
29
29
|
import { packReleaseTarball } from './pack.js';
|
|
@@ -1128,10 +1128,9 @@ async function writeReleasePreviewSummary(root, currentPackages, previewPackages
|
|
|
1128
1128
|
lines.push(` - \`${pkg.name}\`: \`${currentByName.get(pkg.name)?.version ?? 'unknown'}\` -> \`${pkg.version}\``);
|
|
1129
1129
|
}
|
|
1130
1130
|
for (const pkg of previewPackages) {
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
}
|
|
1131
|
+
// A dependency-only bump has no commits of its own, so Nx generates no
|
|
1132
|
+
// changelog for it. The preview says so rather than refusing to render.
|
|
1133
|
+
const contents = releasePreviewChangelogs.get(pkg.projectName) ?? DEPENDENCY_ONLY_RELEASE_NOTES;
|
|
1135
1134
|
lines.push('', `### ${pkg.name} ${pkg.version}`, '', contents.trim());
|
|
1136
1135
|
}
|
|
1137
1136
|
}
|
|
@@ -5,41 +5,80 @@
|
|
|
5
5
|
* world-readable) and never printed. Reading one from the terminal disables
|
|
6
6
|
* echo, so a pasted key does not end up in a scrollback buffer or a screen
|
|
7
7
|
* share.
|
|
8
|
+
*
|
|
9
|
+
* A value lives at repository scope or inside a named GitHub Environment, and
|
|
10
|
+
* a job bound to an environment resolves `secrets.X` from that environment
|
|
11
|
+
* first and from the repository second — which is how one name carries test
|
|
12
|
+
* credentials on a preview stage and live ones in production. Every scope the
|
|
13
|
+
* workflows bind is read before anything is called missing: reading only the
|
|
14
|
+
* repository reports values that do exist as absent, and sends an operator
|
|
15
|
+
* hunting for a secret that is already set.
|
|
16
|
+
*/
|
|
17
|
+
import { type SecretRow } from './index.js';
|
|
18
|
+
/**
|
|
19
|
+
* Every secret this checkout declares that the repository does not hold, in
|
|
20
|
+
* the order an operator should fix them: the ones a workflow already promises
|
|
21
|
+
* break a deploy today, the rest break the next one.
|
|
22
|
+
*/
|
|
23
|
+
export declare function secretsNeedingValues(rows: readonly SecretRow[]): SecretRow[];
|
|
24
|
+
/**
|
|
25
|
+
* Every secret this checkout declares that the named environment does not
|
|
26
|
+
* hold. A name the repository already holds is still offered: an environment
|
|
27
|
+
* value overrides the repository's for a job bound to it, and overriding one
|
|
28
|
+
* stage's credentials is the reason to write at environment scope at all. A
|
|
29
|
+
* repository secret no source declares is not offered — that is a stale value
|
|
30
|
+
* to review, not one to copy into an environment.
|
|
8
31
|
*/
|
|
9
|
-
|
|
10
|
-
|
|
32
|
+
export declare function secretsMissingInEnvironment(rows: readonly SecretRow[], environment: string): SecretRow[];
|
|
33
|
+
/** Why a secret is wanted, so a prompt states what will break without it. */
|
|
34
|
+
export declare function describeNeed(row: SecretRow): string;
|
|
35
|
+
/**
|
|
36
|
+
* Secret names GitHub currently holds at the given scope, or a refusal naming
|
|
37
|
+
* what failed. With no environment that is repository scope; with one it is
|
|
38
|
+
* that environment's own secrets, which are the values a bound job reads
|
|
39
|
+
* first.
|
|
40
|
+
*/
|
|
41
|
+
export declare function readRepositorySecrets(repo: string | undefined, environment?: string): {
|
|
11
42
|
ok: true;
|
|
12
43
|
names: string[];
|
|
13
44
|
} | {
|
|
14
45
|
ok: false;
|
|
15
46
|
reason: string;
|
|
16
47
|
};
|
|
17
|
-
/** Write one secret, value over stdin so it never reaches argv. */
|
|
18
|
-
export declare function writeRepositorySecret(name: string, value: string, repo: string | undefined): Promise<{
|
|
48
|
+
/** Write one secret at the given scope, value over stdin so it never reaches argv. */
|
|
49
|
+
export declare function writeRepositorySecret(name: string, value: string, repo: string | undefined, environment?: string): Promise<{
|
|
19
50
|
ok: true;
|
|
20
51
|
} | {
|
|
21
52
|
ok: false;
|
|
22
53
|
reason: string;
|
|
23
54
|
}>;
|
|
24
55
|
/**
|
|
25
|
-
* Print every known secret
|
|
26
|
-
* promises a value
|
|
27
|
-
* that fails a deploy, and it fails talking about the
|
|
28
|
-
* missing secret.
|
|
56
|
+
* Print every known secret and the scopes holding it. Exit code 1 when a
|
|
57
|
+
* workflow promises a value no scope a bound job reads can supply — that
|
|
58
|
+
* combination is the one that fails a deploy, and it fails talking about the
|
|
59
|
+
* value rather than the missing secret.
|
|
29
60
|
*/
|
|
30
61
|
export declare function secretsStatus(root: string, options: {
|
|
31
62
|
repo?: string;
|
|
63
|
+
env?: string;
|
|
32
64
|
}): number;
|
|
33
|
-
/**
|
|
34
|
-
|
|
65
|
+
/**
|
|
66
|
+
* Set one secret, or - with no name - walk every secret this checkout declares
|
|
67
|
+
* and the target scope does not hold, prompting once each. The walk is the
|
|
68
|
+
* point of the command: an operator should never have to transcribe names out
|
|
69
|
+
* of a status table to know what to paste.
|
|
70
|
+
*/
|
|
71
|
+
export declare function secretsSet(root: string, name: string | undefined, options: {
|
|
35
72
|
repo?: string;
|
|
73
|
+
env?: string;
|
|
36
74
|
}): Promise<number>;
|
|
37
75
|
/**
|
|
38
|
-
* Push every locally fetchable secret to the repository
|
|
39
|
-
* `smoo.secrets` declares a command for: everything else has no
|
|
40
|
-
* and must be pasted with `smoo secrets set`.
|
|
76
|
+
* Push every locally fetchable secret to the repository, or to one environment.
|
|
77
|
+
* Only names `smoo.secrets` declares a command for: everything else has no
|
|
78
|
+
* source here and must be pasted with `smoo secrets set`.
|
|
41
79
|
*/
|
|
42
80
|
export declare function secretsSync(root: string, options: {
|
|
43
81
|
repo?: string;
|
|
82
|
+
env?: string;
|
|
44
83
|
}): Promise<number>;
|
|
45
84
|
//# sourceMappingURL=commands.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"commands.d.ts","sourceRoot":"","sources":["../../src/secrets/commands.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;
|
|
1
|
+
{"version":3,"file":"commands.d.ts","sourceRoot":"","sources":["../../src/secrets/commands.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAIH,OAAO,EAKL,KAAK,SAAS,EAOf,MAAM,YAAY,CAAC;AAGpB;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,SAAS,SAAS,EAAE,GAAG,SAAS,EAAE,CAG5E;AAED;;;;;;;GAOG;AACH,wBAAgB,2BAA2B,CAAC,IAAI,EAAE,SAAS,SAAS,EAAE,EAAE,WAAW,EAAE,MAAM,GAAG,SAAS,EAAE,CAOxG;AAED,6EAA6E;AAC7E,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ands.js
CHANGED
|
@@ -5,15 +5,70 @@
|
|
|
5
5
|
* world-readable) and never printed. Reading one from the terminal disables
|
|
6
6
|
* echo, so a pasted key does not end up in a scrollback buffer or a screen
|
|
7
7
|
* share.
|
|
8
|
+
*
|
|
9
|
+
* A value lives at repository scope or inside a named GitHub Environment, and
|
|
10
|
+
* a job bound to an environment resolves `secrets.X` from that environment
|
|
11
|
+
* first and from the repository second — which is how one name carries test
|
|
12
|
+
* credentials on a preview stage and live ones in production. Every scope the
|
|
13
|
+
* workflows bind is read before anything is called missing: reading only the
|
|
14
|
+
* repository reports values that do exist as absent, and sends an operator
|
|
15
|
+
* hunting for a secret that is already set.
|
|
8
16
|
*/
|
|
9
17
|
import { spawn, spawnSync } from 'node:child_process';
|
|
10
18
|
import { getWorkspacePackages } from '../lib/workspace.js';
|
|
11
|
-
import { fetchLocalSecret, localSecretCommandNames, reconcileSecrets, secretNameMapping, unsatisfiedSecrets, unwiredSecrets, workerSecretNames, workflowSecretNames, } from './index.js';
|
|
12
|
-
|
|
13
|
-
|
|
19
|
+
import { environmentsMissing, fetchLocalSecret, localSecretCommandNames, reconcileSecrets, secretNameMapping, unsatisfiedSecrets, unwiredSecrets, workerSecretNames, workflowEnvironments, workflowSecretNames, } from './index.js';
|
|
20
|
+
import { resolveRepository } from './repository.js';
|
|
21
|
+
/**
|
|
22
|
+
* Every secret this checkout declares that the repository does not hold, in
|
|
23
|
+
* the order an operator should fix them: the ones a workflow already promises
|
|
24
|
+
* break a deploy today, the rest break the next one.
|
|
25
|
+
*/
|
|
26
|
+
export function secretsNeedingValues(rows) {
|
|
27
|
+
const missing = rows.filter((row) => !row.onRepository);
|
|
28
|
+
return [...missing.filter((row) => row.suppliedByWorkflow), ...missing.filter((row) => !row.suppliedByWorkflow)];
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Every secret this checkout declares that the named environment does not
|
|
32
|
+
* hold. A name the repository already holds is still offered: an environment
|
|
33
|
+
* value overrides the repository's for a job bound to it, and overriding one
|
|
34
|
+
* stage's credentials is the reason to write at environment scope at all. A
|
|
35
|
+
* repository secret no source declares is not offered — that is a stale value
|
|
36
|
+
* to review, not one to copy into an environment.
|
|
37
|
+
*/
|
|
38
|
+
export function secretsMissingInEnvironment(rows, environment) {
|
|
39
|
+
const missing = rows.filter((row) => !row.heldByEnvironment.includes(environment) &&
|
|
40
|
+
(row.declaredByWorkers.length > 0 || row.suppliedByWorkflow || row.fetchableLocally));
|
|
41
|
+
return [...missing.filter((row) => row.suppliedByWorkflow), ...missing.filter((row) => !row.suppliedByWorkflow)];
|
|
42
|
+
}
|
|
43
|
+
/** Why a secret is wanted, so a prompt states what will break without it. */
|
|
44
|
+
export function describeNeed(row) {
|
|
45
|
+
const parts = [];
|
|
46
|
+
if (row.declaredByWorkers.length > 0)
|
|
47
|
+
parts.push(`declared by ${row.declaredByWorkers.join(', ')}`);
|
|
48
|
+
if (row.suppliedByWorkflow)
|
|
49
|
+
parts.push('passed by a managed workflow');
|
|
50
|
+
if (row.fetchableLocally)
|
|
51
|
+
parts.push('fetchable locally via smoo.secrets');
|
|
52
|
+
if (row.repositorySecret !== row.name)
|
|
53
|
+
parts.push(`read as ${row.name}`);
|
|
54
|
+
// Naming the environments that already hold it stops an operator from
|
|
55
|
+
// answering a per-stage prompt with a repository-wide value.
|
|
56
|
+
if (row.heldByEnvironment.length > 0)
|
|
57
|
+
parts.push(`held by ${row.heldByEnvironment.join(', ')}`);
|
|
58
|
+
return parts.length > 0 ? ` - ${parts.join('; ')}` : '';
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Secret names GitHub currently holds at the given scope, or a refusal naming
|
|
62
|
+
* what failed. With no environment that is repository scope; with one it is
|
|
63
|
+
* that environment's own secrets, which are the values a bound job reads
|
|
64
|
+
* first.
|
|
65
|
+
*/
|
|
66
|
+
export function readRepositorySecrets(repo, environment) {
|
|
14
67
|
const args = ['secret', 'list', '--json', 'name'];
|
|
15
68
|
if (repo)
|
|
16
69
|
args.push('--repo', repo);
|
|
70
|
+
if (environment)
|
|
71
|
+
args.push('--env', environment);
|
|
17
72
|
const result = spawnSync('gh', args, { encoding: 'utf8' });
|
|
18
73
|
if (result.status !== 0) {
|
|
19
74
|
return {
|
|
@@ -37,11 +92,13 @@ export function readRepositorySecrets(repo) {
|
|
|
37
92
|
}
|
|
38
93
|
return { ok: true, names: names.sort((left, right) => left.localeCompare(right)) };
|
|
39
94
|
}
|
|
40
|
-
/** Write one secret, value over stdin so it never reaches argv. */
|
|
41
|
-
export async function writeRepositorySecret(name, value, repo) {
|
|
95
|
+
/** Write one secret at the given scope, value over stdin so it never reaches argv. */
|
|
96
|
+
export async function writeRepositorySecret(name, value, repo, environment) {
|
|
42
97
|
const args = ['secret', 'set', name];
|
|
43
98
|
if (repo)
|
|
44
99
|
args.push('--repo', repo);
|
|
100
|
+
if (environment)
|
|
101
|
+
args.push('--env', environment);
|
|
45
102
|
const child = spawn('gh', args, { stdio: ['pipe', 'inherit', 'inherit'] });
|
|
46
103
|
child.stdin.end(value);
|
|
47
104
|
const status = await new Promise((resolvePromise) => {
|
|
@@ -51,7 +108,7 @@ export async function writeRepositorySecret(name, value, repo) {
|
|
|
51
108
|
? { ok: true }
|
|
52
109
|
: { ok: false, reason: `gh ${args.join(' ')} exited ${status ?? 'without status'}` };
|
|
53
110
|
}
|
|
54
|
-
function collectSources(root, repositorySecrets) {
|
|
111
|
+
function collectSources(root, repositorySecrets, environmentSecrets = {}) {
|
|
55
112
|
const workspaceDirs = getWorkspacePackages(root).map((pkg) => pkg.path);
|
|
56
113
|
const workerSecrets = workerSecretNames(root, workspaceDirs);
|
|
57
114
|
const workflowSecrets = workflowSecretNames(root);
|
|
@@ -65,12 +122,18 @@ function collectSources(root, repositorySecrets) {
|
|
|
65
122
|
secretNames: secretNameMapping(root, envNames),
|
|
66
123
|
localCommands,
|
|
67
124
|
repositorySecrets,
|
|
125
|
+
environmentSecrets,
|
|
68
126
|
};
|
|
69
127
|
}
|
|
70
|
-
|
|
128
|
+
/** Every scope holding a value for this name, repository first. */
|
|
129
|
+
function heldBy(row) {
|
|
130
|
+
const scopes = row.onRepository ? ['repository', ...row.heldByEnvironment] : row.heldByEnvironment;
|
|
131
|
+
return scopes.length > 0 ? scopes.join(', ') : 'ABSENT';
|
|
132
|
+
}
|
|
133
|
+
function describe(row, scopeWidth) {
|
|
71
134
|
const where = row.declaredByWorkers.length > 0 ? row.declaredByWorkers.join(', ') : '—';
|
|
72
135
|
return [
|
|
73
|
-
row.
|
|
136
|
+
heldBy(row).padEnd(scopeWidth),
|
|
74
137
|
row.name.padEnd(32),
|
|
75
138
|
row.suppliedByWorkflow ? 'workflow' : ' ',
|
|
76
139
|
row.fetchableLocally ? 'local' : ' ',
|
|
@@ -78,22 +141,52 @@ function describe(row) {
|
|
|
78
141
|
].join(' ');
|
|
79
142
|
}
|
|
80
143
|
/**
|
|
81
|
-
* Print every known secret
|
|
82
|
-
* promises a value
|
|
83
|
-
* that fails a deploy, and it fails talking about the
|
|
84
|
-
* missing secret.
|
|
144
|
+
* Print every known secret and the scopes holding it. Exit code 1 when a
|
|
145
|
+
* workflow promises a value no scope a bound job reads can supply — that
|
|
146
|
+
* combination is the one that fails a deploy, and it fails talking about the
|
|
147
|
+
* value rather than the missing secret.
|
|
85
148
|
*/
|
|
86
149
|
export function secretsStatus(root, options) {
|
|
87
|
-
const
|
|
150
|
+
const resolved = resolveRepository(root, options.repo);
|
|
151
|
+
if (!resolved.ok) {
|
|
152
|
+
console.error(resolved.reason);
|
|
153
|
+
return 1;
|
|
154
|
+
}
|
|
155
|
+
const { repo, source } = resolved.choice;
|
|
156
|
+
const repositorySecrets = readRepositorySecrets(repo);
|
|
88
157
|
if (!repositorySecrets.ok) {
|
|
89
158
|
console.error(repositorySecrets.reason);
|
|
90
159
|
return 1;
|
|
91
160
|
}
|
|
92
|
-
|
|
93
|
-
|
|
161
|
+
// The workflows decide which environments a job reads; an explicitly asked
|
|
162
|
+
// for one is shown too, so an operator can inspect a scope before a workflow
|
|
163
|
+
// binds it.
|
|
164
|
+
const boundEnvironments = workflowEnvironments(root);
|
|
165
|
+
const asked = options.env !== undefined && !boundEnvironments.includes(options.env) ? [options.env] : [];
|
|
166
|
+
const environmentSecrets = {};
|
|
167
|
+
const unreadable = [];
|
|
168
|
+
for (const environment of [...boundEnvironments, ...asked]) {
|
|
169
|
+
const held = readRepositorySecrets(repo, environment);
|
|
170
|
+
if (held.ok)
|
|
171
|
+
environmentSecrets[environment] = held.names;
|
|
172
|
+
else
|
|
173
|
+
unreadable.push({ environment, reason: held.reason });
|
|
174
|
+
}
|
|
175
|
+
// An environment that cannot be read is reported, never assumed empty:
|
|
176
|
+
// guessing produces a refusal about a value that may well be set.
|
|
177
|
+
const readable = boundEnvironments.filter((environment) => environment in environmentSecrets);
|
|
178
|
+
const rows = reconcileSecrets(collectSources(root, repositorySecrets.names, environmentSecrets));
|
|
179
|
+
console.log(`repository ${repo} (${source}), holding ${repositorySecrets.names.length} secrets`);
|
|
180
|
+
for (const [environment, names] of Object.entries(environmentSecrets)) {
|
|
181
|
+
console.log(`environment ${environment}, holding ${names.length} secrets`);
|
|
182
|
+
}
|
|
183
|
+
for (const { environment, reason } of unreadable) {
|
|
184
|
+
console.log(`environment ${environment} could not be read, so nothing below claims what it holds: ${reason}`);
|
|
185
|
+
}
|
|
186
|
+
const scopeWidth = Math.max('held by'.length, ...rows.map((row) => heldBy(row).length));
|
|
187
|
+
console.log(`${'held by'.padEnd(scopeWidth)} ${'name'.padEnd(32)} workflow local declared by`);
|
|
94
188
|
for (const row of rows)
|
|
95
|
-
console.log(describe(row));
|
|
96
|
-
const unsatisfied = unsatisfiedSecrets(rows);
|
|
189
|
+
console.log(describe(row, scopeWidth));
|
|
97
190
|
const unwired = unwiredSecrets(rows);
|
|
98
191
|
if (unwired.length > 0) {
|
|
99
192
|
console.log('');
|
|
@@ -102,15 +195,39 @@ export function secretsStatus(root, options) {
|
|
|
102
195
|
'declare it in smoo.github.deploySecrets to have CI supply it.');
|
|
103
196
|
}
|
|
104
197
|
}
|
|
105
|
-
|
|
198
|
+
// A value an environment holds is not a value to duplicate at repository
|
|
199
|
+
// scope: offering it invites two sources of truth for one credential, and
|
|
200
|
+
// the table above already shows where it lives. Only a name no scope holds
|
|
201
|
+
// is a name to set here.
|
|
202
|
+
const needed = secretsNeedingValues(rows).filter((row) => !row.onRepository && row.heldByEnvironment.length === 0);
|
|
203
|
+
if (needed.length > 0) {
|
|
204
|
+
console.log('');
|
|
205
|
+
console.log(`${needed.length} secret(s) have no value in any scope on ${repo}:`);
|
|
206
|
+
for (const row of needed)
|
|
207
|
+
console.log(` ${row.repositorySecret}${describeNeed(row)}`);
|
|
106
208
|
console.log('');
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
209
|
+
console.log(`set them all, one prompt each: smoo secrets set -R ${repo}`);
|
|
210
|
+
console.log(`set one: smoo secrets set ${needed[0]?.repositorySecret ?? 'NAME'} -R ${repo}`);
|
|
211
|
+
}
|
|
212
|
+
const unsatisfied = unsatisfiedSecrets(rows, readable);
|
|
213
|
+
if (unsatisfied.length === 0)
|
|
214
|
+
return 0;
|
|
215
|
+
console.log('');
|
|
216
|
+
for (const row of unsatisfied) {
|
|
217
|
+
const missing = environmentsMissing(row, readable);
|
|
218
|
+
const scopes = missing.length > 0 ? missing.join(', ') : 'the repository';
|
|
219
|
+
console.error(`missing: ${row.name} — a workflow passes secrets.${row.name} and no value exists in ${scopes}.`);
|
|
220
|
+
if (missing.length === 0) {
|
|
221
|
+
console.error(` smoo secrets set ${row.repositorySecret} -R ${repo}`);
|
|
222
|
+
continue;
|
|
110
223
|
}
|
|
111
|
-
|
|
224
|
+
for (const environment of missing) {
|
|
225
|
+
const named = environment.includes(' ') ? `'${environment}'` : environment;
|
|
226
|
+
console.error(` smoo secrets set ${row.repositorySecret} -R ${repo} --env ${named}`);
|
|
227
|
+
}
|
|
228
|
+
console.error(` or one value for every environment: smoo secrets set ${row.repositorySecret} -R ${repo}`);
|
|
112
229
|
}
|
|
113
|
-
return
|
|
230
|
+
return 1;
|
|
114
231
|
}
|
|
115
232
|
/** Read a value with echo disabled when stdin is a terminal; otherwise read piped input. */
|
|
116
233
|
async function readSecretValue(prompt) {
|
|
@@ -143,32 +260,101 @@ async function readSecretValue(prompt) {
|
|
|
143
260
|
}
|
|
144
261
|
return value;
|
|
145
262
|
}
|
|
146
|
-
/**
|
|
147
|
-
|
|
148
|
-
|
|
263
|
+
/**
|
|
264
|
+
* Set one secret, or - with no name - walk every secret this checkout declares
|
|
265
|
+
* and the target scope does not hold, prompting once each. The walk is the
|
|
266
|
+
* point of the command: an operator should never have to transcribe names out
|
|
267
|
+
* of a status table to know what to paste.
|
|
268
|
+
*/
|
|
269
|
+
export async function secretsSet(root, name, options) {
|
|
270
|
+
const resolved = resolveRepository(root, options.repo);
|
|
271
|
+
if (!resolved.ok) {
|
|
272
|
+
console.error(resolved.reason);
|
|
273
|
+
return 1;
|
|
274
|
+
}
|
|
275
|
+
const { repo, source } = resolved.choice;
|
|
276
|
+
const environment = options.env;
|
|
277
|
+
if (name !== undefined)
|
|
278
|
+
return setOne(name, name, repo, environment);
|
|
279
|
+
const held = readRepositorySecrets(repo);
|
|
280
|
+
if (!held.ok) {
|
|
281
|
+
console.error(held.reason);
|
|
282
|
+
return 1;
|
|
283
|
+
}
|
|
284
|
+
const environmentSecrets = {};
|
|
285
|
+
if (environment !== undefined) {
|
|
286
|
+
const inEnvironment = readRepositorySecrets(repo, environment);
|
|
287
|
+
if (!inEnvironment.ok) {
|
|
288
|
+
console.error(inEnvironment.reason);
|
|
289
|
+
return 1;
|
|
290
|
+
}
|
|
291
|
+
environmentSecrets[environment] = inEnvironment.names;
|
|
292
|
+
}
|
|
293
|
+
const rows = reconcileSecrets(collectSources(root, held.names, environmentSecrets));
|
|
294
|
+
const needed = environment === undefined ? secretsNeedingValues(rows) : secretsMissingInEnvironment(rows, environment);
|
|
295
|
+
const target = environment === undefined ? `${repo} (${source})` : `environment ${environment} on ${repo} (${source})`;
|
|
296
|
+
if (needed.length === 0) {
|
|
297
|
+
console.log(`${target} already holds every secret this checkout declares.`);
|
|
298
|
+
return 0;
|
|
299
|
+
}
|
|
300
|
+
console.log(`${needed.length} secret(s) to set on ${target}. Empty input skips one.`);
|
|
301
|
+
let failed = 0;
|
|
302
|
+
let set = 0;
|
|
303
|
+
for (const row of needed) {
|
|
304
|
+
console.log('');
|
|
305
|
+
console.log(`${row.repositorySecret}${describeNeed(row)}`);
|
|
306
|
+
const value = await readSecretValue(' paste value (not echoed, empty to skip): ');
|
|
307
|
+
if (value.length === 0) {
|
|
308
|
+
console.log(`skip ${row.repositorySecret}`);
|
|
309
|
+
continue;
|
|
310
|
+
}
|
|
311
|
+
const written = await writeRepositorySecret(row.repositorySecret, value, repo, environment);
|
|
312
|
+
if (!written.ok) {
|
|
313
|
+
console.error(`fail ${row.repositorySecret}: ${written.reason}`);
|
|
314
|
+
failed += 1;
|
|
315
|
+
continue;
|
|
316
|
+
}
|
|
317
|
+
console.log(`set ${row.repositorySecret}`);
|
|
318
|
+
set += 1;
|
|
319
|
+
}
|
|
320
|
+
console.log('');
|
|
321
|
+
console.log(`${set} set, ${needed.length - set - failed} skipped, ${failed} failed.`);
|
|
322
|
+
return failed === 0 ? 0 : 1;
|
|
323
|
+
}
|
|
324
|
+
async function setOne(envName, repositorySecret, repo, environment) {
|
|
325
|
+
const scope = environment === undefined ? '' : ` in ${environment}`;
|
|
326
|
+
const value = await readSecretValue(`Value for ${repositorySecret}${scope} (not echoed): `);
|
|
149
327
|
if (value.length === 0) {
|
|
150
|
-
console.error(`${
|
|
328
|
+
console.error(`${repositorySecret}: refusing to set an empty value.`);
|
|
151
329
|
return 1;
|
|
152
330
|
}
|
|
153
|
-
const written = await writeRepositorySecret(
|
|
331
|
+
const written = await writeRepositorySecret(repositorySecret, value, repo, environment);
|
|
154
332
|
if (!written.ok) {
|
|
155
333
|
console.error(written.reason);
|
|
156
334
|
return 1;
|
|
157
335
|
}
|
|
158
|
-
console.log(`set ${
|
|
336
|
+
console.log(`set ${repositorySecret}${scope}${envName === repositorySecret ? '' : ` (reads as ${envName})`}`);
|
|
159
337
|
return 0;
|
|
160
338
|
}
|
|
161
339
|
/**
|
|
162
|
-
* Push every locally fetchable secret to the repository
|
|
163
|
-
* `smoo.secrets` declares a command for: everything else has no
|
|
164
|
-
* and must be pasted with `smoo secrets set`.
|
|
340
|
+
* Push every locally fetchable secret to the repository, or to one environment.
|
|
341
|
+
* Only names `smoo.secrets` declares a command for: everything else has no
|
|
342
|
+
* source here and must be pasted with `smoo secrets set`.
|
|
165
343
|
*/
|
|
166
344
|
export async function secretsSync(root, options) {
|
|
345
|
+
const resolved = resolveRepository(root, options.repo);
|
|
346
|
+
if (!resolved.ok) {
|
|
347
|
+
console.error(resolved.reason);
|
|
348
|
+
return 1;
|
|
349
|
+
}
|
|
350
|
+
const { repo } = resolved.choice;
|
|
351
|
+
const environment = options.env;
|
|
167
352
|
const names = localSecretCommandNames(root);
|
|
168
353
|
if (names.length === 0) {
|
|
169
354
|
console.error('smoo.secrets declares no fetch commands; nothing to sync.');
|
|
170
355
|
return 1;
|
|
171
356
|
}
|
|
357
|
+
const scope = environment === undefined ? '' : ` in ${environment}`;
|
|
172
358
|
let failed = 0;
|
|
173
359
|
for (const name of names) {
|
|
174
360
|
const fetched = fetchLocalSecret(root, name);
|
|
@@ -177,13 +363,13 @@ export async function secretsSync(root, options) {
|
|
|
177
363
|
failed += 1;
|
|
178
364
|
continue;
|
|
179
365
|
}
|
|
180
|
-
const written = await writeRepositorySecret(name, fetched.value,
|
|
366
|
+
const written = await writeRepositorySecret(name, fetched.value, repo, environment);
|
|
181
367
|
if (!written.ok) {
|
|
182
368
|
console.error(`fail ${name}: ${written.reason}`);
|
|
183
369
|
failed += 1;
|
|
184
370
|
continue;
|
|
185
371
|
}
|
|
186
|
-
console.log(`set ${name}`);
|
|
372
|
+
console.log(`set ${name}${scope}`);
|
|
187
373
|
}
|
|
188
374
|
return failed === 0 ? 0 : 1;
|
|
189
375
|
}
|
package/dist/secrets/index.d.ts
CHANGED
|
@@ -31,6 +31,13 @@ export interface SecretRow {
|
|
|
31
31
|
fetchableLocally: boolean;
|
|
32
32
|
/** True when the repository holds a secret of this name. */
|
|
33
33
|
onRepository: boolean;
|
|
34
|
+
/**
|
|
35
|
+
* GitHub Environments holding their own value for this name. A job bound to
|
|
36
|
+
* an environment reads that value in preference to the repository's, which
|
|
37
|
+
* is how one name carries test credentials on a preview stage and live ones
|
|
38
|
+
* in production.
|
|
39
|
+
*/
|
|
40
|
+
heldByEnvironment: string[];
|
|
34
41
|
}
|
|
35
42
|
export interface SecretSources {
|
|
36
43
|
/** Worker label -> env names it declares. */
|
|
@@ -43,6 +50,8 @@ export interface SecretSources {
|
|
|
43
50
|
localCommands: readonly string[];
|
|
44
51
|
/** Repository secret names GitHub currently holds. */
|
|
45
52
|
repositorySecrets: readonly string[];
|
|
53
|
+
/** Environment name -> secret names that environment holds. */
|
|
54
|
+
environmentSecrets?: Readonly<Record<string, readonly string[]>>;
|
|
46
55
|
}
|
|
47
56
|
/**
|
|
48
57
|
* One row per name known to any source, sorted, so a reader sees the whole
|
|
@@ -55,11 +64,22 @@ export declare function reconcileSecrets(sources: SecretSources): SecretRow[];
|
|
|
55
64
|
* separately from "declared but not wired into any workflow", because the
|
|
56
65
|
* remedies differ — set a secret, versus declare it in `smoo.github`.
|
|
57
66
|
*/
|
|
58
|
-
export declare function unsatisfiedSecrets(rows: readonly SecretRow[]): SecretRow[];
|
|
67
|
+
export declare function unsatisfiedSecrets(rows: readonly SecretRow[], boundEnvironments?: readonly string[]): SecretRow[];
|
|
68
|
+
/** Bound environments that lack their own value and cannot fall back to the repository. */
|
|
69
|
+
export declare function environmentsMissing(row: SecretRow, boundEnvironments: readonly string[]): string[];
|
|
59
70
|
/** Worker-declared names no managed workflow passes: a CI deploy will run without them. */
|
|
60
71
|
export declare function unwiredSecrets(rows: readonly SecretRow[]): SecretRow[];
|
|
61
72
|
/** Env names the managed workflows pass into a job, from the declarations that render them. */
|
|
62
73
|
export declare function workflowSecretNames(root: string): string[];
|
|
74
|
+
/**
|
|
75
|
+
* GitHub Environments the rendered workflows bind, read from the workflow
|
|
76
|
+
* files rather than from config: a binding may be hand-authored inside a
|
|
77
|
+
* `smoo-local` block, and the file is what GitHub executes either way. A job
|
|
78
|
+
* bound to an environment resolves `secrets.X` from that environment first and
|
|
79
|
+
* from the repository second, so these names are the scopes a value can live
|
|
80
|
+
* in. Expressions are skipped - a computed environment names no fixed scope.
|
|
81
|
+
*/
|
|
82
|
+
export declare function workflowEnvironments(root: string): string[];
|
|
63
83
|
/**
|
|
64
84
|
* Env name -> repository secret for every name in play, following the naming
|
|
65
85
|
* convention and honouring the declared exceptions a repository still needs.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/secrets/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AASH,mGAAmG;AACnG,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,oFAAoF;IACpF,gBAAgB,EAAE,MAAM,CAAC;IACzB,+DAA+D;IAC/D,iBAAiB,EAAE,MAAM,EAAE,CAAC;IAC5B,wEAAwE;IACxE,kBAAkB,EAAE,OAAO,CAAC;IAC5B,mEAAmE;IACnE,gBAAgB,EAAE,OAAO,CAAC;IAC1B,4DAA4D;IAC5D,YAAY,EAAE,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/secrets/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AASH,mGAAmG;AACnG,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,oFAAoF;IACpF,gBAAgB,EAAE,MAAM,CAAC;IACzB,+DAA+D;IAC/D,iBAAiB,EAAE,MAAM,EAAE,CAAC;IAC5B,wEAAwE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