docs: updated workflows examples and options descriptions (#772) [skip ci]

This commit is contained in:
Simon Lecoq
2022-01-14 04:49:14 +01:00
committed by GitHub
parent 44e3992ca9
commit 4d06539136
80 changed files with 2292 additions and 450 deletions

View File

@@ -3,12 +3,16 @@ import fs from "fs"
import yaml from "js-yaml"
import path from "path"
import url from "url"
import fetch from "node-fetch"
//Defined categories
const categories = ["core", "github", "social", "community"]
//Previous descriptors
let previous = null
/**Metadata descriptor parser */
export default async function metadata({log = true} = {}) {
export default async function metadata({log = true, diff = false} = {}) {
//Paths
const __metrics = path.join(path.dirname(url.fileURLToPath(import.meta.url)), "../../..")
const __templates = path.join(__metrics, "source/templates")
@@ -19,6 +23,16 @@ export default async function metadata({log = true} = {}) {
//Init
const logger = log ? console.debug : () => null
//Diff with latest version
if (diff) {
try {
previous = yaml.load(await fetch("https://raw.githubusercontent.com/lowlighter/metrics/latest/action.yml").then(response => response.text()))
}
catch (error) {
logger(error)
}
}
//Load plugins metadata
let Plugins = {}
logger("metrics/metadata > loading plugins metadata")
@@ -254,8 +268,47 @@ metadata.plugin = async function({__plugins, name, logger}) {
const raw = `${await fs.promises.readFile(path.join(__plugins, name, "README.md"), "utf-8")}`
const demo = raw.match(/(?<demo><table>[\s\S]*?<[/]table>)/)?.groups?.demo?.replace(/<[/]?(?:table|tr)>/g, "")?.trim() ?? "<td></td>"
//Options table
const table = [
"| Option | Type *(format)* **[default]** *{allowed values}* | Description |",
"| ------ | -------------------------------- | ----------- |",
Object.entries(inputs).map(([option, {description, type, ...o}]) => {
let row = []
{
const cell = [`${"`"}${option}${"`"}`]
if (type === "token")
cell.push("🔐")
if (!Object.keys(previous?.inputs ?? {}).includes(option))
cell.push("✨")
row.push(cell.join(" "))
}
{
const cell = [`${"`"}${type}${"`"}`]
if ("format" in o)
cell.push(`*(${o.format})*`)
if ("default" in o)
cell.push(`**[${o.default}]**`)
if ("values" in o)
cell.push(`*{${o.values.map(value => `"${value}"`).join(", ")}}*`)
if ("min" in o)
cell.push(`*{${o.min}`)
if (("min" in o)||("max" in o))
cell.push(`${"min" in o ? "" : "*{"}𝑥${"max" in o ? "" : "}*"}`)
if ("max" in o)
cell.push(`${o.max}}*`)
row.push(cell.join(" "))
}
row.push(description)
return `| ${row.join(" | ")} |`
}).join("\n"),
"\n",
"Legend for option icons:",
"* 🔐 Value should be stored in repository secrets",
"* ✨ New feature currently in testing on `master`/`main`"
].flat(Infinity).filter(s => s).join("\n")
//Readme descriptor
meta.readme = {demo}
meta.readme = {demo, table}
}
//Icon