Merge pull request #51 from mikepenz/feature/enhance_tags_sorting

Enhance sorting by using proper semver
This commit is contained in:
Mike Penz
2020-10-19 20:27:12 +02:00
committed by GitHub
8 changed files with 2305 additions and 66 deletions
+3 -1
View File
@@ -61,7 +61,9 @@ Specify the action as part of your GitHub actions workflow:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
```
By default the action will try to automatically retrieve the `tag` from the current commit and automatically resolve the `tag` before. Read more about this here.
By default the action will try to automatically retrieve the `tag` from the current commit and automatically resolve the `tag` before. Automatic previous tag resolving is done using `semver`.
If you require a different versioning scheme please open an issue [issue](https://github.com/mikepenz/release-changelog-builder-action/issues). Alternative you can always specifically supply the `fromTag` via the [configuration](#advanced-workflow-specification).
### Action outputs
+51
View File
@@ -0,0 +1,51 @@
import { resolveConfiguration } from '../src/utils';
import { ReleaseNotesBuilder } from '../src/releaseNotesBuilder';
import { TagInfo, sortTags } from '../src/tags';
it('Should order tags correctly', async () => {
jest.setTimeout(180000)
const tags: TagInfo[] = [
{ name: "2020.4.0", commit: "" },
{ name: "2020.4.0-rc02", commit: "" },
{ name: "2020.3.2", commit: "" },
{ name: "v2020.3.1", commit: "" },
{ name: "2020.3.1-rc03", commit: "" },
{ name: "2020.3.1-rc01", commit: "" },
{ name: "2020.3.1-b01", commit: "" },
{ name: "v2020.3.0", commit: "" }
]
const sorted = sortTags(tags).map(function (tag) {
return tag.name
}).join(",")
expect(sorted).toStrictEqual(`2020.4.0,2020.4.0-rc02,2020.3.2,v2020.3.1,2020.3.1-rc03,2020.3.1-rc01,2020.3.1-b01,v2020.3.0`)
})
it('Should order tags correctly', async () => {
jest.setTimeout(180000)
const tags: TagInfo[] = [
{ name: "0.0.1", commit: "" },
{ name: "0.0.1-rc01", commit: "" },
{ name: "0.1.0", commit: "" },
{ name: "0.1.0-b01", commit: "" },
{ name: "1.0.0", commit: "" },
{ name: "1.0.0-a01", commit: "" },
{ name: "2.0.0", commit: "" },
{ name: "10.0.0", commit: "" },
{ name: "10.1.0", commit: "" },
{ name: "10.1.0-2", commit: "" },
{ name: "20.0.2", commit: "" },
{ name: "100.0.0", commit: "" },
{ name: "1000.0.0", commit: "" },
]
const sorted = sortTags(tags).map(function (tag) {
return tag.name
}).join(",")
expect(sorted).toStrictEqual(`1000.0.0,100.0.0,20.0.2,10.1.0,10.1.0-2,10.0.0,2.0.0,1.0.0,1.0.0-a01,0.1.0,0.1.0-b01,0.0.1,0.0.1-rc01`)
})
Generated Vendored
+2178 -38
View File
File diff suppressed because it is too large Load Diff
Generated Vendored
+1 -1
View File
File diff suppressed because one or more lines are too long
Generated Vendored
+19
View File
@@ -583,6 +583,25 @@ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
semver
ISC
The ISC License
Copyright (c) Isaac Z. Schlueter and Contributors
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
tunnel
MIT
The MIT License (MIT)
+30 -4
View File
@@ -1756,6 +1756,11 @@
"integrity": "sha512-IiPhNnenzkqdSdQH3ifk9LoX7oQe61ZlDdDO4+MUv6FyWdPGDPr26gCPVs3oguZEMq//nFZZpwUZcVuNJsG+DQ==",
"dev": true
},
"@types/semver": {
"version": "7.3.4",
"resolved": "https://registry.npmjs.org/@types/semver/-/semver-7.3.4.tgz",
"integrity": "sha512-+nVsLKlcUCeMzD2ufHEYuJ9a2ovstb6Dp52A5VsoKxDXgvE051XgHI/33I1EymwkRGQkwnA0LkhnUzituGs4EQ=="
},
"@types/stack-utils": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/@types/stack-utils/-/stack-utils-1.0.1.tgz",
@@ -5168,6 +5173,14 @@
"@babel/types": "^7.4.0",
"istanbul-lib-coverage": "^2.0.5",
"semver": "^6.0.0"
},
"dependencies": {
"semver": {
"version": "6.3.0",
"resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz",
"integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==",
"dev": true
}
}
},
"istanbul-lib-report": {
@@ -6031,6 +6044,12 @@
"lodash": "^4.17.19"
}
},
"semver": {
"version": "6.3.0",
"resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz",
"integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==",
"dev": true
},
"source-map": {
"version": "0.5.7",
"resolved": "https://registry.npmjs.org/source-map/-/source-map-0.5.7.tgz",
@@ -7109,6 +7128,14 @@
"natural-compare": "^1.4.0",
"pretty-format": "^24.9.0",
"semver": "^6.2.0"
},
"dependencies": {
"semver": {
"version": "6.3.0",
"resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz",
"integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==",
"dev": true
}
}
},
"jest-util": {
@@ -8457,10 +8484,9 @@
}
},
"semver": {
"version": "6.3.0",
"resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz",
"integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==",
"dev": true
"version": "7.3.2",
"resolved": "https://registry.npmjs.org/semver/-/semver-7.3.2.tgz",
"integrity": "sha512-OrOb32TeeambH6UrhtShmF7CRDqhL6/5XpPNp2DuRH6+9QLw/orhp72j87v8Qa1ScDkvrrBNpZcDejAirJmfXQ=="
},
"set-blocking": {
"version": "2.0.0",
+3 -1
View File
@@ -29,7 +29,9 @@
"@actions/exec": "^1.0.4",
"@actions/github": "^4.0.0",
"@octokit/rest": "^18.0.6",
"moment": "^2.29.1"
"@types/semver": "^7.3.4",
"moment": "^2.29.1",
"semver": "^7.3.2"
},
"devDependencies": {
"@types/jest": "^26.0.14",
+20 -21
View File
@@ -1,5 +1,7 @@
import {Octokit, RestEndpointMethodTypes} from '@octokit/rest'
import * as core from '@actions/core'
import * as semver from 'semver'
import {SemVer} from 'semver'
export interface TagInfo {
name: string
@@ -52,7 +54,7 @@ export class Tags {
ignorePreReleases: boolean,
maxTagsToFetch: number
): Promise<TagInfo | null> {
const tags = this.sortTags(await this.getTags(owner, repo, maxTagsToFetch))
const tags = sortTags(await this.getTags(owner, repo, maxTagsToFetch))
try {
const length = tags.length
@@ -76,8 +78,9 @@ export class Tags {
return null
}
}
}
/*
/*
Sorts an array of tags as shown below:
2020.4.0
@@ -91,23 +94,19 @@ export class Tags {
2020.3.1-a01
2020.3.0
*/
private sortTags(commits: TagInfo[]): TagInfo[] {
commits.sort((b, a) => {
const partsA = a.name.replace(/^v/, '').split('-')
const partsB = b.name.replace(/^v/, '').split('-')
const versionCompare = partsA[0].localeCompare(partsB[0])
if (versionCompare !== 0) {
return versionCompare
} else {
if (partsA.length === 1) {
return 0
} else if (partsB.length === 1) {
return 1
} else {
return partsA[1].localeCompare(partsB[1])
}
}
})
return commits
}
export function sortTags(tags: TagInfo[]): TagInfo[] {
// filter out tags which do not follow semver
const validatedTags = tags.filter(tag => {
const isValid = semver.valid(tag.name) !== null
if(!isValid) {
core.debug(`⚠️ dropped tag ${tag.name} because it is not a valid semver tag`)
}
return isValid
})
// sort using semver
validatedTags.sort((b, a) => {
return new SemVer(a.name).compare(b.name)
})
return validatedTags
}