Skip to content

Commit

Permalink
feat(dry_run): add a new input - "dry_run"
Browse files Browse the repository at this point in the history
  • Loading branch information
cycjimmy committed Oct 18, 2019
1 parent d21e917 commit 65686aa
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ GitHub Action for [Semantic Release](https://github.com/semantic-release/semanti
* inputs:
* `branch`: [Optional] The branch for release. Default `"master"`.
* `extra_plugins`: [Optional] Extra plugins for pre-install. Default `""`.
* `dry_run`: [Optional] Whether to run semantic release in "dry-run" mode. It will override the dryRun attribute in your configuration file. Default `""`.
* outputs:
* `new-release-published`: Whether a new release was published. `true` or `false`

Expand Down
5 changes: 4 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@ inputs:
extra_plugins:
description: 'Extra plugins for pre-install'
default: ''
dry_run:
description: 'Whether to run semantic release in "dry-run" mode. It will override the dryRun attribute in your configuration file'
default: ''
outputs:
new-release-published:
description: "Whether a new release was published"
description: 'Whether a new release was published'
runs:
using: 'node12'
main: 'index.js'
28 changes: 27 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,29 @@ const semanticRelease = require('semantic-release');

const OutputKey_NewReleasePublished = 'new-release-published';

/**
* handleDryRunOption
* @returns {{}|{dryRun: boolean}}
*/
const handleDryRunOption = () => {
const dryRun = core.getInput('dry_run', {required: false}) || '';

switch (dryRun) {
case 'true':
return {dryRun: true};

case 'false':
return {dryRun: false};

default:
return {};
}
};

/**
* Release main task
* @returns {Promise<Promise<never>|undefined>}
*/
const release = async () => {
const branch = core.getInput('branch', {required: false}) || 'master';
const extraPlugins = core.getInput('extra_plugins', {required: false}) || '';
Expand All @@ -26,7 +49,10 @@ const release = async () => {
}
}

const result = await semanticRelease({branch});
const result = await semanticRelease({
branch,
...(handleDryRunOption()),
});

if (!result) {
core.debug('No release published.');
Expand Down

0 comments on commit 65686aa

Please sign in to comment.