diff --git a/README.md b/README.md index 947865a..5214cae 100644 --- a/README.md +++ b/README.md @@ -225,7 +225,14 @@ Useful for projects where the version number may be output by a previous action. version: "${{ steps.previous_step.outputs.version }}" ``` -### dry_run +### minVersion + +Set the minimum version which would be used to create a tag. + +The default value (`0.0.1`) prevents a `0.0.0` from being created. This can also be used when introducing Autotag to a repository which has already tagged. + +For example, if the version `0.1.0` would already have been published, set the `minVersion` to the next patch to prevent a duplicate tag for that version. + If this value is true, the tag will not be pushed. You can check for duplicate versions when creating a pull request. @@ -234,10 +241,9 @@ You can check for duplicate versions when creating a pull request. - uses: butlerlogic/action-autotag@1.0.0 with: GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" - dry_run: true + minVersion: "0.1.1" ``` - ## 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 4e7c3c5..b14ccdc 100644 --- a/action.yml +++ b/action.yml @@ -31,6 +31,10 @@ inputs: version: description: Explicitly set the version here instead of automatically detecting from `package.json`. Useful for non-JavaScript projects where version may be output by a previous action. required: false + minVersion: + description: Minimum version required to create a tag. By default it will prevent a version `0.0.0` from being tagged. Also useful when introducing Autotag to an existing repo, to start auto-tagging from a specific version + required: false + default: '0.0.1' regex_pattern: description: An optional attribute containing the regular expression used to extract the version number. required: false diff --git a/app/main.js b/app/main.js index f788d07..c541b5e 100644 --- a/app/main.js +++ b/app/main.js @@ -1,5 +1,6 @@ import core from '@actions/core' import os from 'os' +import semver from 'semver' import Setup from './lib/setup.js' import Package from './lib/package.js' import Tag from './lib/tag.js' @@ -51,6 +52,23 @@ async function run () { throw new Error(`No version identified${msg}`) } + const minVersion = core.getInput('minVersion', { required: false }) + + // Ensure that version and minVersion are valid SemVer strings + const minVersionSemVer = semver.coerce(minVersion) + const versionSemVer = semver.coerce(version) + if (!minVersionSemVer) { + core.warning(`Skipping min version check. ${minVersion} is not valid SemVer`) + } + if(!versionSemVer) { + core.warning(`Skipping min version check. ${version} is not valid SemVer`) + } + + if (minVersionSemVer && versionSemVer && semver.lt(versionSemVer, minVersionSemVer)) { + core.warning(`Version "${version}" is lower than minimum "${minVersion}"`) + return + } + core.warning(`Recognized "${version}"${msg}`) core.setOutput('version', version) core.debug(` Detected version ${version}`) diff --git a/app/package-lock.json b/app/package-lock.json index 864e226..dc7637f 100644 --- a/app/package-lock.json +++ b/app/package-lock.json @@ -1,6 +1,6 @@ { "name": "autotag-action", - "version": "1.0.3", + "version": "1.1.3", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -211,6 +211,13 @@ "semver": "^5.5.0", "shebang-command": "^1.2.0", "which": "^1.2.9" + }, + "dependencies": { + "semver": { + "version": "5.7.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz", + "integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==" + } } }, "deprecation": { @@ -278,6 +285,14 @@ "resolved": "https://registry.npmjs.org/lodash.uniq/-/lodash.uniq-4.5.0.tgz", "integrity": "sha1-0CJTc662Uq3BvILklFM5qEJ1R3M=" }, + "lru-cache": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", + "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", + "requires": { + "yallist": "^4.0.0" + } + }, "macos-release": { "version": "2.4.1", "resolved": "https://registry.npmjs.org/macos-release/-/macos-release-2.4.1.tgz", @@ -343,9 +358,12 @@ } }, "semver": { - "version": "5.7.1", - "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz", - "integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==" + "version": "7.3.4", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.4.tgz", + "integrity": "sha512-tCfb2WLjqFAtXn4KEdxIhalnRtoKFN7nAwj0B3ZXCbQloV2tq5eDbcTmT68JJD3nRJq24/XgxtQKFIpQdtvmVw==", + "requires": { + "lru-cache": "^6.0.0" + } }, "shebang-command": { "version": "1.2.0", @@ -400,6 +418,11 @@ "version": "1.0.2", "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=" + }, + "yallist": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", + "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==" } } } diff --git a/app/package.json b/app/package.json index 1fa06e5..9927468 100644 --- a/app/package.json +++ b/app/package.json @@ -20,7 +20,8 @@ "license": "MIT", "dependencies": { "@actions/core": "^1.2.2", - "@actions/github": "^2.1.0" + "@actions/github": "^2.1.0", + "semver": "^7.3.4" }, "type": "module" }