Skip to content

Commit

Permalink
continue client
Browse files Browse the repository at this point in the history
  • Loading branch information
lowlighter committed Dec 5, 2023
1 parent 3f1b29c commit 80758cf
Show file tree
Hide file tree
Showing 7 changed files with 377 additions and 215 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ jobs:
task:
- ci:lint
- ci:test
fail-fast: false
steps:
- uses: actions/checkout@v4
- uses: denoland/setup-deno@v1
Expand Down Expand Up @@ -70,3 +71,11 @@ jobs:
context: .
tags: ghcr.io/${{ github.repository }}:v4
push: ${{ github.event_name == 'push' }}

# Test GitHub Action
github-action:
runs-on: ubuntu-latest
needs:
- docker
steps:
- uses: lowlighter/metrics@v4-dev
2 changes: 1 addition & 1 deletion source/engine/utils/language.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ hljs.registerAliases(["html", "ejs"], { languageName: "xml" })
hljs.registerLanguage("yaml", hljsYAML)

/** Language cache */
export const cache = await load("languages.yml") as Record<string, { ace_mode: string; extensions?: string[]; interpreters?: string[] }>
export const cache = await load("languages.yml").catch(() => ({})) as Record<string, { ace_mode: string; extensions?: string[]; interpreters?: string[] }>

/** Language guesser */
// TODO(@lowlighter): to implement
Expand Down
2 changes: 1 addition & 1 deletion source/plugins/.legacy/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default class extends Plugin {
/** Inputs */
readonly inputs = is.object({
version: is.string().regex(/^v3\.[0-9]{1,2}$/).default("v3.34").describe("Metrics version (v3.x)"),
inputs: is.record(is.unknown()).default(() => ({})).describe("Plugin inputs (as described from respective `action.yml`). Some core options are not supported and will have no effect"),
inputs: is.record(is.string(), is.unknown()).default(() => ({})).describe("Plugin inputs (as described from respective `action.yml`). Some core options are not supported and will have no effect"),
})

/** Outputs */
Expand Down
3 changes: 2 additions & 1 deletion source/run/compat/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ export async function compat(
}

// Markdown
if (inputs.markdown) {
if ((inputs.markdown)&&(inputs.config_output.includes("markdown"))) {
// TODO(#1574)
// markdown
// markdown_cache
Expand Down Expand Up @@ -1009,6 +1009,7 @@ export async function compat(
// Print report and config
if (config.patched) {
config.report.warning("Your configuration has been patched to be compatible with v4. Note however that the final result may differ from previous versions, please review the following changes:")
config.report.messages.unshift(config.report.messages.pop()!)
}
log?.(config.report.console())
log?.(yaml(config.content))
Expand Down
21 changes: 18 additions & 3 deletions source/run/compat/report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { bgWhite, black, brightGreen, brightRed, brightYellow, cyan, gray, stripAnsiCode, white, yellow } from "std/fmt/colors.ts"
import * as YAML from "std/yaml/stringify.ts"
import { markdown } from "@engine/utils/markdown.ts"
import { Secret } from "@engine/utils/secret.ts"

/** Compatibility report */
export class Report {
Expand Down Expand Up @@ -64,12 +65,12 @@ export class Report {
}

/** YAML formatter for console */
export function yaml(content: Record<PropertyKey, unknown>, { inline = false } = {}) {
export function yaml(content: Record<PropertyKey, unknown>, { inline = false, colors = true } = {}) {
const regex = {
kv: /^(?<indent>\s*)(?<array>\-\s+)?'?(?<key>\w[.\w-]*)'?(?:(?<kv>:)(?<value>\s.+)?)?$/,
}
const lines = []
for (const line of YAML.stringify(content, { skipInvalid: true, flowLevel: inline ? 1 : -1 }).split("\n")) {
for (const line of YAML.stringify(copy(content) as Record<PropertyKey, unknown>, { skipInvalid: true, flowLevel: inline ? 1 : -1 }).split("\n")) {
if (regex.kv.test(line)) {
let { indent, array = "", kv, key, value } = line.match(regex.kv)!.groups!
let color = white
Expand Down Expand Up @@ -101,5 +102,19 @@ export function yaml(content: Record<PropertyKey, unknown>, { inline = false } =
}
lines.push(line)
}
return lines.join("\n")
const result = lines.join("\n")
if (!colors)
return stripAnsiCode(result)
return result
}

/** Copy record while cleaning out secrets */
function copy(value:unknown):unknown {
if (value instanceof Secret)
return "${{ github.token }}"
if (Array.isArray(value))
return value.map(copy)
if ((value)&&(typeof value === "object"))
return Object.fromEntries(Object.entries(value).map(([key, value]) => [key, copy(value)]))
return value
}
Loading

0 comments on commit 80758cf

Please sign in to comment.