Merge pull request #20 from mikepenz/feature/ignore_pre_releases
Allow to ignore pre-releases to find fromTag
This commit is contained in:
@@ -86,6 +86,7 @@ For advanced usecases additional settings can be provided to the action
|
|||||||
configuration: "configuration_complex.json"
|
configuration: "configuration_complex.json"
|
||||||
owner: "mikepenz"
|
owner: "mikepenz"
|
||||||
repo: "release-changelog-builder-action"
|
repo: "release-changelog-builder-action"
|
||||||
|
ignorePreReleases: "false" # allows to skip any pre releases, if `fromTag` needs to be automatically resolved (ignores 0.0.2-rc02 for example) - only relevant if `fromTag` is not provided
|
||||||
fromTag: "0.0.2"
|
fromTag: "0.0.2"
|
||||||
toTag: "0.0.3"
|
toTag: "0.0.3"
|
||||||
token: ${{ secrets.GITHUB_TOKEN }} # the token to use, for a different repository a PAT is required (Personal access token)
|
token: ${{ secrets.GITHUB_TOKEN }} # the token to use, for a different repository a PAT is required (Personal access token)
|
||||||
|
|||||||
+49
-2
@@ -22,15 +22,62 @@ test('test runs', () => {
|
|||||||
})
|
})
|
||||||
*/
|
*/
|
||||||
|
|
||||||
it('Should be true', async () => {
|
it('Should match generated changelog (tags)', async () => {
|
||||||
jest.setTimeout(180000)
|
jest.setTimeout(180000)
|
||||||
|
|
||||||
const configuration = readConfiguration('configuration.json')
|
const configuration = readConfiguration('configuration.json')
|
||||||
const releaseNotes = new ReleaseNotes({
|
const releaseNotes = new ReleaseNotes({
|
||||||
owner: 'mikepenz',
|
owner: 'mikepenz',
|
||||||
repo: 'release-changelog-builder-action',
|
repo: 'release-changelog-builder-action',
|
||||||
fromTag: null,
|
fromTag: 'v0.0.1',
|
||||||
toTag: 'v0.0.3',
|
toTag: 'v0.0.3',
|
||||||
|
ignorePreReleases: false,
|
||||||
|
configuration: configuration
|
||||||
|
})
|
||||||
|
|
||||||
|
const changeLog = await releaseNotes.pull()
|
||||||
|
console.log(changeLog)
|
||||||
|
expect(changeLog).toStrictEqual(`## 🧪 Tests
|
||||||
|
|
||||||
|
- [CI] Specify Test Case
|
||||||
|
- PR: #10
|
||||||
|
|
||||||
|
`)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('Should match generated changelog (unspecified fromTag)', async () => {
|
||||||
|
jest.setTimeout(180000)
|
||||||
|
|
||||||
|
const configuration = readConfiguration('configuration.json')
|
||||||
|
const releaseNotes = new ReleaseNotes({
|
||||||
|
owner: 'mikepenz',
|
||||||
|
repo: 'release-changelog-builder-action',
|
||||||
|
fromTag: null,
|
||||||
|
toTag: 'v0.0.3',
|
||||||
|
ignorePreReleases: false,
|
||||||
|
configuration: configuration
|
||||||
|
})
|
||||||
|
|
||||||
|
const changeLog = await releaseNotes.pull()
|
||||||
|
console.log(changeLog)
|
||||||
|
expect(changeLog).toStrictEqual(`## 🧪 Tests
|
||||||
|
|
||||||
|
- [CI] Specify Test Case
|
||||||
|
- PR: #10
|
||||||
|
|
||||||
|
`)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('Should match generated changelog (refs)', async () => {
|
||||||
|
jest.setTimeout(180000)
|
||||||
|
|
||||||
|
const configuration = readConfiguration('configuration.json')
|
||||||
|
const releaseNotes = new ReleaseNotes({
|
||||||
|
owner: 'mikepenz',
|
||||||
|
repo: 'release-changelog-builder-action',
|
||||||
|
fromTag: '5ec7a2d86fe9f43fdd38d5e254a1117c8a51b4c3',
|
||||||
|
toTag: 'fa3788c8c4b3373ef8424ce3eb008a5cd07cc5aa',
|
||||||
|
ignorePreReleases: false,
|
||||||
configuration: configuration
|
configuration: configuration
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,9 @@ inputs:
|
|||||||
description: 'the previous tag to compare against'
|
description: 'the previous tag to compare against'
|
||||||
toTag:
|
toTag:
|
||||||
description: 'the new tag created'
|
description: 'the new tag created'
|
||||||
|
ignorePreReleases:
|
||||||
|
description: 'defines if only full releases should be considered to compare against (Only used if fromTag is not defined). E.g. for 1.0.1... 1.0.0-rc02 <- ignore, 1.0.0 <- pick'
|
||||||
|
default: "false"
|
||||||
token:
|
token:
|
||||||
description: 'the token to use to execute the git API requests'
|
description: 'the token to use to execute the git API requests'
|
||||||
outputs:
|
outputs:
|
||||||
|
|||||||
@@ -33,6 +33,8 @@ async function run(): Promise<void> {
|
|||||||
const fromTag = core.getInput('fromTag')
|
const fromTag = core.getInput('fromTag')
|
||||||
let toTag = core.getInput('toTag')
|
let toTag = core.getInput('toTag')
|
||||||
|
|
||||||
|
const ignorePreReleases = core.getInput('ignorePreReleases')
|
||||||
|
|
||||||
if (!toTag) {
|
if (!toTag) {
|
||||||
// if not specified try to retrieve tag from git
|
// if not specified try to retrieve tag from git
|
||||||
const gitHelper = await createCommandManager(repositoryPath)
|
const gitHelper = await createCommandManager(repositoryPath)
|
||||||
@@ -87,6 +89,7 @@ async function run(): Promise<void> {
|
|||||||
repo,
|
repo,
|
||||||
fromTag,
|
fromTag,
|
||||||
toTag,
|
toTag,
|
||||||
|
ignorePreReleases: ignorePreReleases === 'true',
|
||||||
configuration
|
configuration
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
+8
-6
@@ -7,11 +7,12 @@ import {Tags} from './tags'
|
|||||||
import {Configuration, DefaultConfiguration} from './configuration'
|
import {Configuration, DefaultConfiguration} from './configuration'
|
||||||
|
|
||||||
export interface ReleaseNotesOptions {
|
export interface ReleaseNotesOptions {
|
||||||
owner: string
|
owner: string // the owner of the repository
|
||||||
repo: string
|
repo: string // the repository
|
||||||
fromTag: string | null
|
fromTag: string | null // the tag/ref to start from
|
||||||
toTag: string
|
toTag: string // the tag/ref up to
|
||||||
configuration: Configuration
|
ignorePreReleases: boolean // defines if we should ignore any pre-releases for matching, only relevant if fromTag is null
|
||||||
|
configuration: Configuration // the configuration as defined in `configuration.ts`
|
||||||
}
|
}
|
||||||
|
|
||||||
export class ReleaseNotes {
|
export class ReleaseNotes {
|
||||||
@@ -22,7 +23,7 @@ export class ReleaseNotes {
|
|||||||
auth: `token ${token || process.env.GITHUB_TOKEN}`
|
auth: `token ${token || process.env.GITHUB_TOKEN}`
|
||||||
})
|
})
|
||||||
|
|
||||||
const {owner, repo, toTag, configuration} = this.options
|
const {owner, repo, toTag, ignorePreReleases, configuration} = this.options
|
||||||
|
|
||||||
if (!this.options.fromTag) {
|
if (!this.options.fromTag) {
|
||||||
core.debug(`fromTag undefined, trying to resolve via API`)
|
core.debug(`fromTag undefined, trying to resolve via API`)
|
||||||
@@ -32,6 +33,7 @@ export class ReleaseNotes {
|
|||||||
owner,
|
owner,
|
||||||
repo,
|
repo,
|
||||||
toTag,
|
toTag,
|
||||||
|
ignorePreReleases,
|
||||||
configuration.max_tags_to_fetch
|
configuration.max_tags_to_fetch
|
||||||
? configuration.max_tags_to_fetch
|
? configuration.max_tags_to_fetch
|
||||||
: DefaultConfiguration.max_tags_to_fetch
|
: DefaultConfiguration.max_tags_to_fetch
|
||||||
|
|||||||
+20
-7
@@ -49,19 +49,32 @@ export class Tags {
|
|||||||
owner: string,
|
owner: string,
|
||||||
repo: string,
|
repo: string,
|
||||||
tag: string,
|
tag: string,
|
||||||
|
ignorePreReleases: boolean,
|
||||||
maxTagsToFetch: number
|
maxTagsToFetch: number
|
||||||
): Promise<TagInfo | null> {
|
): Promise<TagInfo | null> {
|
||||||
const tags = this.sortTags(await this.getTags(owner, repo, maxTagsToFetch))
|
const tags = this.sortTags(await this.getTags(owner, repo, maxTagsToFetch))
|
||||||
|
|
||||||
const length = tags.length
|
try {
|
||||||
for (let i = 0; i < length; i++) {
|
const length = tags.length
|
||||||
if (tags[i].name.toLowerCase() === tag.toLowerCase()) {
|
for (let i = 0; i < length; i++) {
|
||||||
return tags[i + 1]
|
if (tags[i].name.toLowerCase() === tag.toLowerCase()) {
|
||||||
|
if (ignorePreReleases) {
|
||||||
|
core.info(
|
||||||
|
`Enabled 'ignorePreReleases', searching for the closest release`
|
||||||
|
)
|
||||||
|
for (let ii = i + 1; ii < length; ii++) {
|
||||||
|
if (!tags[ii].name.includes('-')) {
|
||||||
|
return tags[ii]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return tags[i + 1]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return tags[0]
|
||||||
|
} catch (error) {
|
||||||
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
// not found, throw exception?
|
|
||||||
return tags[0]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private sortTags(commits: TagInfo[]): TagInfo[] {
|
private sortTags(commits: TagInfo[]): TagInfo[] {
|
||||||
|
|||||||
Reference in New Issue
Block a user