From 169acace66ec20b509c1ea6d11203241fad35f9a Mon Sep 17 00:00:00 2001 From: Laurent Cozic Date: Tue, 6 Jun 2023 10:50:22 +0100 Subject: [PATCH] Tools: Improve git-changelog tag detection --- packages/tools/git-changelog.ts | 9 +++++++++ packages/tools/package.json | 1 + yarn.lock | 1 + 3 files changed, 11 insertions(+) diff --git a/packages/tools/git-changelog.ts b/packages/tools/git-changelog.ts index 64d0020c1..eb5ec676b 100644 --- a/packages/tools/git-changelog.ts +++ b/packages/tools/git-changelog.ts @@ -3,6 +3,7 @@ // (Desktop|Mobile|Android|iOS[CLI): (New|Improved|Fixed): Some message..... (#ISSUE) import { execCommand, githubUsername } from './tool-utils'; +import * as compareVersions from 'compare-versions'; interface LogEntry { message: string; @@ -91,6 +92,11 @@ function platformFromTag(tagName: string): Platform { throw new Error(`Could not determine platform from tag: "${tagName}"`); } +const versionFromTag = (tag: string) => { + const s = tag.split('-'); + return s[s.length - 1]; +}; + function filterLogs(logs: LogEntry[], platform: Platform) { const output: LogEntry[] = []; const revertedLogs = []; @@ -311,10 +317,13 @@ function capitalizeFirstLetter(string: string) { async function findFirstRelevantTag(baseTag: string, platform: Platform, allTags: string[]) { let baseTagIndex = allTags.indexOf(baseTag); if (baseTagIndex < 0) baseTagIndex = allTags.length; + const baseVersion = versionFromTag(baseTag); for (let i = baseTagIndex - 1; i >= 0; i--) { const tag = allTags[i]; if (platformFromTag(tag) !== platform) continue; + const currentVersion = versionFromTag(tag); + if (compareVersions(baseVersion, currentVersion) <= 0) continue; try { const logs = await gitLog(tag); diff --git a/packages/tools/package.json b/packages/tools/package.json index 7e74bcc00..2987ea41a 100644 --- a/packages/tools/package.json +++ b/packages/tools/package.json @@ -24,6 +24,7 @@ "@joplin/renderer": "^2.10.2", "@types/node-fetch": "2.6.2", "@types/yargs": "17.0.20", + "compare-versions": "3.6.0", "dayjs": "1.11.7", "execa": "4.1.0", "fs-extra": "11.1.0", diff --git a/yarn.lock b/yarn.lock index cbfe7fdc4..1b44f5d54 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5142,6 +5142,7 @@ __metadata: "@types/node": 18.11.18 "@types/node-fetch": 2.6.2 "@types/yargs": 17.0.20 + compare-versions: 3.6.0 dayjs: 1.11.7 execa: 4.1.0 fs-extra: 11.1.0