feat(plugins/community): add support
This commit is contained in:
41
.github/scripts/build.mjs
vendored
41
.github/scripts/build.mjs
vendored
@@ -30,25 +30,9 @@ const secrets = Object.assign(JSON.parse(`${await fs.readFile(__test_secrets)}`)
|
||||
const { plugins, templates } = await metadata({ log: false, diff: true })
|
||||
const workflow = []
|
||||
|
||||
//Config and general documentation auto-generation
|
||||
for (const step of ["config", "documentation"]) {
|
||||
switch (step) {
|
||||
case "config":
|
||||
await update({ source: paths.join(__action, "action.yml"), output: "action.yml" })
|
||||
await update({ source: paths.join(__web, "settings.example.json"), output: "settings.example.json" })
|
||||
break
|
||||
case "documentation":
|
||||
await update({ source: paths.join(__documentation, "README.md"), output: "README.md", options: { root: __readme } })
|
||||
await update({ source: paths.join(__documentation, "plugins.md"), output: "source/plugins/README.md" })
|
||||
await update({ source: paths.join(__documentation, "templates.md"), output: "source/templates/README.md" })
|
||||
await update({ source: paths.join(__documentation, "compatibility.md"), output: ".github/readme/partials/documentation/compatibility.md" })
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
//Plugins
|
||||
for (const id of Object.keys(plugins)) {
|
||||
const { examples, options, readme, tests, header } = await plugin(id)
|
||||
const { examples, options, readme, tests, header, community } = await plugin(id)
|
||||
|
||||
//Readme
|
||||
await fs.writeFile(
|
||||
@@ -58,12 +42,12 @@ for (const id of Object.keys(plugins)) {
|
||||
.replace(/(<!--examples-->)[\s\S]*(<!--\/examples-->)/g, `$1\n${examples.map(({ test, prod, ...step }) => ["```yaml", yaml.dump(step, {quotingType:'"', noCompatMode:true}), "```"].join("\n")).join("\n")}\n$2`)
|
||||
.replace(/(<!--options-->)[\s\S]*(<!--\/options-->)/g, `$1\n${options}\n$2`),
|
||||
)
|
||||
console.log(`Generating source/plugins/${id}/README.md`)
|
||||
console.log(`Generating source/plugins/${community ? "community/" : ""}${id}/README.md`)
|
||||
|
||||
//Tests
|
||||
workflow.push(...examples.map(example => testcase(plugins[id].name, "prod", example)).filter(t => t))
|
||||
await fs.writeFile(tests.path, yaml.dump(examples.map(example => testcase(plugins[id].name, "test", example)).filter(t => t)))
|
||||
console.log(`Generating tests/plugins/${id}.yml`)
|
||||
console.log(`Generating tests/plugins/${community ? "community/" : ""}${id}.yml`)
|
||||
}
|
||||
|
||||
//Templates
|
||||
@@ -85,6 +69,22 @@ for (const id of Object.keys(templates)) {
|
||||
console.log(`Generating tests/templates/${id}.yml`)
|
||||
}
|
||||
|
||||
//Config and general documentation auto-generation
|
||||
for (const step of ["config", "documentation"]) {
|
||||
switch (step) {
|
||||
case "config":
|
||||
await update({ source: paths.join(__action, "action.yml"), output: "action.yml" })
|
||||
await update({ source: paths.join(__web, "settings.example.json"), output: "settings.example.json" })
|
||||
break
|
||||
case "documentation":
|
||||
await update({ source: paths.join(__documentation, "README.md"), output: "README.md", options: { root: __readme } })
|
||||
await update({ source: paths.join(__documentation, "plugins.md"), output: "source/plugins/README.md" })
|
||||
await update({ source: paths.join(__documentation, "templates.md"), output: "source/templates/README.md" })
|
||||
await update({ source: paths.join(__documentation, "compatibility.md"), output: ".github/readme/partials/documentation/compatibility.md" })
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
//Example workflows
|
||||
await update({ source: paths.join(__metrics, ".github/scripts/files/examples.yml"), output: ".github/workflows/examples.yml", context: { steps: yaml.dump(workflow, {quotingType:'"', noCompatMode:true}) } })
|
||||
|
||||
@@ -115,11 +115,12 @@ async function update({ source, output, context = {}, options = {} }) {
|
||||
|
||||
//Get plugin infos
|
||||
async function plugin(id) {
|
||||
const path = paths.join(__plugins, id)
|
||||
const path = paths.join(__plugins, plugins[id].community ? "community" : "", id)
|
||||
const readme = paths.join(path, "README.md")
|
||||
const examples = paths.join(path, "examples.yml")
|
||||
const tests = paths.join(__test_cases, `${id}.plugin.yml`)
|
||||
return {
|
||||
community: plugins[id].community,
|
||||
readme: {
|
||||
path: readme,
|
||||
content: `${await fs.readFile(readme)}`,
|
||||
|
||||
@@ -40,8 +40,22 @@ export default async function metadata({log = true, diff = false} = {}) {
|
||||
for (const name of await fs.promises.readdir(__plugins)) {
|
||||
if (!(await fs.promises.lstat(path.join(__plugins, name))).isDirectory())
|
||||
continue
|
||||
logger(`metrics/metadata > loading plugin metadata [${name}]`)
|
||||
Plugins[name] = await metadata.plugin({__plugins, __templates, name, logger})
|
||||
switch (name) {
|
||||
case "community":{
|
||||
const ___plugins = path.join(__plugins, "community")
|
||||
for (const name of await fs.promises.readdir(___plugins)) {
|
||||
if (!(await fs.promises.lstat(path.join(___plugins, name))).isDirectory())
|
||||
continue
|
||||
logger(`metrics/metadata > loading plugin metadata [community/${name}]`)
|
||||
Plugins[name] = await metadata.plugin({__plugins:___plugins, __templates, name, logger})
|
||||
Plugins[name].community = true
|
||||
}
|
||||
continue
|
||||
}
|
||||
default:
|
||||
logger(`metrics/metadata > loading plugin metadata [${name}]`)
|
||||
Plugins[name] = await metadata.plugin({__plugins, __templates, name, logger})
|
||||
}
|
||||
}
|
||||
//Reorder keys
|
||||
const {base, core, ...plugins} = Plugins //eslint-disable-line no-unused-vars
|
||||
|
||||
@@ -163,10 +163,50 @@ export default async function({log = true, nosettings = false, community = {}} =
|
||||
|
||||
//Load plugins
|
||||
for (const name of await fs.promises.readdir(__plugins)) {
|
||||
switch (name) {
|
||||
case "community":{
|
||||
const ___plugins = path.join(__plugins, "community")
|
||||
for (const name of await fs.promises.readdir(___plugins))
|
||||
await load.plugin(name, {__plugins:___plugins, Plugins, conf, logger})
|
||||
continue
|
||||
}
|
||||
default:
|
||||
await load.plugin(name, {__plugins, Plugins, conf, logger})
|
||||
}
|
||||
}
|
||||
|
||||
//Load metadata
|
||||
conf.metadata = await metadata({log})
|
||||
|
||||
//Store authenticated user
|
||||
if (conf.settings.token) {
|
||||
try {
|
||||
conf.authenticated = (await (new OctokitRest.Octokit({auth:conf.settings.token})).users.getAuthenticated()).data.login
|
||||
logger(`metrics/setup > setup > authenticated as ${conf.authenticated}`)
|
||||
}
|
||||
catch (error) {
|
||||
logger(`metrics/setup > setup > could not verify authentication : ${error}`)
|
||||
}
|
||||
}
|
||||
|
||||
//Set no token property
|
||||
Object.defineProperty(conf.settings, "notoken", {
|
||||
get() {
|
||||
return conf.settings.token === "NOT_NEEDED"
|
||||
},
|
||||
})
|
||||
|
||||
//Conf
|
||||
logger("metrics/setup > setup > success")
|
||||
return {Templates, Plugins, conf}
|
||||
}
|
||||
|
||||
const load = {
|
||||
async plugin(name, {__plugins, Plugins, conf, logger}) {
|
||||
//Search for plugins
|
||||
const directory = path.join(__plugins, name)
|
||||
if (!(await fs.promises.lstat(directory)).isDirectory())
|
||||
continue
|
||||
return
|
||||
//Cache plugins scripts
|
||||
logger(`metrics/setup > load plugin [${name}]`)
|
||||
Plugins[name] = (await import(url.pathToFileURL(path.join(directory, "index.mjs")).href)).default
|
||||
@@ -210,29 +250,4 @@ export default async function({log = true, nosettings = false, community = {}} =
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
//Load metadata
|
||||
conf.metadata = await metadata({log})
|
||||
|
||||
//Store authenticated user
|
||||
if (conf.settings.token) {
|
||||
try {
|
||||
conf.authenticated = (await (new OctokitRest.Octokit({auth:conf.settings.token})).users.getAuthenticated()).data.login
|
||||
logger(`metrics/setup > setup > authenticated as ${conf.authenticated}`)
|
||||
}
|
||||
catch (error) {
|
||||
logger(`metrics/setup > setup > could not verify authentication : ${error}`)
|
||||
}
|
||||
}
|
||||
|
||||
//Set no token property
|
||||
Object.defineProperty(conf.settings, "notoken", {
|
||||
get() {
|
||||
return conf.settings.token === "NOT_NEEDED"
|
||||
},
|
||||
})
|
||||
|
||||
//Conf
|
||||
logger("metrics/setup > setup > success")
|
||||
return {Templates, Plugins, conf}
|
||||
}
|
||||
Reference in New Issue
Block a user