Skip to content

Commit b11b6a6

Browse files
authored
Fix getVersionDescription() to prioritize version tags over non-version tags (#673)
* Fix getVersionDescription() to prioritize version tags over non-version tags This fix modifies the getVersionDescription() method to ensure it only considers valid version tags when describing the current version. It retrieves all tags merged into the current branch, filters them based on a version-compatible regex, and uses the most recent valid version tag for description. If no valid tags are found, it falls back to the default description behavior. This resolves the issue of incorrect tags being used when multiple tags are present. * Update versioning.ts Rewrote getting the description for the last valid tag using `rev-list` and `rev-parse` * Fix formatting * Revert "dist" This reverts commit bd58cbe. * Revert "dist" This reverts commit bd58cbe.
1 parent 461ecf7 commit b11b6a6

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed

dist/index.js

Lines changed: 11 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/model/versioning.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,21 @@ export default class Versioning {
207207
* identifies the current commit.
208208
*/
209209
static async getVersionDescription() {
210-
return this.git(['describe', '--long', '--tags', '--always', 'HEAD']);
210+
const versionTags = (await this.git(['tag', '--list', '--merged', 'HEAD', '--sort=-creatordate']))
211+
.split('\n')
212+
.filter((tag) => new RegExp(this.grepCompatibleInputVersionRegex).test(tag));
213+
214+
if (versionTags.length === 0) {
215+
core.warning('No valid version tags found. Using fallback description.');
216+
217+
return this.git(['describe', '--long', '--tags', '--always', 'HEAD']);
218+
}
219+
220+
const latestVersionTag = versionTags[0];
221+
const commitsCount = (await this.git(['rev-list', `${latestVersionTag}..HEAD`, '--count'])).trim();
222+
const commitHash = (await this.git(['rev-parse', '--short', 'HEAD'])).trim();
223+
224+
return `${latestVersionTag}-${commitsCount}-g${commitHash}`;
211225
}
212226

213227
/**

0 commit comments

Comments
 (0)