rman 2.30.0 → 2.32.0
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/builtins/platforms/node/services/publish.service.js +1 -1
- package/builtins/publish-targets/docker/docker-publish.service.js +30 -6
- package/builtins/publish-targets/spm/index.d.ts +2 -0
- package/builtins/publish-targets/spm/index.js +2 -0
- package/builtins/publish-targets/spm/spm-publish.service.d.ts +74 -0
- package/builtins/publish-targets/spm/spm-publish.service.js +186 -0
- package/builtins/publish-targets/spm/spm.target.d.ts +25 -0
- package/builtins/publish-targets/spm/spm.target.js +47 -0
- package/commands/publish.command.d.ts +3 -0
- package/commands/publish.command.js +55 -12
- package/constants.js +1 -1
- package/core/application.js +3 -0
- package/core/interfaces/publish-target.d.ts +9 -0
- package/package.json +2 -2
- package/utils/exec.d.ts +4 -2
- package/utils/exec.js +1 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { execFile } from 'node:child_process';
|
|
2
2
|
import fs from 'node:fs';
|
|
3
|
+
import os from 'node:os';
|
|
3
4
|
import path from 'node:path';
|
|
4
5
|
import { promisify } from 'node:util';
|
|
5
6
|
import { Service } from '../../../core/classes/service.js';
|
|
@@ -113,7 +114,7 @@ export class DockerPublishService extends Service {
|
|
|
113
114
|
await exec('docker buildx create --use', {
|
|
114
115
|
cwd: repository.dirname,
|
|
115
116
|
app: repository.app,
|
|
116
|
-
stdio: '
|
|
117
|
+
stdio: 'stderr',
|
|
117
118
|
throwOnError: false,
|
|
118
119
|
});
|
|
119
120
|
const result = [];
|
|
@@ -123,9 +124,9 @@ export class DockerPublishService extends Service {
|
|
|
123
124
|
continue;
|
|
124
125
|
}
|
|
125
126
|
try {
|
|
126
|
-
await buildAndPush(repository, entry);
|
|
127
|
+
const digest = await buildAndPush(repository, entry);
|
|
127
128
|
await updateDescription(entry);
|
|
128
|
-
result.push(entry);
|
|
129
|
+
result.push(digest ? { ...entry, artifact: { ref: entry.image, digest } } : entry);
|
|
129
130
|
}
|
|
130
131
|
catch (e) {
|
|
131
132
|
result.push({ ...entry, status: 'error', reason: e.message });
|
|
@@ -205,7 +206,7 @@ async function dockerLogin(app, cwd) {
|
|
|
205
206
|
await exec(`echo "${password}" | docker login --username "${username}" --password-stdin`, {
|
|
206
207
|
cwd,
|
|
207
208
|
app,
|
|
208
|
-
stdio: '
|
|
209
|
+
stdio: 'stderr',
|
|
209
210
|
});
|
|
210
211
|
}
|
|
211
212
|
async function buildAndPush(repository, entry) {
|
|
@@ -234,6 +235,11 @@ async function buildAndPush(repository, entry) {
|
|
|
234
235
|
args.push('-f', `"${dockerfile}"`);
|
|
235
236
|
for (const tag of imageTags(pkg))
|
|
236
237
|
args.push('-t', `"${entry.image}:${tag}"`);
|
|
238
|
+
/** buildx writes what it pushed here - `containerimage.digest` is the pushed index's own, the
|
|
239
|
+
* address `docker buildx imagetools inspect` reports for the tag right after. */
|
|
240
|
+
const metadataDir = fs.mkdtempSync(path.join(os.tmpdir(), 'rman-buildx-'));
|
|
241
|
+
const metadataFile = path.join(metadataDir, 'metadata.json');
|
|
242
|
+
args.push('--metadata-file', `"${metadataFile}"`);
|
|
237
243
|
args.push('--push', '.');
|
|
238
244
|
/** **Shown as it runs and kept**, so a failure can say why. It ran with `stdio: 'inherit'`, and the
|
|
239
245
|
* one thing left to report was the exit code - measured on `panates/syncbridge`, the line that
|
|
@@ -249,8 +255,26 @@ async function buildAndPush(repository, entry) {
|
|
|
249
255
|
process.stderr.write(line + '\n');
|
|
250
256
|
},
|
|
251
257
|
});
|
|
252
|
-
|
|
253
|
-
|
|
258
|
+
try {
|
|
259
|
+
if (result.code)
|
|
260
|
+
throw new Error(`docker build exited with code ${result.code}${failureLines(lines)}`);
|
|
261
|
+
return readPushedDigest(metadataFile);
|
|
262
|
+
}
|
|
263
|
+
finally {
|
|
264
|
+
fs.rmSync(metadataDir, { recursive: true, force: true });
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
/** The digest buildx recorded for what it pushed, or `undefined` when its metadata says none. */
|
|
268
|
+
/* Unreadable metadata is not a failed publish - the image is on the registry either way - so it
|
|
269
|
+
* reads as "no digest", which leaves the entry without an `artifact` rather than failing it. */
|
|
270
|
+
function readPushedDigest(file) {
|
|
271
|
+
try {
|
|
272
|
+
const digest = JSON.parse(fs.readFileSync(file, 'utf-8'))['containerimage.digest'];
|
|
273
|
+
return typeof digest === 'string' && /^sha256:[0-9a-f]{64}$/.test(digest) ? digest : undefined;
|
|
274
|
+
}
|
|
275
|
+
catch {
|
|
276
|
+
return undefined;
|
|
277
|
+
}
|
|
254
278
|
}
|
|
255
279
|
/**
|
|
256
280
|
* The lines of a failed build worth putting in a one-paragraph reason: those saying "error", with
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { Package } from '../../../core/classes/package.js';
|
|
2
|
+
import { Service } from '../../../core/classes/service.js';
|
|
3
|
+
import { type PublishTarget } from '../../../core/interfaces/publish-target.js';
|
|
4
|
+
import { type PackageFilterOptions } from '../../../utils/package-filter.js';
|
|
5
|
+
/** The name this target answers to in `publish.target` and `--target`. */
|
|
6
|
+
export declare const SPM_TARGET = "spm";
|
|
7
|
+
/**
|
|
8
|
+
* Publishes packages to the SyncBridge registry through the repository's own `spm`.
|
|
9
|
+
*
|
|
10
|
+
* **Question B, like every target**: is *this version* on the registry already? `spm view <name>
|
|
11
|
+
* --json` answers it, as `npm view` does for the npm target - `up-to-date` when the version is
|
|
12
|
+
* listed, `publish` when it is not, `error` when the lookup itself failed.
|
|
13
|
+
*/
|
|
14
|
+
export declare class SpmPublishService extends Service {
|
|
15
|
+
/** What `spm publish` prints for a version the registry already has, under `--skip-existing`. */
|
|
16
|
+
protected readonly skippedPattern: RegExp;
|
|
17
|
+
/** `spm publish --no-wait`'s exit code when the registry would ask for approval. */
|
|
18
|
+
protected readonly approvalRequiredExit: number;
|
|
19
|
+
/**
|
|
20
|
+
* What `publish --target spm` would do. Only packages naming `"spm"` in their own `publish.target`
|
|
21
|
+
* are candidates; one with a dirty working tree is an `'error'` (or `'skip'` under
|
|
22
|
+
* `ignoreDirty`), and the rest are asked of the registry.
|
|
23
|
+
*/
|
|
24
|
+
getPlan(options?: SpmPublishService.Options, deps?: SpmPublishService.Deps): Promise<SpmPublishService.Entry[]>;
|
|
25
|
+
/**
|
|
26
|
+
* Publishes every `'publish'` entry with `spm publish --skip-existing`, one package after another,
|
|
27
|
+
* in the package's own directory. A failure is that package's alone and is reported on its entry.
|
|
28
|
+
*/
|
|
29
|
+
applyPlan(plan: SpmPublishService.Entry[]): Promise<SpmPublishService.Entry[]>;
|
|
30
|
+
/** The access and registry `pkg` publishes with: the flag, else its `.rmanrc "publish.spm"`. */
|
|
31
|
+
protected settingsOf(pkg: Package, options: SpmPublishService.Options): SpmPublishService.Settings;
|
|
32
|
+
/** The versions of `pkg` the registry lists - `spm view <name> --json`. Throws when the lookup
|
|
33
|
+
* failed, with spm's own reason. */
|
|
34
|
+
protected view(pkg: Package, registry: string | undefined): Promise<string[]>;
|
|
35
|
+
/** Runs the publish, its output shown on stderr as it comes. `true` when spm skipped the version
|
|
36
|
+
* because the registry has it. */
|
|
37
|
+
protected publish(entry: SpmPublishService.Entry): Promise<boolean>;
|
|
38
|
+
/**
|
|
39
|
+
* Whether nobody can approve a publish: not GitHub Actions (where spm publishes as the job, through
|
|
40
|
+
* its OIDC token) and no terminal. spm is then told `--no-wait`, and refuses at once rather than
|
|
41
|
+
* polling for an approval.
|
|
42
|
+
*/
|
|
43
|
+
protected unattended(): boolean;
|
|
44
|
+
protected registryArgs(registry: string | undefined): string[];
|
|
45
|
+
/** `spm` from the package's own or the repository's `node_modules`. */
|
|
46
|
+
protected spm(pkg: Package, argv: string[], onLine: (line: string, stream: 'stdout' | 'stderr') => void): Promise<void>;
|
|
47
|
+
}
|
|
48
|
+
export declare namespace SpmPublishService {
|
|
49
|
+
/** Injectable registry lookup, so a spec needs neither network nor spm. */
|
|
50
|
+
interface Deps {
|
|
51
|
+
publishedVersions?(pkg: Package, registry: string | undefined): Promise<string[]>;
|
|
52
|
+
}
|
|
53
|
+
interface Options extends PackageFilterOptions {
|
|
54
|
+
/** `--ignore-dirty`: a package with uncommitted changes is skipped rather than an error. */
|
|
55
|
+
ignoreDirty?: boolean;
|
|
56
|
+
/** `--spm-access`, over every package's `publish.spm.access`. */
|
|
57
|
+
access?: 'public' | 'private';
|
|
58
|
+
/** `--spm-registry`, over every package's `publish.spm.registry`. */
|
|
59
|
+
registry?: string;
|
|
60
|
+
}
|
|
61
|
+
interface Settings {
|
|
62
|
+
access?: 'public' | 'private';
|
|
63
|
+
registry?: string;
|
|
64
|
+
}
|
|
65
|
+
interface Entry extends PublishTarget.Entry {
|
|
66
|
+
/** What the plan decided to publish with, read back by `applyPlan` rather than recomputed. */
|
|
67
|
+
settings: Settings;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
declare module '../../../core/classes/service.js' {
|
|
71
|
+
interface ServiceMap {
|
|
72
|
+
spmPublish: SpmPublishService;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import { Service } from '../../../core/classes/service.js';
|
|
2
|
+
import { targetsOf } from '../../../core/interfaces/publish-target.js';
|
|
3
|
+
import { filesOwnedBy } from '../../../utils/bundled-packages.js';
|
|
4
|
+
import { dirtyReason, GitHelper } from '../../../utils/git.js';
|
|
5
|
+
import { filterPackages } from '../../../utils/package-filter.js';
|
|
6
|
+
import { runBin } from '../../../utils/run-bin.js';
|
|
7
|
+
/** The name this target answers to in `publish.target` and `--target`. */
|
|
8
|
+
export const SPM_TARGET = 'spm';
|
|
9
|
+
/**
|
|
10
|
+
* Publishes packages to the SyncBridge registry through the repository's own `spm`.
|
|
11
|
+
*
|
|
12
|
+
* **Question B, like every target**: is *this version* on the registry already? `spm view <name>
|
|
13
|
+
* --json` answers it, as `npm view` does for the npm target - `up-to-date` when the version is
|
|
14
|
+
* listed, `publish` when it is not, `error` when the lookup itself failed.
|
|
15
|
+
*/
|
|
16
|
+
/* **A failed lookup is an `'error'`, never "not published"** - the opposite of the npm and
|
|
17
|
+
* cloudflare checks, on purpose. Their catch-everything shape is a measured cost on the npm side
|
|
18
|
+
* (`npmViewPackage` read a failed lookup as "never published" and proposed a republish every run),
|
|
19
|
+
* and `spm view` was asked for with a distinct failure exit exactly so this one need not guess.
|
|
20
|
+
*
|
|
21
|
+
* **The publish is `--skip-existing`**, which makes it exact even where the lookup cannot be: a
|
|
22
|
+
* private package is invisible to an anonymous read, and spm answers 409 from the write path. A
|
|
23
|
+
* version it skips comes back `up-to-date`, so `--json` does not call it published. */
|
|
24
|
+
export class SpmPublishService extends Service {
|
|
25
|
+
/** What `spm publish` prints for a version the registry already has, under `--skip-existing`. */
|
|
26
|
+
skippedPattern = /is already published to .*: skipped/;
|
|
27
|
+
/** `spm publish --no-wait`'s exit code when the registry would ask for approval. */
|
|
28
|
+
approvalRequiredExit = 3;
|
|
29
|
+
/**
|
|
30
|
+
* What `publish --target spm` would do. Only packages naming `"spm"` in their own `publish.target`
|
|
31
|
+
* are candidates; one with a dirty working tree is an `'error'` (or `'skip'` under
|
|
32
|
+
* `ignoreDirty`), and the rest are asked of the registry.
|
|
33
|
+
*/
|
|
34
|
+
async getPlan(options = {}, deps = {}) {
|
|
35
|
+
const repository = this.repository;
|
|
36
|
+
const git = new GitHelper({ cwd: repository.dirname });
|
|
37
|
+
const packages = filterPackages(repository.getPackages({ toposort: true }), options).filter(pkg => targetsOf(this.app, pkg).some(t => t.name === SPM_TARGET) && !pkg.config.publish?.skip);
|
|
38
|
+
const dirtyFiles = await git.listDirtyFiles({ absolute: true });
|
|
39
|
+
const publishedVersions = deps.publishedVersions ?? ((pkg, registry) => this.view(pkg, registry));
|
|
40
|
+
return Promise.all(packages.map(async (pkg) => {
|
|
41
|
+
const settings = this.settingsOf(pkg, options);
|
|
42
|
+
const base = { package: pkg, version: pkg.version, settings, detail: settings.access };
|
|
43
|
+
const dirty = filesOwnedBy(dirtyFiles, pkg);
|
|
44
|
+
if (dirty.length) {
|
|
45
|
+
return {
|
|
46
|
+
...base,
|
|
47
|
+
status: options.ignoreDirty ? 'skip' : 'error',
|
|
48
|
+
reason: dirtyReason(dirty, repository.dirname),
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
try {
|
|
52
|
+
const versions = await publishedVersions(pkg, settings.registry);
|
|
53
|
+
return versions.includes(pkg.version)
|
|
54
|
+
? { ...base, status: 'up-to-date', reason: `the registry already has ${pkg.name}@${pkg.version}` }
|
|
55
|
+
: { ...base, status: 'publish', reason: versions.length ? `not published yet` : 'never published' };
|
|
56
|
+
}
|
|
57
|
+
catch (e) {
|
|
58
|
+
return { ...base, status: 'error', reason: e.message };
|
|
59
|
+
}
|
|
60
|
+
}));
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Publishes every `'publish'` entry with `spm publish --skip-existing`, one package after another,
|
|
64
|
+
* in the package's own directory. A failure is that package's alone and is reported on its entry.
|
|
65
|
+
*/
|
|
66
|
+
async applyPlan(plan) {
|
|
67
|
+
const result = [];
|
|
68
|
+
for (const entry of plan) {
|
|
69
|
+
if (entry.status !== 'publish') {
|
|
70
|
+
result.push(entry);
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
try {
|
|
74
|
+
const skipped = await this.publish(entry);
|
|
75
|
+
result.push(skipped
|
|
76
|
+
? {
|
|
77
|
+
...entry,
|
|
78
|
+
status: 'up-to-date',
|
|
79
|
+
reason: `the registry already has ${entry.package.name}@${entry.version}`,
|
|
80
|
+
}
|
|
81
|
+
: entry);
|
|
82
|
+
}
|
|
83
|
+
catch (e) {
|
|
84
|
+
result.push({ ...entry, status: 'error', reason: e.message });
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return result;
|
|
88
|
+
}
|
|
89
|
+
/** The access and registry `pkg` publishes with: the flag, else its `.rmanrc "publish.spm"`. */
|
|
90
|
+
settingsOf(pkg, options) {
|
|
91
|
+
const config = pkg.config.publish?.spm;
|
|
92
|
+
return {
|
|
93
|
+
access: options.access ?? config?.access,
|
|
94
|
+
registry: options.registry ?? config?.registry,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
/** The versions of `pkg` the registry lists - `spm view <name> --json`. Throws when the lookup
|
|
98
|
+
* failed, with spm's own reason. */
|
|
99
|
+
async view(pkg, registry) {
|
|
100
|
+
const stdout = [];
|
|
101
|
+
const stderr = [];
|
|
102
|
+
try {
|
|
103
|
+
await this.spm(pkg, ['view', pkg.name, '--json', ...this.registryArgs(registry)], (line, stream) => (stream === 'stdout' ? stdout : stderr).push(line));
|
|
104
|
+
}
|
|
105
|
+
catch (e) {
|
|
106
|
+
/** spm missing is its own sentence - "spm view failed" would hide how to fix it. */
|
|
107
|
+
if (!stderr.length)
|
|
108
|
+
throw e;
|
|
109
|
+
throw new Error(`spm view ${pkg.name} failed${tail(stderr)}`, { cause: e });
|
|
110
|
+
}
|
|
111
|
+
let answer;
|
|
112
|
+
try {
|
|
113
|
+
answer = JSON.parse(stdout.join('\n'));
|
|
114
|
+
}
|
|
115
|
+
catch {
|
|
116
|
+
throw new Error(`spm view ${pkg.name} did not answer JSON - @syncbridge/syncbuild 2.2.0 or later has the command`);
|
|
117
|
+
}
|
|
118
|
+
if (!Array.isArray(answer?.versions))
|
|
119
|
+
throw new Error(`spm view ${pkg.name} answered no "versions" list`);
|
|
120
|
+
return answer.versions.filter((v) => typeof v === 'string');
|
|
121
|
+
}
|
|
122
|
+
/** Runs the publish, its output shown on stderr as it comes. `true` when spm skipped the version
|
|
123
|
+
* because the registry has it. */
|
|
124
|
+
async publish(entry) {
|
|
125
|
+
const { access, registry } = entry.settings;
|
|
126
|
+
const argv = [
|
|
127
|
+
'publish',
|
|
128
|
+
'--skip-existing',
|
|
129
|
+
...(this.unattended() ? ['--no-wait'] : []),
|
|
130
|
+
...(access ? ['--access', access] : []),
|
|
131
|
+
...this.registryArgs(registry),
|
|
132
|
+
];
|
|
133
|
+
const lines = [];
|
|
134
|
+
try {
|
|
135
|
+
await this.spm(entry.package, argv, line => {
|
|
136
|
+
lines.push(line);
|
|
137
|
+
process.stderr.write(line + '\n');
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
catch (e) {
|
|
141
|
+
if (e?.code === this.approvalRequiredExit) {
|
|
142
|
+
throw new Error('the registry asks for approval in Console - publish from a terminal, or from GitHub Actions ' +
|
|
143
|
+
'with "permissions: id-token: write"', { cause: e });
|
|
144
|
+
}
|
|
145
|
+
throw new Error(`spm publish failed${tail(lines)}`, { cause: e });
|
|
146
|
+
}
|
|
147
|
+
return lines.some(l => this.skippedPattern.test(l));
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Whether nobody can approve a publish: not GitHub Actions (where spm publishes as the job, through
|
|
151
|
+
* its OIDC token) and no terminal. spm is then told `--no-wait`, and refuses at once rather than
|
|
152
|
+
* polling for an approval.
|
|
153
|
+
*/
|
|
154
|
+
/* `publish --yes` means "no prompt", and spm outside CI polls for up to ten minutes for a Console
|
|
155
|
+
* approval. `--no-wait` exists for this caller - asked of spm rather than decided here, so a
|
|
156
|
+
* registry that asks no approval (SB_PUBLISH_APPROVAL off) still publishes. */
|
|
157
|
+
unattended() {
|
|
158
|
+
const ci = !!process.env.ACTIONS_ID_TOKEN_REQUEST_URL && !!process.env.ACTIONS_ID_TOKEN_REQUEST_TOKEN;
|
|
159
|
+
return !ci && !process.stdin.isTTY;
|
|
160
|
+
}
|
|
161
|
+
registryArgs(registry) {
|
|
162
|
+
return registry ? ['--registry', registry] : [];
|
|
163
|
+
}
|
|
164
|
+
/** `spm` from the package's own or the repository's `node_modules`. */
|
|
165
|
+
async spm(pkg, argv, onLine) {
|
|
166
|
+
try {
|
|
167
|
+
await runBin('spm', argv, { cwd: pkg.dirname, app: this.app, logLevel: 'silent', onLine });
|
|
168
|
+
}
|
|
169
|
+
catch (e) {
|
|
170
|
+
if (/was not found/.test(e?.message ?? '')) {
|
|
171
|
+
throw new Error('"spm" is not installed in this repository - add @syncbridge/syncbuild as a devDependency', {
|
|
172
|
+
cause: e,
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
throw e;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
/** The lines of a failed spm run worth a reason - those saying "error", at most four; else the
|
|
180
|
+
* last two spm printed, which is where it says why (`... could not be reached: bad port`). */
|
|
181
|
+
function tail(lines) {
|
|
182
|
+
const said = lines.map(l => l.trim()).filter(Boolean);
|
|
183
|
+
const errors = [...new Set(said.filter(l => /error|refused|denied|not signed/i.test(l)))].slice(0, 4);
|
|
184
|
+
const picked = errors.length ? errors : said.slice(-2);
|
|
185
|
+
return picked.length ? ':\n' + picked.map(l => ` ${l}`).join('\n') : '';
|
|
186
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { PublishFilesKeys, PublishTarget } from '../../../core/interfaces/publish-target.js';
|
|
2
|
+
import type { ConfigValue, ScopedVars } from '../../../interfaces/rman-config.interface.js';
|
|
3
|
+
/**
|
|
4
|
+
* **`publish.spm.*`** - this target's own config block, reaching `RmanConfig` through the
|
|
5
|
+
* `PublishTargetConfigs` slot `publish.command.ts` exports, as `publish.docker.*` does.
|
|
6
|
+
*/
|
|
7
|
+
export interface SpmPublishOptions extends SpmPublishOptionsKeys, ScopedVars {
|
|
8
|
+
}
|
|
9
|
+
export interface SpmPublishOptionsKeys extends PublishFilesKeys {
|
|
10
|
+
/** Who may see the package: `"public"` or `"private"`. spm's own default - a new package is
|
|
11
|
+
* private - applies when unset. `--spm-access` overrides it. */
|
|
12
|
+
access?: ConfigValue<'public' | 'private'>;
|
|
13
|
+
/** The registry's address. spm's own default - `SB_REGISTRY_URL`, else registry.syncbridge.io -
|
|
14
|
+
* applies when unset. `--spm-registry` overrides it. */
|
|
15
|
+
registry?: ConfigValue<string>;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* **The SyncBridge registry, as a publish target** - through `spm`, the way the `npm` target goes
|
|
19
|
+
* through `npm`.
|
|
20
|
+
*
|
|
21
|
+
* Opt-in, so no `claims`: a package ships here by naming `"spm"` in its own `publish.target`. `spm`
|
|
22
|
+
* itself comes from the repository - `@syncbridge/syncbuild` installed there - and is run from its
|
|
23
|
+
* `node_modules/.bin`.
|
|
24
|
+
*/
|
|
25
|
+
export declare const spmPublishTarget: PublishTarget;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { SPM_TARGET } from './spm-publish.service.js';
|
|
2
|
+
/**
|
|
3
|
+
* **The SyncBridge registry, as a publish target** - through `spm`, the way the `npm` target goes
|
|
4
|
+
* through `npm`.
|
|
5
|
+
*
|
|
6
|
+
* Opt-in, so no `claims`: a package ships here by naming `"spm"` in its own `publish.target`. `spm`
|
|
7
|
+
* itself comes from the repository - `@syncbridge/syncbuild` installed there - and is run from its
|
|
8
|
+
* `node_modules/.bin`.
|
|
9
|
+
*/
|
|
10
|
+
/* **Built in rather than shipped by syncbuild - the user's call**: rman already carries the npm
|
|
11
|
+
* registry's whole half (`npm view`, `npm publish`), and the SyncBridge registry is the same kind of
|
|
12
|
+
* thing and ours. What is spm's stays in spm: the lookup is `spm view`, the publish `spm publish`,
|
|
13
|
+
* and anything rman needs that spm cannot answer is asked of spm rather than reimplemented here. */
|
|
14
|
+
export const spmPublishTarget = {
|
|
15
|
+
name: SPM_TARGET,
|
|
16
|
+
describe: 'Publish to the SyncBridge registry (spm publish)',
|
|
17
|
+
options: {
|
|
18
|
+
spmAccess: {
|
|
19
|
+
target: 'cli',
|
|
20
|
+
cliName: 'spm-access',
|
|
21
|
+
describe: 'Who may see a package published to the SyncBridge registry: public or private - over "publish.spm.access".',
|
|
22
|
+
type: 'string',
|
|
23
|
+
},
|
|
24
|
+
spmRegistry: {
|
|
25
|
+
target: 'cli',
|
|
26
|
+
cliName: 'spm-registry',
|
|
27
|
+
describe: 'The SyncBridge registry to publish to - over "publish.spm.registry" and SB_REGISTRY_URL.',
|
|
28
|
+
type: 'string',
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
getPlan(ctx) {
|
|
32
|
+
return ctx.app.getService('spmPublish').getPlan(optionsOf(ctx));
|
|
33
|
+
},
|
|
34
|
+
applyPlan(ctx, plan) {
|
|
35
|
+
/** The entries are this target's own - `getPlan` produced them. */
|
|
36
|
+
return ctx.app.getService('spmPublish').applyPlan(plan);
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
/** The shared filters plus this target's two flags - read here so the service takes a plain
|
|
40
|
+
* options object and stays callable without a CLI. */
|
|
41
|
+
function optionsOf(ctx) {
|
|
42
|
+
return {
|
|
43
|
+
...ctx.options,
|
|
44
|
+
access: ctx.args.spmAccess,
|
|
45
|
+
registry: ctx.args.spmRegistry,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { CloudflarePublishOptions } from '../builtins/publish-targets/cloudflare/cloudflare.target.js';
|
|
2
2
|
import type { DockerPublishOptions } from '../builtins/publish-targets/docker/docker.target.js';
|
|
3
|
+
import type { SpmPublishOptions } from '../builtins/publish-targets/spm/spm.target.js';
|
|
3
4
|
import type { RmanApplication } from '../core/application.js';
|
|
4
5
|
import { type RmanConfig } from '../interfaces/rman-config.interface.js';
|
|
5
6
|
/** Hoisted for `ArgsOf` - see `version.command.ts` and `RmanConfig.ArgsOf` for why. */
|
|
@@ -114,6 +115,8 @@ export interface PublishTargetConfigs {
|
|
|
114
115
|
/** Required once `"cloudflare"` is one of a package's `publish.target`s - `kind` says Pages or
|
|
115
116
|
* Workers. */
|
|
116
117
|
cloudflare?: CloudflarePublishOptions;
|
|
118
|
+
/** `"spm"`'s settings - who may see the package, and which registry. Both optional. */
|
|
119
|
+
spm?: SpmPublishOptions;
|
|
117
120
|
}
|
|
118
121
|
type Args = RmanConfig.ArgsOf<typeof config, typeof COMMAND>;
|
|
119
122
|
/**
|
|
@@ -36,8 +36,10 @@ const config = {
|
|
|
36
36
|
json: {
|
|
37
37
|
target: 'cli',
|
|
38
38
|
alias: 'j',
|
|
39
|
-
describe: 'Print
|
|
40
|
-
'
|
|
39
|
+
describe: 'Print JSON instead of text - one entry per package and target. With --dry-run it is the plan ' +
|
|
40
|
+
'("is there anything to publish?", e.g. a CI release gate); otherwise it is printed once the ' +
|
|
41
|
+
'run is over and says what happened: "published" entries, with the digest a registry returned ' +
|
|
42
|
+
'under "artifact".',
|
|
41
43
|
type: 'boolean',
|
|
42
44
|
},
|
|
43
45
|
ignoreDirty: {
|
|
@@ -151,10 +153,18 @@ const publishCommand = registerCommand(app => {
|
|
|
151
153
|
}
|
|
152
154
|
}
|
|
153
155
|
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
156
|
+
/** One document per run, whichever way it ends: the plan under `--dry-run` or on any exit
|
|
157
|
+
* before publishing, what happened once it has. */
|
|
158
|
+
let printed = false;
|
|
159
|
+
const printJson = (doc) => {
|
|
160
|
+
if (!args.json || printed)
|
|
161
|
+
return;
|
|
162
|
+
printed = true;
|
|
163
|
+
console.log(JSON.stringify(doc, undefined, 2));
|
|
164
|
+
};
|
|
165
|
+
if (args.dryRun)
|
|
166
|
+
printJson(jsonPlan(plans));
|
|
167
|
+
if (!args.json) {
|
|
158
168
|
for (const [target, plan] of plans) {
|
|
159
169
|
printPlan(plan, target.name);
|
|
160
170
|
printFiles(plan, target);
|
|
@@ -165,12 +175,14 @@ const publishCommand = registerCommand(app => {
|
|
|
165
175
|
if (requested?.length) {
|
|
166
176
|
const empty = [...plans].filter(([, plan]) => !plan.length).map(([target]) => target.name);
|
|
167
177
|
if (empty.length) {
|
|
178
|
+
printJson(jsonPlan(plans));
|
|
168
179
|
throw logged(`--target ${empty.join(', ')} was given, but no package ships there ` + '(see .rmanrc "publish.target").');
|
|
169
180
|
}
|
|
170
181
|
}
|
|
171
182
|
const all = [...plans.values()].flat();
|
|
172
183
|
const errors = all.filter(e => e.status === 'error');
|
|
173
184
|
if (errors.length) {
|
|
185
|
+
printJson(jsonPlan(plans));
|
|
174
186
|
const allDirty = errors.every(e => e.reason?.startsWith(UNCOMMITTED));
|
|
175
187
|
throw logged(allDirty
|
|
176
188
|
? `${errors.length} package(s) have uncommitted local changes ` +
|
|
@@ -178,6 +190,7 @@ const publishCommand = registerCommand(app => {
|
|
|
178
190
|
: `${errors.length} package(s) failed to prepare for publish - see the errors above`);
|
|
179
191
|
}
|
|
180
192
|
if (!all.some(e => e.status === 'publish')) {
|
|
193
|
+
printJson(jsonPlan(plans));
|
|
181
194
|
if (!args.json)
|
|
182
195
|
console.log(colors.gray('Nothing to publish.'));
|
|
183
196
|
return;
|
|
@@ -187,14 +200,18 @@ const publishCommand = registerCommand(app => {
|
|
|
187
200
|
let proceed = !!args.yes;
|
|
188
201
|
if (!proceed) {
|
|
189
202
|
if (!process.stdout.isTTY) {
|
|
190
|
-
|
|
203
|
+
printJson(jsonPlan(plans));
|
|
204
|
+
console.error(colors.gray('Not a TTY - refusing to prompt. Pass --yes to publish non-interactively.'));
|
|
191
205
|
return;
|
|
192
206
|
}
|
|
193
207
|
proceed = await confirm('Publish these packages?');
|
|
194
208
|
}
|
|
195
|
-
if (!proceed)
|
|
209
|
+
if (!proceed) {
|
|
210
|
+
printJson(jsonPlan(plans));
|
|
196
211
|
return;
|
|
212
|
+
}
|
|
197
213
|
const outcomes = [];
|
|
214
|
+
const results = new Map();
|
|
198
215
|
const publishedBy = new Map();
|
|
199
216
|
let waited = false;
|
|
200
217
|
for (const [target, plan] of plans) {
|
|
@@ -213,10 +230,12 @@ const publishCommand = registerCommand(app => {
|
|
|
213
230
|
finally {
|
|
214
231
|
staged?.restore();
|
|
215
232
|
}
|
|
216
|
-
|
|
233
|
+
results.set(target, applied);
|
|
234
|
+
const done = printApplied(applied, plan, target.name, args.json ? console.error : console.log);
|
|
217
235
|
outcomes.push(...done);
|
|
218
236
|
publishedBy.set(target, done.filter(o => o.entry.status === 'publish').map(o => o.entry));
|
|
219
237
|
}
|
|
238
|
+
printJson(jsonResult(plans, results));
|
|
220
239
|
if (!args.json)
|
|
221
240
|
printRecap(outcomes);
|
|
222
241
|
writeStepSummary(outcomes);
|
|
@@ -339,6 +358,30 @@ function jsonPlan(plans) {
|
|
|
339
358
|
reason: entry.reason,
|
|
340
359
|
})));
|
|
341
360
|
}
|
|
361
|
+
/**
|
|
362
|
+
* `--json` once the run has published: the plan's rows, each as it ended - `published` for one that
|
|
363
|
+
* went up (with the registry's `artifact`, where the target reports one), `error` for one that did
|
|
364
|
+
* not, and a row nothing was asked of as it was planned.
|
|
365
|
+
*/
|
|
366
|
+
/* **`published`, not the plan's `publish`**, so a document read after the run cannot be mistaken
|
|
367
|
+
* for a plan that has yet to happen. The release workflow counts these and takes the digests from
|
|
368
|
+
* `artifact` - `syncbridge-io/syncbridge` deploys by them. */
|
|
369
|
+
function jsonResult(plans, results) {
|
|
370
|
+
return [...plans].flatMap(([target, plan]) => plan.map(planned => {
|
|
371
|
+
const entry = planned.status === 'publish'
|
|
372
|
+
? (results.get(target)?.find(e => e.package === planned.package) ?? planned)
|
|
373
|
+
: planned;
|
|
374
|
+
return {
|
|
375
|
+
name: entry.package.name,
|
|
376
|
+
target: target.name,
|
|
377
|
+
status: planned.status === 'publish' && entry.status === 'publish' ? 'published' : entry.status,
|
|
378
|
+
version: entry.version,
|
|
379
|
+
detail: entry.detail,
|
|
380
|
+
reason: entry.reason,
|
|
381
|
+
...(entry.artifact && { artifact: entry.artifact }),
|
|
382
|
+
};
|
|
383
|
+
}));
|
|
384
|
+
}
|
|
342
385
|
function printPlan(entries, label) {
|
|
343
386
|
const prefix = colors.gray(`[${label}] `);
|
|
344
387
|
for (const e of entries) {
|
|
@@ -392,17 +435,17 @@ async function waitForPublished(ctx, publishedBy) {
|
|
|
392
435
|
* was already an error before anything ran has been printed once by `printPlan`, and printing it
|
|
393
436
|
* again under "failed" would read as a push that was attempted and did not work.
|
|
394
437
|
*/
|
|
395
|
-
function printApplied(applied, plan, label) {
|
|
438
|
+
function printApplied(applied, plan, label, log) {
|
|
396
439
|
const prefix = colors.gray(`[${label}] `);
|
|
397
440
|
const outcomes = [];
|
|
398
441
|
for (const entry of applied) {
|
|
399
442
|
if (plan.find(e => e.package === entry.package)?.status !== 'publish')
|
|
400
443
|
continue;
|
|
401
444
|
if (entry.status === 'publish') {
|
|
402
|
-
|
|
445
|
+
log(colors.green('published'), prefix + colors.cyan(entry.package.name), entry.detail ?? entry.version);
|
|
403
446
|
}
|
|
404
447
|
else if (entry.status === 'error') {
|
|
405
|
-
|
|
448
|
+
log(colors.red('failed'), prefix + colors.cyan(entry.package.name), colors.red(entry.reason ?? ''));
|
|
406
449
|
}
|
|
407
450
|
else
|
|
408
451
|
continue;
|
package/constants.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '2.
|
|
1
|
+
export const version = '2.32.0';
|
package/core/application.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { CloudflarePublishService, cloudflarePublishTarget } from '../builtins/publish-targets/cloudflare/index.js';
|
|
2
2
|
import { DockerPublishService, dockerPublishTarget } from '../builtins/publish-targets/docker/index.js';
|
|
3
|
+
import { SpmPublishService, spmPublishTarget } from '../builtins/publish-targets/spm/index.js';
|
|
3
4
|
import { ChangelogService } from '../services/changelog.service.js';
|
|
4
5
|
import { ConfigService } from '../services/config-service.js';
|
|
5
6
|
import { ExecService } from '../services/exec.service.js';
|
|
@@ -101,10 +102,12 @@ export class RmanApplication {
|
|
|
101
102
|
this.setService('import', a => new ImportService(a));
|
|
102
103
|
this.setService('list', a => new ListService(a));
|
|
103
104
|
this.setService('run', a => new RunService(a));
|
|
105
|
+
this.setService('spmPublish', a => new SpmPublishService(a));
|
|
104
106
|
this.setService('version', a => new VersionService(a));
|
|
105
107
|
// Register core targets.
|
|
106
108
|
this.publishTargets.add(dockerPublishTarget);
|
|
107
109
|
this.publishTargets.add(cloudflarePublishTarget);
|
|
110
|
+
this.publishTargets.add(spmPublishTarget);
|
|
108
111
|
}
|
|
109
112
|
/** Which platform claims a directory - the first whose manifest provider recognizes it, because
|
|
110
113
|
* before a package is read there is nothing else to go on. `basePlatform` when none does, so the
|
|
@@ -129,6 +129,15 @@ export declare namespace PublishTarget {
|
|
|
129
129
|
/** Printed after the package name - docker's resolved `<namespace>/<image>`, for instance. */
|
|
130
130
|
detail?: string;
|
|
131
131
|
reason?: string;
|
|
132
|
+
/**
|
|
133
|
+
* What `applyPlan` actually pushed, when the registry names it by content: `ref` is where it went
|
|
134
|
+
* and `digest` the content address the registry returned. Set by a target on a published entry,
|
|
135
|
+
* never in a plan - nothing has been pushed yet there.
|
|
136
|
+
*/
|
|
137
|
+
artifact?: {
|
|
138
|
+
ref: string;
|
|
139
|
+
digest: string;
|
|
140
|
+
};
|
|
132
141
|
}
|
|
133
142
|
}
|
|
134
143
|
/**
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rman",
|
|
3
3
|
"description": "Repository manager",
|
|
4
|
-
"version": "2.
|
|
4
|
+
"version": "2.32.0",
|
|
5
5
|
"author": "Panates",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"dependencies": {
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"fast-glob": "^3.3.3",
|
|
15
15
|
"fast-tokenizer": "^1.10.1",
|
|
16
16
|
"ini": "^7.0.0",
|
|
17
|
-
"js-yaml": "^5.
|
|
17
|
+
"js-yaml": "^5.5.0",
|
|
18
18
|
"micromatch": "^4.0.8",
|
|
19
19
|
"power-tasks": "^1.14.2",
|
|
20
20
|
"semver": "^7.8.5",
|
package/utils/exec.d.ts
CHANGED
|
@@ -10,8 +10,10 @@ export interface ExecOptions {
|
|
|
10
10
|
*/
|
|
11
11
|
app?: RmanApplication;
|
|
12
12
|
/** 'inherit' streams the child directly to our stdio (used for non-TTY/CI passthrough).
|
|
13
|
-
* '
|
|
14
|
-
|
|
13
|
+
* 'stderr' does the same with the child's stdout sent to our stderr, for a command whose own
|
|
14
|
+
* stdout is a document. 'pipe' (default) captures output so the caller can drive a live view
|
|
15
|
+
* via onLine. */
|
|
16
|
+
stdio?: 'inherit' | 'stderr' | 'pipe';
|
|
15
17
|
cwd?: string;
|
|
16
18
|
env?: Record<string, string | undefined>;
|
|
17
19
|
onLine?: (line: string, stdio: 'stderr' | 'stdout') => void;
|
package/utils/exec.js
CHANGED
|
@@ -22,7 +22,7 @@ export async function exec(command, options) {
|
|
|
22
22
|
};
|
|
23
23
|
opts.cwd = opts.cwd || process.cwd();
|
|
24
24
|
const spawnOptions = {
|
|
25
|
-
stdio: opts.stdio === 'inherit' ? 'inherit' : 'pipe',
|
|
25
|
+
stdio: opts.stdio === 'inherit' ? 'inherit' : opts.stdio === 'stderr' ? ['inherit', 2, 2] : 'pipe',
|
|
26
26
|
env: opts.env,
|
|
27
27
|
cwd: opts.cwd,
|
|
28
28
|
shell: true,
|