- if only a single tag is available resolve the initial commit as fallback. this is meant to support initial release scenarios

- FIX https://github.com/mikepenz/release-changelog-builder-action/issues/276
This commit is contained in:
Mike Penz
2021-07-05 08:57:37 +02:00
parent 080a1286ce
commit 762538b445
5 changed files with 71 additions and 30 deletions
Generated Vendored
+34 -16
View File
@@ -250,6 +250,16 @@ class GitCommandManager {
return output.stdout.trim(); return output.stdout.trim();
}); });
} }
initialCommit() {
return __awaiter(this, void 0, void 0, function* () {
const revListOutput = yield this.execGit([
'rev-list',
'--max-parents=0',
'HEAD'
]);
return revListOutput.stdout.trim();
});
}
static createCommandManager(workingDirectory) { static createCommandManager(workingDirectory) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
const result = new GitCommandManager(); const result = new GitCommandManager();
@@ -812,7 +822,7 @@ class ReleaseNotesBuilder {
core.startGroup(`🔖 Resolve previous tag`); core.startGroup(`🔖 Resolve previous tag`);
core.debug(`fromTag undefined, trying to resolve via API`); core.debug(`fromTag undefined, trying to resolve via API`);
const tagsApi = new tags_1.Tags(octokit); const tagsApi = new tags_1.Tags(octokit);
const previousTag = yield tagsApi.findPredecessorTag(this.owner, this.repo, this.toTag, this.ignorePreReleases, this.configuration.max_tags_to_fetch || 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); configuration_1.DefaultConfiguration.max_tags_to_fetch, this.configuration.tag_resolver || configuration_1.DefaultConfiguration.tag_resolver);
if (previousTag == null) { if (previousTag == null) {
utils_1.failOrError(`💥 Unable to retrieve previous tag given ${this.toTag}`, this.failOnError); utils_1.failOrError(`💥 Unable to retrieve previous tag given ${this.toTag}`, this.failOnError);
@@ -888,6 +898,7 @@ exports.sortTags = exports.Tags = void 0;
const core = __importStar(__nccwpck_require__(2186)); const core = __importStar(__nccwpck_require__(2186));
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);
class Tags { class Tags {
constructor(octokit) { constructor(octokit) {
this.octokit = octokit; this.octokit = octokit;
@@ -929,31 +940,38 @@ class Tags {
return tagsInfo; return tagsInfo;
}); });
} }
findPredecessorTag(owner, repo, tag, ignorePreReleases, maxTagsToFetch, tagResolver) { findPredecessorTag(repositoryPath, owner, repo, tag, ignorePreReleases, maxTagsToFetch, tagResolver) {
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 = sortTags(yield this.getTags(owner, repo, maxTagsToFetch), tagResolver);
try { try {
const length = tags.length; const length = tags.length;
for (let i = 0; i < length; i++) { if (tags.length > 1) {
if (tags[i].name.toLocaleLowerCase() === tag.toLocaleLowerCase()) { for (let i = 0; i < length; i++) {
if (ignorePreReleases) { if (tags[i].name.toLocaleLowerCase() === tag.toLocaleLowerCase()) {
core.info(`️ Enabled 'ignorePreReleases', searching for the closest release`); if (ignorePreReleases) {
for (let ii = i + 1; ii < length; ii++) { core.info(`️ Enabled 'ignorePreReleases', searching for the closest release`);
if (!tags[ii].name.includes('-')) { for (let ii = i + 1; ii < length; ii++) {
return tags[ii]; if (!tags[ii].name.includes('-')) {
return tags[ii];
}
} }
} }
return tags[i + 1];
} }
return tags[i + 1];
} }
} }
else {
core.info(`️ Only one tag found for the given repository. Usually this is the case for the initial release.`);
// if not specified try to retrieve tag from git
const gitHelper = yield gitHelper_1.createCommandManager(repositoryPath);
const initialCommit = yield gitHelper.initialCommit();
core.info(`🔖 Resolved initial commit (${initialCommit}) from 'git rev-list --max-parents=0 HEAD'`);
return { name: 'initial', commit: initialCommit };
}
return tags[0]; return tags[0];
} }
catch (error) { catch (error) {
if (tags.length < 1) { if (tags.length <= 0) {
core.warning(`⚠️ Only one tag found for the given repository`);
}
else if (tags.length < 0) {
core.warning(`⚠️ No tag found for the given repository`); core.warning(`⚠️ No tag found for the given repository`);
} }
return null; return null;
@@ -6142,7 +6160,7 @@ const Endpoints = {
} }
}; };
const VERSION = "5.3.1"; const VERSION = "5.3.7";
function endpointsToMethods(octokit, endpointsMap) { function endpointsToMethods(octokit, endpointsMap) {
const newMethods = {}; const newMethods = {};
@@ -6527,7 +6545,7 @@ var pluginRequestLog = __nccwpck_require__(8883);
var pluginPaginateRest = __nccwpck_require__(4193); var pluginPaginateRest = __nccwpck_require__(4193);
var pluginRestEndpointMethods = __nccwpck_require__(3044); var pluginRestEndpointMethods = __nccwpck_require__(3044);
const VERSION = "18.6.0"; const VERSION = "18.6.6";
const Octokit = core.Octokit.plugin(pluginRequestLog.requestLog, pluginRestEndpointMethods.legacyRestEndpointMethods, pluginPaginateRest.paginateRest).defaults({ const Octokit = core.Octokit.plugin(pluginRequestLog.requestLog, pluginRestEndpointMethods.legacyRestEndpointMethods, pluginPaginateRest.paginateRest).defaults({
userAgent: `octokit-rest.js/${VERSION}` userAgent: `octokit-rest.js/${VERSION}`
Generated Vendored
+1 -1
View File
File diff suppressed because one or more lines are too long
+9
View File
@@ -35,6 +35,15 @@ class GitCommandManager {
return output.stdout.trim() return output.stdout.trim()
} }
async initialCommit(): Promise<string> {
const revListOutput = await this.execGit([
'rev-list',
'--max-parents=0',
'HEAD'
])
return revListOutput.stdout.trim()
}
static async createCommandManager( static async createCommandManager(
workingDirectory: string workingDirectory: string
): Promise<GitCommandManager> { ): Promise<GitCommandManager> {
+1
View File
@@ -79,6 +79,7 @@ export class ReleaseNotesBuilder {
const tagsApi = new Tags(octokit) const tagsApi = new Tags(octokit)
const previousTag = await tagsApi.findPredecessorTag( const previousTag = await tagsApi.findPredecessorTag(
this.repositoryPath,
this.owner, this.owner,
this.repo, this.repo,
this.toTag, this.toTag,
+26 -13
View File
@@ -3,6 +3,7 @@ import * as core from '@actions/core'
import * as semver from 'semver' import * as semver from 'semver'
import {SemVer} from 'semver' import {SemVer} from 'semver'
import {TagResolver} from './configuration' import {TagResolver} from './configuration'
import {createCommandManager} from './gitHelper'
export interface TagInfo { export interface TagInfo {
name: string name: string
@@ -50,6 +51,7 @@ export class Tags {
} }
async findPredecessorTag( async findPredecessorTag(
repositoryPath: string,
owner: string, owner: string,
repo: string, repo: string,
tag: string, tag: string,
@@ -64,26 +66,37 @@ export class Tags {
try { try {
const length = tags.length const length = tags.length
for (let i = 0; i < length; i++) { if (tags.length > 1) {
if (tags[i].name.toLocaleLowerCase() === tag.toLocaleLowerCase()) { for (let i = 0; i < length; i++) {
if (ignorePreReleases) { if (tags[i].name.toLocaleLowerCase() === tag.toLocaleLowerCase()) {
core.info( if (ignorePreReleases) {
`️ Enabled 'ignorePreReleases', searching for the closest release` core.info(
) `️ Enabled 'ignorePreReleases', searching for the closest release`
for (let ii = i + 1; ii < length; ii++) { )
if (!tags[ii].name.includes('-')) { for (let ii = i + 1; ii < length; ii++) {
return tags[ii] if (!tags[ii].name.includes('-')) {
return tags[ii]
}
} }
} }
return tags[i + 1]
} }
return tags[i + 1]
} }
} else {
core.info(
`️ Only one tag found for the given repository. Usually this is the case for the initial release.`
)
// if not specified try to retrieve tag from git
const gitHelper = await createCommandManager(repositoryPath)
const initialCommit = await gitHelper.initialCommit()
core.info(
`🔖 Resolved initial commit (${initialCommit}) from 'git rev-list --max-parents=0 HEAD'`
)
return {name: 'initial', commit: initialCommit}
} }
return tags[0] return tags[0]
} catch (error) { } catch (error) {
if (tags.length < 1) { if (tags.length <= 0) {
core.warning(`⚠️ Only one tag found for the given repository`)
} else if (tags.length < 0) {
core.warning(`⚠️ No tag found for the given repository`) core.warning(`⚠️ No tag found for the given repository`)
} }
return null return null