Skip to content

Commit

Permalink
continue
Browse files Browse the repository at this point in the history
  • Loading branch information
lowlighter committed Oct 19, 2023
1 parent bc90d66 commit 61c12df
Show file tree
Hide file tree
Showing 3 changed files with 155 additions and 58 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:

# Build and push Docker image
docker:
if: github.event_name == 'push' && github.ref == 'refs/heads/v4-dev'
if: github.ref == 'refs/heads/v4-dev'
runs-on: ubuntu-latest
needs:
- analyze
Expand All @@ -60,11 +60,13 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: docker/login-action@v3
if: github.event_name == 'push'
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ github.token }}
- uses: docker/build-push-action@v5
with:
context: .
tags: ${{ github.repository }}:v4
push: true
push: ${{ github.event_name == 'push' }}
40 changes: 8 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ See [#1533](https://github.com/lowlighter/metrics/discussions/1533)

## ✈️ Migration guide

> ℹ️ This is still subject to change, see this guide more as a "pre-release note"/"roadmap progress". It may be used later on to create a migration tool from v3 to v4. Plugins not yet listed are not
> yet migrated. This guide will be updated later on
For convenience, _metrics_ offers a [v3 to v4 migration script](/source/run/cli/compat.ts).

### Migration and progression

Expand All @@ -19,16 +18,18 @@ See [#1533](https://github.com/lowlighter/metrics/discussions/1533)
- [x] Plugin framework
- [x] Processor framework
- [ ] Docs auto-generation
- [ ] Code coverage and unit test (not too bad currently !)
- [ ] GitHub Action
- [x] Implement `publish.gist`
- [x] Implement `publish.file`
- [ ] Implement `publish.git` (almost finished, needs to handle the PR merge)
- [x] Docker image
- [ ] Web server
- [ ] Config crafter (big draft)
- [ ] Config crafter (kind of ok, needs some polishing)
- [x] OAuth support
- [ ] Deno deployment (partial support)
- [ ] Vercel deployment (next priority)
- [ ] Plugins
- [ ] Plugins (will add lines, languages and activity as part of pre-release)
- [x] A simple plugin
- [x] A plugin that requires puppeteer
- [x] A plugin that requires an external library
Expand All @@ -55,40 +56,20 @@ See [#1533](https://github.com/lowlighter/metrics/discussions/1533)
- 🧩 **Plugins**
- 📆 **Commit calendar**
- ✨ Merged `isocalendar` and `calendar` plugins, which means that both plugins now have same level of features
-`isocalendar` can now display multiple years and a specific year
-`isocalendar` can now display multiple years or a specific year rather than just last 180 or 365 days
-`calendar` can now display additional stats (such as commits per day, streaks, etc.)
-`calendar.args.view` can now be set to `isometric` or `top-down`
-`calendar.args.range` can now be set to `last-180-days`, `last-365-days`, a specific year or a custom range
-`calendar.args.range.from` can now be set to `registration`, `-n` years relative to `calendar.args.range.to` or a specific year
-`calendar.args.range.to` can now be set to `current-year` or a specific year
-`calendar.args.colors` can now be set to `auto`, `halloween` or `winter`
-`plugin_calendar: yes` ➡️ `plugins: [{id: calendar}]` with `args`
-`plugin_calendar_limit: 0` ➡️ `calendar.args.range: {from: registration, to: current-year}`
-`plugin_calendar_limit: (n > 0)` ➡️ `calendar.args.range: {from: (-n), to: current-year}`
-`plugin_calendar_limit: (n < 0)` ➡️ Use `calendar.args.range.from` with a specific year
- 🎫 **Gists**
- 🐞 Fine-grained tokens always returns `null` data
-`plugin_gists: yes` ➡️ `plugins: [{id: gists}]`
-`gists.args.forks` can now be configured
-`gists.args.visibility` can now be set to `public` or `all`

- 🗼 **Rss feed**
-`plugin_rss: yes` ➡️ `plugins: [{id: rss}]` with `args`
-`plugin_rss_source` ➡️ `rss.args.feed`
-`plugin_rss_limit` ➡️ `rss.args.limit`
-`plugin_rss_limit: 0` ➡️ `rss.args.limit: null`
-`rss.args.limit` no longer has an upper limit (lower limit was changed to `1`)
- 📸 **Website screenshot**
-_This plugin was renamed `webscrap` and is now part of official plugins_
- ➡️ Use `webscrap` plugin
-`plugin_screenshot: yes` ➡️ `plugins: [{id: webscrap}]` with `args`
-`plugin_screenshot_url` ➡️ `webscrap.args.url`
-`plugin_screenshot_selector` ➡️ `webscrap.args.select`
-`plugin_screenshot_mode` ➡️ `webscrap.args.mode`
-`plugin_screenshot_viewport` ➡️ `webscrap.args.viewport.width` and `webscrap.args.viewport.height`
-`plugin_screenshot_wait` ➡️ `webscrap.args.wait`
-`plugin_screenshot_background` ➡️ `webscrap.args.background`
- 📸 **Webscrap**
-`rss.args.limit` no longer has an upper limit (lower limit was changed to `1`)
- 📸 **Webscraping**
- ✨ Added `screenshot` as part of official plugins
- 💭 **GitHub Community Support**
- ❌ Removed as it was already deprecated
Expand Down Expand Up @@ -134,13 +115,8 @@ See [#1533](https://github.com/lowlighter/metrics/discussions/1533)
- ❌ Files are not stored automatically in `/metrics_renders`, it is required to call manually the `publish.file` processor
-`output_action: none` ➡️ `processors: [{id: publish.file}]`
-`debug_print` ➡️ `processors: [{id: publish.console}]`
-`debug_flags`
-`debug_flags: --halloween` ➡️ `calendar.args.colors: halloween`
-`debug_flags: --winter` ➡️ `calendar.args.colors: winter`
-`setup_community_templates` ➡️ `plugins[].template: https://...`
-`query` ➡️ `plugins[].template: https://...?params`
-`dryrun` ➡️ Don't put any publisher processor
-`experimental_features`
-`verify`
- 🪄 **Processors**
- 🧪 **Assertions**
Expand Down
167 changes: 143 additions & 24 deletions source/run/cli/compat.ts
Original file line number Diff line number Diff line change
@@ -1,46 +1,165 @@
// deno-lint-ignore-file no-explicit-any no-unused-vars
//import { env } from "@utils/io.ts"
//import core from "y/@actions/[email protected]"

import core from "y/@actions/[email protected]"
import * as YAML from "std/yaml/mod.ts"
import {
bgBrightMagenta,
blue,
brightBlue,
brightCyan,
brightGreen,
brightGreen as g,
brightMagenta,
brightRed as r,
brightYellow,
cyan,
cyan as b,
gray,
green,
magenta,
white,
yellow,
yellow as y,
} from "std/fmt/colors.ts"
type compat = any

function deprecated(message: string) {
console.warn()
function deprecated(input: string, replacement: Record<string, unknown> | null) {
if (replacement === null) {
core.warn(`${r(input)} is not supported anymore`)
} else {
core.warn(`${r(input)} is deprecated, use the following configuration snippet instead:\n\n${yaml({ config: replacement })}`)
}
}

function notice(plugin: string) {
console.info()
}

const to = {
boolean(value: any) {
return true
},
function yaml(content: Record<string, unknown>) {
const regex = {
kv: /^(?<indent>\s*)(?<array>\-\s+)?'?(?<key>\w[.\w-]*)'?(?:(?<kv>:)(?<value>\s.+)?)?$/,
}
const lines = []
for (const line of YAML.stringify(content).split("\n")) {
if (regex.kv.test(line)) {
let { indent, array = "", kv, key, value } = line.match(regex.kv)!.groups!
let color = white
if (!kv) {
value = key
}
value = value?.trim()
switch (true) {
case ["null"].includes(value):
color = gray
break
case ["{}", "[]", "true", "false"].includes(value):
color = yellow
break
case !Number.isNaN(Number(value)):
color = yellow
break
case /^'.+'$/.test(value):
value = value.replace(/^'|'$/g, "")
color = yellow
break
}
lines.push(`${indent}${array}${kv ? `${cyan(key)}: ${color(value ?? "")}` : color(value ?? "")}`)
continue
}
lines.push(line)
}
return lines.join("\n")
}

export function compat(inputs: compat) {
const config = { plugins: [] } as compat

/*-
- ❗ `plugin_introduction: yes` ➡️ `plugins: [{id: introduction}]`
- ❌ `` ➡️ `processors: [{id: inject.style, args: {style: ".introduction .title { display: none }"}}]`
*/
// 🙋 Introduction
if (to.boolean(inputs.plugin_introduction)) {
if (inputs.plugin_introduction) {
const plugin = { introduction: {} } as compat
deprecated(`"plugin_introduction" is deprecated, use <introduction> plugin`)
if (!inputs.plugin_introduction_title) {
plugin.processors = [{ "inject.style": { style: ".introduction .title { display: none }" } }]
}
config.plugins.push(plugin)
deprecated("plugin_introduction", { plugins: [plugin] })
}

deprecated(`<plugin_introduction_title> is deprecated, use <calendar> plugin with <calendar.range: ${duration}>`)
const title = to.boolean(inputs.plugin_introduction_title)
if (!title) {
plugin.processors = [{ id: "inject.style", args: { style: ".introduction .title { display: none }" } }]
// 📅 Isometric commit calendar
if (inputs.plugin_isocalendar) {
const plugin = { calendar: { view: "isometric" } } as compat
plugin.calendar.duration = { "half-year": "last-180-days", "full-year": "last-365-days" }[inputs.plugin_isocalendar_duration as string] ?? "last-180-days"
if (inputs.debug_flags.find((f: string) => ["--halloween", "--winter"].includes(f))) {
plugin.calendar.colors = inputs.debug_flags.find((f: string) => ["--halloween", "--winter"].includes(f)).replace("--", "")
}
config.plugins.push(plugin)
deprecated("plugin_isocalendar", { plugins: [plugin] })
}

// 📅 Commit calendar
if (inputs.plugin_calendar) {
const plugin = { calendar: { view: "top-down" } } as compat
switch (true) {
case inputs.plugin_calendar_limit === 0:
plugin.calendar.range = { from: "registration", to: "current-year" }
break
case inputs.plugin_calendar_limit > 0:
plugin.calendar.range = { from: -inputs.plugin_calendar_limit, to: "current-year" }
break
case inputs.plugin_calendar_limit < 0:
//TODO(@lowlighter): from = registration - n
plugin.calendar.range = { from: -inputs.plugin_calendar_limit, to: "current-year" }
break
}
if (inputs.debug_flags.find((f: string) => ["--halloween", "--winter"].includes(f))) {
plugin.calendar.colors = inputs.debug_flags.find((f: string) => ["--halloween", "--winter"].includes(f)).replace("--", "")
}
config.plugins.push(plugin)
deprecated("plugin_calendar", { plugins: [plugin] })
}

// 📅 Isometric commit calendar
if (to.boolean(inputs.plugin_isocalendar)) {
deprecated(`"plugin_isocalendar" is deprecated, use "{plugins:{calendar:{view:isometric}}}"`)
const duration = { "half-year": "last-180-days", "full-year": "last-365-days" }[inputs.plugin_isocalendar_duration as string] ?? "last-180-days"
deprecated(`<plugin_isocalendar_duration> is deprecated, use <calendar> plugin with <calendar.range: ${duration}>`)
config.plugins.push({ calendar: { view: "isometric", duration } })
// 🎫 Gists
if (inputs.plugin_gists) {
const plugin = { gists: {} } as compat
config.plugins.push(plugin)
deprecated("plugin_gists", { plugins: [plugin] })
}

// 🗼 Rss feed
if (inputs.plugin_rss) {
const plugin = { rss: {} } as compat
plugin.rss.feed = inputs.plugin_rss_source
plugin.rss.limit = (inputs.plugin_rss_limit > 0) ? inputs.plugin_rss_limit : null
config.plugins.push(plugin)
deprecated("plugin_rss", { plugins: [plugin] })
}

// 📸 Website screenshot
if (inputs.plugin_screenshot) {
const plugin = { webscraping: {} } as compat
plugin.webscraping.url = inputs.plugin_screenshot_url
plugin.webscraping.select = inputs.plugin_screenshot_selector
plugin.webscraping.mode = inputs.plugin_screenshot_mode
plugin.webscraping.viewport = { width: inputs.plugin_screenshot_viewport_width, height: inputs.plugin_screenshot_viewport_height }
plugin.webscraping.wait = inputs.plugin_screenshot_wait
plugin.webscraping.background = inputs.plugin_screenshot_background
config.plugins.push(plugin)
deprecated("plugin_screenshot", { plugins: [plugin] })
}

// 💭 GitHub Community Support
if (inputs.plugin_support) {
deprecated("plugin_support", null)
}

// ❌ Removed options
if (inputs.debug_flags) {
deprecated("debug_flags", null)
}
if (inputs.dryrun) {
deprecated("dryrun", null)
}
if (inputs.experimental_features) {
deprecated("experimental_features", null)
}

return config
Expand Down

0 comments on commit 61c12df

Please sign in to comment.