From 96636b210deccf7ee489e1c0d084c68221c63313 Mon Sep 17 00:00:00 2001 From: Tomasz Pluskiewicz Date: Sat, 30 Jan 2021 16:09:56 +0100 Subject: [PATCH 1/6] feat: restrict version to tag --- README.md | 15 +++++++++++++++ action.yml | 4 ++++ app/main.js | 6 ++++++ 3 files changed, 25 insertions(+) diff --git a/README.md b/README.md index e851691..ce9a8da 100644 --- a/README.md +++ b/README.md @@ -225,6 +225,21 @@ Useful for projects where the version number may be output by a previous action. version: "${{ steps.previous_step.outputs.version }}" ``` +### 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 preent a duplicate tag. + +```yaml +- uses: butlerlogic/action-autotag@1.0.0 + with: + GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" + 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 f7d2128..016b87f 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` to be 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 0d6bce1..4a5b8d9 100644 --- a/app/main.js +++ b/app/main.js @@ -48,6 +48,12 @@ async function run () { if (!version) { throw new Error(`No version identified${msg}`) } + + const minVersion = core.getInput('minVersion', { required: false }) + if (version < minVersion) { + core.warning(`Version "${version}" is lower than minimum "${minVersion}"`) + return + } core.warning(`Recognized "${version}"${msg}`) core.setOutput('version', version) From f4c706a89c51dc5cb64866f22fa8dc86c039ea6d Mon Sep 17 00:00:00 2001 From: Tomasz Pluskiewicz Date: Sat, 30 Jan 2021 16:10:58 +0100 Subject: [PATCH 2/6] chore: typo --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 016b87f..a2535c8 100644 --- a/action.yml +++ b/action.yml @@ -32,7 +32,7 @@ inputs: 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` to be tagged. Also useful when introducing Autotag to an existing repo, to start auto-tagging from a specific version + 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: From 2451ded74efb2c6a70c93e3f4342ce3dcc1369fd Mon Sep 17 00:00:00 2001 From: tpluscode Date: Sat, 30 Jan 2021 16:19:26 +0100 Subject: [PATCH 3/6] refactor: use semver to compare versions --- app/main.js | 7 ++++--- app/package-lock.json | 31 +++++++++++++++++++++++++++---- app/package.json | 3 ++- 3 files changed, 33 insertions(+), 8 deletions(-) diff --git a/app/main.js b/app/main.js index 4a5b8d9..96ed4fd 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' @@ -17,7 +18,7 @@ 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()) - + // Extract the version number using the supplied strategy let version = core.getInput('root', { required: false }) @@ -48,9 +49,9 @@ async function run () { if (!version) { throw new Error(`No version identified${msg}`) } - + const minVersion = core.getInput('minVersion', { required: false }) - if (version < minVersion) { + if (semver.lt(version, minVersion)) { core.warning(`Version "${version}" is lower than minimum "${minVersion}"`) return } 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" } From f558f9692c94449502db14bb6753df59610c26a7 Mon Sep 17 00:00:00 2001 From: Tomasz Pluskiewicz Date: Sat, 30 Jan 2021 21:34:05 +0100 Subject: [PATCH 4/6] fix: ensure that versions are valid SerVer before comparing --- app/main.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/app/main.js b/app/main.js index 96ed4fd..496a231 100644 --- a/app/main.js +++ b/app/main.js @@ -51,7 +51,18 @@ async function run () { } const minVersion = core.getInput('minVersion', { required: false }) - if (semver.lt(version, minVersion)) { + + // 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, minVersion)) { core.warning(`Version "${version}" is lower than minimum "${minVersion}"`) return } From 34ff0e619e4869547c1df5fc43d9076699bc8c22 Mon Sep 17 00:00:00 2001 From: Tomasz Pluskiewicz Date: Sat, 30 Jan 2021 21:36:10 +0100 Subject: [PATCH 5/6] chore: typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ce9a8da..72fc240 100644 --- a/README.md +++ b/README.md @@ -231,7 +231,7 @@ 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 preent a duplicate tag. +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. ```yaml - uses: butlerlogic/action-autotag@1.0.0 From 666c617ea193aa1de6f29dc41d449abbb554198b Mon Sep 17 00:00:00 2001 From: Tomasz Pluskiewicz Date: Mon, 1 Feb 2021 11:12:31 +0100 Subject: [PATCH 6/6] fix: correct comparison call --- app/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/main.js b/app/main.js index 496a231..fb0285f 100644 --- a/app/main.js +++ b/app/main.js @@ -62,7 +62,7 @@ async function run () { core.warning(`Skipping min version check. ${version} is not valid SemVer`) } - if (minVersionSemVer && versionSemVer && semver.lt(versionSemVer, minVersion)) { + if (minVersionSemVer && versionSemVer && semver.lt(versionSemVer, minVersionSemVer)) { core.warning(`Version "${version}" is lower than minimum "${minVersion}"`) return }