Add GitHub Skyline plugin (#147)

This commit is contained in:
Simon Lecoq
2021-02-20 19:50:31 +01:00
committed by GitHub
parent 66d7c79acb
commit 91bebb44cc
9 changed files with 734 additions and 4 deletions

View File

@@ -0,0 +1,27 @@
### 🌇 GitHub Skyline 3D calendar
⚠️ This plugin significantly increase file size, prefer using it as standalone.
The *skyline* plugin lets you display your 3D commits calendar from [skyline.github.com](https://skyline.github.com/).
<table>
<td align="center">
<img src="https://github.com/lowlighter/lowlighter/blob/master/metrics.plugin.skyline.svg">
<img width="900" height="1" alt="">
</td>
</table>
This uses puppeteer to generate collect image frames, and use CSS animations to create an animated rendering (GIF images are not animated in GitHub flavored markdown rendering which is why this design choice was made).
#### Examples workflows
[➡️ Available options for this plugin](metadata.yml)
```yaml
- uses: lowlighter/metrics@latest
with:
# ... other options
plugin_skyline: yes
plugin_skyline_year: 0 # Set to 0 to display current year
plugin_skyline_frames: 60 # Use 60 frames (half-loop)
```

View File

@@ -0,0 +1,49 @@
//Setup
export default async function({login, q, imports, data, account}, {enabled = false} = {}) {
//Plugin execution
try {
//Check if plugin is enabled and requirements are met
if ((!enabled)||(!q.skyline))
return null
//Load inputs
let {year, frames} = imports.metadata.plugins.skyline.inputs({data, account, q})
if (Number.isNaN(year)) {
year = new Date().getFullYear()
console.debug(`metrics/compute/${login}/plugins > skyline > year set to ${year}`)
}
const width = 454
const height = 284
//Start puppeteer and navigate to skyline.github.com
console.debug(`metrics/compute/${login}/plugins > skyline > starting browser`)
const browser = await imports.puppeteer.launch({headless:true, executablePath:process.env.PUPPETEER_BROWSER_PATH, args:["--no-sandbox", "--disable-extensions", "--disable-setuid-sandbox", "--disable-dev-shm-usage"]})
console.debug(`metrics/compute/${login}/plugins > skyline > started ${await browser.version()}`)
const page = await browser.newPage()
await page.setViewport({width, height})
//Load page
console.debug(`metrics/compute/${login}/plugins > skyline > loading skyline.github.com/${login}/${year}`)
await page.goto(`https://skyline.github.com/${login}/${year}`, {timeout:90*1000})
console.debug(`metrics/compute/${login}/plugins > skyline > waiting for initial render`)
const frame = page.mainFrame()
await page.waitForFunction('[...document.querySelectorAll("span")].map(span => span.innerText).includes("Download STL file")', {timeout:90*1000})
await frame.evaluate(() => [...document.querySelectorAll("button, footer, a")].map(element => element.remove()))
//Generate gif
console.debug(`metrics/compute/${login}/plugins > skyline > generating frames`)
const framed = await imports.puppeteergif({page, width, height, frames, scale:0.5})
//Close puppeteer
await browser.close()
//Results
return {frames:framed}
}
//Handle errors
catch (error) {
throw {error:{message:"An error occured", instance:error}}
}
}

View File

@@ -0,0 +1,28 @@
name: "🌇 GitHub Skyline 3D calendar"
cost: N/A
categorie: github
supports:
- user
inputs:
# Enable or disable plugin
plugin_skyline:
description: Display GitHub Skyline 3D calendar
type: boolean
default: no
# Displayed year
plugin_skyline_year:
description: Displayed year
type: number
default: "current-year"
min: 2008
# Number of frames
# Use 120 for a full-loop and 60 for a half-loop
plugin_skyline_frames:
description: Number of frames
type: number
default: 60
min: 1
max: 120

View File

@@ -0,0 +1,8 @@
- name: Skyline plugin (default)
uses: lowlighter/metrics@latest
with:
token: NOT_NEEDED
plugin_skyline: yes
timeout: 1800000
modes:
- action