- rework toTag resolving fallback if build was not started from a tag
- fallback to retrieve `toTag` from git API (only if 2 tags are available) - FIX https://github.com/mikepenz/release-changelog-builder-action/issues/427 - FIX https://github.com/mikepenz/release-changelog-builder-action/issues/433 - introduce test case to verify
This commit is contained in:
@@ -138,9 +138,9 @@ The action supports flexible configuration options to modify vast areas of its b
|
||||
|
||||
⚠️ Please note: It is required to have a `checkout` step prior to the changelog step, to allow the action to discover the configuration file.
|
||||
|
||||
⚠️ When running this action for a non tags trigger the `toTag` can't be automatically resolved, as such it is either required to provide `toTag` directly, or to specify a different `fetch-depth:` with the checkout action to include tags.
|
||||
⚠️ When running this action for a non tags trigger the `toTag` will be automatically resolved using the latest tag as retrieved by the git API.
|
||||
|
||||
💡 By default not specifying `fromTag` or `toTag` will resolve `toTag` from either the `ref` or alternatively fallback to the latest tag from git. `fromTag` is resolved by sorting tags using [semver](https://semver.org/). Check the [configuration](#configuration-specification) for alternatives.
|
||||
💡 By default not specifying `fromTag` or `toTag` will resolve `toTag` from either the `ref` or alternatively fallback to the latest tag from the git API. `fromTag` is resolved by sorting tags using [semver](https://semver.org/). Check the [configuration](#configuration-specification) for alternatives.
|
||||
|
||||
This configuration is a `.json` file in the following format.
|
||||
|
||||
|
||||
@@ -28,6 +28,26 @@ it('Should match generated changelog (unspecified fromTag)', async () => {
|
||||
`)
|
||||
})
|
||||
|
||||
it('Should match generated changelog (unspecified tags)', async () => {
|
||||
const configuration = resolveConfiguration('', 'configs/configuration.json')
|
||||
const releaseNotesBuilder = new ReleaseNotesBuilder(
|
||||
null,
|
||||
'.',
|
||||
'mikepenz',
|
||||
'action-junit-report-legacy',
|
||||
null,
|
||||
null,
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
configuration
|
||||
)
|
||||
|
||||
const changeLog = await releaseNotesBuilder.build()
|
||||
console.log(changeLog)
|
||||
expect(changeLog).toStrictEqual(`## 🐛 Fixes\n\n- Stacktrace Data can be an array\n - PR: #39\n\n`)
|
||||
})
|
||||
|
||||
it('Should use empty placeholder', async () => {
|
||||
const configuration = resolveConfiguration('', 'configs/configuration.json')
|
||||
const releaseNotesBuilder = new ReleaseNotesBuilder(
|
||||
|
||||
+86
-41
@@ -750,10 +750,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||
exports.ReleaseNotesBuilder = void 0;
|
||||
const core = __importStar(__nccwpck_require__(2186));
|
||||
const github = __importStar(__nccwpck_require__(5438));
|
||||
const configuration_1 = __nccwpck_require__(5527);
|
||||
const rest_1 = __nccwpck_require__(5375);
|
||||
const gitHelper_1 = __nccwpck_require__(353);
|
||||
const releaseNotes_1 = __nccwpck_require__(5882);
|
||||
const tags_1 = __nccwpck_require__(7532);
|
||||
const utils_1 = __nccwpck_require__(918);
|
||||
@@ -772,22 +770,8 @@ class ReleaseNotesBuilder {
|
||||
this.configuration = configuration;
|
||||
}
|
||||
build() {
|
||||
var _a, _b;
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
// ensure to resolve the toTag if it was not provided
|
||||
if (!this.toTag) {
|
||||
// if not specified try to retrieve tag from github.context.ref
|
||||
if (github.context.ref.startsWith('refs/tags/')) {
|
||||
this.toTag = github.context.ref.replace('refs/tags/', '');
|
||||
core.info(`🔖 Resolved current tag (${this.toTag}) from the 'github.context.ref'`);
|
||||
}
|
||||
else {
|
||||
// if not specified try to retrieve tag from git
|
||||
const gitHelper = yield gitHelper_1.createCommandManager(this.repositoryPath);
|
||||
const latestTag = yield gitHelper.latestTag();
|
||||
this.toTag = latestTag;
|
||||
core.info(`🔖 Resolved current tag (${this.toTag}) from 'git rev-list --tags --skip=0 --max-count=1'`);
|
||||
}
|
||||
}
|
||||
if (!this.owner) {
|
||||
utils_1.failOrError(`💥 Missing or couldn't resolve 'owner'`, this.failOnError);
|
||||
return null;
|
||||
@@ -804,34 +788,34 @@ class ReleaseNotesBuilder {
|
||||
core.setOutput('repo', this.repo);
|
||||
core.debug(`Resolved 'repo' as ${this.repo}`);
|
||||
}
|
||||
if (!this.toTag) {
|
||||
utils_1.failOrError(`💥 Missing or couldn't resolve 'toTag'`, this.failOnError);
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
core.setOutput('toTag', this.toTag);
|
||||
core.debug(`Resolved 'toTag' as ${this.toTag}`);
|
||||
}
|
||||
core.endGroup();
|
||||
// load octokit instance
|
||||
const octokit = new rest_1.Octokit({
|
||||
auth: `token ${this.token || process.env.GITHUB_TOKEN}`
|
||||
});
|
||||
// ensure to resolve the fromTag if it was not provided specifically
|
||||
if (!this.fromTag) {
|
||||
core.startGroup(`🔖 Resolve previous tag`);
|
||||
core.debug(`fromTag undefined, trying to resolve via API`);
|
||||
const tagsApi = new tags_1.Tags(octokit);
|
||||
const previousTag = yield tagsApi.findPredecessorTag(this.repositoryPath, this.owner, this.repo, this.toTag, this.ignorePreReleases, this.configuration.max_tags_to_fetch ||
|
||||
configuration_1.DefaultConfiguration.max_tags_to_fetch, this.configuration.tag_resolver || configuration_1.DefaultConfiguration.tag_resolver);
|
||||
if (previousTag == null) {
|
||||
utils_1.failOrError(`💥 Unable to retrieve previous tag given ${this.toTag}`, this.failOnError);
|
||||
return null;
|
||||
}
|
||||
this.fromTag = previousTag.name;
|
||||
core.debug(`fromTag resolved via previousTag as: ${previousTag.name}`);
|
||||
core.endGroup();
|
||||
// ensure proper from <-> to tag range
|
||||
core.startGroup(`🔖 Resolve tags`);
|
||||
const tagsApi = new tags_1.Tags(octokit);
|
||||
const tagRange = yield tagsApi.retrieveRange(this.repositoryPath, this.owner, this.repo, this.fromTag, this.toTag, this.ignorePreReleases, this.configuration.max_tags_to_fetch ||
|
||||
configuration_1.DefaultConfiguration.max_tags_to_fetch, this.configuration.tag_resolver || configuration_1.DefaultConfiguration.tag_resolver);
|
||||
const thisTag = (_a = tagRange.to) === null || _a === void 0 ? void 0 : _a.name;
|
||||
if (!thisTag) {
|
||||
utils_1.failOrError(`💥 Missing or couldn't resolve 'toTag'`, this.failOnError);
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
this.toTag = thisTag;
|
||||
core.setOutput('toTag', thisTag);
|
||||
core.debug(`Resolved 'toTag' as ${thisTag}`);
|
||||
}
|
||||
const previousTag = (_b = tagRange.from) === null || _b === void 0 ? void 0 : _b.name;
|
||||
if (previousTag == null) {
|
||||
utils_1.failOrError(`💥 Unable to retrieve previous tag given ${this.toTag}`, this.failOnError);
|
||||
return null;
|
||||
}
|
||||
this.fromTag = previousTag;
|
||||
core.debug(`fromTag resolved via previousTag as: ${previousTag}`);
|
||||
core.endGroup();
|
||||
const options = {
|
||||
owner: this.owner,
|
||||
repo: this.repo,
|
||||
@@ -896,6 +880,7 @@ var __asyncValues = (this && this.__asyncValues) || function (o) {
|
||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||
exports.sortTags = exports.Tags = void 0;
|
||||
const core = __importStar(__nccwpck_require__(2186));
|
||||
const github = __importStar(__nccwpck_require__(5438));
|
||||
const semver = __importStar(__nccwpck_require__(1383));
|
||||
const semver_1 = __nccwpck_require__(1383);
|
||||
const gitHelper_1 = __nccwpck_require__(353);
|
||||
@@ -940,9 +925,9 @@ class Tags {
|
||||
return tagsInfo;
|
||||
});
|
||||
}
|
||||
findPredecessorTag(repositoryPath, owner, repo, tag, ignorePreReleases, maxTagsToFetch, tagResolver) {
|
||||
findPredecessorTag(sortedTags, repositoryPath, tag, ignorePreReleases) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const tags = sortTags(yield this.getTags(owner, repo, maxTagsToFetch), tagResolver);
|
||||
const tags = sortedTags;
|
||||
try {
|
||||
const length = tags.length;
|
||||
if (tags.length > 1) {
|
||||
@@ -978,6 +963,66 @@ class Tags {
|
||||
}
|
||||
});
|
||||
}
|
||||
retrieveRange(repositoryPath, owner, repo, fromTag, toTag, ignorePreReleases, maxTagsToFetch, tagResolver) {
|
||||
var _a;
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const tags = sortTags(yield this.getTags(owner, repo, maxTagsToFetch), tagResolver);
|
||||
let resultToTag;
|
||||
let resultFromTag;
|
||||
// ensure to resolve the toTag if it was not provided
|
||||
if (!toTag) {
|
||||
// if not specified try to retrieve tag from github.context.ref
|
||||
if (((_a = github.context.ref) === null || _a === void 0 ? void 0 : _a.startsWith('refs/tags/')) === true) {
|
||||
toTag = github.context.ref.replace('refs/tags/', '');
|
||||
core.info(`🔖 Resolved current tag (${toTag}) from the 'github.context.ref'`);
|
||||
resultToTag = {
|
||||
name: toTag,
|
||||
commit: toTag
|
||||
};
|
||||
}
|
||||
else if (tags.length > 1) {
|
||||
resultToTag = tags[0];
|
||||
core.info(`🔖 Resolved current tag (${resultToTag.name}) from the tags git API`);
|
||||
}
|
||||
else {
|
||||
// if not specified try to retrieve tag from git
|
||||
const gitHelper = yield gitHelper_1.createCommandManager(repositoryPath);
|
||||
const latestTag = yield gitHelper.latestTag();
|
||||
core.info(`🔖 Resolved current tag (${latestTag}) from 'git rev-list --tags --skip=0 --max-count=1'`);
|
||||
resultToTag = {
|
||||
name: latestTag,
|
||||
commit: latestTag
|
||||
};
|
||||
}
|
||||
}
|
||||
else {
|
||||
resultToTag = {
|
||||
name: toTag,
|
||||
commit: toTag
|
||||
};
|
||||
}
|
||||
// ensure toTag is specified
|
||||
toTag = resultToTag.name;
|
||||
// resolve the fromTag if not defined
|
||||
if (!fromTag) {
|
||||
core.debug(`fromTag undefined, trying to resolve via API`);
|
||||
resultFromTag = yield this.findPredecessorTag(tags, repositoryPath, toTag, ignorePreReleases);
|
||||
if (resultFromTag != null) {
|
||||
core.info(`🔖 Resolved previous tag (${resultFromTag.name}) from the tags git API`);
|
||||
}
|
||||
}
|
||||
else {
|
||||
resultFromTag = {
|
||||
name: fromTag,
|
||||
commit: fromTag
|
||||
};
|
||||
}
|
||||
return {
|
||||
from: resultFromTag,
|
||||
to: resultToTag
|
||||
};
|
||||
});
|
||||
}
|
||||
}
|
||||
exports.Tags = Tags;
|
||||
/*
|
||||
|
||||
+1
-1
File diff suppressed because one or more lines are too long
+34
-54
@@ -1,8 +1,6 @@
|
||||
import * as core from '@actions/core'
|
||||
import * as github from '@actions/github'
|
||||
import {Configuration, DefaultConfiguration} from './configuration'
|
||||
import {Octokit} from '@octokit/rest'
|
||||
import {createCommandManager} from './gitHelper'
|
||||
import {ReleaseNotes} from './releaseNotes'
|
||||
import {Tags} from './tags'
|
||||
import {failOrError} from './utils'
|
||||
@@ -23,25 +21,6 @@ export class ReleaseNotesBuilder {
|
||||
) {}
|
||||
|
||||
async build(): Promise<string | null> {
|
||||
// ensure to resolve the toTag if it was not provided
|
||||
if (!this.toTag) {
|
||||
// if not specified try to retrieve tag from github.context.ref
|
||||
if (github.context.ref.startsWith('refs/tags/')) {
|
||||
this.toTag = github.context.ref.replace('refs/tags/', '')
|
||||
core.info(
|
||||
`🔖 Resolved current tag (${this.toTag}) from the 'github.context.ref'`
|
||||
)
|
||||
} else {
|
||||
// if not specified try to retrieve tag from git
|
||||
const gitHelper = await createCommandManager(this.repositoryPath)
|
||||
const latestTag = await gitHelper.latestTag()
|
||||
this.toTag = latestTag
|
||||
core.info(
|
||||
`🔖 Resolved current tag (${this.toTag}) from 'git rev-list --tags --skip=0 --max-count=1'`
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
if (!this.owner) {
|
||||
failOrError(`💥 Missing or couldn't resolve 'owner'`, this.failOnError)
|
||||
return null
|
||||
@@ -57,14 +36,6 @@ export class ReleaseNotesBuilder {
|
||||
core.setOutput('repo', this.repo)
|
||||
core.debug(`Resolved 'repo' as ${this.repo}`)
|
||||
}
|
||||
|
||||
if (!this.toTag) {
|
||||
failOrError(`💥 Missing or couldn't resolve 'toTag'`, this.failOnError)
|
||||
return null
|
||||
} else {
|
||||
core.setOutput('toTag', this.toTag)
|
||||
core.debug(`Resolved 'toTag' as ${this.toTag}`)
|
||||
}
|
||||
core.endGroup()
|
||||
|
||||
// load octokit instance
|
||||
@@ -72,34 +43,43 @@ export class ReleaseNotesBuilder {
|
||||
auth: `token ${this.token || process.env.GITHUB_TOKEN}`
|
||||
})
|
||||
|
||||
// ensure to resolve the fromTag if it was not provided specifically
|
||||
if (!this.fromTag) {
|
||||
core.startGroup(`🔖 Resolve previous tag`)
|
||||
core.debug(`fromTag undefined, trying to resolve via API`)
|
||||
const tagsApi = new Tags(octokit)
|
||||
// ensure proper from <-> to tag range
|
||||
core.startGroup(`🔖 Resolve tags`)
|
||||
const tagsApi = new Tags(octokit)
|
||||
const tagRange = await tagsApi.retrieveRange(
|
||||
this.repositoryPath,
|
||||
this.owner,
|
||||
this.repo,
|
||||
this.fromTag,
|
||||
this.toTag,
|
||||
this.ignorePreReleases,
|
||||
this.configuration.max_tags_to_fetch ||
|
||||
DefaultConfiguration.max_tags_to_fetch,
|
||||
this.configuration.tag_resolver || DefaultConfiguration.tag_resolver
|
||||
)
|
||||
|
||||
const previousTag = await tagsApi.findPredecessorTag(
|
||||
this.repositoryPath,
|
||||
this.owner,
|
||||
this.repo,
|
||||
this.toTag,
|
||||
this.ignorePreReleases,
|
||||
this.configuration.max_tags_to_fetch ||
|
||||
DefaultConfiguration.max_tags_to_fetch,
|
||||
this.configuration.tag_resolver || DefaultConfiguration.tag_resolver
|
||||
)
|
||||
if (previousTag == null) {
|
||||
failOrError(
|
||||
`💥 Unable to retrieve previous tag given ${this.toTag}`,
|
||||
this.failOnError
|
||||
)
|
||||
return null
|
||||
}
|
||||
this.fromTag = previousTag.name
|
||||
core.debug(`fromTag resolved via previousTag as: ${previousTag.name}`)
|
||||
core.endGroup()
|
||||
const thisTag = tagRange.to?.name
|
||||
if (!thisTag) {
|
||||
failOrError(`💥 Missing or couldn't resolve 'toTag'`, this.failOnError)
|
||||
return null
|
||||
} else {
|
||||
this.toTag = thisTag
|
||||
core.setOutput('toTag', thisTag)
|
||||
core.debug(`Resolved 'toTag' as ${thisTag}`)
|
||||
}
|
||||
|
||||
const previousTag = tagRange.from?.name
|
||||
if (previousTag == null) {
|
||||
failOrError(
|
||||
`💥 Unable to retrieve previous tag given ${this.toTag}`,
|
||||
this.failOnError
|
||||
)
|
||||
return null
|
||||
}
|
||||
this.fromTag = previousTag
|
||||
core.debug(`fromTag resolved via previousTag as: ${previousTag}`)
|
||||
core.endGroup()
|
||||
|
||||
const options = {
|
||||
owner: this.owner,
|
||||
repo: this.repo,
|
||||
|
||||
+95
-10
@@ -1,10 +1,16 @@
|
||||
import * as core from '@actions/core'
|
||||
import * as github from '@actions/github'
|
||||
import * as semver from 'semver'
|
||||
import {Octokit, RestEndpointMethodTypes} from '@octokit/rest'
|
||||
import {SemVer} from 'semver'
|
||||
import {TagResolver} from './configuration'
|
||||
import {createCommandManager} from './gitHelper'
|
||||
|
||||
export interface TagResult {
|
||||
from: TagInfo | null
|
||||
to: TagInfo | null
|
||||
}
|
||||
|
||||
export interface TagInfo {
|
||||
name: string
|
||||
commit: string
|
||||
@@ -51,19 +57,12 @@ export class Tags {
|
||||
}
|
||||
|
||||
async findPredecessorTag(
|
||||
sortedTags: TagInfo[],
|
||||
repositoryPath: string,
|
||||
owner: string,
|
||||
repo: string,
|
||||
tag: string,
|
||||
ignorePreReleases: boolean,
|
||||
maxTagsToFetch: number,
|
||||
tagResolver: TagResolver
|
||||
ignorePreReleases: boolean
|
||||
): Promise<TagInfo | null> {
|
||||
const tags = sortTags(
|
||||
await this.getTags(owner, repo, maxTagsToFetch),
|
||||
tagResolver
|
||||
)
|
||||
|
||||
const tags = sortedTags
|
||||
try {
|
||||
const length = tags.length
|
||||
if (tags.length > 1) {
|
||||
@@ -102,6 +101,92 @@ export class Tags {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
async retrieveRange(
|
||||
repositoryPath: string,
|
||||
owner: string,
|
||||
repo: string,
|
||||
fromTag: string | null,
|
||||
toTag: string | null,
|
||||
ignorePreReleases: boolean,
|
||||
maxTagsToFetch: number,
|
||||
tagResolver: TagResolver
|
||||
): Promise<TagResult> {
|
||||
const tags = sortTags(
|
||||
await this.getTags(owner, repo, maxTagsToFetch),
|
||||
tagResolver
|
||||
)
|
||||
|
||||
let resultToTag: TagInfo | null
|
||||
let resultFromTag: TagInfo | null
|
||||
|
||||
// ensure to resolve the toTag if it was not provided
|
||||
if (!toTag) {
|
||||
// if not specified try to retrieve tag from github.context.ref
|
||||
if (github.context.ref?.startsWith('refs/tags/') === true) {
|
||||
toTag = github.context.ref.replace('refs/tags/', '')
|
||||
core.info(
|
||||
`🔖 Resolved current tag (${toTag}) from the 'github.context.ref'`
|
||||
)
|
||||
resultToTag = {
|
||||
name: toTag,
|
||||
commit: toTag
|
||||
}
|
||||
} else if (tags.length > 1) {
|
||||
resultToTag = tags[0]
|
||||
core.info(
|
||||
`🔖 Resolved current tag (${resultToTag.name}) from the tags git API`
|
||||
)
|
||||
} else {
|
||||
// if not specified try to retrieve tag from git
|
||||
const gitHelper = await createCommandManager(repositoryPath)
|
||||
const latestTag = await gitHelper.latestTag()
|
||||
core.info(
|
||||
`🔖 Resolved current tag (${latestTag}) from 'git rev-list --tags --skip=0 --max-count=1'`
|
||||
)
|
||||
resultToTag = {
|
||||
name: latestTag,
|
||||
commit: latestTag
|
||||
}
|
||||
}
|
||||
} else {
|
||||
resultToTag = {
|
||||
name: toTag,
|
||||
commit: toTag
|
||||
}
|
||||
}
|
||||
|
||||
// ensure toTag is specified
|
||||
toTag = resultToTag.name
|
||||
|
||||
// resolve the fromTag if not defined
|
||||
if (!fromTag) {
|
||||
core.debug(`fromTag undefined, trying to resolve via API`)
|
||||
|
||||
resultFromTag = await this.findPredecessorTag(
|
||||
tags,
|
||||
repositoryPath,
|
||||
toTag,
|
||||
ignorePreReleases
|
||||
)
|
||||
|
||||
if (resultFromTag != null) {
|
||||
core.info(
|
||||
`🔖 Resolved previous tag (${resultFromTag.name}) from the tags git API`
|
||||
)
|
||||
}
|
||||
} else {
|
||||
resultFromTag = {
|
||||
name: fromTag,
|
||||
commit: fromTag
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
from: resultFromTag,
|
||||
to: resultToTag
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user