Skip to content

Commit 194401d

Browse files
Added output only mode, fixes: #51
1 parent d413cb0 commit 194401d

File tree

5 files changed

+20
-1
lines changed

5 files changed

+20
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ This workflow has additional options that you can use to customize it for your u
5656
| `commit_message` | `Updated with the latest blog posts` | Allows you to customize the commit message | No |
5757
| `committer_username` | `blog-post-bot` | Allows you to customize the committer username | No |
5858
| `committer_email` | `[email protected]` | Allows you to customize the committer email | No |
59+
| `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. This will also prevent committing to readme. | No |
5960

6061
### Advanced usage examples
6162
#### StackOverflow example

action.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,13 @@ inputs:
7777
description: "Email id used while committing to the repo"
7878
default: "[email protected]"
7979
required: false
80+
output_only:
81+
description: "Prevent updating the readme, instead sets the output to the output variable named `results`"
82+
default: "false"
83+
required: false
84+
outputs:
85+
results:
86+
description: "JSON stringified array of posts"
8087

8188
runs:
8289
using: node12

blog-post-workflow.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,8 +353,17 @@ Promise.allSettled(promiseArray).then((results) => {
353353
if (newReadme !== readmeData) {
354354
core.info('Writing to ' + README_FILE_PATH);
355355
fs.writeFileSync(README_FILE_PATH, newReadme);
356+
const outputOnly = core.getInput('output_only') !== 'false';
357+
356358
if (!process.env.TEST_MODE) {
357-
await commitReadme();
359+
if (!outputOnly) {
360+
// Commit to readme
361+
await commitReadme();
362+
} else {
363+
// Sets output as output as `results` variable in github action
364+
core.info('outputOnly mode: set `results` variable. Readme not updated.');
365+
core.setOutput('results', postsArray);
366+
}
358367
}
359368
} else {
360369
core.info('No change detected, skipping');

local-run.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ fs.writeFile(path.join(__dirname, 'test', 'Readme.md'), template, () => {
2626
process.env.INPUT_TITLE_MAX_LENGTH = '';
2727
process.env.INPUT_DESCRIPTION_MAX_LENGTH = '';
2828
process.env.INPUT_ITEM_EXEC = '';
29+
process.env.INPUT_OUTPUT_ONLY = 'false';
2930
const testFile = process.env.DIST ? './dist/blog-post-workflow' :'./blog-post-workflow';
3031
console.log('Testing: ', testFile);
3132
require(testFile);

test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const DEFAULT_TEST_ENV = {
1818
INPUT_TITLE_MAX_LENGTH: '',
1919
INPUT_DESCRIPTION_MAX_LENGTH: '',
2020
INPUT_ITEM_EXEC: '',
21+
INPUT_OUTPUT_ONLY: 'false',
2122
TEST_MODE: 'true'
2223
};
2324

0 commit comments

Comments
 (0)