@agentage/cli 0.72.0 → 0.73.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/dist/commands/extension/create-source.d.ts +1 -1
- package/dist/commands/extension/create-source.js +6 -2
- package/dist/commands/extension/release-changed.js +12 -6
- package/dist/commands/extension/release-ignore.d.ts +17 -0
- package/dist/commands/extension/release-ignore.js +73 -0
- package/dist/commands/extension/release-npm.d.ts +5 -0
- package/dist/commands/extension/release-npm.js +22 -0
- package/dist/commands/extension/release-plan.js +15 -8
- package/dist/commands/extension/release.js +1 -1
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const TEMPLATE = "agentage/
|
|
1
|
+
export declare const TEMPLATE = "agentage/kit:template";
|
|
2
2
|
export declare const OWN_TEMPLATES: string[];
|
|
3
3
|
export declare const fromRefusal: (from: string) => string;
|
|
4
4
|
export declare const repoRef: (from: string) => {
|
|
@@ -5,8 +5,12 @@ import { promisify } from 'node:util';
|
|
|
5
5
|
import { holdSignals } from '../../core/loader/dispose.js';
|
|
6
6
|
const run = promisify(execFile);
|
|
7
7
|
// The kit repo holds the template in its folder template/; the old repo held it at its root.
|
|
8
|
-
export const TEMPLATE = 'agentage/
|
|
9
|
-
export const OWN_TEMPLATES = [
|
|
8
|
+
export const TEMPLATE = 'agentage/kit:template';
|
|
9
|
+
export const OWN_TEMPLATES = [
|
|
10
|
+
TEMPLATE,
|
|
11
|
+
'agentage/platform:template',
|
|
12
|
+
'agentage/extension-template',
|
|
13
|
+
];
|
|
10
14
|
// owner/repo, then #branch and :folder, each optional: nothing that can pass for a flag or leave the repo.
|
|
11
15
|
const FROM = /^[\w.-]+\/[\w.-]+(?:#\w[\w./-]*)?(?::\w[\w.-]*(?:\/\w[\w.-]*)*)?$/;
|
|
12
16
|
export const fromRefusal = (from) => !FROM.test(from) || from.includes('..')
|
|
@@ -2,6 +2,7 @@ import { join } from 'node:path';
|
|
|
2
2
|
import { CliError } from '../../lib/json-output.js';
|
|
3
3
|
import { writeCiCopy } from './release-folders.js';
|
|
4
4
|
import { imagesOf, releaseGuard } from './release-guard.js';
|
|
5
|
+
import { amber, npmRefusal } from './release-npm.js';
|
|
5
6
|
import { fetchTags, git, planRelease } from './release-plan.js';
|
|
6
7
|
import { rowsOf, summary } from './release-summary.js';
|
|
7
8
|
import { attach, buildImages, fail, idChecks, npmVersion, onMaster, publish, PUBLISH_SECONDS, scoped, step, takeSecrets, } from './release-steps.js';
|
|
@@ -55,9 +56,11 @@ const prepare = async (s, p) => {
|
|
|
55
56
|
step(`version: ${p.id} is ${p.version} in this CI copy only`);
|
|
56
57
|
return pkg;
|
|
57
58
|
};
|
|
58
|
-
const npmStep = async (s, run, dir, pkg) => {
|
|
59
|
+
const npmStep = async (s, run, { dir, pkg, refusal }) => {
|
|
59
60
|
if (pkg['private'] === true)
|
|
60
61
|
return step('npm: private package, not published');
|
|
62
|
+
if (refusal)
|
|
63
|
+
return amber(`npm: ${refusal}`);
|
|
61
64
|
const push = scoped(s.deps.exec(dir, PUBLISH_SECONDS), s.secrets);
|
|
62
65
|
await publish(run, push, pkg, s.secrets['npm']?.['NPM_TOKEN']);
|
|
63
66
|
};
|
|
@@ -72,16 +75,19 @@ const imagesStep = async (s, p, run, pkg) => {
|
|
|
72
75
|
return built ? buildImages(dir, oneImage, s.deps.tool, committedBut(s)) : [];
|
|
73
76
|
};
|
|
74
77
|
// The record is the "released" marker: it goes up only after npm has the version.
|
|
75
|
-
const releaseOne = async (s, p) => {
|
|
78
|
+
const releaseOne = async (s, p, row) => {
|
|
76
79
|
const pkg = await prepare(s, p);
|
|
77
80
|
const dir = join(s.root, p.rel);
|
|
78
81
|
const run = scoped(s.deps.exec(dir, s.timeout), s.secrets);
|
|
79
82
|
const isPrivate = pkg['private'] === true;
|
|
80
|
-
|
|
83
|
+
const refusal = isPrivate ? undefined : await npmRefusal(run, s.repo, pkg);
|
|
84
|
+
if (refusal)
|
|
85
|
+
row.result = 'released, AMBER: npm skipped';
|
|
86
|
+
if (!isPrivate && !refusal)
|
|
81
87
|
await npmVersion(run);
|
|
82
88
|
await createTag(s, p.tag);
|
|
83
89
|
const records = await imagesStep(s, p, run, pkg);
|
|
84
|
-
await npmStep(s, run, dir, pkg);
|
|
90
|
+
await npmStep(s, run, { dir, pkg, refusal });
|
|
85
91
|
if (records.length > 0)
|
|
86
92
|
await attach(run, p.tag, s.repo, records, s.sha);
|
|
87
93
|
return {
|
|
@@ -89,7 +95,7 @@ const releaseOne = async (s, p) => {
|
|
|
89
95
|
version: p.version,
|
|
90
96
|
tag: p.tag,
|
|
91
97
|
built: records.length > 0,
|
|
92
|
-
published: !isPrivate,
|
|
98
|
+
published: !isPrivate && !refusal,
|
|
93
99
|
};
|
|
94
100
|
};
|
|
95
101
|
// Every changed extension is tried; its folder then no longer counts as a change for the next build.
|
|
@@ -98,7 +104,7 @@ const releaseAll = async (s, plan) => {
|
|
|
98
104
|
const rows = rowsOf(plan.refused, 'refused');
|
|
99
105
|
for (const p of plan.changed) {
|
|
100
106
|
const row = { id: p.id, version: p.version, result: 'released' };
|
|
101
|
-
await releaseOne(s, p).then((r) => void released.push(r), (err) => Object.assign(row, { result: 'failed', err }));
|
|
107
|
+
await releaseOne(s, p, row).then((r) => void released.push(r), (err) => Object.assign(row, { result: 'failed', err }));
|
|
102
108
|
s.written.push(p.rel);
|
|
103
109
|
rows.push(row);
|
|
104
110
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
type Rule = {
|
|
2
|
+
re: RegExp;
|
|
3
|
+
keep: boolean;
|
|
4
|
+
};
|
|
5
|
+
export declare const DEFAULT_IGNORE: string[];
|
|
6
|
+
export declare const ALWAYS_COUNTS: string[];
|
|
7
|
+
export declare const IGNORE_FILE = ".release-ignore";
|
|
8
|
+
export declare const globToRegex: (glob: string) => RegExp;
|
|
9
|
+
export declare const parseIgnore: (text: string) => Rule[];
|
|
10
|
+
export declare const isIgnored: (rules: Rule[], path: string) => boolean;
|
|
11
|
+
export type Sorted = {
|
|
12
|
+
counted: string[];
|
|
13
|
+
ignored: string[];
|
|
14
|
+
};
|
|
15
|
+
export declare const sortChanged: (root: string, rel: string, diff: string) => Promise<Sorted>;
|
|
16
|
+
export declare const firstFive: (files: string[]) => string;
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
// Anchored at the folder root: a deeper .md or docs/ may be served by the site or the image.
|
|
4
|
+
export const DEFAULT_IGNORE = [
|
|
5
|
+
'/*.md',
|
|
6
|
+
'/docs/**',
|
|
7
|
+
'/.github/**',
|
|
8
|
+
'/.repo-doctor.yml',
|
|
9
|
+
'/.gitignore',
|
|
10
|
+
'/.prettierrc*',
|
|
11
|
+
'/.editorconfig',
|
|
12
|
+
'/LICENSE',
|
|
13
|
+
];
|
|
14
|
+
// What goes into the image always counts, whatever an ignore pattern says.
|
|
15
|
+
export const ALWAYS_COUNTS = ['/package.json', '/package-lock.json', '/src/**', '/Dockerfile*'];
|
|
16
|
+
export const IGNORE_FILE = '.release-ignore';
|
|
17
|
+
const TOKENS = {
|
|
18
|
+
'**/': '(?:.*/)?',
|
|
19
|
+
'/**': '(?:/.*)?',
|
|
20
|
+
'**': '.*',
|
|
21
|
+
'*': '[^/]*',
|
|
22
|
+
'?': '[^/]',
|
|
23
|
+
};
|
|
24
|
+
// Gitignore-style: a pattern with a slash is anchored to the folder, one without matches any depth.
|
|
25
|
+
export const globToRegex = (glob) => {
|
|
26
|
+
const bare = glob.replace(/\/$/, '');
|
|
27
|
+
const anchored = bare.includes('/');
|
|
28
|
+
const body = bare
|
|
29
|
+
.replace(/^\//, '')
|
|
30
|
+
.replace(/\*\*\/|\/\*\*|\*\*|\*|\?|[.+^${}()|[\]\\]/g, (t) => TOKENS[t] ?? `\\${t}`);
|
|
31
|
+
return new RegExp(`^${anchored ? '' : '(?:.*/)?'}${body}$`);
|
|
32
|
+
};
|
|
33
|
+
const ruleOf = (line) => {
|
|
34
|
+
const keep = line.startsWith('!');
|
|
35
|
+
return { re: globToRegex(keep ? line.slice(1) : line), keep };
|
|
36
|
+
};
|
|
37
|
+
export const parseIgnore = (text) => text
|
|
38
|
+
.split('\n')
|
|
39
|
+
.map((l) => l.trim())
|
|
40
|
+
.filter((l) => l !== '' && !l.startsWith('#'))
|
|
41
|
+
.map(ruleOf);
|
|
42
|
+
// The path and each folder above it: `docs` also matches `docs/a.md`.
|
|
43
|
+
const candidates = (path) => path.split('/').map((_, i, parts) => parts.slice(0, i + 1).join('/'));
|
|
44
|
+
const hits = (re, path) => candidates(path).some((p) => re.test(p));
|
|
45
|
+
// The last matching rule wins, as in .gitignore.
|
|
46
|
+
export const isIgnored = (rules, path) => {
|
|
47
|
+
if (ALWAYS_COUNTS.some((g) => hits(globToRegex(g), path)))
|
|
48
|
+
return false;
|
|
49
|
+
let ignored = false;
|
|
50
|
+
for (const rule of rules)
|
|
51
|
+
if (hits(rule.re, path))
|
|
52
|
+
ignored = !rule.keep;
|
|
53
|
+
return ignored;
|
|
54
|
+
};
|
|
55
|
+
const rulesAt = async (dir) => {
|
|
56
|
+
const text = await readFile(join(dir, IGNORE_FILE), 'utf8').catch(() => '');
|
|
57
|
+
return parseIgnore([...DEFAULT_IGNORE, text].join('\n'));
|
|
58
|
+
};
|
|
59
|
+
// `diff` names files from the repo root; the patterns read them from the extension folder.
|
|
60
|
+
export const sortChanged = async (root, rel, diff) => {
|
|
61
|
+
const rules = await rulesAt(join(root, rel));
|
|
62
|
+
const prefix = rel === '.' ? '' : `${rel}/`;
|
|
63
|
+
const files = diff.split('\0').filter(Boolean);
|
|
64
|
+
const local = files.map((f) => f.slice(prefix.length));
|
|
65
|
+
return {
|
|
66
|
+
counted: local.filter((f) => !isIgnored(rules, f)),
|
|
67
|
+
ignored: local.filter((f) => isIgnored(rules, f)),
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
export const firstFive = (files) => {
|
|
71
|
+
const more = files.length > 5 ? ` and ${files.length - 5} more` : '';
|
|
72
|
+
return `${files.slice(0, 5).join(', ')}${more}`;
|
|
73
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { ExtensionPackage } from '@agentage/extension/tool';
|
|
2
|
+
import type { Exec } from './release-guard.js';
|
|
3
|
+
export declare const OPT_IN = "agentagePublishFromPrivateRepo";
|
|
4
|
+
export declare const amber: (line: string) => void;
|
|
5
|
+
export declare const npmRefusal: (run: Exec, repo: string, pkg: ExtensionPackage) => Promise<string | undefined>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { fail, step } from './release-steps.js';
|
|
2
|
+
// The kit refuses unknown keys under `agentage`: the opt-in is a top-level package.json key.
|
|
3
|
+
export const OPT_IN = 'agentagePublishFromPrivateRepo';
|
|
4
|
+
export const amber = (line) => console.log(`AMBER ${line}`);
|
|
5
|
+
const optedIn = (pkg) => {
|
|
6
|
+
const config = pkg['publishConfig'];
|
|
7
|
+
return config?.access === 'public' && pkg[OPT_IN] === true;
|
|
8
|
+
};
|
|
9
|
+
const howTo = `set publishConfig.access to "public" and ${OPT_IN} to true to publish it`;
|
|
10
|
+
// Only a repo GitHub names public, or an opt-in, goes to npm; no clear answer stops the release.
|
|
11
|
+
export const npmRefusal = async (run, repo, pkg) => {
|
|
12
|
+
const read = await run('gh', ['api', `repos/${repo}`, '--jq', '.private']);
|
|
13
|
+
const answer = read.out.trim();
|
|
14
|
+
if (read.ok && answer === 'false')
|
|
15
|
+
return undefined;
|
|
16
|
+
if (!read.ok || answer !== 'true')
|
|
17
|
+
fail(`npm: cannot read whether ${repo} is private (${read.err || answer || 'no answer'})`);
|
|
18
|
+
if (!optedIn(pkg))
|
|
19
|
+
return `${repo} is a private repo: npm skipped; ${howTo}`;
|
|
20
|
+
step(`npm: ${repo} is private, ${pkg.name} opts in to public npm`);
|
|
21
|
+
return undefined;
|
|
22
|
+
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { dateVersion, lastTag, newestTags, tagOf } from './release-date.js';
|
|
2
2
|
import { extensionFolders } from './release-folders.js';
|
|
3
|
+
import { firstFive, sortChanged } from './release-ignore.js';
|
|
3
4
|
import { RECORD } from './release-guard.js';
|
|
4
5
|
import { fail, step } from './release-steps.js';
|
|
5
6
|
// A build that always fails stops here: no new tag after this many tags in a row with no record.
|
|
@@ -42,15 +43,21 @@ const unrecorded = async (c, f, tags) => {
|
|
|
42
43
|
// From the last tag, not the push range: a run the concurrency group dropped is caught up here.
|
|
43
44
|
const whyOf = async (c, f, tags, last) => {
|
|
44
45
|
if (!last)
|
|
45
|
-
return `has no ${f.id}@* tag yet
|
|
46
|
+
return { why: `has no ${f.id}@* tag yet`, ignored: [] };
|
|
46
47
|
const missing = await unrecorded(c, f, tags);
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
// No renames: a move from src/ to docs/ names the src/ path; -z keeps odd names exact.
|
|
49
|
+
const args = ['diff', '--name-only', '-z', '--no-renames', last, c.sha, '--', f.rel];
|
|
50
|
+
const { counted, ignored } = await sortChanged(c.root, f.rel, await git(c.run, args, 'changed'));
|
|
51
|
+
if (counted.length > 0)
|
|
52
|
+
return { why: `differs from ${last} in ${firstFive(counted)}`, ignored };
|
|
50
53
|
// A release that failed after its tag: the next commit releases it with a new N.
|
|
51
54
|
if (missing[0] === last)
|
|
52
|
-
return `equals ${last}, which has no record
|
|
53
|
-
return
|
|
55
|
+
return { why: `equals ${last}, which has no record`, ignored };
|
|
56
|
+
return { ignored };
|
|
57
|
+
};
|
|
58
|
+
const sameAs = (f, last, ignored) => {
|
|
59
|
+
const only = ignored.length > 0 ? `; only ignored files changed: ${firstFive(ignored)}` : '';
|
|
60
|
+
step(`unchanged: ${f.id} (${f.rel}) is the same as ${String(last)}${only}`);
|
|
54
61
|
};
|
|
55
62
|
// A re-run of an old commit must not give older code a higher version than its last tag.
|
|
56
63
|
const inHistory = async (c, last, at) => {
|
|
@@ -72,10 +79,10 @@ const planOne = async (c, f) => {
|
|
|
72
79
|
return planned(f, last.slice(f.id.length + 1), `${last} is on this commit: resume it`);
|
|
73
80
|
if (last)
|
|
74
81
|
await inHistory(c, last, at);
|
|
75
|
-
const why = await whyOf(c, f, tags, last);
|
|
82
|
+
const { why, ignored } = await whyOf(c, f, tags, last);
|
|
76
83
|
if (why)
|
|
77
84
|
return planned(f, dateVersion(f.id, tags, c.now), why);
|
|
78
|
-
|
|
85
|
+
sameAs(f, last, ignored);
|
|
79
86
|
return undefined;
|
|
80
87
|
};
|
|
81
88
|
// One refused extension never stops the plan of the others.
|
|
@@ -55,6 +55,6 @@ export const addRelease = (group, release) => {
|
|
|
55
55
|
.description('Release an extension from its v* tag in CI: guard, images, one image, records, npm package')
|
|
56
56
|
.option('--dir <path>', 'the extension package folder (default: the current folder)')
|
|
57
57
|
.option('--timeout <seconds>', 'bound on each git, GitHub and npm check (default: 60; npm publish: 300)', Number)
|
|
58
|
-
.option('--changed', 'each extension (root or extensions/*) whose folder changed since its last <id>@* tag;
|
|
58
|
+
.option('--changed', 'each extension (root or extensions/*) whose folder changed since its last <id>@* tag; root docs/**, root *.md, .github/** and repo config (plus .release-ignore patterns) never trigger a release, package.json, the lock, src/** and Dockerfile* always do; a private repo skips npm unless the package opts in')
|
|
59
59
|
.option('--dry-run', 'with --changed: print what it would release, change nothing')).action(release);
|
|
60
60
|
};
|