@entrinsik/vite-plugin-informer 2.6.0 → 2.7.0-beta.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/bin/ci.js +157 -0
- package/bin/publish.js +29 -111
- package/package.json +2 -1
- package/src/assemble.js +11 -3
- package/src/github-oidc.js +58 -0
- package/src/marketplaces.js +61 -0
- package/src/publish-payload.js +125 -0
package/bin/ci.js
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* informer-ci — publish one build to every configured marketplace, using
|
|
5
|
+
* GitHub Actions OIDC instead of a stored publish key.
|
|
6
|
+
*
|
|
7
|
+
* The workflow step is deliberately inert:
|
|
8
|
+
*
|
|
9
|
+
* permissions:
|
|
10
|
+
* id-token: write
|
|
11
|
+
* ...
|
|
12
|
+
* - run: npx informer-ci
|
|
13
|
+
* env:
|
|
14
|
+
* INFORMER_MARKETPLACES: ${{ vars.INFORMER_MARKETPLACES }}
|
|
15
|
+
*
|
|
16
|
+
* Everything interesting lives here rather than in YAML, so fixing it is an
|
|
17
|
+
* npm release rather than a pull request into every customer's repo.
|
|
18
|
+
*
|
|
19
|
+
* For a single marketplace with a `lmpub_` key — locally, or on CI that is not
|
|
20
|
+
* GitHub Actions — use `informer-publish` instead. This command needs the OIDC
|
|
21
|
+
* endpoint only GitHub's runner provides.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
import { appendFile } from 'node:fs/promises';
|
|
25
|
+
import { resolve } from 'node:path';
|
|
26
|
+
import { publish } from '../src/publish.js';
|
|
27
|
+
import { preparePublish, tagVersion } from '../src/publish-payload.js';
|
|
28
|
+
import { parseMarketplaces, normalizeMarketplaceUrl } from '../src/marketplaces.js';
|
|
29
|
+
import { canMintIdToken, mintIdToken } from '../src/github-oidc.js';
|
|
30
|
+
import { loadEnv, parseModeArg } from '../src/env.js';
|
|
31
|
+
|
|
32
|
+
const mode = parseModeArg(process.argv);
|
|
33
|
+
loadEnv({ mode });
|
|
34
|
+
|
|
35
|
+
const projectRoot = resolve('.');
|
|
36
|
+
|
|
37
|
+
// --- Targets: explicit flags replace the configured list entirely, so a
|
|
38
|
+
// workflow_dispatch can re-publish to a subset without editing config. ---
|
|
39
|
+
let targets;
|
|
40
|
+
try {
|
|
41
|
+
const explicit = argValues('--marketplace').map(normalizeMarketplaceUrl);
|
|
42
|
+
targets = explicit.length ? [...new Set(explicit)] : parseMarketplaces(process.env.INFORMER_MARKETPLACES);
|
|
43
|
+
} catch (err) {
|
|
44
|
+
fail(err.message);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (!targets.length) {
|
|
48
|
+
fail(
|
|
49
|
+
'No marketplaces configured. Set the INFORMER_MARKETPLACES repo variable to one cloud-api URL per line, e.g.\n' +
|
|
50
|
+
' https://lm.example.com/cloud-api\n' +
|
|
51
|
+
' or pass --marketplace <url>.'
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (!canMintIdToken()) {
|
|
56
|
+
fail(
|
|
57
|
+
'informer-ci needs GitHub Actions OIDC, which is not available here.\n' +
|
|
58
|
+
' In a workflow, give the job `permissions: id-token: write`.\n' +
|
|
59
|
+
' Outside GitHub Actions, publish with a key instead: informer-publish.'
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// --- Build the payload ONCE. Every marketplace gets identical bytes. ---
|
|
64
|
+
let payload;
|
|
65
|
+
try {
|
|
66
|
+
payload = await preparePublish({
|
|
67
|
+
projectRoot,
|
|
68
|
+
version: argValue('--version') || tagVersion(process.env.GITHUB_REF_NAME)
|
|
69
|
+
});
|
|
70
|
+
} catch (err) {
|
|
71
|
+
fail(err.message);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
for (const w of payload.warnings || []) console.warn(` warning: ${w}`);
|
|
75
|
+
|
|
76
|
+
const { name, slug, version, channel, files, icon, screenshots } = payload;
|
|
77
|
+
console.log(
|
|
78
|
+
`Publishing ${name} v${version} (${channel}) to ${targets.length} marketplace${targets.length === 1 ? '' : 's'} — ` +
|
|
79
|
+
`${files.length} files${screenshots.length ? `, ${screenshots.length} screenshot${screenshots.length === 1 ? '' : 's'}` : ''}`
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
// --- Fan out. One target failing must not stop the others: a marketplace that
|
|
83
|
+
// is down should not withhold the release from the ones that are up. ---
|
|
84
|
+
const results = [];
|
|
85
|
+
for (const marketplaceUrl of targets) {
|
|
86
|
+
const label = hostOf(marketplaceUrl);
|
|
87
|
+
try {
|
|
88
|
+
// Audience is the marketplace itself, so a token minted for one
|
|
89
|
+
// License Manager is not replayable at another.
|
|
90
|
+
const token = await mintIdToken(marketplaceUrl);
|
|
91
|
+
const result = await publish({ marketplaceUrl, token, files, icon, screenshots, fields: payload.fields });
|
|
92
|
+
for (const w of result.warnings || []) console.warn(` warning (${label}): ${w}`);
|
|
93
|
+
console.log(` ✓ ${label} — published ${slug} v${version} (${result.channel || channel})`);
|
|
94
|
+
results.push({ label, ok: true });
|
|
95
|
+
} catch (err) {
|
|
96
|
+
console.error(` ✗ ${label} — ${err.message}`);
|
|
97
|
+
results.push({ label, ok: false, error: err.message });
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
await writeSummary(results);
|
|
102
|
+
|
|
103
|
+
const failed = results.filter(r => !r.ok);
|
|
104
|
+
if (failed.length) {
|
|
105
|
+
console.error(`\n${failed.length} of ${results.length} marketplaces failed.`);
|
|
106
|
+
process.exit(1);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// --- helpers ---
|
|
110
|
+
|
|
111
|
+
function argValue(flag) {
|
|
112
|
+
const i = process.argv.indexOf(flag);
|
|
113
|
+
return i !== -1 && process.argv[i + 1] ? process.argv[i + 1] : undefined;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** Every occurrence of a repeatable flag, e.g. --marketplace a --marketplace b. */
|
|
117
|
+
function argValues(flag) {
|
|
118
|
+
const out = [];
|
|
119
|
+
process.argv.forEach((arg, i) => {
|
|
120
|
+
if (arg === flag && process.argv[i + 1]) out.push(process.argv[i + 1]);
|
|
121
|
+
});
|
|
122
|
+
return out;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function hostOf(url) {
|
|
126
|
+
try {
|
|
127
|
+
return new URL(url).host;
|
|
128
|
+
} catch {
|
|
129
|
+
return url;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* A per-target line in the job summary. Without this the Actions UI shows one
|
|
135
|
+
* opaque step for what is really N independent publishes — the observability
|
|
136
|
+
* the old matrix-of-jobs gave up when fan-out moved in here.
|
|
137
|
+
*/
|
|
138
|
+
async function writeSummary(rows) {
|
|
139
|
+
const path = process.env.GITHUB_STEP_SUMMARY;
|
|
140
|
+
if (!path || !rows.length) return;
|
|
141
|
+
const body = [
|
|
142
|
+
`### ${name} v${version} (${channel})`,
|
|
143
|
+
'',
|
|
144
|
+
'| Marketplace | Result |',
|
|
145
|
+
'| --- | --- |',
|
|
146
|
+
...rows.map(r => `| ${r.label} | ${r.ok ? 'published' : `failed — ${r.error.replace(/\|/g, '\\|')}`} |`),
|
|
147
|
+
''
|
|
148
|
+
].join('\n');
|
|
149
|
+
await appendFile(path, body).catch(() => {
|
|
150
|
+
// A summary is a nicety; never fail a good publish over it.
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function fail(message) {
|
|
155
|
+
console.error(message);
|
|
156
|
+
process.exit(1);
|
|
157
|
+
}
|
package/bin/publish.js
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
/**
|
|
4
|
+
* informer-publish — publish this app to ONE marketplace using a vendor
|
|
5
|
+
* publish key. Works anywhere: locally, GitHub Actions, or any other CI.
|
|
6
|
+
*
|
|
7
|
+
* For fanning one build out to several marketplaces from GitHub Actions
|
|
8
|
+
* without storing a key, see `informer-ci` (OIDC trusted publishing).
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { resolve } from 'node:path';
|
|
8
12
|
import { publish } from '../src/publish.js';
|
|
13
|
+
import { preparePublish, tagVersion } from '../src/publish-payload.js';
|
|
9
14
|
import { loadEnv, parseModeArg } from '../src/env.js';
|
|
10
15
|
|
|
11
16
|
const mode = parseModeArg(process.argv);
|
|
@@ -20,87 +25,41 @@ if (!marketplaceUrl || !token) {
|
|
|
20
25
|
console.error('Missing required environment variables.');
|
|
21
26
|
console.error(' INFORMER_MARKETPLACE_URL=https://<license-manager-host>/cloud-api');
|
|
22
27
|
console.error(' INFORMER_PUBLISH_TOKEN=lmpub_<vendor publish key>');
|
|
28
|
+
if (process.env.INFORMER_MARKETPLACES) {
|
|
29
|
+
console.error('\nINFORMER_MARKETPLACES is set — for a multi-marketplace CI publish, run `informer-ci` instead.');
|
|
30
|
+
}
|
|
23
31
|
process.exit(1);
|
|
24
32
|
}
|
|
25
33
|
|
|
26
|
-
//
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
pkg = JSON.parse(await readFile(join(projectRoot, 'package.json'), 'utf8'));
|
|
31
|
-
} catch {
|
|
32
|
-
console.error('Could not read package.json in current directory.');
|
|
33
|
-
process.exit(1);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const inf = pkg.informer || {};
|
|
37
|
-
const name = inf.name || pkg.name;
|
|
38
|
-
const slug = inf.slug || defaultSlug(name);
|
|
39
|
-
|
|
40
|
-
// Version: prefer the git tag (CI: GITHUB_REF_NAME=vX.Y.Z), then --version, then package.json.
|
|
41
|
-
const version = argValue('--version') || tagVersion(process.env.GITHUB_REF_NAME) || pkg.version;
|
|
42
|
-
|
|
43
|
-
if (!name || !slug || !version) {
|
|
44
|
-
console.error('Need a name, slug, and version. Set package.json "informer.name"/"informer.slug" and tag a release (vX.Y.Z) or pass --version.');
|
|
45
|
-
process.exit(1);
|
|
34
|
+
// A repo mid-migration to trusted publishing can have both configured. Publish
|
|
35
|
+
// what it was asked to publish, but say that only one target is being used.
|
|
36
|
+
if (process.env.INFORMER_MARKETPLACES && process.env.GITHUB_ACTIONS) {
|
|
37
|
+
console.warn('Note: INFORMER_MARKETPLACES is set but ignored here — `informer-ci` is the multi-marketplace command.');
|
|
46
38
|
}
|
|
47
39
|
|
|
48
|
-
|
|
49
|
-
const changeNotes = await extractNotes(join(projectRoot, 'CHANGELOG.md'), version);
|
|
50
|
-
|
|
51
|
-
// Provenance (GitHub Actions). All optional — best-effort audit trail.
|
|
52
|
-
const sourceRepo = process.env.GITHUB_REPOSITORY || undefined;
|
|
53
|
-
const sourceCommit = process.env.GITHUB_SHA || undefined;
|
|
54
|
-
const ciRun = process.env.GITHUB_RUN_ID
|
|
55
|
-
? `${process.env.GITHUB_SERVER_URL || 'https://github.com'}/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}`
|
|
56
|
-
: undefined;
|
|
40
|
+
const projectRoot = resolve('.');
|
|
57
41
|
|
|
58
|
-
|
|
59
|
-
let files;
|
|
42
|
+
let payload;
|
|
60
43
|
try {
|
|
61
|
-
|
|
44
|
+
payload = await preparePublish({
|
|
45
|
+
// Prefer an explicit --version, then the git tag (CI: GITHUB_REF_NAME=vX.Y.Z),
|
|
46
|
+
// then package.json.
|
|
47
|
+
version: argValue('--version') || tagVersion(process.env.GITHUB_REF_NAME),
|
|
48
|
+
projectRoot
|
|
49
|
+
});
|
|
62
50
|
} catch (err) {
|
|
63
51
|
console.error(err.message);
|
|
64
52
|
process.exit(1);
|
|
65
53
|
}
|
|
66
54
|
|
|
67
|
-
|
|
68
|
-
// local handlers (see openapi-local.js) and ship it in the archive as root
|
|
69
|
-
// openapi.json — the License Manager extracts it (like informer.yaml), stores
|
|
70
|
-
// it per version, and diffs the public surface against the previous version.
|
|
71
|
-
const { spec: apiSpec, warnings: apiWarnings } = await buildLocalOpenApi({ projectRoot, name, slug, version });
|
|
72
|
-
for (const w of apiWarnings) console.warn(` warning: ${w}`);
|
|
73
|
-
if (apiSpec) files.push({ rel: 'openapi.json', content: JSON.stringify(apiSpec, null, 2) });
|
|
55
|
+
for (const w of payload.warnings || []) console.warn(` warning: ${w}`);
|
|
74
56
|
|
|
75
|
-
const
|
|
76
|
-
const screenshots = await resolveScreenshots(projectRoot, inf.screenshots);
|
|
77
|
-
const channel = version.includes('-') ? 'beta' : 'stable';
|
|
57
|
+
const { name, slug, version, channel, files, icon, screenshots, fields } = payload;
|
|
78
58
|
|
|
79
|
-
console.log(`Publishing ${name} v${version} (${channel}) — ${files.length} files${screenshots.length ? `, ${screenshots.length} screenshot${screenshots.length === 1 ? '' : 's'}` : ''}${changeNotes ? '' : ' — no release notes found'}`);
|
|
59
|
+
console.log(`Publishing ${name} v${version} (${channel}) — ${files.length} files${screenshots.length ? `, ${screenshots.length} screenshot${screenshots.length === 1 ? '' : 's'}` : ''}${fields.changeNotes ? '' : ' — no release notes found'}`);
|
|
80
60
|
|
|
81
61
|
try {
|
|
82
|
-
const result = await publish({
|
|
83
|
-
marketplaceUrl,
|
|
84
|
-
token,
|
|
85
|
-
files,
|
|
86
|
-
icon,
|
|
87
|
-
screenshots,
|
|
88
|
-
fields: {
|
|
89
|
-
name,
|
|
90
|
-
slug,
|
|
91
|
-
version,
|
|
92
|
-
shortDescription: inf.shortDescription,
|
|
93
|
-
description: inf.description || pkg.description,
|
|
94
|
-
categories: inf.categories,
|
|
95
|
-
documentationUrl: inf.documentationUrl,
|
|
96
|
-
requires: inf.requires,
|
|
97
|
-
metadata: inf.metadata,
|
|
98
|
-
changeNotes,
|
|
99
|
-
sourceRepo,
|
|
100
|
-
sourceCommit,
|
|
101
|
-
ciRun
|
|
102
|
-
}
|
|
103
|
-
});
|
|
62
|
+
const result = await publish({ marketplaceUrl, token, files, icon, screenshots, fields });
|
|
104
63
|
console.log(`Published ${slug} v${version} (${result.channel || channel}).`);
|
|
105
64
|
// Server-side advisories (e.g. "public API changed without a major bump").
|
|
106
65
|
for (const w of result.warnings || []) console.warn(` warning: ${w}`);
|
|
@@ -115,44 +74,3 @@ function argValue(flag) {
|
|
|
115
74
|
const i = process.argv.indexOf(flag);
|
|
116
75
|
return i !== -1 && process.argv[i + 1] ? process.argv[i + 1] : undefined;
|
|
117
76
|
}
|
|
118
|
-
|
|
119
|
-
function tagVersion(ref) {
|
|
120
|
-
return ref ? ref.replace(/^v/, '') : undefined;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
function defaultSlug(value) {
|
|
124
|
-
if (!value) return undefined;
|
|
125
|
-
const base = value.startsWith('@') && value.includes('/') ? value.split('/')[1] : value;
|
|
126
|
-
return base.toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-+|-+$/g, '');
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
async function resolveIcon(root, configured) {
|
|
130
|
-
const candidates = [configured, 'favicon.svg', join('public', 'favicon.svg'), join('dist', 'favicon.svg')].filter(Boolean);
|
|
131
|
-
for (const rel of candidates) {
|
|
132
|
-
const abs = resolve(root, rel);
|
|
133
|
-
try {
|
|
134
|
-
await access(abs);
|
|
135
|
-
return { abs, filename: rel.split(/[/\\]/).pop() };
|
|
136
|
-
} catch {
|
|
137
|
-
// try next candidate
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
return undefined;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
// Collect listing screenshots from a `screenshots/` directory (override via
|
|
144
|
-
// package.json informer.screenshots), ordered by filename. Returns
|
|
145
|
-
// [{abs, filename}] for the publisher to upload; empty when none exist.
|
|
146
|
-
async function resolveScreenshots(root, configuredDir) {
|
|
147
|
-
const dir = resolve(root, configuredDir || 'screenshots');
|
|
148
|
-
let names;
|
|
149
|
-
try {
|
|
150
|
-
names = await readdir(dir);
|
|
151
|
-
} catch {
|
|
152
|
-
return []; // no screenshots directory — nothing to upload
|
|
153
|
-
}
|
|
154
|
-
return names
|
|
155
|
-
.filter(n => /\.(png|jpe?g|webp|gif)$/i.test(n))
|
|
156
|
-
.sort((a, b) => a.localeCompare(b, undefined, { numeric: true }))
|
|
157
|
-
.map(n => ({ abs: join(dir, n), filename: n }));
|
|
158
|
-
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@entrinsik/vite-plugin-informer",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.7.0-beta.0",
|
|
4
4
|
"description": "Vite plugin and deploy tool for Informer App development",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "node --test"
|
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
"bin": {
|
|
31
31
|
"informer-deploy": "./bin/deploy.js",
|
|
32
32
|
"informer-publish": "./bin/publish.js",
|
|
33
|
+
"informer-ci": "./bin/ci.js",
|
|
33
34
|
"informer-init": "./bin/init.js",
|
|
34
35
|
"informer-workspace": "./bin/workspace.js",
|
|
35
36
|
"create-magic-report": "./bin/init.js"
|
package/src/assemble.js
CHANGED
|
@@ -17,7 +17,11 @@ import { join, relative, posix } from 'node:path';
|
|
|
17
17
|
// API.md is the author-written integration guide: deployed to the library root
|
|
18
18
|
// (the live openapi.json route folds it into info.description) and tarred into
|
|
19
19
|
// the published archive for the marketplace listing's Integrate surface.
|
|
20
|
-
|
|
20
|
+
// README.md is the docs fallback the gallery/app-menu Documentation surfaces
|
|
21
|
+
// already honor server-side (docs.html is preferred — ship that via public/ so
|
|
22
|
+
// the Vite build lands it at the library root). Without README.md here, a
|
|
23
|
+
// CLI-deployed app could never light those surfaces up via its README.
|
|
24
|
+
const ROOT_CONFIG_FILES = ['informer.yaml', 'data-access.yaml', 'API.md', 'README.md'];
|
|
21
25
|
const SOURCE_DIRS = ['migrations', 'tools', 'mcp', 'server', 'webhooks', 'lib', 'shared'];
|
|
22
26
|
|
|
23
27
|
// Entries never worth shipping in an app's server-side library: OS/editor
|
|
@@ -32,8 +36,12 @@ async function exists(path) {
|
|
|
32
36
|
try {
|
|
33
37
|
await access(path);
|
|
34
38
|
return true;
|
|
35
|
-
} catch {
|
|
36
|
-
|
|
39
|
+
} catch (err) {
|
|
40
|
+
// Only genuine absence is a quiet skip. Anything else (EACCES, EIO)
|
|
41
|
+
// means the file is there but unreadable — silently dropping it would
|
|
42
|
+
// publish an incomplete archive with no signal, so fail the build.
|
|
43
|
+
if (err.code === 'ENOENT' || err.code === 'ENOTDIR') return false;
|
|
44
|
+
throw new Error(`Cannot read "${path}" (${err.code}) — fix permissions or remove the file.`);
|
|
37
45
|
}
|
|
38
46
|
}
|
|
39
47
|
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GitHub Actions OIDC — "trusted publishing".
|
|
3
|
+
*
|
|
4
|
+
* The runner exposes a token-minting endpoint to jobs that declare
|
|
5
|
+
* `permissions: id-token: write`. The token it returns asserts which repository
|
|
6
|
+
* and workflow asked for it, signed by GitHub; the License Manager verifies it
|
|
7
|
+
* and maps the `repository` claim to a vendor account. Nothing long-lived is
|
|
8
|
+
* stored in the customer's repo, which is the whole point.
|
|
9
|
+
*
|
|
10
|
+
* The audience is requested PER MARKETPLACE, so a token minted for one License
|
|
11
|
+
* Manager cannot be replayed against another.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
const REQUEST_URL = 'ACTIONS_ID_TOKEN_REQUEST_URL';
|
|
15
|
+
const REQUEST_TOKEN = 'ACTIONS_ID_TOKEN_REQUEST_TOKEN';
|
|
16
|
+
|
|
17
|
+
/** True when the two runner-injected OIDC variables are present. */
|
|
18
|
+
export function canMintIdToken() {
|
|
19
|
+
return Boolean(process.env[REQUEST_URL] && process.env[REQUEST_TOKEN]);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Mint an OIDC token for one marketplace.
|
|
24
|
+
*
|
|
25
|
+
* @param {string} audience the marketplace URL this token may be spent at
|
|
26
|
+
* @returns {Promise<string>} the JWT
|
|
27
|
+
*/
|
|
28
|
+
export async function mintIdToken(audience) {
|
|
29
|
+
const base = process.env[REQUEST_URL];
|
|
30
|
+
const requestToken = process.env[REQUEST_TOKEN];
|
|
31
|
+
|
|
32
|
+
if (!base || !requestToken) {
|
|
33
|
+
// Nearly always a missing permissions block: the variables are injected
|
|
34
|
+
// only for jobs that asked for the capability, so name the fix.
|
|
35
|
+
throw new Error(
|
|
36
|
+
'No GitHub OIDC token endpoint available. Add to the job:\n' +
|
|
37
|
+
' permissions:\n' +
|
|
38
|
+
' id-token: write\n' +
|
|
39
|
+
' (or publish with a key using `informer-publish`).'
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const url = `${base}&audience=${encodeURIComponent(audience)}`;
|
|
44
|
+
let res;
|
|
45
|
+
try {
|
|
46
|
+
res = await fetch(url, { headers: { Authorization: `Bearer ${requestToken}` } });
|
|
47
|
+
} catch (err) {
|
|
48
|
+
throw new Error(`Could not reach the GitHub OIDC token endpoint: ${err.message}`);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (!res.ok) {
|
|
52
|
+
throw new Error(`GitHub refused to mint an OIDC token (${res.status} ${res.statusText}).`);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const body = await res.json().catch(() => ({}));
|
|
56
|
+
if (!body.value) throw new Error('GitHub OIDC token response contained no token.');
|
|
57
|
+
return body.value;
|
|
58
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The list of marketplaces a CI publish fans out to.
|
|
3
|
+
*
|
|
4
|
+
* Fan-out lives in the CLI rather than the workflow, so the value never has to
|
|
5
|
+
* survive a YAML `fromJSON()` — which means it does not have to BE json. People
|
|
6
|
+
* edit this by hand in a repo-variable textarea, so accept the forms they
|
|
7
|
+
* actually type: a json array, or one URL per line, or comma-separated.
|
|
8
|
+
*
|
|
9
|
+
* Bare URLs on purpose, no labels. Nothing that writes this list (Studio, a
|
|
10
|
+
* human) knows whether an instance is dev, qa, or prod — only the person
|
|
11
|
+
* reading the hostname does.
|
|
12
|
+
*/
|
|
13
|
+
export function parseMarketplaces(raw) {
|
|
14
|
+
if (!raw) return [];
|
|
15
|
+
|
|
16
|
+
const trimmed = String(raw).trim();
|
|
17
|
+
let values;
|
|
18
|
+
|
|
19
|
+
if (trimmed.startsWith('[')) {
|
|
20
|
+
let parsed;
|
|
21
|
+
try {
|
|
22
|
+
parsed = JSON.parse(trimmed);
|
|
23
|
+
} catch (err) {
|
|
24
|
+
throw new Error(`INFORMER_MARKETPLACES looks like JSON but does not parse: ${err.message}`);
|
|
25
|
+
}
|
|
26
|
+
if (!Array.isArray(parsed)) throw new Error('INFORMER_MARKETPLACES must be an array of marketplace URLs.');
|
|
27
|
+
values = parsed;
|
|
28
|
+
} else {
|
|
29
|
+
values = trimmed.split(/[\s,]+/);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const urls = values.map(v => String(v).trim()).filter(Boolean).map(normalizeMarketplaceUrl);
|
|
33
|
+
|
|
34
|
+
// A duplicate would publish the same version twice to one marketplace, and
|
|
35
|
+
// the second attempt 409s — turning a working config into a red build.
|
|
36
|
+
return [...new Set(urls)];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Canonical form for comparison and display.
|
|
41
|
+
*
|
|
42
|
+
* A trailing slash makes two spellings of one marketplace look like two
|
|
43
|
+
* marketplaces — which matters most to whatever is checking "am I already in
|
|
44
|
+
* this list?" before appending.
|
|
45
|
+
*/
|
|
46
|
+
export function normalizeMarketplaceUrl(value) {
|
|
47
|
+
let url;
|
|
48
|
+
try {
|
|
49
|
+
url = new URL(String(value).trim());
|
|
50
|
+
} catch {
|
|
51
|
+
throw new Error(`Not a valid marketplace URL: ${value}`);
|
|
52
|
+
}
|
|
53
|
+
if (url.protocol !== 'http:' && url.protocol !== 'https:') {
|
|
54
|
+
throw new Error(`Marketplace URL must be http(s): ${value}`);
|
|
55
|
+
}
|
|
56
|
+
url.hostname = url.hostname.toLowerCase();
|
|
57
|
+
url.pathname = url.pathname.replace(/\/+$/, '');
|
|
58
|
+
url.hash = '';
|
|
59
|
+
url.search = '';
|
|
60
|
+
return url.toString();
|
|
61
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { readFile, access, readdir } from 'node:fs/promises';
|
|
2
|
+
import { resolve, join } from 'node:path';
|
|
3
|
+
import { collectAppFiles } from './assemble.js';
|
|
4
|
+
import { extractNotes } from './changelog.js';
|
|
5
|
+
import { buildLocalOpenApi } from './openapi-local.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Everything a publish needs, assembled once.
|
|
9
|
+
*
|
|
10
|
+
* Split out of bin/publish.js so `informer-ci` can build the payload a single
|
|
11
|
+
* time and hand the SAME files to several marketplaces — a version has to be
|
|
12
|
+
* byte-identical everywhere it lands, and re-assembling per target would only
|
|
13
|
+
* create opportunities for it not to be.
|
|
14
|
+
*
|
|
15
|
+
* Throws on anything that should stop a publish; the bins print and exit.
|
|
16
|
+
*/
|
|
17
|
+
export async function preparePublish({ projectRoot = resolve('.'), version: versionOverride } = {}) {
|
|
18
|
+
let pkg;
|
|
19
|
+
try {
|
|
20
|
+
pkg = JSON.parse(await readFile(join(projectRoot, 'package.json'), 'utf8'));
|
|
21
|
+
} catch {
|
|
22
|
+
throw new Error('Could not read package.json in current directory.');
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const inf = pkg.informer || {};
|
|
26
|
+
const name = inf.name || pkg.name;
|
|
27
|
+
const slug = inf.slug || defaultSlug(name);
|
|
28
|
+
const version = versionOverride || pkg.version;
|
|
29
|
+
|
|
30
|
+
if (!name || !slug || !version) {
|
|
31
|
+
throw new Error('Need a name, slug, and version. Set package.json "informer.name"/"informer.slug" and tag a release (vX.Y.Z) or pass --version.');
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Release notes: the section for this version, else the cumulative Unreleased block.
|
|
35
|
+
const changeNotes = await extractNotes(join(projectRoot, 'CHANGELOG.md'), version);
|
|
36
|
+
|
|
37
|
+
// Assemble the same file set a deploy produces.
|
|
38
|
+
const files = await collectAppFiles({ distDir: join(projectRoot, 'dist'), projectRoot });
|
|
39
|
+
|
|
40
|
+
// Freeze the API contract with this version: build the OpenAPI doc from the
|
|
41
|
+
// local handlers and ship it in the archive as root openapi.json — the
|
|
42
|
+
// License Manager extracts it, stores it per version, and diffs the public
|
|
43
|
+
// surface against the previous version.
|
|
44
|
+
const { spec: apiSpec, warnings } = await buildLocalOpenApi({ projectRoot, name, slug, version });
|
|
45
|
+
if (apiSpec) files.push({ rel: 'openapi.json', content: JSON.stringify(apiSpec, null, 2) });
|
|
46
|
+
|
|
47
|
+
const icon = await resolveIcon(projectRoot, inf.icon);
|
|
48
|
+
const screenshots = await resolveScreenshots(projectRoot, inf.screenshots);
|
|
49
|
+
|
|
50
|
+
// Provenance (GitHub Actions). All optional — best-effort audit trail.
|
|
51
|
+
const sourceRepo = process.env.GITHUB_REPOSITORY || undefined;
|
|
52
|
+
const sourceCommit = process.env.GITHUB_SHA || undefined;
|
|
53
|
+
const ciRun = process.env.GITHUB_RUN_ID
|
|
54
|
+
? `${process.env.GITHUB_SERVER_URL || 'https://github.com'}/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}`
|
|
55
|
+
: undefined;
|
|
56
|
+
|
|
57
|
+
return {
|
|
58
|
+
name,
|
|
59
|
+
slug,
|
|
60
|
+
version,
|
|
61
|
+
// The server derives the channel too; this copy is for local reporting.
|
|
62
|
+
channel: version.includes('-') ? 'beta' : 'stable',
|
|
63
|
+
files,
|
|
64
|
+
icon,
|
|
65
|
+
screenshots,
|
|
66
|
+
warnings,
|
|
67
|
+
fields: {
|
|
68
|
+
name,
|
|
69
|
+
slug,
|
|
70
|
+
version,
|
|
71
|
+
shortDescription: inf.shortDescription,
|
|
72
|
+
description: inf.description || pkg.description,
|
|
73
|
+
categories: inf.categories,
|
|
74
|
+
documentationUrl: inf.documentationUrl,
|
|
75
|
+
requires: inf.requires,
|
|
76
|
+
metadata: inf.metadata,
|
|
77
|
+
changeNotes,
|
|
78
|
+
sourceRepo,
|
|
79
|
+
sourceCommit,
|
|
80
|
+
ciRun
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** `vX.Y.Z` (GITHUB_REF_NAME) → `X.Y.Z`. */
|
|
86
|
+
export function tagVersion(ref) {
|
|
87
|
+
return ref ? ref.replace(/^v/, '') : undefined;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export function defaultSlug(value) {
|
|
91
|
+
if (!value) return undefined;
|
|
92
|
+
const base = value.startsWith('@') && value.includes('/') ? value.split('/')[1] : value;
|
|
93
|
+
return base.toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-+|-+$/g, '');
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
async function resolveIcon(root, configured) {
|
|
97
|
+
const candidates = [configured, 'favicon.svg', join('public', 'favicon.svg'), join('dist', 'favicon.svg')].filter(Boolean);
|
|
98
|
+
for (const rel of candidates) {
|
|
99
|
+
const abs = resolve(root, rel);
|
|
100
|
+
try {
|
|
101
|
+
await access(abs);
|
|
102
|
+
return { abs, filename: rel.split(/[/\\]/).pop() };
|
|
103
|
+
} catch {
|
|
104
|
+
// try next candidate
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return undefined;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// Collect listing screenshots from a `screenshots/` directory (override via
|
|
111
|
+
// package.json informer.screenshots), ordered by filename. Returns
|
|
112
|
+
// [{abs, filename}] for the publisher to upload; empty when none exist.
|
|
113
|
+
async function resolveScreenshots(root, configuredDir) {
|
|
114
|
+
const dir = resolve(root, configuredDir || 'screenshots');
|
|
115
|
+
let names;
|
|
116
|
+
try {
|
|
117
|
+
names = await readdir(dir);
|
|
118
|
+
} catch {
|
|
119
|
+
return []; // no screenshots directory — nothing to upload
|
|
120
|
+
}
|
|
121
|
+
return names
|
|
122
|
+
.filter(n => /\.(png|jpe?g|webp|gif)$/i.test(n))
|
|
123
|
+
.sort((a, b) => a.localeCompare(b, undefined, { numeric: true }))
|
|
124
|
+
.map(n => ({ abs: join(dir, n), filename: n }));
|
|
125
|
+
}
|