- 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.
|
⚠️ 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.
|
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 () => {
|
it('Should use empty placeholder', async () => {
|
||||||
const configuration = resolveConfiguration('', 'configs/configuration.json')
|
const configuration = resolveConfiguration('', 'configs/configuration.json')
|
||||||
const releaseNotesBuilder = new ReleaseNotesBuilder(
|
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 }));
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||||
exports.ReleaseNotesBuilder = void 0;
|
exports.ReleaseNotesBuilder = void 0;
|
||||||
const core = __importStar(__nccwpck_require__(2186));
|
const core = __importStar(__nccwpck_require__(2186));
|
||||||
const github = __importStar(__nccwpck_require__(5438));
|
|
||||||
const configuration_1 = __nccwpck_require__(5527);
|
const configuration_1 = __nccwpck_require__(5527);
|
||||||
const rest_1 = __nccwpck_require__(5375);
|
const rest_1 = __nccwpck_require__(5375);
|
||||||
const gitHelper_1 = __nccwpck_require__(353);
|
|
||||||
const releaseNotes_1 = __nccwpck_require__(5882);
|
const releaseNotes_1 = __nccwpck_require__(5882);
|
||||||
const tags_1 = __nccwpck_require__(7532);
|
const tags_1 = __nccwpck_require__(7532);
|
||||||
const utils_1 = __nccwpck_require__(918);
|
const utils_1 = __nccwpck_require__(918);
|
||||||
@@ -772,22 +770,8 @@ class ReleaseNotesBuilder {
|
|||||||
this.configuration = configuration;
|
this.configuration = configuration;
|
||||||
}
|
}
|
||||||
build() {
|
build() {
|
||||||
|
var _a, _b;
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
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) {
|
if (!this.owner) {
|
||||||
utils_1.failOrError(`💥 Missing or couldn't resolve 'owner'`, this.failOnError);
|
utils_1.failOrError(`💥 Missing or couldn't resolve 'owner'`, this.failOnError);
|
||||||
return null;
|
return null;
|
||||||
@@ -804,34 +788,34 @@ class ReleaseNotesBuilder {
|
|||||||
core.setOutput('repo', this.repo);
|
core.setOutput('repo', this.repo);
|
||||||
core.debug(`Resolved 'repo' as ${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();
|
core.endGroup();
|
||||||
// load octokit instance
|
// load octokit instance
|
||||||
const octokit = new rest_1.Octokit({
|
const octokit = new rest_1.Octokit({
|
||||||
auth: `token ${this.token || process.env.GITHUB_TOKEN}`
|
auth: `token ${this.token || process.env.GITHUB_TOKEN}`
|
||||||
});
|
});
|
||||||
// ensure to resolve the fromTag if it was not provided specifically
|
// ensure proper from <-> to tag range
|
||||||
if (!this.fromTag) {
|
core.startGroup(`🔖 Resolve tags`);
|
||||||
core.startGroup(`🔖 Resolve previous tag`);
|
const tagsApi = new tags_1.Tags(octokit);
|
||||||
core.debug(`fromTag undefined, trying to resolve via API`);
|
const tagRange = yield tagsApi.retrieveRange(this.repositoryPath, this.owner, this.repo, this.fromTag, this.toTag, this.ignorePreReleases, this.configuration.max_tags_to_fetch ||
|
||||||
const tagsApi = new tags_1.Tags(octokit);
|
configuration_1.DefaultConfiguration.max_tags_to_fetch, this.configuration.tag_resolver || configuration_1.DefaultConfiguration.tag_resolver);
|
||||||
const previousTag = yield tagsApi.findPredecessorTag(this.repositoryPath, this.owner, this.repo, this.toTag, this.ignorePreReleases, this.configuration.max_tags_to_fetch ||
|
const thisTag = (_a = tagRange.to) === null || _a === void 0 ? void 0 : _a.name;
|
||||||
configuration_1.DefaultConfiguration.max_tags_to_fetch, this.configuration.tag_resolver || configuration_1.DefaultConfiguration.tag_resolver);
|
if (!thisTag) {
|
||||||
if (previousTag == null) {
|
utils_1.failOrError(`💥 Missing or couldn't resolve 'toTag'`, this.failOnError);
|
||||||
utils_1.failOrError(`💥 Unable to retrieve previous tag given ${this.toTag}`, this.failOnError);
|
return null;
|
||||||
return null;
|
|
||||||
}
|
|
||||||
this.fromTag = previousTag.name;
|
|
||||||
core.debug(`fromTag resolved via previousTag as: ${previousTag.name}`);
|
|
||||||
core.endGroup();
|
|
||||||
}
|
}
|
||||||
|
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 = {
|
const options = {
|
||||||
owner: this.owner,
|
owner: this.owner,
|
||||||
repo: this.repo,
|
repo: this.repo,
|
||||||
@@ -896,6 +880,7 @@ var __asyncValues = (this && this.__asyncValues) || function (o) {
|
|||||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||||
exports.sortTags = exports.Tags = void 0;
|
exports.sortTags = exports.Tags = void 0;
|
||||||
const core = __importStar(__nccwpck_require__(2186));
|
const core = __importStar(__nccwpck_require__(2186));
|
||||||
|
const github = __importStar(__nccwpck_require__(5438));
|
||||||
const semver = __importStar(__nccwpck_require__(1383));
|
const semver = __importStar(__nccwpck_require__(1383));
|
||||||
const semver_1 = __nccwpck_require__(1383);
|
const semver_1 = __nccwpck_require__(1383);
|
||||||
const gitHelper_1 = __nccwpck_require__(353);
|
const gitHelper_1 = __nccwpck_require__(353);
|
||||||
@@ -940,9 +925,9 @@ class Tags {
|
|||||||
return tagsInfo;
|
return tagsInfo;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
findPredecessorTag(repositoryPath, owner, repo, tag, ignorePreReleases, maxTagsToFetch, tagResolver) {
|
findPredecessorTag(sortedTags, repositoryPath, tag, ignorePreReleases) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
const tags = sortTags(yield this.getTags(owner, repo, maxTagsToFetch), tagResolver);
|
const tags = sortedTags;
|
||||||
try {
|
try {
|
||||||
const length = tags.length;
|
const length = tags.length;
|
||||||
if (tags.length > 1) {
|
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;
|
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 core from '@actions/core'
|
||||||
import * as github from '@actions/github'
|
|
||||||
import {Configuration, DefaultConfiguration} from './configuration'
|
import {Configuration, DefaultConfiguration} from './configuration'
|
||||||
import {Octokit} from '@octokit/rest'
|
import {Octokit} from '@octokit/rest'
|
||||||
import {createCommandManager} from './gitHelper'
|
|
||||||
import {ReleaseNotes} from './releaseNotes'
|
import {ReleaseNotes} from './releaseNotes'
|
||||||
import {Tags} from './tags'
|
import {Tags} from './tags'
|
||||||
import {failOrError} from './utils'
|
import {failOrError} from './utils'
|
||||||
@@ -23,25 +21,6 @@ export class ReleaseNotesBuilder {
|
|||||||
) {}
|
) {}
|
||||||
|
|
||||||
async build(): Promise<string | null> {
|
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) {
|
if (!this.owner) {
|
||||||
failOrError(`💥 Missing or couldn't resolve 'owner'`, this.failOnError)
|
failOrError(`💥 Missing or couldn't resolve 'owner'`, this.failOnError)
|
||||||
return null
|
return null
|
||||||
@@ -57,14 +36,6 @@ export class ReleaseNotesBuilder {
|
|||||||
core.setOutput('repo', this.repo)
|
core.setOutput('repo', this.repo)
|
||||||
core.debug(`Resolved 'repo' as ${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()
|
core.endGroup()
|
||||||
|
|
||||||
// load octokit instance
|
// load octokit instance
|
||||||
@@ -72,34 +43,43 @@ export class ReleaseNotesBuilder {
|
|||||||
auth: `token ${this.token || process.env.GITHUB_TOKEN}`
|
auth: `token ${this.token || process.env.GITHUB_TOKEN}`
|
||||||
})
|
})
|
||||||
|
|
||||||
// ensure to resolve the fromTag if it was not provided specifically
|
// ensure proper from <-> to tag range
|
||||||
if (!this.fromTag) {
|
core.startGroup(`🔖 Resolve tags`)
|
||||||
core.startGroup(`🔖 Resolve previous tag`)
|
const tagsApi = new Tags(octokit)
|
||||||
core.debug(`fromTag undefined, trying to resolve via API`)
|
const tagRange = await tagsApi.retrieveRange(
|
||||||
const tagsApi = new Tags(octokit)
|
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(
|
const thisTag = tagRange.to?.name
|
||||||
this.repositoryPath,
|
if (!thisTag) {
|
||||||
this.owner,
|
failOrError(`💥 Missing or couldn't resolve 'toTag'`, this.failOnError)
|
||||||
this.repo,
|
return null
|
||||||
this.toTag,
|
} else {
|
||||||
this.ignorePreReleases,
|
this.toTag = thisTag
|
||||||
this.configuration.max_tags_to_fetch ||
|
core.setOutput('toTag', thisTag)
|
||||||
DefaultConfiguration.max_tags_to_fetch,
|
core.debug(`Resolved 'toTag' as ${thisTag}`)
|
||||||
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 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 = {
|
const options = {
|
||||||
owner: this.owner,
|
owner: this.owner,
|
||||||
repo: this.repo,
|
repo: this.repo,
|
||||||
|
|||||||
+95
-10
@@ -1,10 +1,16 @@
|
|||||||
import * as core from '@actions/core'
|
import * as core from '@actions/core'
|
||||||
|
import * as github from '@actions/github'
|
||||||
import * as semver from 'semver'
|
import * as semver from 'semver'
|
||||||
import {Octokit, RestEndpointMethodTypes} from '@octokit/rest'
|
import {Octokit, RestEndpointMethodTypes} from '@octokit/rest'
|
||||||
import {SemVer} from 'semver'
|
import {SemVer} from 'semver'
|
||||||
import {TagResolver} from './configuration'
|
import {TagResolver} from './configuration'
|
||||||
import {createCommandManager} from './gitHelper'
|
import {createCommandManager} from './gitHelper'
|
||||||
|
|
||||||
|
export interface TagResult {
|
||||||
|
from: TagInfo | null
|
||||||
|
to: TagInfo | null
|
||||||
|
}
|
||||||
|
|
||||||
export interface TagInfo {
|
export interface TagInfo {
|
||||||
name: string
|
name: string
|
||||||
commit: string
|
commit: string
|
||||||
@@ -51,19 +57,12 @@ export class Tags {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async findPredecessorTag(
|
async findPredecessorTag(
|
||||||
|
sortedTags: TagInfo[],
|
||||||
repositoryPath: string,
|
repositoryPath: string,
|
||||||
owner: string,
|
|
||||||
repo: string,
|
|
||||||
tag: string,
|
tag: string,
|
||||||
ignorePreReleases: boolean,
|
ignorePreReleases: boolean
|
||||||
maxTagsToFetch: number,
|
|
||||||
tagResolver: TagResolver
|
|
||||||
): Promise<TagInfo | null> {
|
): Promise<TagInfo | null> {
|
||||||
const tags = sortTags(
|
const tags = sortedTags
|
||||||
await this.getTags(owner, repo, maxTagsToFetch),
|
|
||||||
tagResolver
|
|
||||||
)
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const length = tags.length
|
const length = tags.length
|
||||||
if (tags.length > 1) {
|
if (tags.length > 1) {
|
||||||
@@ -102,6 +101,92 @@ export class Tags {
|
|||||||
return null
|
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