feat(core): add output_condition option (#620) [skip ci]
This commit is contained in:
@@ -93,6 +93,7 @@ async function wait(seconds) {
|
||||
retries,
|
||||
"retries.delay":retries_delay,
|
||||
"output.action":_action,
|
||||
"output.condition":_output_condition,
|
||||
delay,
|
||||
...config
|
||||
} = metadata.plugins.core.inputs.action({core})
|
||||
@@ -321,9 +322,31 @@ async function wait(seconds) {
|
||||
throw error ?? new Error("Could not render metrics")
|
||||
info("Status", "complete")
|
||||
|
||||
//Save output to renders output folder
|
||||
//Output condition
|
||||
info.break()
|
||||
info.section("Saving")
|
||||
info("Output condition", _output_condition)
|
||||
if ((_output_condition === "skip-if-only-metadata-changed")&&((committer.commit) || (committer.pr))) {
|
||||
const {svg} = await import("../metrics/utils.mjs")
|
||||
let data = ""
|
||||
try {
|
||||
data = `${Buffer.from((await committer.rest.repos.getContent({...github.context.repo, ref:`heads/${committer.head}`, path:filename})).data.content, "base64")}`
|
||||
}
|
||||
catch (error) {
|
||||
if (error.response.status !== 404)
|
||||
throw error
|
||||
}
|
||||
const previous = await svg.hash(data)
|
||||
info("Previous hash", previous)
|
||||
const current = await svg.hash(rendered)
|
||||
info("Current hash", current)
|
||||
const changed = (previous !== current)
|
||||
info("Content changed", changed)
|
||||
if (!changed)
|
||||
committer.commit = false
|
||||
}
|
||||
|
||||
//Save output to renders output folder
|
||||
if (dryrun)
|
||||
info("Actions to perform", "(none)")
|
||||
else {
|
||||
|
||||
@@ -24,6 +24,7 @@ import fetch from "node-fetch"
|
||||
import readline from "readline"
|
||||
import emoji from "emoji-name-map"
|
||||
import minimatch from "minimatch"
|
||||
import crypto from "crypto"
|
||||
prism_lang()
|
||||
|
||||
//Exports
|
||||
@@ -413,6 +414,29 @@ export const svg = {
|
||||
console.debug("metrics/svg/resize > rendering complete")
|
||||
return {resized, mime}
|
||||
},
|
||||
/**Hash a SVG (removing its metadata first)*/
|
||||
async hash(rendered) {
|
||||
//Handle empty case
|
||||
if (!rendered)
|
||||
return null
|
||||
//Instantiate browser if needed
|
||||
if (!svg.resize.browser) {
|
||||
svg.resize.browser = await puppeteer.launch()
|
||||
console.debug(`metrics/svg/hash > started ${await svg.resize.browser.version()}`)
|
||||
}
|
||||
//Compute hash
|
||||
const page = await svg.resize.browser.newPage()
|
||||
await page.setContent(rendered, {waitUntil:["load", "domcontentloaded", "networkidle2"]})
|
||||
const data = await page.evaluate(async () => {
|
||||
document.querySelector("footer")?.remove()
|
||||
return document.querySelector("svg").outerHTML
|
||||
})
|
||||
const hash = crypto.createHash("md5").update(data).digest("hex")
|
||||
//Result
|
||||
await page.close()
|
||||
console.debug(`metrics/svg/hash > MD5=${hash}`)
|
||||
return hash
|
||||
},
|
||||
/**Render twemojis */
|
||||
async twemojis(rendered, {custom = true} = {}) {
|
||||
//Load emojis
|
||||
|
||||
Reference in New Issue
Block a user