Skip to content

Commit

Permalink
Added output only mode, fixes: #51
Browse files Browse the repository at this point in the history
  • Loading branch information
gautamkrishnar committed Jan 11, 2021
1 parent d413cb0 commit 194401d
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,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` | `[email protected]` | 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. This will also prevent committing to readme. | No |

### Advanced usage examples
#### StackOverflow example
Expand Down
7 changes: 7 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ inputs:
description: "Email id used while committing to the repo"
default: "[email protected]"
required: false
output_only:
description: "Prevent updating the readme, instead sets the output to the output variable named `results`"
default: "false"
required: false
outputs:
results:
description: "JSON stringified array of posts"

runs:
using: node12
Expand Down
11 changes: 10 additions & 1 deletion blog-post-workflow.js
Original file line number Diff line number Diff line change
Expand Up @@ -353,8 +353,17 @@ Promise.allSettled(promiseArray).then((results) => {
if (newReadme !== readmeData) {
core.info('Writing to ' + README_FILE_PATH);
fs.writeFileSync(README_FILE_PATH, newReadme);
const outputOnly = core.getInput('output_only') !== 'false';

if (!process.env.TEST_MODE) {
await commitReadme();
if (!outputOnly) {
// Commit to readme
await commitReadme();
} else {
// Sets output as output as `results` variable in github action
core.info('outputOnly mode: set `results` variable. Readme not updated.');
core.setOutput('results', postsArray);
}
}
} else {
core.info('No change detected, skipping');
Expand Down
1 change: 1 addition & 0 deletions local-run.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ fs.writeFile(path.join(__dirname, 'test', 'Readme.md'), template, () => {
process.env.INPUT_TITLE_MAX_LENGTH = '';
process.env.INPUT_DESCRIPTION_MAX_LENGTH = '';
process.env.INPUT_ITEM_EXEC = '';
process.env.INPUT_OUTPUT_ONLY = 'false';
const testFile = process.env.DIST ? './dist/blog-post-workflow' :'./blog-post-workflow';
console.log('Testing: ', testFile);
require(testFile);
Expand Down
1 change: 1 addition & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const DEFAULT_TEST_ENV = {
INPUT_TITLE_MAX_LENGTH: '',
INPUT_DESCRIPTION_MAX_LENGTH: '',
INPUT_ITEM_EXEC: '',
INPUT_OUTPUT_ONLY: 'false',
TEST_MODE: 'true'
};

Expand Down

0 comments on commit 194401d

Please sign in to comment.