-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
continue and implement .legacy plugin
- Loading branch information
1 parent
83af929
commit cd4c9c0
Showing
14 changed files
with
294 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,7 +40,7 @@ | |
}, | ||
"tasks": { | ||
// ' | ||
"qq": "rm -rf .coverage && deno test --coverage=.coverage --no-check --unstable --trace-ops --allow-all source --filter='calendar' && deno coverage .coverage --include='^file:.*/calendar/mod.ts'", | ||
"qq": "rm -rf .coverage && deno test --coverage=.coverage --no-check --unstable --trace-ops --allow-all source --filter='base64' && deno coverage .coverage --include='^file:.*/transform.base64/mod.ts'", | ||
"q": "rm -rf .coverage && deno test --coverage=.coverage --unstable --trace-ops --fail-fast --allow-all source && deno coverage .coverage --exclude='/dom/'", | ||
|
||
"make": "deno run --allow-env --allow-read --allow-write=.deno-make.json --allow-run=deno https://deno.land/x/[email protected]/mod.ts $0" | ||
|
@@ -79,6 +79,7 @@ | |
"cdn.jsdelivr.net/gh/jdecked/twemoji@latest/assets" | ||
], | ||
"run": [ | ||
"docker", | ||
"$CHROME_BIN" | ||
], | ||
"read": [ | ||
|
@@ -89,6 +90,7 @@ | |
"metrics.config.yml" | ||
], | ||
"write": [ | ||
"$TMP", | ||
"$HOME/.config/chromium/SingletonLock" | ||
], | ||
"env": true | ||
|
@@ -131,12 +133,14 @@ | |
"cdn.jsdelivr.net/gh/jdecked/twemoji@latest/assets", | ||
// Testing | ||
"example.com", | ||
"loremflickr.com", | ||
// Browser downloads | ||
"googlechromelabs.github.io/chrome-for-testing", | ||
"edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing" | ||
], | ||
"run": [ | ||
"deno", | ||
"docker", | ||
"$CHROME_BIN" | ||
], | ||
"read": [ | ||
|
@@ -146,6 +150,7 @@ | |
"write": [ | ||
".test", | ||
".cache", | ||
"$TMP", | ||
"$HOME/.config/chromium/SingletonLock" | ||
], | ||
"env": true | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
// Imports | ||
import { is, parse, Plugin } from "@engine/components/plugin.ts" | ||
import { Logger } from "@engine/utils/log.ts" | ||
import { command } from "@engine/utils/deno/command.ts" | ||
import { throws } from "@engine/utils/errors.ts" | ||
import { read } from "@engine/utils/deno/io.ts" | ||
import { encodeBase64 } from "std/encoding/base64.ts" | ||
|
||
/** Plugin */ | ||
export default class extends Plugin { | ||
/** Import meta */ | ||
static readonly meta = import.meta | ||
|
||
/** Name */ | ||
readonly name = "🏛️ Legacy plugins execution" | ||
|
||
/** Category */ | ||
readonly category = "metrics" | ||
|
||
/** Description */ | ||
readonly description = "Executes plugins using metrics v3 docker image" | ||
|
||
/** Supports */ | ||
readonly supports = ["user", "organization", "repository"] | ||
|
||
/** 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"), | ||
}) | ||
|
||
/** Outputs */ | ||
readonly outputs = is.object({ | ||
content: is.string().describe("Rendered content (base64 encoded)"), | ||
}) | ||
|
||
/** Permissions */ | ||
readonly permissions = ["run:docker", "write:tmp"] | ||
|
||
/** Action */ | ||
protected async action() { | ||
const { handle } = this.context | ||
const { version, inputs } = await parse(this.inputs, this.context.args) | ||
|
||
// Prepare context | ||
const context = { | ||
fixed: { | ||
use_prebuilt_image: true, | ||
config_base64: true, | ||
output_action: "none", | ||
filename: "metrics.legacy", | ||
config_output: "svg", | ||
// TODO(@lowlighter): set mime type according to config_output | ||
// auto / svg / png / jpeg / json / markdown / markdown-pdf / insights | ||
}, | ||
inherited: { | ||
token: this.context.token.read(), | ||
user: handle?.split("/")[0], | ||
repo: handle?.split("/")[1], | ||
template: this.context.template, | ||
config_timezone: this.context.timezone, | ||
retries: this.context.retries.attempts, | ||
retries_delay: this.context.retries.delay, | ||
plugins_errors_fatal: this.context.fatal, | ||
debug: Logger.channels[this.context.logs] >= Logger.channels.debug, | ||
use_mocked_data: this.context.mock, | ||
github_api_rest: this.context.api, | ||
github_api_graphql: this.context.api, | ||
}, | ||
editable: [ | ||
/^base(?:_|$)/, | ||
/^repositories(?:_|$)/, | ||
/^users_ignored$/, | ||
/^commits_authoring$/, | ||
/^markdown$/, | ||
/^optimize$/, | ||
/^setup_community_templates$/, | ||
/^query$/, | ||
/^extras_(?:css|js)$/, | ||
/^config_(?:order|twemoji|gemoji|octicon|display|animations|padding|presets)$/, | ||
/^delay$/, | ||
/^quota_required_(?:rest|graphql|search)$/, | ||
/^verify$/, | ||
/^debug_flags$/, | ||
/^experimental_features$/, | ||
/^plugin_\w+$/, | ||
], | ||
inputs: {} as Record<PropertyKey, unknown>, | ||
} | ||
Object.assign(context.inputs, context.fixed, context.inherited) | ||
|
||
// Register user inputs | ||
for (const [key, value] of Object.entries(inputs)) { | ||
if (key in context.fixed) { | ||
this.log.warn(`ignoring ${key}: cannot be overriden in this context`) | ||
continue | ||
} | ||
if ((key in context.inherited) || (context.editable.some((regex) => regex.test(key)))) { | ||
this.log.trace(`registering: ${key}=${value}`) | ||
context.inputs[key] = value | ||
continue | ||
} | ||
this.log.warn(`ignoring ${key}: not supported in this context`) | ||
} | ||
|
||
// Execute docker image | ||
const tmp = await Deno.makeTempDir({ prefix: "metrics_legacy_" }) | ||
try { | ||
const env = Object.fromEntries(Object.entries(context.inputs).map(([key, value]) => [`INPUT_${key.toLocaleUpperCase()}`, `${value ?? ""}`])) | ||
this.log.trace(env) | ||
const { success } = await command(`docker run --rm ${Object.keys(env).map((key) => `--env ${key}`).join(" ")} --volume=${tmp}:/renders ghcr.io/lowlighter/metrics:${version}`, { | ||
log: this.log, | ||
env, | ||
}) | ||
if (!success) { | ||
throws("Failed to execute metrics") | ||
} | ||
this.context.template = "legacy" | ||
return { content: encodeBase64(await read(`${tmp}/metrics.legacy`)) } | ||
} finally { | ||
await Deno.remove(tmp, { recursive: true }) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<section class="legacy"> | ||
<% if (result instanceof Error) { %> | ||
<div class="error"> | ||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M2.343 13.657A8 8 0 1113.657 2.343 8 8 0 012.343 13.657zM6.03 4.97a.75.75 0 00-1.06 1.06L6.94 8 4.97 9.97a.75.75 0 101.06 1.06L8 9.06l1.97 1.97a.75.75 0 101.06-1.06L9.06 8l1.97-1.97a.75.75 0 10-1.06-1.06L8 6.94 6.03 4.97z"></path></svg> | ||
<span><%= result.message %></span> | ||
</div> | ||
<% } else { %> | ||
<img src="data:image/svg+xml;base64,<%= result.content %>"> | ||
<% } %> | ||
</section> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
- name: supports `version` | ||
plugins: | ||
# - .legacy: | ||
# version: v3.34 | ||
# handle: octocat | ||
# processors: | ||
# - assert: | ||
# html: | ||
# select: .legacy img | ||
# count: 1= | ||
- .legacy: | ||
version: v3.99 | ||
handle: octocat | ||
fatal: false | ||
logs: none | ||
processors: | ||
- assert: | ||
error: /failed to execute metrics/i | ||
|
||
#- name: supports `inputs` | ||
# plugins: | ||
# - .legacy: | ||
# inputs: | ||
# use_prebuilt_image: false | ||
# dryrun: true | ||
# base: header | ||
# handle: octocat | ||
# processors: | ||
# - assert: | ||
# html: | ||
# select: .legacy img | ||
# count: 1= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.