Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(version_tag): add glob support #29

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change Log

### 1.3.1
ExtractVersionFromTagTask:
- support glob(7) pattern in version computing

### 1.3.0

Update packages
Expand Down
2 changes: 1 addition & 1 deletion tasks/ExtractVersionFromTagTask/.taskkey
Original file line number Diff line number Diff line change
@@ -1 +1 @@
aedcd18b-1e2c-4aa4-a227-46e5aa1f7cae
124054dd-ca4d-4adc-918a-860b63207325
16 changes: 13 additions & 3 deletions tasks/ExtractVersionFromTagTask/extract-version-from-tag.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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}*`);
Expand All @@ -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));
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a part I'm not sure about.
There should be a way of extracting the prefix part using the matcher, better than trying matching the prefix by gradually adding more letters and matching each candidates until it doesn't matches anymore...

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('.');
Expand Down
26 changes: 23 additions & 3 deletions tasks/ExtractVersionFromTagTask/extract-version-from-tag.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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}*`);
Expand Down Expand Up @@ -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];
}

Expand Down
124 changes: 102 additions & 22 deletions tasks/ExtractVersionFromTagTask/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion tasks/ExtractVersionFromTagTask/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion vss-extension.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down