diff --git a/README.md b/README.md index 203e4c9..4c22147 100644 --- a/README.md +++ b/README.md @@ -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` diff --git a/action.yml b/action.yml index f9aabd9..6598bac 100644 --- a/action.yml +++ b/action.yml @@ -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' diff --git a/src/index.js b/src/index.js index 7fc1cb4..58aa000 100644 --- a/src/index.js +++ b/src/index.js @@ -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|undefined>} + */ const release = async () => { const branch = core.getInput('branch', {required: false}) || 'master'; const extraPlugins = core.getInput('extra_plugins', {required: false}) || ''; @@ -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.');