- move pre-release detection to "versioning"
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { TagInfo, filterTags, sortTags } from "github-pr-collector/lib/tags"
|
import { TagInfo, filterTags, prepareAndSortTags } from "github-pr-collector/lib/tags"
|
||||||
|
|
||||||
jest.setTimeout(180000)
|
jest.setTimeout(180000)
|
||||||
|
|
||||||
@@ -17,7 +17,7 @@ it('Should order tags correctly using semver', async () => {
|
|||||||
const tagResolver = {
|
const tagResolver = {
|
||||||
method: 'semver'
|
method: 'semver'
|
||||||
}
|
}
|
||||||
const sorted = sortTags(tags, tagResolver)
|
const sorted = prepareAndSortTags(tags, tagResolver)
|
||||||
.map(function (tag) {
|
.map(function (tag) {
|
||||||
return tag.name
|
return tag.name
|
||||||
})
|
})
|
||||||
@@ -46,7 +46,7 @@ it('Should order tags correctly using semver', async () => {
|
|||||||
const tagResolver = {
|
const tagResolver = {
|
||||||
method: 'non-existing-method'
|
method: 'non-existing-method'
|
||||||
}
|
}
|
||||||
const sorted = sortTags(tags, tagResolver)
|
const sorted = prepareAndSortTags(tags, tagResolver)
|
||||||
.map(function (tag) {
|
.map(function (tag) {
|
||||||
return tag.name
|
return tag.name
|
||||||
})
|
})
|
||||||
@@ -75,7 +75,7 @@ it('Should order tags alphabetical', async () => {
|
|||||||
const tagResolver = {
|
const tagResolver = {
|
||||||
method: 'sort'
|
method: 'sort'
|
||||||
}
|
}
|
||||||
const sorted = sortTags(tags, tagResolver)
|
const sorted = prepareAndSortTags(tags, tagResolver)
|
||||||
.map(function (tag) {
|
.map(function (tag) {
|
||||||
return tag.name
|
return tag.name
|
||||||
})
|
})
|
||||||
|
|||||||
+18
-9
@@ -26239,7 +26239,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|||||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||||
exports.sortTags = exports.filterTags = exports.Tags = void 0;
|
exports.prepareAndSortTags = exports.filterTags = exports.Tags = void 0;
|
||||||
const core = __importStar(__nccwpck_require__(2186));
|
const core = __importStar(__nccwpck_require__(2186));
|
||||||
const github = __importStar(__nccwpck_require__(5438));
|
const github = __importStar(__nccwpck_require__(5438));
|
||||||
const semver = __importStar(__nccwpck_require__(1383));
|
const semver = __importStar(__nccwpck_require__(1383));
|
||||||
@@ -26330,7 +26330,7 @@ class Tags {
|
|||||||
if (ignorePreReleases) {
|
if (ignorePreReleases) {
|
||||||
core.info(`ℹ️ Enabled 'ignorePreReleases', searching for the closest release`);
|
core.info(`ℹ️ Enabled 'ignorePreReleases', searching for the closest release`);
|
||||||
for (let ii = i + 1; ii < length; ii++) {
|
for (let ii = i + 1; ii < length; ii++) {
|
||||||
if (!tags[ii].name.includes('-')) {
|
if (!tags[ii].preRelease) {
|
||||||
return tags[ii];
|
return tags[ii];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -26374,7 +26374,7 @@ class Tags {
|
|||||||
else {
|
else {
|
||||||
transformedTags = filteredTags;
|
transformedTags = filteredTags;
|
||||||
}
|
}
|
||||||
let tags = sortTags(transformedTags, tagResolver);
|
let tags = prepareAndSortTags(transformedTags, tagResolver);
|
||||||
if (tagTransformer != null) {
|
if (tagTransformer != null) {
|
||||||
// restore the original name, after sorting
|
// restore the original name, after sorting
|
||||||
tags = filteredTags.map(function (tag) {
|
tags = filteredTags.map(function (tag) {
|
||||||
@@ -26495,16 +26495,17 @@ function transformTags(tags, transformer) {
|
|||||||
2020.3.1-a01
|
2020.3.1-a01
|
||||||
2020.3.0
|
2020.3.0
|
||||||
*/
|
*/
|
||||||
function sortTags(tags, tagResolver) {
|
function prepareAndSortTags(tags, tagResolver) {
|
||||||
if (tagResolver.method === 'sort') {
|
if (tagResolver.method === 'sort') {
|
||||||
return stringSorting(tags);
|
return stringTags(tags);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return semVerSorting(tags);
|
// semver is default
|
||||||
|
return semVerTags(tags);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
exports.sortTags = sortTags;
|
exports.prepareAndSortTags = prepareAndSortTags;
|
||||||
function semVerSorting(tags) {
|
function semVerTags(tags) {
|
||||||
// filter out tags which do not follow semver
|
// filter out tags which do not follow semver
|
||||||
const validatedTags = tags.filter(tag => {
|
const validatedTags = tags.filter(tag => {
|
||||||
const isValid = semver.valid(tag.name, {
|
const isValid = semver.valid(tag.name, {
|
||||||
@@ -26513,6 +26514,11 @@ function semVerSorting(tags) {
|
|||||||
if (!isValid) {
|
if (!isValid) {
|
||||||
core.debug(`⚠️ dropped tag ${tag.name} because it is not a valid semver tag`);
|
core.debug(`⚠️ dropped tag ${tag.name} because it is not a valid semver tag`);
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
tag.preRelease = semver.prerelease(tag.name, {
|
||||||
|
loose: true
|
||||||
|
}) != null;
|
||||||
|
}
|
||||||
return isValid;
|
return isValid;
|
||||||
});
|
});
|
||||||
// sort using semver
|
// sort using semver
|
||||||
@@ -26524,7 +26530,10 @@ function semVerSorting(tags) {
|
|||||||
});
|
});
|
||||||
return validatedTags;
|
return validatedTags;
|
||||||
}
|
}
|
||||||
function stringSorting(tags) {
|
function stringTags(tags) {
|
||||||
|
for (const tag of tags) {
|
||||||
|
tag.preRelease = tag.name.includes('-');
|
||||||
|
}
|
||||||
return tags.sort((b, a) => {
|
return tags.sort((b, a) => {
|
||||||
const partsA = a.name.replace(/^v/, '').split('-');
|
const partsA = a.name.replace(/^v/, '').split('-');
|
||||||
const partsB = b.name.replace(/^v/, '').split('-');
|
const partsB = b.name.replace(/^v/, '').split('-');
|
||||||
|
|||||||
+1
-1
File diff suppressed because one or more lines are too long
@@ -16,6 +16,7 @@ export interface TagResult {
|
|||||||
export interface TagInfo {
|
export interface TagInfo {
|
||||||
name: string
|
name: string
|
||||||
commit?: string
|
commit?: string
|
||||||
|
preRelease?: boolean
|
||||||
date?: moment.Moment
|
date?: moment.Moment
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,7 +105,7 @@ export class Tags {
|
|||||||
if (ignorePreReleases) {
|
if (ignorePreReleases) {
|
||||||
core.info(`ℹ️ Enabled 'ignorePreReleases', searching for the closest release`)
|
core.info(`ℹ️ Enabled 'ignorePreReleases', searching for the closest release`)
|
||||||
for (let ii = i + 1; ii < length; ii++) {
|
for (let ii = i + 1; ii < length; ii++) {
|
||||||
if (!tags[ii].name.includes('-')) {
|
if (!tags[ii].preRelease) {
|
||||||
return tags[ii]
|
return tags[ii]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -157,7 +158,7 @@ export class Tags {
|
|||||||
transformedTags = filteredTags
|
transformedTags = filteredTags
|
||||||
}
|
}
|
||||||
|
|
||||||
let tags = sortTags(transformedTags, tagResolver)
|
let tags = prepareAndSortTags(transformedTags, tagResolver)
|
||||||
|
|
||||||
if (tagTransformer != null) {
|
if (tagTransformer != null) {
|
||||||
// restore the original name, after sorting
|
// restore the original name, after sorting
|
||||||
@@ -278,15 +279,16 @@ function transformTags(tags: TagInfo[], transformer: RegexTransformer): TagInfo[
|
|||||||
2020.3.1-a01
|
2020.3.1-a01
|
||||||
2020.3.0
|
2020.3.0
|
||||||
*/
|
*/
|
||||||
export function sortTags(tags: TagInfo[], tagResolver: TagResolver): TagInfo[] {
|
export function prepareAndSortTags(tags: TagInfo[], tagResolver: TagResolver): TagInfo[] {
|
||||||
if (tagResolver.method === 'sort') {
|
if (tagResolver.method === 'sort') {
|
||||||
return stringSorting(tags)
|
return stringTags(tags)
|
||||||
} else {
|
} else {
|
||||||
return semVerSorting(tags)
|
// semver is default
|
||||||
|
return semVerTags(tags)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function semVerSorting(tags: TagInfo[]): TagInfo[] {
|
function semVerTags(tags: TagInfo[]): TagInfo[] {
|
||||||
// filter out tags which do not follow semver
|
// filter out tags which do not follow semver
|
||||||
const validatedTags = tags.filter(tag => {
|
const validatedTags = tags.filter(tag => {
|
||||||
const isValid =
|
const isValid =
|
||||||
@@ -295,6 +297,10 @@ function semVerSorting(tags: TagInfo[]): TagInfo[] {
|
|||||||
}) !== null
|
}) !== null
|
||||||
if (!isValid) {
|
if (!isValid) {
|
||||||
core.debug(`⚠️ dropped tag ${tag.name} because it is not a valid semver tag`)
|
core.debug(`⚠️ dropped tag ${tag.name} because it is not a valid semver tag`)
|
||||||
|
} else {
|
||||||
|
tag.preRelease = semver.prerelease(tag.name, {
|
||||||
|
loose: true
|
||||||
|
}) != null
|
||||||
}
|
}
|
||||||
return isValid
|
return isValid
|
||||||
})
|
})
|
||||||
@@ -309,7 +315,11 @@ function semVerSorting(tags: TagInfo[]): TagInfo[] {
|
|||||||
return validatedTags
|
return validatedTags
|
||||||
}
|
}
|
||||||
|
|
||||||
function stringSorting(tags: TagInfo[]): TagInfo[] {
|
function stringTags(tags: TagInfo[]): TagInfo[] {
|
||||||
|
for (const tag of tags) {
|
||||||
|
tag.preRelease = tag.name.includes('-')
|
||||||
|
}
|
||||||
|
|
||||||
return tags.sort((b, a) => {
|
return tags.sort((b, a) => {
|
||||||
const partsA = a.name.replace(/^v/, '').split('-')
|
const partsA = a.name.replace(/^v/, '').split('-')
|
||||||
const partsB = b.name.replace(/^v/, '').split('-')
|
const partsB = b.name.replace(/^v/, '').split('-')
|
||||||
|
|||||||
Reference in New Issue
Block a user