@intellectual-frontiers/libraries 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +8 -2
- package/dist/affected.d.ts +28 -0
- package/dist/affected.js +250 -0
- package/dist/changes.d.ts +27 -0
- package/dist/changes.js +470 -0
- package/dist/check.d.ts +15 -0
- package/dist/check.js +198 -0
- package/dist/generate-ontology.d.ts +37 -0
- package/dist/generate-ontology.js +293 -0
- package/dist/generate-workflows.d.ts +12 -0
- package/dist/generate-workflows.js +102 -0
- package/dist/imports/nist-sp-800-53.import.d.ts +33 -0
- package/dist/imports/nist-sp-800-53.import.js +34 -0
- package/dist/imports/schema-org.import.d.ts +33 -0
- package/dist/imports/schema-org.import.js +31 -0
- package/dist/install-bun.d.ts +1 -0
- package/dist/install-bun.js +58 -0
- package/dist/libraries.d.ts +79 -0
- package/dist/libraries.js +386 -0
- package/dist/mod.d.ts +16 -0
- package/dist/mod.js +16 -0
- package/dist/newer.d.ts +27 -0
- package/dist/newer.js +147 -0
- package/dist/oscal-register.d.ts +65 -0
- package/dist/oscal-register.js +344 -0
- package/dist/pack-library.d.ts +47 -0
- package/dist/pack-library.js +498 -0
- package/dist/pins.d.ts +15 -0
- package/dist/pins.js +29 -0
- package/dist/publish-ontology.d.ts +160 -0
- package/dist/publish-ontology.js +227 -0
- package/dist/versions.d.ts +26 -0
- package/dist/versions.js +556 -0
- package/dist/workflows/definitions.d.ts +65 -0
- package/dist/workflows/definitions.js +619 -0
- package/dist/workflows/mod.d.ts +10 -0
- package/dist/workflows/mod.js +10 -0
- package/dist/workflows/model.d.ts +143 -0
- package/dist/workflows/model.js +81 -0
- package/dist/workflows/render.d.ts +9 -0
- package/dist/workflows/render.js +179 -0
- package/package.json +129 -4
- package/src/affected.ts +265 -0
- package/src/changes.ts +546 -0
- package/src/check.ts +223 -0
- package/src/generate-ontology.ts +350 -0
- package/src/generate-workflows.ts +103 -0
- package/src/imports/nist-sp-800-53.import.ts +36 -0
- package/src/imports/schema-org.import.ts +31 -0
- package/src/install-bun.ts +53 -0
- package/src/libraries.ts +385 -0
- package/src/mod.ts +16 -0
- package/src/newer.ts +154 -0
- package/src/oscal-register.ts +443 -0
- package/src/pack-library.ts +522 -0
- package/src/pins.ts +30 -0
- package/src/publish-ontology.ts +354 -0
- package/src/versions.ts +594 -0
- package/src/workflows/definitions.ts +855 -0
- package/src/workflows/mod.ts +30 -0
- package/src/workflows/model.ts +187 -0
- package/src/workflows/render.ts +176 -0
package/dist/check.js
ADDED
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Check a Mizan folder against the rules Mizan adds to the format (commons 0003-mizan FR-013 to FR-015, 0018-standards-first FR-009).
|
|
3
|
+
*
|
|
4
|
+
* bun commons/libraries/src/check.ts check commons/spec-kit against commons/spec-kit/mizan.baseline.txt
|
|
5
|
+
* bun commons/libraries/src/check.ts --root DIR check DIR (a folder holding specs/)
|
|
6
|
+
* bun commons/libraries/src/check.ts --register DIR the folder of the registers (and of the baseline, `mizan.baseline.txt` beside `registry.tsv`) where it is not the root
|
|
7
|
+
* bun commons/libraries/src/check.ts --defined-by also hold commons' own terms to the requirement-to-term stage (0003-mizan FR-044), which a harness turns on with `specTerms.definitions`
|
|
8
|
+
* bun commons/libraries/src/check.ts --baseline FILE hold the findings against FILE
|
|
9
|
+
* bun commons/libraries/src/check.ts --write-baseline write the baseline from today's findings (to start it, or to shrink it: never to add a line to pass)
|
|
10
|
+
* bun commons/libraries/src/check.ts --level L0|L1|L2|L3 hold the folder to the rules of that conformance level only (commons 0028-conformance-levels; L3, every rule, where it is not given)
|
|
11
|
+
* bun commons/libraries/src/check.ts --all [--repo DIR] also run the `verify` of every library a manifest declares, each from its folder (the libraries of DIR, this repository by default); without it nothing inside a library is read
|
|
12
|
+
* bun commons/libraries/src/check.ts --today YYYY-MM-DD count the 90 days of a decision from that day (for a test); commons' own folder also holds its ontologies' terms to 0018-standards-first FR-003 to FR-005
|
|
13
|
+
*
|
|
14
|
+
* It prints every new finding and every stale baseline line on standard error, writes nothing without `--write-baseline`, and exits 1 where a finding is new or a baseline
|
|
15
|
+
* line no longer occurs, so that the baseline only shrinks (0003-mizan FR-015). The rules are plugins (`rules.ts`); this file only reads the folder and judges.
|
|
16
|
+
*
|
|
17
|
+
* Spec: 0001-libraries FR-008
|
|
18
|
+
*
|
|
19
|
+
* @module
|
|
20
|
+
*/
|
|
21
|
+
import { fileURLToPath } from "node:url";
|
|
22
|
+
import process from "node:process";
|
|
23
|
+
import { stdio } from "@intellectual-frontiers/system";
|
|
24
|
+
import { packagingTerms } from "@intellectual-frontiers/ontology/audit";
|
|
25
|
+
import { audienceModels, bases, classes, conformanceLevels, conformanceRequirements, jurisdictionLevels, integrationDirections, rungKinds, subjectKinds, mz, terms, } from "@intellectual-frontiers/ontology/mizan";
|
|
26
|
+
import * as ifccmOntology from "@intellectual-frontiers/ontology/ifccm";
|
|
27
|
+
import * as ifrOntology from "@intellectual-frontiers/ontology/ifr";
|
|
28
|
+
import * as ifqsOntology from "@intellectual-frontiers/ontology/ifqs";
|
|
29
|
+
import { pm } from "@intellectual-frontiers/ontology/supply-chain/packaging";
|
|
30
|
+
import { rulePlugins } from "@intellectual-frontiers/mizan/rules";
|
|
31
|
+
import { holdHarness } from "@intellectual-frontiers/mizan/harness";
|
|
32
|
+
import { DEFAULT_LEVEL, LEVELS, levelOf } from "@intellectual-frontiers/mizan/levels";
|
|
33
|
+
import { verifyAll } from "./libraries.js";
|
|
34
|
+
import { readWorks } from "@intellectual-frontiers/mizan/versions/scan";
|
|
35
|
+
import { BASELINE_COMMENTS, readSpecTexts } from "@intellectual-frontiers/mizan/spec-files";
|
|
36
|
+
import { definitionsOf } from "@intellectual-frontiers/mizan/spec-terms";
|
|
37
|
+
export { BASELINE_COMMENTS, readSpecTexts };
|
|
38
|
+
/** The records of an audit of terms as the rules read them: each term of a vocabulary and the basis it rests on (0018-standards-first FR-003 to FR-005). */
|
|
39
|
+
export function termRecordsOf(audit) {
|
|
40
|
+
const kinds = new Map([
|
|
41
|
+
[bases.Adopts.iri, "adopts"],
|
|
42
|
+
[bases.Specializes.iri, "specializes"],
|
|
43
|
+
[bases.Maps.iri, "maps"],
|
|
44
|
+
[bases.Unaligned.iri, "unaligned"],
|
|
45
|
+
]);
|
|
46
|
+
return audit.map((t) => ({
|
|
47
|
+
iri: t.values.termIri,
|
|
48
|
+
basis: kinds.get(t.values.basis.iri) ?? "unaligned",
|
|
49
|
+
...(t.values.standardTerm === undefined ? {} : { standardTerm: t.values.standardTerm }),
|
|
50
|
+
...(t.values.justification === undefined ? {} : { justification: t.values.justification }),
|
|
51
|
+
...(t.values.addedOn === undefined ? {} : { addedOn: t.values.addedOn }),
|
|
52
|
+
decision: t.values.decision !== undefined,
|
|
53
|
+
...(t.values.deprecatedOn === undefined ? {} : { deprecatedOn: t.values.deprecatedOn }),
|
|
54
|
+
...(t.values.replacedBy === undefined ? {} : { replacedBy: t.values.replacedBy }),
|
|
55
|
+
...(t.values.definedBy === undefined ? {} : { definedBy: t.values.definedBy }),
|
|
56
|
+
}));
|
|
57
|
+
}
|
|
58
|
+
/** Mizan's own terms and the packaging ontology's as the rules read them. */
|
|
59
|
+
export function mizanTermRecords() {
|
|
60
|
+
return termRecordsOf([...terms, ...packagingTerms, ...ifccmOntology.terms, ...ifqsOntology.terms, ...ifrOntology.terms]);
|
|
61
|
+
}
|
|
62
|
+
/** The prefixes of commons' own ontologies and their namespaces. */
|
|
63
|
+
const PREFIXES = {
|
|
64
|
+
mz: "https://www.intellectualfrontiers.com/ontology/mizan#",
|
|
65
|
+
pm: "https://www.intellectualfrontiers.com/ontology/packaging#",
|
|
66
|
+
ifccm: ifccmOntology.IFCCM.iri,
|
|
67
|
+
ifqs: ifqsOntology.IFQS.iri,
|
|
68
|
+
ifr: ifrOntology.IFR.iri,
|
|
69
|
+
};
|
|
70
|
+
/** The CURIE of a term of commons' own ontologies: `mz:` or `pm:` and its local name, or the IRI where it is of neither. */
|
|
71
|
+
function curieOf(iri) {
|
|
72
|
+
for (const [prefix, ns] of Object.entries(PREFIXES))
|
|
73
|
+
if (iri.startsWith(ns))
|
|
74
|
+
return `${prefix}:${iri.slice(ns.length)}`;
|
|
75
|
+
return iri;
|
|
76
|
+
}
|
|
77
|
+
/** The deprecated terms of commons' own ontologies, by CURIE, with what replaces each (0018-standards-first): a specification that names one is found. */
|
|
78
|
+
export function deprecatedTerms() {
|
|
79
|
+
return new Map([...terms, ...packagingTerms, ...ifccmOntology.terms, ...ifqsOntology.terms, ...ifrOntology.terms].flatMap((t) => t.values.deprecatedOn === undefined ? [] : [[curieOf(t.values.termIri), curieOf(t.values.replacedBy ?? "")]]));
|
|
80
|
+
}
|
|
81
|
+
/** The command line. Returns the exit status: 0, or 1 where a finding is new or a baseline line is stale. */
|
|
82
|
+
export function main(argv, plugins = rulePlugins, today = new Date().toISOString().slice(0, 10)) {
|
|
83
|
+
const arg = (name) => {
|
|
84
|
+
const i = argv.indexOf(name);
|
|
85
|
+
return i >= 0 ? argv[i + 1] : undefined;
|
|
86
|
+
};
|
|
87
|
+
const root = arg("--root") ?? fileURLToPath(new URL("../../spec-kit", import.meta.url));
|
|
88
|
+
const own = arg("--root") === undefined;
|
|
89
|
+
const asked = arg("--level");
|
|
90
|
+
const level = asked === undefined ? DEFAULT_LEVEL : levelOf(asked);
|
|
91
|
+
if (level === undefined) {
|
|
92
|
+
stdio.stderr.writeSync(`check: --level ${asked ?? ""} is not a conformance level; the levels are ${LEVELS.join(", ")}\n`);
|
|
93
|
+
return 2;
|
|
94
|
+
}
|
|
95
|
+
return holdHarness({
|
|
96
|
+
level,
|
|
97
|
+
root,
|
|
98
|
+
baselineFile: arg("--baseline") ?? `${(arg("--register") ?? root).replace(/[\\/]$/, "")}/mizan.baseline.txt`,
|
|
99
|
+
today: arg("--today") ?? today,
|
|
100
|
+
plugins,
|
|
101
|
+
writeBaseline: argv.includes("--write-baseline"),
|
|
102
|
+
// commons' own folder (no --root) also holds its ontologies to the standards rules (0018-standards-first FR-001, FR-003, FR-005)
|
|
103
|
+
...(own
|
|
104
|
+
? {
|
|
105
|
+
works: readWorks(fileURLToPath(new URL("../../..", import.meta.url))),
|
|
106
|
+
terms: mizanTermRecords(),
|
|
107
|
+
termsFile: "commons/ontology",
|
|
108
|
+
completeness: [
|
|
109
|
+
{
|
|
110
|
+
file: "commons/ontology/src/audit/packaging.ts",
|
|
111
|
+
ontology: Object.values(pm).map((t) => t.iri),
|
|
112
|
+
recorded: packagingTerms.map((t) => t.values.termIri),
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
file: "commons/ontology/src/mizan/mizan.ts",
|
|
116
|
+
ontology: classes.map((c) => c.iri),
|
|
117
|
+
recorded: terms.map((t) => t.values.termIri),
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
file: "commons/ontology/src/ifccm/ifccm.ts",
|
|
121
|
+
ontology: ifccmOntology.classes.map((c) => c.iri),
|
|
122
|
+
recorded: ifccmOntology.terms.map((t) => t.values.termIri),
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
file: "commons/ontology/src/ifqs/ifqs.ts",
|
|
126
|
+
ontology: ifqsOntology.classes.map((c) => c.iri),
|
|
127
|
+
recorded: ifqsOntology.terms.map((t) => t.values.termIri),
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
file: "commons/ontology/src/ifr/ifr.ts",
|
|
131
|
+
ontology: ifrOntology.classes.map((c) => c.iri),
|
|
132
|
+
recorded: ifrOntology.terms.map((t) => t.values.termIri),
|
|
133
|
+
},
|
|
134
|
+
],
|
|
135
|
+
specTerms: {
|
|
136
|
+
known: {
|
|
137
|
+
mz: new Set([
|
|
138
|
+
...Object.keys(mz),
|
|
139
|
+
...Object.keys(bases),
|
|
140
|
+
...Object.keys(jurisdictionLevels),
|
|
141
|
+
...Object.keys(integrationDirections),
|
|
142
|
+
...Object.keys(rungKinds),
|
|
143
|
+
...Object.keys(conformanceLevels),
|
|
144
|
+
...Object.keys(conformanceRequirements),
|
|
145
|
+
...Object.keys(subjectKinds),
|
|
146
|
+
...Object.keys(audienceModels),
|
|
147
|
+
]),
|
|
148
|
+
pm: new Set(Object.keys(pm)),
|
|
149
|
+
ifr: ifrOntology.termNames,
|
|
150
|
+
ifccm: new Set([
|
|
151
|
+
...Object.keys(ifccmOntology.ifccm),
|
|
152
|
+
...[
|
|
153
|
+
ifccmOntology.changeRequestKinds,
|
|
154
|
+
ifccmOntology.changeRequestStates,
|
|
155
|
+
ifccmOntology.issueReferenceKinds,
|
|
156
|
+
ifccmOntology.enforcementPhases,
|
|
157
|
+
ifccmOntology.regulatedDomains,
|
|
158
|
+
ifccmOntology.traceStages,
|
|
159
|
+
ifccmOntology.authorityFunctions,
|
|
160
|
+
ifccmOntology.gitCapabilities,
|
|
161
|
+
ifccmOntology.gitManagerKinds,
|
|
162
|
+
].flatMap((l) => Object.keys(l)),
|
|
163
|
+
]),
|
|
164
|
+
ifqs: new Set([
|
|
165
|
+
...Object.keys(ifqsOntology.ifqs),
|
|
166
|
+
...[
|
|
167
|
+
ifqsOntology.evidenceGrades,
|
|
168
|
+
ifqsOntology.testOutcomes,
|
|
169
|
+
ifqsOntology.freshnessStates,
|
|
170
|
+
ifqsOntology.nonconformanceStates,
|
|
171
|
+
ifqsOntology.capaStates,
|
|
172
|
+
ifqsOntology.qualityTiers,
|
|
173
|
+
ifqsOntology.audiences,
|
|
174
|
+
].flatMap((l) => Object.keys(l)),
|
|
175
|
+
]),
|
|
176
|
+
},
|
|
177
|
+
deprecated: deprecatedTerms(),
|
|
178
|
+
// the requirement-to-term stage (0003-mizan FR-044) is opt-in for commons' own folder: its findings are not put in the baseline, which only shrinks
|
|
179
|
+
...(argv.includes("--defined-by") ? { definitions: definitionsOf(mizanTermRecords(), PREFIXES) } : {}),
|
|
180
|
+
},
|
|
181
|
+
}
|
|
182
|
+
: {}),
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
/** The command, with `--all` (0028-conformance-levels FR-012): the check, and then the `verify` of every library a manifest declares, each named with its status. Returns the exit status. */
|
|
186
|
+
export async function run(argv) {
|
|
187
|
+
const checked = main(argv);
|
|
188
|
+
if (!argv.includes("--all"))
|
|
189
|
+
return checked;
|
|
190
|
+
const at = argv.indexOf("--repo");
|
|
191
|
+
const repo = at >= 0 ? (argv[at + 1] ?? ".") : fileURLToPath(new URL("../../..", import.meta.url));
|
|
192
|
+
const results = await verifyAll(repo);
|
|
193
|
+
for (const r of results)
|
|
194
|
+
stdio.stderr.writeSync(`verify ${r.name}: ${r.code === 0 ? "passed" : `FAILED (exit ${r.code})`}\n`);
|
|
195
|
+
return checked === 0 && results.every((r) => r.code === 0) ? 0 : checked === 2 ? 2 : 1;
|
|
196
|
+
}
|
|
197
|
+
if (import.meta.main)
|
|
198
|
+
process.exitCode = await run(process.argv.slice(2));
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { type OntologyFile } from "@intellectual-frontiers/rdf";
|
|
2
|
+
import { digestOf as digestOfFiles, ExportRefused, type OntologyPublication } from "./publish-ontology.js";
|
|
3
|
+
export { ExportRefused };
|
|
4
|
+
/** The command that writes the file again. */
|
|
5
|
+
export declare const RUN = "bun commons/libraries/src/generate-ontology.ts";
|
|
6
|
+
/** Where the Turtle is written, from commons' folder. */
|
|
7
|
+
export declare const TURTLE_PATH = "generated/mizan.auto.ttl";
|
|
8
|
+
/** Mizan's own ontology, as it is published (0019-mizan-integrations FR-010 to FR-019). */
|
|
9
|
+
export declare const MIZAN: OntologyPublication;
|
|
10
|
+
/** The ontology of Intellectual Frontiers Capabilities Configuration Management (commons 0020-ifccm), as it is published. */
|
|
11
|
+
export declare const IFCCM: OntologyPublication;
|
|
12
|
+
/** The ontology of the Intellectual Frontiers Quality System (commons 0021-ifqs, 0022-trust), as it is published. */
|
|
13
|
+
export declare const IFQS: OntologyPublication;
|
|
14
|
+
/** The ontology of Intellectual Frontiers Releases (commons 0026-works-versioning), as it is published. */
|
|
15
|
+
export declare const IFR: OntologyPublication;
|
|
16
|
+
/** The ontologies of commons that are published, each from its own typed modules: Mizan's, then the ones its specifications define. */
|
|
17
|
+
export declare const publications: readonly OntologyPublication[];
|
|
18
|
+
/** The exports of the ontology (0019-mizan-integrations FR-010): everything but its Turtle, by its path from commons' folder. */
|
|
19
|
+
export declare function exportsOf(auditDigest: string): Promise<ReadonlyMap<string, string>>;
|
|
20
|
+
/** Every file the ontologies make, by its path from commons' folder, in the order they are written. */
|
|
21
|
+
export declare function wanted(): Promise<ReadonlyMap<string, string>>;
|
|
22
|
+
/** The SHA-256 of the ontology's canonical N-Triples (0012-ontology FR-012): it changes with a fact, never with the layout of a module. */
|
|
23
|
+
export declare const digestOf: typeof digestOfFiles;
|
|
24
|
+
/** The text of an exporter's result, or a thrown sentence naming what the ontology states that the form cannot hold (`main` turns it into exit 2). */
|
|
25
|
+
export declare function textOf(r: {
|
|
26
|
+
readonly kind: "ok";
|
|
27
|
+
readonly value: string;
|
|
28
|
+
} | {
|
|
29
|
+
readonly kind: "err";
|
|
30
|
+
readonly error: readonly string[];
|
|
31
|
+
}, what: string): string;
|
|
32
|
+
/** The findings a rule of the kernel finds in the ontology, one sentence each; none where it is sound. */
|
|
33
|
+
export declare function findingsOf(of: readonly OntologyFile[]): readonly string[];
|
|
34
|
+
/** The ontology as canonical Turtle: every file's individuals, with every file's prefixes. */
|
|
35
|
+
export declare function turtleOf(of: readonly OntologyFile[], digest: string, source?: string): string;
|
|
36
|
+
/** The command line: write the files, or with `--check` say whether they are what the ontology makes. Returns the exit status (0, 1 stale, 2 the ontology breaks a rule). */
|
|
37
|
+
export declare function main(argv: readonly string[], commons?: string): Promise<number>;
|
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generate the Mizan ontology's Turtle from its TypeScript (commons 0012-ontology FR-011, 0016-ladder).
|
|
3
|
+
*
|
|
4
|
+
* bun commons/libraries/src/generate-ontology.ts write commons/generated/mizan.auto.ttl
|
|
5
|
+
* bun commons/libraries/src/generate-ontology.ts --check exit 1, writing nothing, where the file is not what the ontology makes
|
|
6
|
+
*
|
|
7
|
+
* The ontology (commons/ontology/src/mizan/*.ts) is the source, read as the typed values it is; the Turtle is never edited by hand. The ontology is checked first: a rule
|
|
8
|
+
* it breaks stops the run (exit 2) with every finding named.
|
|
9
|
+
*
|
|
10
|
+
* Spec: 0001-libraries FR-008
|
|
11
|
+
*
|
|
12
|
+
* @module
|
|
13
|
+
*/
|
|
14
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
15
|
+
import process from "node:process";
|
|
16
|
+
import { fileURLToPath } from "node:url";
|
|
17
|
+
import { files as auditFiles, packagingTerms } from "@intellectual-frontiers/ontology/audit";
|
|
18
|
+
import { Authority, bases, classes, Decision, files, integrationDirections, rungKinds, Jurisdiction, jurisdictionLevels, MZ, MZID, OntologyTerm, mizanOntology, properties, Rung, Standard, terms, } from "@intellectual-frontiers/ontology/mizan";
|
|
19
|
+
import * as ifccmOntology from "@intellectual-frontiers/ontology/ifccm";
|
|
20
|
+
import * as ifrOntology from "@intellectual-frontiers/ontology/ifr";
|
|
21
|
+
import * as ifqsOntology from "@intellectual-frontiers/ontology/ifqs";
|
|
22
|
+
import { formatRdfFinding, validate } from "@intellectual-frontiers/rdf";
|
|
23
|
+
import { stdio } from "@intellectual-frontiers/system";
|
|
24
|
+
import { exportDcat } from "@intellectual-frontiers/mizan/integrations/pure/export-dcat";
|
|
25
|
+
import { CC0, digestOf as digestOfFiles, distributionsOf, ExportRefused, listsOf, membersOf, publishedFiles, textOf as textOfResult, turtleOf as turtleOfFiles, } from "./publish-ontology.js";
|
|
26
|
+
export { ExportRefused };
|
|
27
|
+
/** The command that writes the file again. */
|
|
28
|
+
export const RUN = "bun commons/libraries/src/generate-ontology.ts";
|
|
29
|
+
/** Where the Turtle is written, from commons' folder. */
|
|
30
|
+
export const TURTLE_PATH = "generated/mizan.auto.ttl";
|
|
31
|
+
/** Mizan's own ontology, as it is published (0019-mizan-integrations FR-010 to FR-019). */
|
|
32
|
+
export const MIZAN = {
|
|
33
|
+
name: "mizan",
|
|
34
|
+
ns: { prefix: "mz", iri: MZ.iri },
|
|
35
|
+
idNs: { prefix: "mzid", iri: MZID.iri },
|
|
36
|
+
curies: [
|
|
37
|
+
["mz", MZ.iri],
|
|
38
|
+
["xsd", "http://www.w3.org/2001/XMLSchema#"],
|
|
39
|
+
["rdfs", "http://www.w3.org/2000/01/rdf-schema#"],
|
|
40
|
+
["skos", "http://www.w3.org/2004/02/skos/core#"],
|
|
41
|
+
["dcterms", "http://purl.org/dc/terms/"],
|
|
42
|
+
["pm", "https://www.intellectualfrontiers.com/ontology/packaging#"],
|
|
43
|
+
["schema", "https://schema.org/"],
|
|
44
|
+
],
|
|
45
|
+
files,
|
|
46
|
+
ontology: mizanOntology,
|
|
47
|
+
classes,
|
|
48
|
+
properties,
|
|
49
|
+
terms: [...terms, ...packagingTerms],
|
|
50
|
+
schemas: [Rung, Jurisdiction, Authority, Standard, Decision, OntologyTerm],
|
|
51
|
+
lists: [
|
|
52
|
+
{ name: "Basis", table: "mizan_basis", members: membersOf(bases) },
|
|
53
|
+
{ name: "JurisdictionLevel", table: "mizan_jurisdiction_level", members: membersOf(jurisdictionLevels) },
|
|
54
|
+
{ name: "RungKind", table: "mizan_rung_kind", members: membersOf(rungKinds) },
|
|
55
|
+
{ name: "IntegrationDirection", table: "mizan_integration_direction", members: membersOf(integrationDirections) },
|
|
56
|
+
],
|
|
57
|
+
source: "commons/ontology/src/mizan/*.ts (commons 0016-ladder, 0018-standards-first, 0012-ontology FR-011)",
|
|
58
|
+
run: RUN,
|
|
59
|
+
shapes: { prefix: "mzsh", iri: "https://www.intellectualfrontiers.com/ontology/mizan-shapes#" },
|
|
60
|
+
schemasIri: "https://www.intellectualfrontiers.com/ontology/mizan-schemas",
|
|
61
|
+
sssomSetId: "https://www.intellectualfrontiers.com/ontology/mizan-mappings",
|
|
62
|
+
sssomCuries: {
|
|
63
|
+
dcterms: "http://purl.org/dc/terms/",
|
|
64
|
+
pm: "https://www.intellectualfrontiers.com/ontology/packaging#",
|
|
65
|
+
schema: "https://schema.org/",
|
|
66
|
+
},
|
|
67
|
+
viewTitle: "Mizan: the shared ontology",
|
|
68
|
+
license: CC0,
|
|
69
|
+
};
|
|
70
|
+
/** The ontology of Intellectual Frontiers Capabilities Configuration Management (commons 0020-ifccm), as it is published. */
|
|
71
|
+
export const IFCCM = {
|
|
72
|
+
name: "ifccm",
|
|
73
|
+
ns: { prefix: "ifccm", iri: ifccmOntology.IFCCM.iri },
|
|
74
|
+
idNs: { prefix: "mzid", iri: MZID.iri },
|
|
75
|
+
curies: [
|
|
76
|
+
["ifccm", ifccmOntology.IFCCM.iri],
|
|
77
|
+
["mz", MZ.iri],
|
|
78
|
+
["xsd", "http://www.w3.org/2001/XMLSchema#"],
|
|
79
|
+
["rdfs", "http://www.w3.org/2000/01/rdf-schema#"],
|
|
80
|
+
["skos", "http://www.w3.org/2004/02/skos/core#"],
|
|
81
|
+
["dcterms", "http://purl.org/dc/terms/"],
|
|
82
|
+
["prov", "http://www.w3.org/ns/prov#"],
|
|
83
|
+
["oslc_cm", "http://open-services.net/ns/cm#"],
|
|
84
|
+
],
|
|
85
|
+
files: ifccmOntology.files,
|
|
86
|
+
ontology: ifccmOntology.ifccmOntology,
|
|
87
|
+
classes: ifccmOntology.classes,
|
|
88
|
+
properties: ifccmOntology.properties,
|
|
89
|
+
terms: ifccmOntology.terms,
|
|
90
|
+
schemas: [
|
|
91
|
+
ifccmOntology.Capability,
|
|
92
|
+
ifccmOntology.ChangeRequest,
|
|
93
|
+
ifccmOntology.Change,
|
|
94
|
+
ifccmOntology.ConfigurationItem,
|
|
95
|
+
ifccmOntology.Baseline,
|
|
96
|
+
ifccmOntology.HarnessDeclaration,
|
|
97
|
+
ifccmOntology.RegulatedDomain,
|
|
98
|
+
ifccmOntology.TraceStage,
|
|
99
|
+
ifccmOntology.AuthorityFunction,
|
|
100
|
+
],
|
|
101
|
+
lists: listsOf("ifccm", [
|
|
102
|
+
["ChangeRequestKind", ifccmOntology.changeRequestKinds],
|
|
103
|
+
["ChangeRequestState", ifccmOntology.changeRequestStates],
|
|
104
|
+
["IssueReferenceKind", ifccmOntology.issueReferenceKinds],
|
|
105
|
+
["EnforcementPhase", ifccmOntology.enforcementPhases],
|
|
106
|
+
["RegulatedDomain", ifccmOntology.regulatedDomains],
|
|
107
|
+
["TraceStage", ifccmOntology.traceStages],
|
|
108
|
+
["AuthorityFunction", ifccmOntology.authorityFunctions],
|
|
109
|
+
["GitCapability", ifccmOntology.gitCapabilities],
|
|
110
|
+
["GitManagerKind", ifccmOntology.gitManagerKinds],
|
|
111
|
+
]),
|
|
112
|
+
source: "commons/ontology/src/ifccm/*.ts",
|
|
113
|
+
run: RUN,
|
|
114
|
+
shapes: { prefix: "ifccmsh", iri: "https://www.intellectualfrontiers.com/ontology/ifccm-shapes#" },
|
|
115
|
+
schemasIri: "https://www.intellectualfrontiers.com/ontology/ifccm-schemas",
|
|
116
|
+
sssomSetId: "https://www.intellectualfrontiers.com/ontology/ifccm-mappings",
|
|
117
|
+
sssomCuries: { dcterms: "http://purl.org/dc/terms/", prov: "http://www.w3.org/ns/prov#", oslc_cm: "http://open-services.net/ns/cm#" },
|
|
118
|
+
viewTitle: "Intellectual Frontiers Capabilities Configuration Management: the ontology",
|
|
119
|
+
license: CC0,
|
|
120
|
+
};
|
|
121
|
+
/** The ontology of the Intellectual Frontiers Quality System (commons 0021-ifqs, 0022-trust), as it is published. */
|
|
122
|
+
export const IFQS = {
|
|
123
|
+
name: "ifqs",
|
|
124
|
+
ns: { prefix: "ifqs", iri: ifqsOntology.IFQS.iri },
|
|
125
|
+
idNs: { prefix: "mzid", iri: MZID.iri },
|
|
126
|
+
curies: [
|
|
127
|
+
["ifqs", ifqsOntology.IFQS.iri],
|
|
128
|
+
["mz", MZ.iri],
|
|
129
|
+
["xsd", "http://www.w3.org/2001/XMLSchema#"],
|
|
130
|
+
["rdfs", "http://www.w3.org/2000/01/rdf-schema#"],
|
|
131
|
+
["skos", "http://www.w3.org/2004/02/skos/core#"],
|
|
132
|
+
["dcterms", "http://purl.org/dc/terms/"],
|
|
133
|
+
["prov", "http://www.w3.org/ns/prov#"],
|
|
134
|
+
["dcat", "http://www.w3.org/ns/dcat#"],
|
|
135
|
+
],
|
|
136
|
+
files: ifqsOntology.files,
|
|
137
|
+
ontology: ifqsOntology.ifqsOntology,
|
|
138
|
+
classes: ifqsOntology.classes,
|
|
139
|
+
properties: ifqsOntology.properties,
|
|
140
|
+
terms: ifqsOntology.terms,
|
|
141
|
+
schemas: [
|
|
142
|
+
ifqsOntology.TestRun,
|
|
143
|
+
ifqsOntology.TestCase,
|
|
144
|
+
ifqsOntology.Evidence,
|
|
145
|
+
ifqsOntology.EvidenceFile,
|
|
146
|
+
ifqsOntology.Nonconformance,
|
|
147
|
+
ifqsOntology.Capa,
|
|
148
|
+
ifqsOntology.QualityObjective,
|
|
149
|
+
ifqsOntology.ReviewDebt,
|
|
150
|
+
ifqsOntology.AssessorPack,
|
|
151
|
+
],
|
|
152
|
+
lists: listsOf("ifqs", [
|
|
153
|
+
["EvidenceGrade", ifqsOntology.evidenceGrades],
|
|
154
|
+
["TestOutcome", ifqsOntology.testOutcomes],
|
|
155
|
+
["FreshnessState", ifqsOntology.freshnessStates],
|
|
156
|
+
["NonconformanceState", ifqsOntology.nonconformanceStates],
|
|
157
|
+
["CapaState", ifqsOntology.capaStates],
|
|
158
|
+
["QualityTier", ifqsOntology.qualityTiers],
|
|
159
|
+
["Audience", ifqsOntology.audiences],
|
|
160
|
+
]),
|
|
161
|
+
source: "commons/ontology/src/ifqs/*.ts",
|
|
162
|
+
run: RUN,
|
|
163
|
+
shapes: { prefix: "ifqssh", iri: "https://www.intellectualfrontiers.com/ontology/ifqs-shapes#" },
|
|
164
|
+
schemasIri: "https://www.intellectualfrontiers.com/ontology/ifqs-schemas",
|
|
165
|
+
sssomSetId: "https://www.intellectualfrontiers.com/ontology/ifqs-mappings",
|
|
166
|
+
sssomCuries: { dcterms: "http://purl.org/dc/terms/", prov: "http://www.w3.org/ns/prov#", dcat: "http://www.w3.org/ns/dcat#" },
|
|
167
|
+
viewTitle: "Intellectual Frontiers Quality System: the ontology",
|
|
168
|
+
license: CC0,
|
|
169
|
+
};
|
|
170
|
+
/** The ontology of Intellectual Frontiers Releases (commons 0026-works-versioning), as it is published. */
|
|
171
|
+
export const IFR = {
|
|
172
|
+
name: "ifr",
|
|
173
|
+
ns: { prefix: "ifr", iri: ifrOntology.IFR.iri },
|
|
174
|
+
idNs: { prefix: "mzid", iri: MZID.iri },
|
|
175
|
+
curies: [
|
|
176
|
+
["ifr", ifrOntology.IFR.iri],
|
|
177
|
+
["ifqs", ifqsOntology.IFQS.iri],
|
|
178
|
+
["mz", MZ.iri],
|
|
179
|
+
["xsd", "http://www.w3.org/2001/XMLSchema#"],
|
|
180
|
+
["rdfs", "http://www.w3.org/2000/01/rdf-schema#"],
|
|
181
|
+
["skos", "http://www.w3.org/2004/02/skos/core#"],
|
|
182
|
+
["dcterms", "http://purl.org/dc/terms/"],
|
|
183
|
+
["prov", "http://www.w3.org/ns/prov#"],
|
|
184
|
+
["schema", "https://schema.org/"],
|
|
185
|
+
],
|
|
186
|
+
files: ifrOntology.files,
|
|
187
|
+
ontology: ifrOntology.ifrOntology,
|
|
188
|
+
classes: ifrOntology.classes,
|
|
189
|
+
properties: ifrOntology.properties,
|
|
190
|
+
terms: ifrOntology.terms,
|
|
191
|
+
schemas: [ifrOntology.ReleaseTag, ifrOntology.ApprovalRecord, ifrOntology.Retention],
|
|
192
|
+
lists: listsOf("ifr", Object.entries(ifrOntology.codeLists)),
|
|
193
|
+
source: "commons/ontology/src/ifr/*.ts",
|
|
194
|
+
run: RUN,
|
|
195
|
+
shapes: { prefix: "ifrsh", iri: "https://www.intellectualfrontiers.com/ontology/ifr-shapes#" },
|
|
196
|
+
schemasIri: "https://www.intellectualfrontiers.com/ontology/ifr-schemas",
|
|
197
|
+
sssomSetId: "https://www.intellectualfrontiers.com/ontology/ifr-mappings",
|
|
198
|
+
sssomCuries: {
|
|
199
|
+
dcterms: "http://purl.org/dc/terms/",
|
|
200
|
+
prov: "http://www.w3.org/ns/prov#",
|
|
201
|
+
schema: "https://schema.org/",
|
|
202
|
+
gitdocs: "https://git-scm.com/docs/",
|
|
203
|
+
},
|
|
204
|
+
viewTitle: "Intellectual Frontiers Releases: the ontology",
|
|
205
|
+
license: CC0,
|
|
206
|
+
};
|
|
207
|
+
/** The ontologies of commons that are published, each from its own typed modules: Mizan's, then the ones its specifications define. */
|
|
208
|
+
export const publications = [MIZAN, IFCCM, IFQS, IFR];
|
|
209
|
+
/** Where the generated files are downloaded from: this repository's `commons/` folder on its default branch. */
|
|
210
|
+
const DOWNLOAD_BASE = "https://raw.githubusercontent.com/intellectual-frontiers/.github/main/commons/";
|
|
211
|
+
/** The exports of the ontology (0019-mizan-integrations FR-010): everything but its Turtle, by its path from commons' folder. */
|
|
212
|
+
export async function exportsOf(auditDigest) {
|
|
213
|
+
const out = new Map();
|
|
214
|
+
const catalogNote = `AUTO-GENERATED by ${RUN} from commons/ontology/*/*.ts (commons 0019-mizan-integrations FR-018). Do not edit: change the ontologies.`;
|
|
215
|
+
for (const p of publications) {
|
|
216
|
+
for (const [path, text] of await publishedFiles(p))
|
|
217
|
+
out.set(path, text);
|
|
218
|
+
}
|
|
219
|
+
out.set("generated/mizan-audit-packaging.auto.ttl", turtleOf(auditFiles, auditDigest, "commons/ontology/src/audit/*.ts (commons 0018-standards-first FR-003)"));
|
|
220
|
+
out.set("generated/mizan-catalog.auto.ttl", textOf(exportDcat({
|
|
221
|
+
iri: "https://www.intellectualfrontiers.com/ontology/mizan-catalog",
|
|
222
|
+
title: "Mizan, the IF Spec Profile: published ontologies",
|
|
223
|
+
description: "The ontologies Intellectual Frontiers publishes with Mizan, each with the files generated from it.",
|
|
224
|
+
license: CC0,
|
|
225
|
+
publisher: { iri: "https://www.intellectualfrontiers.com/", name: "Intellectual Frontiers" },
|
|
226
|
+
downloadBase: DOWNLOAD_BASE,
|
|
227
|
+
comments: [catalogNote],
|
|
228
|
+
datasets: publications.map((p) => ({
|
|
229
|
+
id: p.name,
|
|
230
|
+
ontologyIri: p.ns.iri.replace(/#$/, ""),
|
|
231
|
+
...(p.ontology.values.versionInfo === undefined ? {} : { versionInfo: p.ontology.values.versionInfo }),
|
|
232
|
+
title: p.ontology.values.label?.value ?? p.name,
|
|
233
|
+
...(p.ontology.values.description === undefined ? {} : { description: p.ontology.values.description.value }),
|
|
234
|
+
distributions: distributionsOf(p.name, p.ontology.values.label?.value ?? p.name),
|
|
235
|
+
})),
|
|
236
|
+
}), "a DCAT catalog"));
|
|
237
|
+
return out;
|
|
238
|
+
}
|
|
239
|
+
/** Every file the ontologies make, by its path from commons' folder, in the order they are written. */
|
|
240
|
+
export async function wanted() {
|
|
241
|
+
return exportsOf(await digestOf(auditFiles));
|
|
242
|
+
}
|
|
243
|
+
/** The SHA-256 of the ontology's canonical N-Triples (0012-ontology FR-012): it changes with a fact, never with the layout of a module. */
|
|
244
|
+
export const digestOf = digestOfFiles;
|
|
245
|
+
/** The text of an exporter's result, or a thrown sentence naming what the ontology states that the form cannot hold (`main` turns it into exit 2). */
|
|
246
|
+
export function textOf(r, what) {
|
|
247
|
+
return textOfResult(r, what, "Mizan");
|
|
248
|
+
}
|
|
249
|
+
/** The findings a rule of the kernel finds in the ontology, one sentence each; none where it is sound. */
|
|
250
|
+
export function findingsOf(of) {
|
|
251
|
+
return validate(of.flatMap((f) => f.individuals)).map(formatRdfFinding);
|
|
252
|
+
}
|
|
253
|
+
/** The ontology as canonical Turtle: every file's individuals, with every file's prefixes. */
|
|
254
|
+
export function turtleOf(of, digest, source = "commons/ontology/src/mizan/*.ts (commons 0016-ladder, 0018-standards-first, 0012-ontology FR-011)") {
|
|
255
|
+
return turtleOfFiles(of, RUN, digest, source);
|
|
256
|
+
}
|
|
257
|
+
/** The command line: write the files, or with `--check` say whether they are what the ontology makes. Returns the exit status (0, 1 stale, 2 the ontology breaks a rule). */
|
|
258
|
+
export async function main(argv, commons = fileURLToPath(new URL("../..", import.meta.url))) {
|
|
259
|
+
for (const p of publications) {
|
|
260
|
+
const found = findingsOf(p.files);
|
|
261
|
+
if (found.length > 0) {
|
|
262
|
+
stdio.stderr.writeSync(`the ${p.name} ontology breaks its own rules:\n${found.map((f) => ` - ${f}\n`).join("")}`);
|
|
263
|
+
return 2;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
let want;
|
|
267
|
+
try {
|
|
268
|
+
want = await wanted();
|
|
269
|
+
}
|
|
270
|
+
catch (e) {
|
|
271
|
+
if (!(e instanceof ExportRefused))
|
|
272
|
+
throw e;
|
|
273
|
+
stdio.stderr.writeSync(`${e.message}\n`);
|
|
274
|
+
return 2;
|
|
275
|
+
}
|
|
276
|
+
const root = commons.replace(/[\\/]$/, "");
|
|
277
|
+
if (argv.includes("--check")) {
|
|
278
|
+
const stale = [...want]
|
|
279
|
+
.filter(([rel, text]) => !existsSync(`${root}/${rel}`) || readFileSync(`${root}/${rel}`, "utf8").replaceAll("\r\n", "\n") !== text)
|
|
280
|
+
.map(([rel]) => rel);
|
|
281
|
+
for (const rel of stale)
|
|
282
|
+
stdio.stderr.writeSync(`commons/${rel} is not what the ontology makes; run: ${RUN}\n`);
|
|
283
|
+
return stale.length > 0 ? 1 : 0;
|
|
284
|
+
}
|
|
285
|
+
mkdirSync(`${root}/generated`, { recursive: true });
|
|
286
|
+
for (const [rel, text] of want) {
|
|
287
|
+
writeFileSync(`${root}/${rel}`, text);
|
|
288
|
+
stdio.stdout.writeSync(`wrote commons/${rel}\n`);
|
|
289
|
+
}
|
|
290
|
+
return 0;
|
|
291
|
+
}
|
|
292
|
+
if (import.meta.main)
|
|
293
|
+
process.exitCode = await main(process.argv.slice(2));
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** The files the model makes, by their path from the repository's root, and what is wrong with the model or the folder. */
|
|
2
|
+
export declare function outputs(repo: string): {
|
|
3
|
+
readonly files: ReadonlyMap<string, string>;
|
|
4
|
+
readonly problems: readonly string[];
|
|
5
|
+
};
|
|
6
|
+
/** Writes (or, with `write` false, only compares) the files; the paths that are not what the model makes, and the problems. */
|
|
7
|
+
export declare function synchronize(repo: string, write: boolean): {
|
|
8
|
+
readonly stale: readonly string[];
|
|
9
|
+
readonly problems: readonly string[];
|
|
10
|
+
};
|
|
11
|
+
/** The command line. Returns the exit status: 0, or 1 where a file is not what the model makes, a workflow is written by hand or the model has a finding. */
|
|
12
|
+
export declare function main(argv: readonly string[]): number;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The workflows of this repository, written from the typed model (commons 0030-generated-workflows FR-001, FR-004, FR-006, FR-008): every file under `.github/workflows/` is `<name>.auto.yml` and made here, and so is
|
|
3
|
+
* `.github/actions/bun/action.yml`, whose name GitHub fixes.
|
|
4
|
+
*
|
|
5
|
+
* bun commons/libraries/src/generate-workflows.ts write the files that are not what the model makes
|
|
6
|
+
* bun commons/libraries/src/generate-workflows.ts --check write nothing and exit 1 where a file is not what the model makes, where a workflow is written by hand, or where the model has a finding
|
|
7
|
+
* other flags: --repo DIR (the repository, the working folder by default)
|
|
8
|
+
*
|
|
9
|
+
* @remarks
|
|
10
|
+
* The workflow of each library of commons is made from its manifest (`commons/<name>/library.ts`, 0027-commons-libraries FR-012) and the facts of its CI that the manifest does not hold
|
|
11
|
+
* (`LIBRARY_CI` of `workflows/definitions.ts`); the others are written as values there. A file that is not `.auto.yml` in the workflows' folder, and a generated file that no workflow makes, are findings
|
|
12
|
+
* (nothing is deleted). Line ends are not compared: a Windows checkout of a file is the file.
|
|
13
|
+
*
|
|
14
|
+
* @limits
|
|
15
|
+
* It reads manifests and writes files; it does not run a workflow and does not ask GitHub whether it accepts one (`tests/commons-workflows-schema.test.ts` validates the files against the schema GitHub's tools publish).
|
|
16
|
+
*
|
|
17
|
+
* Spec: 0001-libraries FR-005
|
|
18
|
+
*
|
|
19
|
+
* @module
|
|
20
|
+
*/
|
|
21
|
+
import process from "node:process";
|
|
22
|
+
import { ACTIONS, workflows } from "./workflows/definitions.js";
|
|
23
|
+
import { validateAction, validateWorkflow } from "./workflows/model.js";
|
|
24
|
+
import { renderAction, renderWorkflow } from "./workflows/render.js";
|
|
25
|
+
import { inputsOf } from "./affected.js";
|
|
26
|
+
import { readLibraries } from "./libraries.js";
|
|
27
|
+
import { existsSync, readDirSync, readTextFileSync, writeTextFileSync, mkdirSync } from "@intellectual-frontiers/system/fs";
|
|
28
|
+
import { stdio } from "@intellectual-frontiers/system";
|
|
29
|
+
const RUN = "bun commons/libraries/src/generate-workflows.ts";
|
|
30
|
+
const FOLDER = ".github/workflows";
|
|
31
|
+
/** The files the model makes, by their path from the repository's root, and what is wrong with the model or the folder. */
|
|
32
|
+
export function outputs(repo) {
|
|
33
|
+
const root = repo.replace(/[\\/]$/, "");
|
|
34
|
+
const problems = [];
|
|
35
|
+
const libraries = [];
|
|
36
|
+
for (const f of readLibraries(root)) {
|
|
37
|
+
if ("problem" in f)
|
|
38
|
+
problems.push(`commons/${f.dir}/library.ts: ${f.problem}`);
|
|
39
|
+
else {
|
|
40
|
+
if (f.library.distribution.includes("npm") && !existsSync(`${root}/commons/${f.library.name}/tools/pack.ts`))
|
|
41
|
+
problems.push(`commons/${f.library.name} is published to npm and has no tools/pack.ts, which its publish workflow runs (0030-generated-workflows FR-009)`);
|
|
42
|
+
libraries.push({
|
|
43
|
+
name: f.library.name,
|
|
44
|
+
verify: f.library.verify,
|
|
45
|
+
paths: inputsOf(root, f.library.name).paths,
|
|
46
|
+
distribution: f.library.distribution,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
const files = new Map();
|
|
51
|
+
for (const w of workflows(libraries)) {
|
|
52
|
+
problems.push(...validateWorkflow(w));
|
|
53
|
+
files.set(`${FOLDER}/${w.file}.auto.yml`, renderWorkflow(w));
|
|
54
|
+
}
|
|
55
|
+
for (const a of ACTIONS) {
|
|
56
|
+
problems.push(...validateAction(a));
|
|
57
|
+
files.set(`.github/actions/${a.folder}/action.yml`, renderAction(a));
|
|
58
|
+
}
|
|
59
|
+
const dir = `${root}/${FOLDER}`;
|
|
60
|
+
for (const e of existsSync(dir) ? readDirSync(dir) : []) {
|
|
61
|
+
if (!e.isFile)
|
|
62
|
+
continue;
|
|
63
|
+
const path = `${FOLDER}/${e.name}`;
|
|
64
|
+
if (!e.name.endsWith(".auto.yml"))
|
|
65
|
+
problems.push(`${path} is written by hand: a workflow is made by ${RUN} and is named <name>.auto.yml (FR-001)`);
|
|
66
|
+
else if (!files.has(path))
|
|
67
|
+
problems.push(`${path} is no workflow's file: remove it, or give the model a workflow for it (FR-004)`);
|
|
68
|
+
}
|
|
69
|
+
return { files, problems };
|
|
70
|
+
}
|
|
71
|
+
const lf = (s) => s.replace(/\r\n/g, "\n");
|
|
72
|
+
/** Writes (or, with `write` false, only compares) the files; the paths that are not what the model makes, and the problems. */
|
|
73
|
+
export function synchronize(repo, write) {
|
|
74
|
+
const root = repo.replace(/[\\/]$/, "");
|
|
75
|
+
const { files, problems } = outputs(root);
|
|
76
|
+
const stale = [];
|
|
77
|
+
for (const [path, text] of files) {
|
|
78
|
+
const at = `${root}/${path}`;
|
|
79
|
+
if (existsSync(at) && lf(readTextFileSync(at)) === text)
|
|
80
|
+
continue;
|
|
81
|
+
stale.push(path);
|
|
82
|
+
if (write && problems.length === 0) {
|
|
83
|
+
mkdirSync(at.slice(0, at.lastIndexOf("/")), { recursive: true });
|
|
84
|
+
writeTextFileSync(at, text);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return { stale, problems };
|
|
88
|
+
}
|
|
89
|
+
/** The command line. Returns the exit status: 0, or 1 where a file is not what the model makes, a workflow is written by hand or the model has a finding. */
|
|
90
|
+
export function main(argv) {
|
|
91
|
+
const at = argv.indexOf("--repo");
|
|
92
|
+
const repo = at >= 0 ? (argv[at + 1] ?? ".") : ".";
|
|
93
|
+
const check = argv.includes("--check");
|
|
94
|
+
const r = synchronize(repo, !check);
|
|
95
|
+
for (const p of r.problems)
|
|
96
|
+
stdio.stderr.writeSync(`${p}\n`);
|
|
97
|
+
for (const s of r.stale)
|
|
98
|
+
stdio.stderr.writeSync(check ? `${s} is not what the model makes; run: ${RUN}\n` : `wrote ${s}\n`);
|
|
99
|
+
return r.problems.length > 0 || (check && r.stale.length > 0) ? 1 : 0;
|
|
100
|
+
}
|
|
101
|
+
if (import.meta.main)
|
|
102
|
+
process.exitCode = main(process.argv.slice(2));
|