5
0
Fork 0
mirror of https://github.com/cycjimmy/semantic-release-action.git synced 2025-11-07 10:46:56 +00:00

feat(dry_run): add a new input - "dry_run"

This commit is contained in:
cycjimmy 2019-10-18 13:49:05 +08:00
parent d21e9173cb
commit 65686aabe7
3 changed files with 32 additions and 2 deletions

View file

@ -12,6 +12,7 @@ GitHub Action for [Semantic Release](https://github.com/semantic-release/semanti
* inputs: * inputs:
* `branch`: [Optional] The branch for release. Default `"master"`. * `branch`: [Optional] The branch for release. Default `"master"`.
* `extra_plugins`: [Optional] Extra plugins for pre-install. Default `""`. * `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: * outputs:
* `new-release-published`: Whether a new release was published. `true` or `false` * `new-release-published`: Whether a new release was published. `true` or `false`

View file

@ -11,9 +11,12 @@ inputs:
extra_plugins: extra_plugins:
description: 'Extra plugins for pre-install' description: 'Extra plugins for pre-install'
default: '' 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: outputs:
new-release-published: new-release-published:
description: "Whether a new release was published" description: 'Whether a new release was published'
runs: runs:
using: 'node12' using: 'node12'
main: 'index.js' main: 'index.js'

View file

@ -5,6 +5,29 @@ const semanticRelease = require('semantic-release');
const OutputKey_NewReleasePublished = 'new-release-published'; 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 release = async () => {
const branch = core.getInput('branch', {required: false}) || 'master'; const branch = core.getInput('branch', {required: false}) || 'master';
const extraPlugins = core.getInput('extra_plugins', {required: false}) || ''; 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) { if (!result) {
core.debug('No release published.'); core.debug('No release published.');