Skip to content

Commit 4d06539

Browse files
authoredJan 14, 2022
docs: updated workflows examples and options descriptions (#772) [skip ci]
1 parent 44e3992 commit 4d06539

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+2271
-429
lines changed
 

‎.github/examples.mjs

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
//Imports
2+
import fs from "fs/promises"
3+
import fss from "fs"
4+
import paths from "path"
5+
import url from "url"
6+
import metadata from "../source/app/metrics/metadata.mjs"
7+
import yaml from "js-yaml"
8+
9+
//Paths
10+
const __metrics = paths.join(paths.dirname(url.fileURLToPath(import.meta.url)), "..")
11+
const __templates = paths.join(paths.join(__metrics, "source/templates/"))
12+
const __plugins = paths.join(paths.join(__metrics, "source/plugins/"))
13+
14+
//Load plugins metadata
15+
const {plugins, templates} = await metadata({log:false, diff:true})
16+
17+
async function plugin(id) {
18+
const path = paths.join(__plugins, id)
19+
const readme = paths.join(path, "README.md")
20+
const examples = paths.join(path, "examples.yml")
21+
return {
22+
readme:{
23+
path:readme,
24+
content:`${await fs.readFile(readme)}`
25+
},
26+
examples:fss.existsSync(examples) ? yaml.load(await fs.readFile(examples), "utf8") ?? [] : [],
27+
options:plugins[id].readme.table
28+
}
29+
}
30+
31+
//Plugins
32+
for (const id of Object.keys(plugins)) {
33+
const {examples, options, readme} = await plugin(id)
34+
//Plugin readme
35+
await fs.writeFile(readme.path, readme.content
36+
.replace(/(<!--examples-->)[\s\S]*(<!--\/examples-->)/g, `$1\n${examples.map(({test, prod, ...step}) => ["```yaml", yaml.dump(step), "```"].join("\n")).join("\n")}\n$2`)
37+
.replace(/(<!--options-->)[\s\S]*(<!--\/options-->)/g, `$1\n${options}\n$2`)
38+
)
39+
//Plugin tests
40+
}
41+
42+
//Templates
43+
44+
//Workflow

‎source/app/metrics/metadata.mjs

+55-2
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,16 @@ import fs from "fs"
33
import yaml from "js-yaml"
44
import path from "path"
55
import url from "url"
6+
import fetch from "node-fetch"
67

78
//Defined categories
89
const categories = ["core", "github", "social", "community"]
910

11+
//Previous descriptors
12+
let previous = null
13+
1014
/**Metadata descriptor parser */
11-
export default async function metadata({log = true} = {}) {
15+
export default async function metadata({log = true, diff = false} = {}) {
1216
//Paths
1317
const __metrics = path.join(path.dirname(url.fileURLToPath(import.meta.url)), "../../..")
1418
const __templates = path.join(__metrics, "source/templates")
@@ -19,6 +23,16 @@ export default async function metadata({log = true} = {}) {
1923
//Init
2024
const logger = log ? console.debug : () => null
2125

26+
//Diff with latest version
27+
if (diff) {
28+
try {
29+
previous = yaml.load(await fetch("https://raw.githubusercontent.com/lowlighter/metrics/latest/action.yml").then(response => response.text()))
30+
}
31+
catch (error) {
32+
logger(error)
33+
}
34+
}
35+
2236
//Load plugins metadata
2337
let Plugins = {}
2438
logger("metrics/metadata > loading plugins metadata")
@@ -254,8 +268,47 @@ metadata.plugin = async function({__plugins, name, logger}) {
254268
const raw = `${await fs.promises.readFile(path.join(__plugins, name, "README.md"), "utf-8")}`
255269
const demo = raw.match(/(?<demo><table>[\s\S]*?<[/]table>)/)?.groups?.demo?.replace(/<[/]?(?:table|tr)>/g, "")?.trim() ?? "<td></td>"
256270

271+
//Options table
272+
const table = [
273+
"| Option | Type *(format)* **[default]** *{allowed values}* | Description |",
274+
"| ------ | -------------------------------- | ----------- |",
275+
Object.entries(inputs).map(([option, {description, type, ...o}]) => {
276+
let row = []
277+
{
278+
const cell = [`${"`"}${option}${"`"}`]
279+
if (type === "token")
280+
cell.push("🔐")
281+
if (!Object.keys(previous?.inputs ?? {}).includes(option))
282+
cell.push("✨")
283+
row.push(cell.join(" "))
284+
}
285+
{
286+
const cell = [`${"`"}${type}${"`"}`]
287+
if ("format" in o)
288+
cell.push(`*(${o.format})*`)
289+
if ("default" in o)
290+
cell.push(`**[${o.default}]**`)
291+
if ("values" in o)
292+
cell.push(`*{${o.values.map(value => `"${value}"`).join(", ")}}*`)
293+
if ("min" in o)
294+
cell.push(`*{${o.min} ≤`)
295+
if (("min" in o)||("max" in o))
296+
cell.push(`${"min" in o ? "" : "*{"}𝑥${"max" in o ? "" : "}*"}`)
297+
if ("max" in o)
298+
cell.push(`≤ ${o.max}}*`)
299+
row.push(cell.join(" "))
300+
}
301+
row.push(description)
302+
return `| ${row.join(" | ")} |`
303+
}).join("\n"),
304+
"\n",
305+
"Legend for option icons:",
306+
"* 🔐 Value should be stored in repository secrets",
307+
"* ✨ New feature currently in testing on `master`/`main`"
308+
].flat(Infinity).filter(s => s).join("\n")
309+
257310
//Readme descriptor
258-
meta.readme = {demo}
311+
meta.readme = {demo, table}
259312
}
260313

261314
//Icon

0 commit comments

Comments
 (0)
Failed to load comments.