fix(app/action): mishandled config_output (#1293)

This commit is contained in:
Simon Lecoq
2022-11-23 00:16:30 +01:00
committed by GitHub
parent f791122af2
commit f40e0a995d
2 changed files with 39 additions and 27 deletions

View File

@@ -318,6 +318,9 @@ function quit(reason) {
console.debug(error) console.debug(error)
} }
info("Previous render sha", committer.sha ?? "(none)") info("Previous render sha", committer.sha ?? "(none)")
//Compatibility check
if ((_action === "gist")&&(["png", "jpeg", "markdown-pdf"].includes(_output)))
throw new Error(`"config_output: ${_output}" is not supported with "config_action: ${_action}"`)
} }
else if (dryrun) { else if (dryrun) {
info("Dry-run", true) info("Dry-run", true)
@@ -398,18 +401,21 @@ function quit(reason) {
//Render metrics //Render metrics
info.break() info.break()
info.section("Rendering") info.section("Rendering")
let rendered = await retry(async () => { let {rendered, mime} = await retry(async () => {
const {rendered, errors} = await metrics({login: user, q}, {graphql, rest, plugins, conf, die, verify, convert}, {Plugins, Templates}) const {rendered, mime, errors} = await metrics({login: user, q}, {graphql, rest, plugins, conf, die, verify, convert}, {Plugins, Templates})
if (errors.length) { if (errors.length) {
console.warn(`::group::${errors.length} error(s) occurred`) console.warn(`::group::${errors.length} error(s) occurred`)
console.warn(util.inspect(errors, {depth: Infinity, maxStringLength: 256})) console.warn(util.inspect(errors, {depth: Infinity, maxStringLength: 256}))
console.warn("::endgroup::") console.warn("::endgroup::")
} }
return rendered return {rendered, mime}
}, {retries, delay: retries_delay}) }, {retries, delay: retries_delay})
if (!rendered) if (!rendered)
throw new Error("Could not render metrics") throw new Error("Could not render metrics")
info("Status", "complete") info("Status", "complete")
info("MIME type", mime)
const buffer = typeof rendered === "object" ? rendered instanceof Buffer ? rendered : Buffer.from(JSON.stringify(rendered)) : Buffer.from(`${rendered}`)
//Debug print //Debug print
if (dprint) { if (dprint) {
@@ -421,6 +427,7 @@ function quit(reason) {
//Output condition //Output condition
info.break() info.break()
info.section("Saving") info.section("Saving")
if (_output === "svg") {
info("Output condition", _output_condition) info("Output condition", _output_condition)
if ((_output_condition === "data-changed") && ((committer.commit) || (committer.pr))) { if ((_output_condition === "data-changed") && ((committer.commit) || (committer.pr))) {
const {svg} = await import("../metrics/utils.mjs") const {svg} = await import("../metrics/utils.mjs")
@@ -443,13 +450,16 @@ function quit(reason) {
if (!changed) if (!changed)
committer.commit = false committer.commit = false
} }
}
else
info("Output condition", `Not applicable for ${_output}`)
//Save output to renders output folder //Save output to renders output folder
if (dryrun) if (dryrun)
info("Actions to perform", "(none)") info("Actions to perform", "(none)")
else { else {
await fs.mkdir(paths.dirname(paths.join("/renders", filename)), {recursive: true}) await fs.mkdir(paths.dirname(paths.join("/renders", filename)), {recursive: true})
await fs.writeFile(paths.join("/renders", filename), Buffer.from(typeof rendered === "object" ? JSON.stringify(rendered) : `${rendered}`)) await fs.writeFile(paths.join("/renders", filename), buffer)
info(`Save to /metrics_renders/${filename}`, "ok") info(`Save to /metrics_renders/${filename}`, "ok")
info("Output action", _action) info("Output action", _action)
} }
@@ -517,7 +527,7 @@ function quit(reason) {
//Upload to gist (this is done as user since committer_token may not have gist rights) //Upload to gist (this is done as user since committer_token may not have gist rights)
if (committer.gist) { if (committer.gist) {
await retry(async () => { await retry(async () => {
await rest.gists.update({gist_id: committer.gist, files: {[filename]: {content: rendered}}}) await rest.gists.update({gist_id: committer.gist, files: {[filename]: {content: buffer.toString()}}})
info(`Upload to gist ${committer.gist}`, "ok") info(`Upload to gist ${committer.gist}`, "ok")
committer.commit = false committer.commit = false
}, {retries: retries_output_action, delay: retries_delay_output_action}) }, {retries: retries_output_action, delay: retries_delay_output_action})
@@ -530,7 +540,7 @@ function quit(reason) {
...github.context.repo, ...github.context.repo,
path: filename, path: filename,
message: committer.message, message: committer.message,
content: Buffer.from(typeof rendered === "object" ? JSON.stringify(rendered) : `${rendered}`).toString("base64"), content: buffer.toString("base64"),
branch: committer.pr ? committer.head : committer.branch, branch: committer.pr ? committer.head : committer.branch,
...(committer.sha ? {sha: committer.sha} : {}), ...(committer.sha ? {sha: committer.sha} : {}),
}) })

View File

@@ -106,6 +106,8 @@ inputs:
- `gist`: push output to `committer_gist` - `gist`: push output to `committer_gist`
> 💡 When using `pull-request`, you will need to set the last job with a `pull-request-*` action instead, else it won't be merged > 💡 When using `pull-request`, you will need to set the last job with a `pull-request-*` action instead, else it won't be merged
> ⚠️ As GitHub gists API does not support binary files upload, `gist` does not support [`config_output`](/source/plugins/core/README.md#config_output) set to either `png`, `jpeg` or `markdown-pdf`
type: string type: string
default: commit default: commit
values: values: