Plugin pagespeed detailed and workflow refactor (#15)
* Display debug logs on error * Add workflow generator * Minor plugins adjustements * Add plugin_pagespeed_detailed option * Rename computed.plugins to plugins * Rebuild * Fix mishandling of boolean value in url for web instance * Add pagespeed.detailled option for web instances * Update formatting of pagespeed detailed report * Add version display and prefers-color-scheme for web instance
This commit is contained in:
@@ -5,10 +5,13 @@
|
||||
import ncc from "@vercel/ncc"
|
||||
import minify from "babel-minify"
|
||||
import colors from "colors"
|
||||
import ejs from "ejs"
|
||||
|
||||
//Initialization
|
||||
const __dirname = path.join(path.dirname(url.fileURLToPath(import.meta.url)), "..")
|
||||
const __action = path.join(__dirname, "action")
|
||||
const __workflows = path.join(__dirname, ".github/workflows")
|
||||
const __utils = path.join(__dirname, "utils")
|
||||
const __src = path.join(__dirname, "src")
|
||||
const __plugins = path.join(__src, "plugins")
|
||||
const __templates = path.join(__src, "templates")
|
||||
@@ -57,6 +60,48 @@
|
||||
|
||||
}
|
||||
|
||||
//Workflow
|
||||
{
|
||||
//Build
|
||||
const code = await ejs.renderFile(path.join(__utils, "workflow.yml"), {
|
||||
releases:["master", "latest"],
|
||||
templates:(await fs.promises.readdir(__templates)).filter(name => !/.*[.]mjs$/.test(name)).sort(),
|
||||
testcase(context = {}) {
|
||||
return [`with:`, ...Object.entries({
|
||||
token:"${{ secrets.METRICS_TOKEN }}",
|
||||
dryrun:true,
|
||||
repositories:1,
|
||||
template:"${{ matrix.template }}",
|
||||
base:"",
|
||||
plugins_errors_fatal:true,
|
||||
...context
|
||||
}).map(([key, value]) => `${" ".repeat(5)}${key}: ${
|
||||
typeof value === "boolean" ? (value ? "yes" : "no") :
|
||||
typeof value === "string" ? (!value ? `""` : value) :
|
||||
value
|
||||
}`)].join("\n")
|
||||
},
|
||||
}, {async:true})
|
||||
console.log(`Generated workflow`.grey)
|
||||
|
||||
//Save build
|
||||
if (actions.includes("build")) {
|
||||
fs.promises.writeFile(path.join(__workflows, "workflow.yml"), code)
|
||||
console.log(`Generated workflow saved to ${path.join(__workflows, "dist/index.js")}`.green)
|
||||
}
|
||||
|
||||
//Check build
|
||||
if (actions.includes("check")) {
|
||||
const status = `${await fs.promises.readFile(path.join(__workflows, "workflow.yml"))}` === code
|
||||
if (status)
|
||||
console.log(`Workflow is up-to-date`.grey)
|
||||
else {
|
||||
console.log(`Workflow is outdated`.red)
|
||||
errors.push(`Workflow is outdated, run "npm run build" to fix it`)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Action
|
||||
{
|
||||
//Build
|
||||
|
||||
185
utils/workflow.yml
Normal file
185
utils/workflow.yml
Normal file
@@ -0,0 +1,185 @@
|
||||
name: Build
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ master ]
|
||||
pull_request:
|
||||
branches: [ master ]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
- name: Setup
|
||||
uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: 15.x
|
||||
- name: Install
|
||||
run: npm ci
|
||||
- name: Build
|
||||
run: npm run build
|
||||
- name: Test
|
||||
run: npm test
|
||||
|
||||
analyze:
|
||||
runs-on: ubuntu-latest
|
||||
needs: <%- JSON.stringify(releases.map(release => `test@${release}`)) %>
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
- name: Setup
|
||||
uses: github/codeql-action/init@v1
|
||||
with:
|
||||
languages: javascript
|
||||
config-file: ./.github/config/codeql.yml
|
||||
- name: Analyze
|
||||
uses: github/codeql-action/analyze@v1
|
||||
|
||||
# Tests cases below are auto generated through `npm run build`
|
||||
# Edit utils/workflow.yml instead if you need to update workflow
|
||||
<% for (const release of releases) { %>
|
||||
test@<%- release %>:
|
||||
needs: build
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
template: <%- JSON.stringify(templates) %>
|
||||
steps:
|
||||
|
||||
- name: ${{ matrix.template }} > Base
|
||||
uses: lowlighter/metrics@<%- release %>
|
||||
<%- testcase({
|
||||
base: "header, activity, community, repositories, metadata",
|
||||
}) %>
|
||||
|
||||
- name: ${{ matrix.template }} > Plugin > PageSpeed
|
||||
uses: lowlighter/metrics@<%- release %>
|
||||
<%- testcase({
|
||||
plugin_pagespeed: true,
|
||||
plugin_pagespeed_token: "${{ secrets.PAGESPEED_TOKEN }}",
|
||||
}) %>
|
||||
|
||||
- name: ${{ matrix.template }} > Plugin > PageSpeed (detailed)
|
||||
uses: lowlighter/metrics@<%- release %>
|
||||
<%- testcase({
|
||||
plugin_pagespeed: true,
|
||||
plugin_pagespeed_detailed: true,
|
||||
plugin_pagespeed_token: "${{ secrets.PAGESPEED_TOKEN }}",
|
||||
}) %>
|
||||
|
||||
- name: ${{ matrix.template }} > Plugin > Music (playlist - apple)
|
||||
uses: lowlighter/metrics@<%- release %>
|
||||
<%- testcase({
|
||||
plugin_music: true,
|
||||
plugin_music_playlist: "${{ secrets.MUSIC_PLAYLIST_APPLE }}",
|
||||
}) %>
|
||||
|
||||
- name: ${{ matrix.template }} > Plugin > Music (playlist - spotify)
|
||||
uses: lowlighter/metrics@<%- release %>
|
||||
<%- testcase({
|
||||
plugin_music: true,
|
||||
plugin_music_playlist: "${{ secrets.MUSIC_PLAYLIST_SPOTIFY }}",
|
||||
}) %>
|
||||
|
||||
- name: ${{ matrix.template }} > Plugin > Music (recent - spotify)
|
||||
uses: lowlighter/metrics@<%- release %>
|
||||
<%- testcase({
|
||||
plugin_music: true,
|
||||
plugin_music_provider: "spotify",
|
||||
plugin_music_token: "${{ secrets.SPOTIFY_TOKENS }}",
|
||||
}) %>
|
||||
|
||||
- name: ${{ matrix.template }} > Plugin > Posts (dev.to)
|
||||
uses: lowlighter/metrics@<%- release %>
|
||||
<%- testcase({
|
||||
plugin_posts: true,
|
||||
plugin_posts_source: "dev.to",
|
||||
}) %>
|
||||
|
||||
- name: ${{ matrix.template }} > Plugin > Isocalendar
|
||||
uses: lowlighter/metrics@<%- release %>
|
||||
<%- testcase({
|
||||
plugin_isocalendar: true,
|
||||
}) %>
|
||||
|
||||
- name: ${{ matrix.template }} > Plugin > Isocalendar (full year)
|
||||
uses: lowlighter/metrics@<%- release %>
|
||||
<%- testcase({
|
||||
plugin_isocalendar: true,
|
||||
plugin_isocalendar_duration: "full-year",
|
||||
}) %>
|
||||
|
||||
- name: ${{ matrix.template }} > Plugin > Habits
|
||||
uses: lowlighter/metrics@<%- release %>
|
||||
<%- testcase({
|
||||
plugin_habits: true,
|
||||
}) %>
|
||||
|
||||
- name: ${{ matrix.template }} > Plugin > Languages
|
||||
uses: lowlighter/metrics@<%- release %>
|
||||
<%- testcase({
|
||||
plugin_languages: true,
|
||||
}) %>
|
||||
|
||||
- name: ${{ matrix.template }} > Plugin > Follow-up
|
||||
uses: lowlighter/metrics@<%- release %>
|
||||
<%- testcase({
|
||||
plugin_followup: true,
|
||||
}) %>
|
||||
|
||||
- name: ${{ matrix.template }} > Plugin > Lines
|
||||
uses: lowlighter/metrics@<%- release %>
|
||||
<%- testcase({
|
||||
plugin_lines: true,
|
||||
}) %>
|
||||
|
||||
- name: ${{ matrix.template }} > Plugin > Traffic
|
||||
uses: lowlighter/metrics@<%- release %>
|
||||
<%- testcase({
|
||||
plugin_traffic: true,
|
||||
}) %>
|
||||
|
||||
- name: ${{ matrix.template }} > Plugin > Gists
|
||||
uses: lowlighter/metrics@<%- release %>
|
||||
<%- testcase({
|
||||
plugin_gists: true,
|
||||
}) %>
|
||||
|
||||
- name: ${{ matrix.template }} > Plugin > Topics (stars)
|
||||
uses: lowlighter/metrics@<%- release %>
|
||||
<%- testcase({
|
||||
plugin_topics: true,
|
||||
plugin_topics_sort: "stars",
|
||||
}) %>
|
||||
|
||||
- name: ${{ matrix.template }} > Plugin > Topics (activity)
|
||||
uses: lowlighter/metrics@<%- release %>
|
||||
<%- testcase({
|
||||
plugin_topics: true,
|
||||
plugin_topics_sort: "activity",
|
||||
}) %>
|
||||
|
||||
- name: ${{ matrix.template }} > Plugin > Topics (starred)
|
||||
uses: lowlighter/metrics@<%- release %>
|
||||
<%- testcase({
|
||||
plugin_topics: true,
|
||||
plugin_topics_sort: "starred",
|
||||
}) %>
|
||||
|
||||
- name: ${{ matrix.template }} > Plugin > Topics (random)
|
||||
uses: lowlighter/metrics@<%- release %>
|
||||
<%- testcase({
|
||||
plugin_topics: true,
|
||||
plugin_topics_sort: "random",
|
||||
}) %>
|
||||
|
||||
- name: ${{ matrix.template }} > Plugin > Projects
|
||||
uses: lowlighter/metrics@<%- release %>
|
||||
<%- testcase({
|
||||
plugin_projects: true,
|
||||
plugin_projects_limit: 2,
|
||||
}) %>
|
||||
|
||||
<% } -%>
|
||||
Reference in New Issue
Block a user