From 8a4f4d8b4fa0aefbbedf904bcb6fc96defb8bf3d Mon Sep 17 00:00:00 2001 From: bana118 Date: Wed, 2 Jun 2021 19:53:21 +0900 Subject: [PATCH] add dry_run option --- README.md | 13 +++++++++++++ action.yml | 3 +++ app/main.js | 17 +++++++++++++---- 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index e851691..947865a 100644 --- a/README.md +++ b/README.md @@ -225,6 +225,19 @@ Useful for projects where the version number may be output by a previous action. version: "${{ steps.previous_step.outputs.version }}" ``` +### dry_run + +If this value is true, the tag will not be pushed. +You can check for duplicate versions when creating a pull request. + +```yaml +- uses: butlerlogic/action-autotag@1.0.0 + with: + GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" + dry_run: true +``` + + ## Developer Notes If you are building an action that runs after this one, be aware this action produces several [outputs](https://help.github.com/en/articles/metadata-syntax-for-github-actions#outputs): diff --git a/action.yml b/action.yml index f7d2128..4e7c3c5 100644 --- a/action.yml +++ b/action.yml @@ -34,6 +34,9 @@ inputs: regex_pattern: description: An optional attribute containing the regular expression used to extract the version number. required: false + dry_run: + description: If this value is true, the tag will not be pushed. + required: false outputs: tagname: description: Returns the new tag value. Empty if a tag is not created. diff --git a/app/main.js b/app/main.js index 0d6bce1..f788d07 100644 --- a/app/main.js +++ b/app/main.js @@ -17,7 +17,9 @@ async function run () { // Identify the tag parsing strategy const root = core.getInput('root', { required: false }) || core.getInput('package_root', { required: false }) || './' const strategy = (core.getInput('regex_pattern', { required: false }) || '').trim().length > 0 ? 'regex' : ((core.getInput('strategy', { required: false }) || 'package').trim().toLowerCase()) - + + // If this value is true, the tag will not be pushed + const isDryRun = core.getInput('dry_run', { required: false }); // Extract the version number using the supplied strategy let version = core.getInput('root', { required: false }) @@ -60,22 +62,29 @@ async function run () { core.getInput('tag_suffix', { required: false }) ) - core.warning(`Attempting to create ${tag.name} tag.`) + if (isDryRun === "true") { + core.warning(`"${tag.name}" tag is not pushed because the dry_run option was set.`) + } else { + core.warning(`Attempting to create ${tag.name} tag.`) + } + core.setOutput('tagrequested', tag.name) core.setOutput('prerelease', tag.prerelease ? 'yes' : 'no') core.setOutput('build', tag.build ? 'yes' : 'no') // Check for existance of tag and abort (short circuit) if it already exists. if (await tag.exists()) { - core.warning(`"${tag.name}" tag already exists.` + os.EOL) + core.setFailed(`"${tag.name}" tag already exists.` + os.EOL) core.setOutput('tagname', '') return } // The tag setter will autocorrect the message if necessary. tag.message = core.getInput('tag_message', { required: false }).trim() - await tag.push() + if (isDryRun !== "true") { + await tag.push() + } core.setOutput('tagname', tag.name) core.setOutput('tagsha', tag.sha) core.setOutput('taguri', tag.uri)