Skip to content

Commit 9ebbe9b

Browse files
author
Julien Bouquillon
authored
fix: add config.yaml json schemas (#411)
1 parent 5327c88 commit 9ebbe9b

File tree

4 files changed

+1352
-0
lines changed

4 files changed

+1352
-0
lines changed

docs/config.schema.json

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-07/schema#",
3+
"title": "kontinuous config.yaml JSON schema",
4+
"markdownDescription": "See [config documentation](https://socialgouv.github.io/kontinuous/#/./advanced/configuration)",
5+
"type": "object",
6+
"properties": {
7+
"projectName": {
8+
"title": "Name of the rancher project. useful to guess the namespace rancher-project-id",
9+
"type": "string"
10+
},
11+
"ciNamespace": {
12+
"title": "Name of the CI namespace. useful to copy secrets",
13+
"examples": [
14+
"ci-myapp"
15+
],
16+
"type": "string"
17+
},
18+
"config": {
19+
"title": "project kontinuous configuration",
20+
"markdownDescription": "see [documentation](https://socialgouv.github.io/kontinuous/#/./advanced/configuration)",
21+
"type": "object"
22+
},
23+
"options": {
24+
"title": "project kontinuous options",
25+
"markdownDescription": "see [documentation](https://socialgouv.github.io/kontinuous/#/./advanced/configuration)",
26+
"type": "object"
27+
},
28+
"dependencies": {
29+
"type": "object",
30+
"properties": {
31+
"fabrique": {
32+
"$ref": "../plugins/fabrique/config.schema.json"
33+
},
34+
"contrib": {
35+
"$ref": "../plugins/contrib/config.schema.json"
36+
}
37+
},
38+
"required": []
39+
}
40+
},
41+
"required": []
42+
}
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
/*
2+
* Extract plugins configurations JSON schemas
3+
*/
4+
5+
const { readdirSync, existsSync, writeFileSync } = require("node:fs")
6+
const camelCase = require("lodash.camelcase")
7+
8+
const folders =
9+
"patches,post-deploy,pre-deploy,validators,values-compilers".split(",")
10+
11+
// extract list of files from a folder
12+
const getFilesFromPath = (path, camelify = false) =>
13+
(existsSync(path) &&
14+
readdirSync(path)
15+
.map((file) => ({
16+
id: camelify
17+
? camelCase(file.replace(/^[\d.]+(.*?)\.js/g, "$1"))
18+
: file,
19+
path: file,
20+
}))
21+
.filter(Boolean)) ||
22+
[]
23+
24+
const getDependencies = (path) => ({
25+
type: "object",
26+
properties: {
27+
fabrique: {
28+
$ref: `${path}/plugins/fabrique/config.schema.json`,
29+
},
30+
contrib: {
31+
$ref: `${path}/plugins/contrib/config.schema.json`,
32+
},
33+
},
34+
required: [],
35+
})
36+
37+
const getPluginSchema = (plugin, dependencies) => {
38+
const properties = folders.reduce((allFolders, folder) => {
39+
const folderPath = `../plugins/${plugin}/${folder}`
40+
if (!existsSync(folderPath)) return allFolders
41+
const folderProperties = getFilesFromPath(folderPath, true).reduce(
42+
(a, file) => ({
43+
...a,
44+
[file.id]: {
45+
type: "object",
46+
title: file.id,
47+
markdownDescription: `Configuration of the ${file.id} plugin\n\nSee [plugin source](https://github.com/SocialGouv/kontinuous/blob/master/plugins/${plugin}/${folder}/${file.path})`,
48+
properties: {
49+
enabled: {
50+
title: `${file.id}.enabled`,
51+
description: "Enable or disable this plugin",
52+
type: "boolean",
53+
},
54+
options: {
55+
title: `${file.id}.options`,
56+
markdownDescription: `Options of the ${file.id} plugin\n\nSee [plugin source](https://github.com/SocialGouv/kontinuous/blob/master/plugins/${plugin}/${folder}/${file.path})`,
57+
type: "object",
58+
properties: {},
59+
},
60+
},
61+
},
62+
}),
63+
{}
64+
)
65+
return {
66+
...allFolders,
67+
[folder]: {
68+
type: "object",
69+
title: folder,
70+
markdownDescription: `Options from the ${folder} type.`,
71+
properties: folderProperties,
72+
},
73+
}
74+
}, {})
75+
76+
const extendsEnum = getFilesFromPath(`../plugins/${plugin}/extends`).map(
77+
(file) => file.path.replace(/\.yaml$/, "")
78+
)
79+
return {
80+
type: "object",
81+
title: `kontinuous ${plugin} plugin configuration.`,
82+
markdownDescription: `See ${plugin} plugin [default configuration](https://github.com/SocialGouv/kontinuous/blob/master/plugins/${plugin}/kontinuous.yaml)`,
83+
properties: {
84+
...properties,
85+
dependencies,
86+
extends: {
87+
title: "Additional configs to extend from",
88+
type: "array",
89+
items: {
90+
type: "object",
91+
properties: {
92+
name: {
93+
type: "string",
94+
enum: (extendsEnum.length && extendsEnum) || undefined,
95+
},
96+
ifEnv: {
97+
type: "array",
98+
items: {
99+
type: "string",
100+
enum: ["dev", "preprod", "prod"],
101+
},
102+
},
103+
},
104+
},
105+
},
106+
},
107+
}
108+
}
109+
110+
const baseJsonSchema = {
111+
$schema: "http://json-schema.org/draft-07/schema#",
112+
title: "kontinuous config.yaml JSON schema",
113+
markdownDescription:
114+
"See [config documentation](https://socialgouv.github.io/kontinuous/#/./advanced/configuration)",
115+
type: "object",
116+
properties: {
117+
projectName: {
118+
title:
119+
"Name of the rancher project. useful to guess the namespace rancher-project-id",
120+
type: "string",
121+
},
122+
ciNamespace: {
123+
title: "Name of the CI namespace. useful to copy secrets",
124+
examples: ["ci-myapp"],
125+
type: "string",
126+
},
127+
config: {
128+
title: "project kontinuous configuration",
129+
markdownDescription:
130+
"see [documentation](https://socialgouv.github.io/kontinuous/#/./advanced/configuration)",
131+
type: "object",
132+
},
133+
options: {
134+
title: "project kontinuous options",
135+
markdownDescription:
136+
"see [documentation](https://socialgouv.github.io/kontinuous/#/./advanced/configuration)",
137+
type: "object",
138+
},
139+
dependencies: getDependencies(".."),
140+
},
141+
required: [],
142+
}
143+
144+
writeFileSync("./config.schema.json", JSON.stringify(baseJsonSchema, null, 2))
145+
146+
writeFileSync(
147+
"../plugins/contrib/config.schema.json",
148+
JSON.stringify(getPluginSchema("contrib", getDependencies("../..")), null, 2)
149+
)
150+
151+
writeFileSync(
152+
"../plugins/fabrique/config.schema.json",
153+
JSON.stringify(getPluginSchema("fabrique", getDependencies("../..")), null, 2)
154+
)

0 commit comments

Comments
 (0)