* Fallback: resolve tag refs via git ls-remote and return the latest tag by semver. * git ls-remote returns refs sorted by refname (alphabetically), so we parse all tags * and pick the highest semantic version.
(repoUrl: string)
| 76 | * and pick the highest semantic version. |
| 77 | */ |
| 78 | async function getLatestReleaseTagFromGit(repoUrl: string): Promise<string> { |
| 79 | const gitUrl = repoUrl.includes('.git') ? repoUrl : `${repoUrl}.git`; |
| 80 | const result = await runCliCommand(`git ls-remote --tags --refs ${gitUrl}`, undefined, true); |
| 81 | const lines = result.stdout.trim().split('\n').filter(Boolean); |
| 82 | const tags: string[] = []; |
| 83 | for (const line of lines) { |
| 84 | const ref = line.split(/\s+/)[1]; |
| 85 | if (ref?.startsWith('refs/tags/')) { |
| 86 | const tag = ref.slice('refs/tags/'.length); |
| 87 | if (tag) tags.push(tag); |
| 88 | } |
| 89 | } |
| 90 | if (tags.length === 0) { |
| 91 | throw new Error('No tags found in repository'); |
| 92 | } |
| 93 | tags.sort(compareSemverTags); |
| 94 | return tags[tags.length - 1]!; |
| 95 | } |
| 96 | |
| 97 | /** @deprecated Use getLatestReleaseTag for the GitHub "Latest" release; this returns an arbitrary tag from git ls-remote. */ |
| 98 | export async function resolveLatestReleaseRef(repoUrl: string): Promise<string> { |
no test coverage detected