@adea-ai/app-framework 0.28.0 → 0.28.1
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/cli/cli-runner.d.ts +4 -0
- package/dist/cli/cli-runner.js +14 -1
- package/dist/cli/release-cut-cli.js +2 -2
- package/dist/framework-source.json +1 -1
- package/dist/release/feed-release-cut.js +30 -10
- package/dist/release/github-release-cut.js +16 -0
- package/dist/release/release-cut.d.ts +8 -1
- package/dist/release/release-cut.js +9 -1
- package/package.json +1 -1
package/dist/cli/cli-runner.d.ts
CHANGED
|
@@ -4,5 +4,9 @@
|
|
|
4
4
|
export declare function runCli(failure: string | ((error: unknown) => string), main: () => unknown, options?: {
|
|
5
5
|
requireGitHubActions?: boolean;
|
|
6
6
|
}): Promise<void>;
|
|
7
|
+
/** An error's message, safe to print: local paths and URL queries are replaced by
|
|
8
|
+
* placeholders, control characters dropped and the text bounded. Use it only for commands
|
|
9
|
+
* whose errors never embed key material. */
|
|
10
|
+
export declare function redactedErrorMessage(error: unknown): string;
|
|
7
11
|
/** Parse a JSON file that is a regular file, not a link, of 1 to `maxBytes` bytes. */
|
|
8
12
|
export declare function readJsonFile(path: string, maxBytes: number): Promise<unknown>;
|
package/dist/cli/cli-runner.js
CHANGED
|
@@ -12,6 +12,19 @@ async function runCli(failure, main, options = {}) {
|
|
|
12
12
|
process.exitCode = 1;
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
|
+
var MAX_ERROR_LENGTH = 400;
|
|
16
|
+
/** An error's message, safe to print: local paths and URL queries are replaced by
|
|
17
|
+
* placeholders, control characters dropped and the text bounded. Use it only for commands
|
|
18
|
+
* whose errors never embed key material. */
|
|
19
|
+
function redactedErrorMessage(error) {
|
|
20
|
+
const raw = error instanceof Error ? error.message : String(error);
|
|
21
|
+
const redacted = Array.from(raw, (char) => {
|
|
22
|
+
const code = char.charCodeAt(0);
|
|
23
|
+
if (char === "\n" || char === " ") return " ";
|
|
24
|
+
return code < 32 || code === 127 ? "" : char;
|
|
25
|
+
}).join("").replace(/\bfile:\/\/\S+/gi, "<path>").replace(/(\bhttps?:\/\/[^\s?#'"`]+)[?#][^\s'"`]*/gi, "$1").replace(/(?<![\w.:/\\-])(?:~|[A-Za-z]:)?[\\/][^\s'"`:,;()<>]+/g, "<path>").trim();
|
|
26
|
+
return (redacted.length > MAX_ERROR_LENGTH ? `${redacted.slice(0, MAX_ERROR_LENGTH)}…` : redacted) || "Unknown error";
|
|
27
|
+
}
|
|
15
28
|
/** Parse a JSON file that is a regular file, not a link, of 1 to `maxBytes` bytes. */
|
|
16
29
|
async function readJsonFile(path, maxBytes) {
|
|
17
30
|
const info = await lstat(path);
|
|
@@ -20,4 +33,4 @@ async function readJsonFile(path, maxBytes) {
|
|
|
20
33
|
if (bytes.length !== info.size) throw new Error("Configuration file changed");
|
|
21
34
|
return JSON.parse(bytes.toString("utf8"));
|
|
22
35
|
}
|
|
23
|
-
export { readJsonFile, runCli };
|
|
36
|
+
export { readJsonFile, redactedErrorMessage, runCli };
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
|
-
import { readJsonFile, runCli } from "./cli-runner.js";
|
|
2
|
+
import { readJsonFile, redactedErrorMessage, runCli } from "./cli-runner.js";
|
|
3
3
|
import { gitCli } from "../release/local-provenance.js";
|
|
4
4
|
import { runReleaseCutCommand } from "../release/release-cut-command.js";
|
|
5
5
|
import { hostReleasePlatform, runLocalReleaseCut } from "../release/local-release.js";
|
|
6
6
|
// src/cli/release-cut-cli.ts
|
|
7
7
|
var local = process.argv[2] === "--local";
|
|
8
|
-
await runCli(
|
|
8
|
+
await runCli((error) => `Unable to cut the release: ${redactedErrorMessage(error)}. Check the trusted workflow or local checkout and release configuration.`, async () => {
|
|
9
9
|
const [kind, path, sourceSha, ...extra] = process.argv.slice(local ? 3 : 2);
|
|
10
10
|
if (kind !== "daily" && kind !== "dev" || !path || extra.length || !sourceSha !== !local) throw new Error("Invalid workflow invocation");
|
|
11
11
|
const config = await readJsonFile(path, 65536);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":"0.28.
|
|
1
|
+
{"version":"0.28.1","commit":"9ced256448ba7f6b0d77d359dc5a68157dc34dd7"}
|
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
import { gitIsAncestor } from "./local-provenance.js";
|
|
2
2
|
// src/release/feed-release-cut.ts
|
|
3
|
+
function checkVersion(version) {
|
|
4
|
+
if (typeof version !== "string" || version.length > 64 || !/^(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)$/.test(version)) throw new Error("Invalid source version");
|
|
5
|
+
}
|
|
6
|
+
/** The highest `N` among `tags` of the form `v<version>-dev.N`; 0 when none. A malformed
|
|
7
|
+
* counter fails closed, except among bare tags (`tagsOnly`), where a name that is not a
|
|
8
|
+
* canonical dev tag can never collide with a cut and is skipped. */
|
|
9
|
+
function highestCounter(tags, version, tagsOnly = false) {
|
|
10
|
+
const prefix = `v${version}-dev.`;
|
|
11
|
+
let highest = 0;
|
|
12
|
+
for (const tag of tags) {
|
|
13
|
+
if (!tag.startsWith(prefix)) continue;
|
|
14
|
+
const suffix = tag.slice(prefix.length);
|
|
15
|
+
if (!/^[1-9]\d{0,15}$/.test(suffix) || !Number.isSafeInteger(Number(suffix))) {
|
|
16
|
+
if (tagsOnly) continue;
|
|
17
|
+
throw new Error("Invalid dev release counter");
|
|
18
|
+
}
|
|
19
|
+
highest = Math.max(highest, Number(suffix));
|
|
20
|
+
}
|
|
21
|
+
return highest;
|
|
22
|
+
}
|
|
3
23
|
function checkTag(tag) {
|
|
4
24
|
if (!/^v\d+\.\d+\.\d+(?:-dev\.\d+)?$/.test(tag) || tag.length > 65) throw new Error("Invalid release tag");
|
|
5
25
|
}
|
|
@@ -66,16 +86,16 @@ function createFeedReleaseCutProvider(options) {
|
|
|
66
86
|
},
|
|
67
87
|
pendingBuild: async () => "idle",
|
|
68
88
|
async highestDevCounter(version) {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
89
|
+
checkVersion(version);
|
|
90
|
+
return highestCounter([...ledger.releases.map((item) => item.tag), ...created.keys()], version);
|
|
91
|
+
},
|
|
92
|
+
async highestDevTag(version) {
|
|
93
|
+
checkVersion(version);
|
|
94
|
+
return highestCounter((await git([
|
|
95
|
+
"tag",
|
|
96
|
+
"--list",
|
|
97
|
+
`v${version}-dev.*`
|
|
98
|
+
])).split("\n").map((line) => line.trim()).filter(Boolean), version, true);
|
|
79
99
|
},
|
|
80
100
|
async tagExists(tag) {
|
|
81
101
|
checkTag(tag);
|
|
@@ -62,6 +62,22 @@ function createGitHubReleaseCutProvider(options) {
|
|
|
62
62
|
}
|
|
63
63
|
throw new Error("Release history exceeds inspection limit");
|
|
64
64
|
},
|
|
65
|
+
async highestDevTag(version) {
|
|
66
|
+
if (typeof version !== "string" || version.length > 64 || !/^(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)$/.test(version)) throw new Error("Invalid source version");
|
|
67
|
+
const prefix = `refs/tags/v${version}-dev.`;
|
|
68
|
+
const result = await read(`${base}/git/matching-refs/tags/${encodeURIComponent(`v${version}-dev.`)}`);
|
|
69
|
+
if (!Array.isArray(result) || result.length > 1e5) throw new Error("Invalid tag history");
|
|
70
|
+
let highest = 0;
|
|
71
|
+
for (const value of result) {
|
|
72
|
+
const ref = value?.ref;
|
|
73
|
+
if (typeof ref !== "string") throw new Error("Invalid tag history");
|
|
74
|
+
if (!ref.startsWith(prefix)) continue;
|
|
75
|
+
const suffix = ref.slice(prefix.length);
|
|
76
|
+
if (!/^[1-9]\d{0,15}$/.test(suffix) || !Number.isSafeInteger(Number(suffix))) continue;
|
|
77
|
+
highest = Math.max(highest, Number(suffix));
|
|
78
|
+
}
|
|
79
|
+
return highest;
|
|
80
|
+
},
|
|
65
81
|
async find(tag) {
|
|
66
82
|
if (!/^v\d+\.\d+\.\d+(?:-dev\.\d+)?$/.test(tag) || tag.length > 65) throw new Error("Invalid release tag");
|
|
67
83
|
const kind = tag.includes("-dev.") ? "dev" : "daily";
|
|
@@ -20,6 +20,10 @@ export type ReleaseCutProvider = {
|
|
|
20
20
|
pendingBuild(release: CutRelease): Promise<'pending' | 'idle' | 'unknown'>;
|
|
21
21
|
/** Inspect all existing dev releases of a dev version line; errors must fail closed. */
|
|
22
22
|
highestDevCounter(version: string): Promise<number>;
|
|
23
|
+
/** The highest dev counter among the Git tags of a dev version line, with or without a
|
|
24
|
+
* release (0 when none). A tag left by an earlier release system or a deleted release keeps
|
|
25
|
+
* its counter taken, so a new cut numbers above it instead of colliding. */
|
|
26
|
+
highestDevTag(version: string): Promise<number>;
|
|
23
27
|
/** Check the actual Git tag even when no release exists. */
|
|
24
28
|
tagExists(tag: string): Promise<boolean>;
|
|
25
29
|
dispatch(tag: string): Promise<void>;
|
|
@@ -39,7 +43,10 @@ export declare function nextDevVersion(released: string): string;
|
|
|
39
43
|
* `v<next>-dev.N` for the next unreleased version (see `nextDevVersion`), where N counts
|
|
40
44
|
* that version's dev releases from 1, so it starts again at 1 when a release moves the
|
|
41
45
|
* next version: `v0.112.0-dev.15` is followed, after the `v0.112.0` release, by
|
|
42
|
-
* `v0.113.0-dev.1`.
|
|
46
|
+
* `v0.113.0-dev.1`. A new cut also numbers above every existing dev tag of the version,
|
|
47
|
+
* so tags with no trusted release (from an earlier release system) are skipped, never
|
|
48
|
+
* reused or moved: with `v0.73.0-dev.1` and `dev.2` tagged but unreleased, the cut is
|
|
49
|
+
* `v0.73.0-dev.3`.
|
|
43
50
|
*/
|
|
44
51
|
export declare function cutRelease(options: {
|
|
45
52
|
kind: 'dev' | 'daily';
|
|
@@ -18,7 +18,10 @@ function nextDevVersion(released) {
|
|
|
18
18
|
* `v<next>-dev.N` for the next unreleased version (see `nextDevVersion`), where N counts
|
|
19
19
|
* that version's dev releases from 1, so it starts again at 1 when a release moves the
|
|
20
20
|
* next version: `v0.112.0-dev.15` is followed, after the `v0.112.0` release, by
|
|
21
|
-
* `v0.113.0-dev.1`.
|
|
21
|
+
* `v0.113.0-dev.1`. A new cut also numbers above every existing dev tag of the version,
|
|
22
|
+
* so tags with no trusted release (from an earlier release system) are skipped, never
|
|
23
|
+
* reused or moved: with `v0.73.0-dev.1` and `dev.2` tagged but unreleased, the cut is
|
|
24
|
+
* `v0.73.0-dev.3`.
|
|
22
25
|
*/
|
|
23
26
|
async function cutRelease(options) {
|
|
24
27
|
const { kind, sourceSha, releasedVersion, provider } = options;
|
|
@@ -33,6 +36,11 @@ async function cutRelease(options) {
|
|
|
33
36
|
if (highest > 0 && !newest) throw new Error("Dev release history changed");
|
|
34
37
|
if (newest && newest.sourceSha !== sourceSha && !await provider.isAncestor(newest.sourceSha, sourceSha)) throw new Error("Dev release source is not newer than the last dev release");
|
|
35
38
|
count = newest?.sourceSha === sourceSha ? highest : highest + 1;
|
|
39
|
+
if (count > highest) {
|
|
40
|
+
const tagged = await provider.highestDevTag(version);
|
|
41
|
+
if (!Number.isSafeInteger(tagged) || tagged < 0) throw new Error("Dev tag history is invalid");
|
|
42
|
+
count = Math.max(count, tagged + 1);
|
|
43
|
+
}
|
|
36
44
|
}
|
|
37
45
|
const tag = `v${version}${kind === "dev" ? `-dev.${count}` : ""}`;
|
|
38
46
|
let release = await provider.find(tag);
|