diff --git a/source/app/action/index.mjs b/source/app/action/index.mjs index b0f26892..f4931f43 100644 --- a/source/app/action/index.mjs +++ b/source/app/action/index.mjs @@ -67,7 +67,7 @@ filename, optimize, verify, debug, "debug.flags":dflags, "use.mocked.data":mocked, dryrun, "plugins.errors.fatal":die, - "committer.token":_token, "committer.branch":_branch, "committer.message":_message, + "committer.token":_token, "committer.branch":_branch, "committer.message":_message, "committer.gist":_gist, "use.prebuilt.image":_image, retries, "retries.delay":retries_delay, "output.action":_action, @@ -127,6 +127,7 @@ if (!dryrun) { //Compute committer informations committer.token = _token || token + committer.gist = _action === "gist" ? _gist : null committer.commit = true committer.message = _message.replace(/[$][{]filename[}]/g, filename) committer.pr = /^pull-request/.test(_action) @@ -138,6 +139,9 @@ throw new Error("You must provide a valid GitHub token to commit your metrics") info("Committer branch", committer.branch) info("Committer head branch", committer.head) + //Gist + if (committer.gist) + info("Committer Gist id", committer.gist) //Instantiate API for committer committer.rest = github.getOctokit(committer.token) info("Committer REST API", "ok") @@ -279,6 +283,13 @@ } } + //Upload to gist (this is done as user since committer_token may not have gist rights) + if (committer.gist) { + await rest.gists.update({gist_id:committer.gist, files:{[filename]:{content:rendered}}}) + info(`Upload to gist ${committer.gist}`, "ok") + committer.commit = false + } + //Commit metrics if (committer.commit) { await committer.rest.repos.createOrUpdateFileContents({ diff --git a/source/plugins/core/README.md b/source/plugins/core/README.md index 0a27fd77..8a25613e 100644 --- a/source/plugins/core/README.md +++ b/source/plugins/core/README.md @@ -153,7 +153,7 @@ Specify a single value to apply it to both height and with, and two values to us config_padding: 6%, 10% # 6% width padding, 10% height padding ``` -### 🧶 Using commits, pull requests or manual review to handle metrics output +### 🧶 Using commits, pull requests, manual reviews or gists to handle metrics output It is possible to configure output behaviour using `output_action` option, which can be set to: - `none`, where output will be generated in `/rendered/${filename}` without being pushed @@ -163,6 +163,8 @@ It is possible to configure output behaviour using `output_action` option, which - By appending either `-merge`, `-squash` or `-rebase`, pull request will be automatically merged with given method - This method is useful to combine all editions of a single run with multiples metrics steps into a single commit on targetted branch - If you choose to manually merge pull requests, be sure to disable `push:` triggers on your workflow, as it'll count as your own commit +- `gist`, where output will be stored an already existing gist + - To use this feature, a `gists` scope must be granted to your `token` and `committer_gist` identifier must be provided #### ℹ️ Examples workflows diff --git a/source/plugins/core/metadata.yml b/source/plugins/core/metadata.yml index c725fad9..fec32abc 100644 --- a/source/plugins/core/metadata.yml +++ b/source/plugins/core/metadata.yml @@ -52,6 +52,14 @@ inputs: type: string default: Update ${filename} - [Skip GitHub Action] + # Instead of saving metrics to a repository, it's possible to save them to a gist to avoid "commits pollution" + # Gist must be created prior and you must pass its identifier in the following option + # Set "gist" in "output_action" to use this option + committer_gist: + description: Gist used to store metrics + type: string + default: "" + # Rendered metrics output path, relative to repository's root filename: description: Rendered metrics output path @@ -83,6 +91,7 @@ inputs: - pull-request-merge # Same as "pull-request" and additionaly merge pull request - pull-request-squash # Same as "pull-request" and additionaly squash and merge pull request - pull-request-rebase # Same as "pull-request" and additionaly rebase and merge pull request + - gist # Save output to "committer_gist" # Optimize SVG image to reduce its filesize # Some templates may not support this option