From 163d740666c7653a5752a18280177abecc20cc5d Mon Sep 17 00:00:00 2001 From: gautamkrishnar Date: Tue, 30 Nov 2021 23:21:10 +0530 Subject: [PATCH] added JSON file output, fixes: #110 --- README.md | 2 +- blog-post-workflow.js | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index bad813e..06c307e 100644 --- a/README.md +++ b/README.md @@ -64,7 +64,7 @@ This workflow has additional options that you can use to customize it for your u | `commit_message` | `Updated with the latest blog posts` | Allows you to customize the commit message | No | | `committer_username` | `blog-post-bot` | Allows you to customize the committer username | No | | `committer_email` | `blog-post-bot@example.com` | Allows you to customize the committer email | No | -| `output_only` | `false` | Sets the generated array as `results` [output variable](https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-syntax-for-github-actions#jobsjob_idoutputs) so that it can be consumed in other actions and parsed via utilities like [jq](https://stedolan.github.io/jq/). This will also prevent committing to readme. See [#51](https://github.com/gautamkrishnar/blog-post-workflow/issues/51#issuecomment-758570235) for more details about the output format and how to use it. | No | +| `output_only` | `false` | Sets the generated array as `results` [output variable](https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-syntax-for-github-actions#jobsjob_idoutputs) so that it can be consumed in other actions and parsed via utilities like [jq](https://stedolan.github.io/jq/). This will also prevent committing to readme. See [#51](https://github.com/gautamkrishnar/blog-post-workflow/issues/51#issuecomment-758570235) for more details about the output format and how to use it. This will also generate a JSON file named `/tmp/blog_post_workflow_output.json` that you can use to consume the generated data and avoid issues like [#110](https://github.com/gautamkrishnar/blog-post-workflow/issues/110). | No | | `enable_keepalive` | `true` | Workflow will automatically do a dummy commit to keep the repository active if there is no commit activity for the last 50 days. GitHub will stop running all cron based triggers if the repository is not active for more than 60 days. This flag allows you to disable this feature. See [#53](https://git.io/Jtm4V) for more details. | No | | `retry_count` | `0` | Maximum number of times to retry the fetch operation if it fails, See [#66](https://github.com/gautamkrishnar/blog-post-workflow/issues/66) for more details. | No | | `retry_wait_time` | `1` | Time to wait before each retry operation in seconds. | No | diff --git a/blog-post-workflow.js b/blog-post-workflow.js index 9933d8a..459e584 100644 --- a/blog-post-workflow.js +++ b/blog-post-workflow.js @@ -20,6 +20,7 @@ const { ignoreMediumComments, ignoreStackOverflowComments } = require('./filters'); +const path = require("path"); // Blog workflow code const userAgent = core.getInput('user_agent'); @@ -290,6 +291,11 @@ Promise.allSettled(promiseArray).then((results) => { // Sets output as output as `results` variable in github action core.info('outputOnly mode: set `results` variable. Readme not committed.'); core.setOutput('results', postsArray); + const outputFilePath = path.join('/','tmp', 'blog_post_workflow_output.json'); + if(fs.existsSync(outputFilePath)) { + fs.rmSync(outputFilePath); + } + fs.writeFileSync(outputFilePath, postsArray, { encoding: 'utf-8'}); process.exit(jobFailFlag ? 1 : 0); }