From 9dacb94b2c9ca70fb59ad22f85faa8dad4b094d8 Mon Sep 17 00:00:00 2001 From: Mateo MARTINEZ Date: Mon, 3 Jul 2023 16:44:17 +0200 Subject: [PATCH 1/2] feat(version_tag): add glob support --- CHANGELOG.md | 4 + tasks/ExtractVersionFromTagTask/.taskkey | 2 +- .../extract-version-from-tag.js | 16 ++- .../extract-version-from-tag.ts | 26 +++- .../package-lock.json | 124 ++++++++++++++---- tasks/ExtractVersionFromTagTask/package.json | 3 +- vss-extension.json | 2 +- 7 files changed, 146 insertions(+), 31 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dcd7f59..30a3ddd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Change Log +### 1.3.1 +ExtractVersionFromTagTask: +- support glob(7) pattern in version computing + ### 1.3.0 Update packages diff --git a/tasks/ExtractVersionFromTagTask/.taskkey b/tasks/ExtractVersionFromTagTask/.taskkey index f35018c..dbbc8f8 100644 --- a/tasks/ExtractVersionFromTagTask/.taskkey +++ b/tasks/ExtractVersionFromTagTask/.taskkey @@ -1 +1 @@ -aedcd18b-1e2c-4aa4-a227-46e5aa1f7cae \ No newline at end of file +a55a0cb9-8431-46c7-adb7-97a87d34b75e \ No newline at end of file diff --git a/tasks/ExtractVersionFromTagTask/extract-version-from-tag.js b/tasks/ExtractVersionFromTagTask/extract-version-from-tag.js index 3625c23..c040f02 100644 --- a/tasks/ExtractVersionFromTagTask/extract-version-from-tag.js +++ b/tasks/ExtractVersionFromTagTask/extract-version-from-tag.js @@ -11,6 +11,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge Object.defineProperty(exports, "__esModule", { value: true }); const task = require("azure-pipelines-task-lib/task"); const fs = require("fs"); +const minimatch = require("minimatch"); const MAJOR = 'MAJOR'; const MINOR = 'MINOR'; const PATCH = 'PATCH'; @@ -31,7 +32,7 @@ function run() { task.cd(projectFolderPath); let git = task.which('git', true); var args = ["describe", "--tags", "--abbrev=0"]; - // Add prefix match if need + // Add prefix match if need if (tagPrefixMatch !== undefined && tagPrefixMatch.trim().length !== 0) { task.debug(`Add match ${tagPrefixMatch}`); args.push(`--match=${tagPrefixMatch}*`); @@ -52,8 +53,17 @@ function run() { originalTag = originalTag.split('\n')[0]; } var tag = originalTag.toLowerCase(); - if (tag.startsWith(splitPrefix)) { - var tagSplitted = tag.split(splitPrefix); + var prefixCandidates = Array.from({ length: tag.length }, (_, index) => tag.substring(0, index + 1)); + task.debug(`Prefix candidates: ${prefixCandidates.toString()}`); + var globSplitPrefix = minimatch.match(prefixCandidates, splitPrefix, { + nobrace: true, + noglobstar: true, + noext: true, + nocomment: true, + }).at(-1); + task.debug(`actual tag split match: ${globSplitPrefix}`); + if (tag.startsWith(globSplitPrefix)) { + var tagSplitted = tag.split(globSplitPrefix); tag = tagSplitted[1]; } var versionsIndicator = tag.split('.'); diff --git a/tasks/ExtractVersionFromTagTask/extract-version-from-tag.ts b/tasks/ExtractVersionFromTagTask/extract-version-from-tag.ts index 0d91434..c0f70e5 100644 --- a/tasks/ExtractVersionFromTagTask/extract-version-from-tag.ts +++ b/tasks/ExtractVersionFromTagTask/extract-version-from-tag.ts @@ -1,5 +1,6 @@ import task = require('azure-pipelines-task-lib/task'); import fs = require('fs'); +import minimatch = require('minimatch'); const MAJOR: string = 'MAJOR'; const MINOR: string = 'MINOR'; @@ -25,7 +26,7 @@ async function run() { let git: string = task.which('git', true); var args = ["describe", "--tags", "--abbrev=0"]; - // Add prefix match if need + // Add prefix match if need if (tagPrefixMatch !== undefined && tagPrefixMatch.trim().length !== 0) { task.debug(`Add match ${tagPrefixMatch}`); args.push(`--match=${tagPrefixMatch}*`); @@ -53,8 +54,27 @@ async function run() { var tag = originalTag.toLowerCase(); - if (tag.startsWith(splitPrefix)) { - var tagSplitted = tag.split(splitPrefix); + var prefixCandidates = Array.from( + {length: tag.length}, + (_, index) => tag.substring(0, index+1) + ); + task.debug(`Prefix candidates: ${prefixCandidates.toString()}`); + + var globSplitPrefix = minimatch.match( + prefixCandidates, + splitPrefix, + { + nobrace:true, + noglobstar:true, + noext: true, + nocomment: true, + } + ).at(-1); + + task.debug(`actual tag split match: ${globSplitPrefix}`); + + if (tag.startsWith(globSplitPrefix)) { + var tagSplitted = tag.split(globSplitPrefix); tag = tagSplitted[1]; } diff --git a/tasks/ExtractVersionFromTagTask/package-lock.json b/tasks/ExtractVersionFromTagTask/package-lock.json index 9f3256f..dc3c401 100644 --- a/tasks/ExtractVersionFromTagTask/package-lock.json +++ b/tasks/ExtractVersionFromTagTask/package-lock.json @@ -10,7 +10,8 @@ "license": "ISC", "dependencies": { "azure-pipelines-task-lib": "^4.4.0", - "fs": "0.0.1-security" + "fs": "0.0.1-security", + "minimatch": "^9.0.2" }, "devDependencies": { "@types/node": "^20.3.1", @@ -73,18 +74,37 @@ "uuid": "^3.0.1" } }, + "node_modules/azure-pipelines-task-lib/node_modules/brace-expansion": { + "version": "1.1.11", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", + "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", + "dependencies": { + "balanced-match": "^1.0.0", + "concat-map": "0.0.1" + } + }, + "node_modules/azure-pipelines-task-lib/node_modules/minimatch": { + "version": "3.0.5", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.5.tgz", + "integrity": "sha512-tUpxzX0VAzJHjLu0xUfFv1gwVp9ba3IOuRAVH2EGuRW8a5emA2FlACLqiT/lDVtS1W+TGNwqz3sWaNyLgDJWuw==", + "dependencies": { + "brace-expansion": "^1.1.7" + }, + "engines": { + "node": "*" + } + }, "node_modules/balanced-match": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==" }, "node_modules/brace-expansion": { - "version": "1.1.11", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", - "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz", + "integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==", "dependencies": { - "balanced-match": "^1.0.0", - "concat-map": "0.0.1" + "balanced-match": "^1.0.0" } }, "node_modules/buffer-from": { @@ -123,7 +143,7 @@ "node_modules/concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", - "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=" + "integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==" }, "node_modules/concat-stream": { "version": "1.6.2", @@ -220,6 +240,26 @@ "url": "https://github.com/sponsors/isaacs" } }, + "node_modules/glob/node_modules/brace-expansion": { + "version": "1.1.11", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", + "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", + "dependencies": { + "balanced-match": "^1.0.0", + "concat-map": "0.0.1" + } + }, + "node_modules/glob/node_modules/minimatch": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", + "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", + "dependencies": { + "brace-expansion": "^1.1.7" + }, + "engines": { + "node": "*" + } + }, "node_modules/has": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz", @@ -327,14 +367,17 @@ } }, "node_modules/minimatch": { - "version": "3.0.5", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.5.tgz", - "integrity": "sha512-tUpxzX0VAzJHjLu0xUfFv1gwVp9ba3IOuRAVH2EGuRW8a5emA2FlACLqiT/lDVtS1W+TGNwqz3sWaNyLgDJWuw==", + "version": "9.0.2", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.2.tgz", + "integrity": "sha512-PZOT9g5v2ojiTL7r1xF6plNHLtOeTpSlDI007As2NlA2aYBMfVom17yqa6QzhmDP8QOhn7LjHTg7DFCVSSa6yg==", "dependencies": { - "brace-expansion": "^1.1.7" + "brace-expansion": "^2.0.1" }, "engines": { - "node": "*" + "node": ">=16 || 14 >=14.17" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" } }, "node_modules/mockery": { @@ -641,6 +684,25 @@ "shelljs": "^0.8.5", "sync-request": "6.1.0", "uuid": "^3.0.1" + }, + "dependencies": { + "brace-expansion": { + "version": "1.1.11", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", + "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", + "requires": { + "balanced-match": "^1.0.0", + "concat-map": "0.0.1" + } + }, + "minimatch": { + "version": "3.0.5", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.5.tgz", + "integrity": "sha512-tUpxzX0VAzJHjLu0xUfFv1gwVp9ba3IOuRAVH2EGuRW8a5emA2FlACLqiT/lDVtS1W+TGNwqz3sWaNyLgDJWuw==", + "requires": { + "brace-expansion": "^1.1.7" + } + } } }, "balanced-match": { @@ -649,12 +711,11 @@ "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==" }, "brace-expansion": { - "version": "1.1.11", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", - "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz", + "integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==", "requires": { - "balanced-match": "^1.0.0", - "concat-map": "0.0.1" + "balanced-match": "^1.0.0" } }, "buffer-from": { @@ -687,7 +748,7 @@ "concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", - "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=" + "integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==" }, "concat-stream": { "version": "1.6.2", @@ -761,6 +822,25 @@ "minimatch": "^3.0.4", "once": "^1.3.0", "path-is-absolute": "^1.0.0" + }, + "dependencies": { + "brace-expansion": { + "version": "1.1.11", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", + "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", + "requires": { + "balanced-match": "^1.0.0", + "concat-map": "0.0.1" + } + }, + "minimatch": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", + "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", + "requires": { + "brace-expansion": "^1.1.7" + } + } } }, "has": { @@ -848,11 +928,11 @@ } }, "minimatch": { - "version": "3.0.5", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.5.tgz", - "integrity": "sha512-tUpxzX0VAzJHjLu0xUfFv1gwVp9ba3IOuRAVH2EGuRW8a5emA2FlACLqiT/lDVtS1W+TGNwqz3sWaNyLgDJWuw==", + "version": "9.0.2", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.2.tgz", + "integrity": "sha512-PZOT9g5v2ojiTL7r1xF6plNHLtOeTpSlDI007As2NlA2aYBMfVom17yqa6QzhmDP8QOhn7LjHTg7DFCVSSa6yg==", "requires": { - "brace-expansion": "^1.1.7" + "brace-expansion": "^2.0.1" } }, "mockery": { diff --git a/tasks/ExtractVersionFromTagTask/package.json b/tasks/ExtractVersionFromTagTask/package.json index 0eedb98..bf98c62 100644 --- a/tasks/ExtractVersionFromTagTask/package.json +++ b/tasks/ExtractVersionFromTagTask/package.json @@ -14,7 +14,8 @@ "license": "ISC", "dependencies": { "azure-pipelines-task-lib": "^4.4.0", - "fs": "0.0.1-security" + "fs": "0.0.1-security", + "minimatch": "^9.0.2" }, "devDependencies": { "@types/node": "^20.3.1", diff --git a/vss-extension.json b/vss-extension.json index 7fd0af1..a8ba6e5 100644 --- a/vss-extension.json +++ b/vss-extension.json @@ -2,7 +2,7 @@ "manifestVersion": 1, "id": "mobile-versioning-task", "name": "Mobile Versioning", - "version": "1.3.0", + "version": "1.3.1", "publisher": "damienaicheh", "public": true, "targets": [ From 149b0d307ee56f76799b73549829f3a38c6cec47 Mon Sep 17 00:00:00 2001 From: Mateo MARTINEZ Date: Tue, 4 Jul 2023 10:11:01 +0200 Subject: [PATCH 2/2] fix: update task key --- tasks/ExtractVersionFromTagTask/.taskkey | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasks/ExtractVersionFromTagTask/.taskkey b/tasks/ExtractVersionFromTagTask/.taskkey index dbbc8f8..e00d9c9 100644 --- a/tasks/ExtractVersionFromTagTask/.taskkey +++ b/tasks/ExtractVersionFromTagTask/.taskkey @@ -1 +1 @@ -a55a0cb9-8431-46c7-adb7-97a87d34b75e \ No newline at end of file +124054dd-ca4d-4adc-918a-860b63207325 \ No newline at end of file