Skip to content

Commit 7875577

Browse files
atscottthePunderWoman
authored andcommitted
build: fix changelog generation for last rev
updates changelog generation to work when releasing the first final version.
1 parent 36c2f4b commit 7875577

1 file changed

Lines changed: 37 additions & 2 deletions

File tree

vscode-ng-language-service/tools/release.mts

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ async function main(): Promise<void> {
8080
}
8181

8282
console.log(chalk.blue(`Releasing from ${branchToReleaseFrom}.`));
83-
await exec(`git fetch ${angularRepoRemote} ${branchToReleaseFrom}`);
83+
await exec(`git fetch ${angularRepoRemote} ${branchToReleaseFrom} --tags`);
8484

8585
const currentVersion = await getCurrentVersion();
8686
const newVersion = await getNewVersion(currentVersion);
@@ -240,8 +240,9 @@ async function prepareReleasePullRequest(
240240
* @param toVersion The version to generate the changelog for.
241241
*/
242242
async function generateChangelog(fromVersion: string, toVersion: string): Promise<string> {
243+
const previousTag = await getPreviousTag(fromVersion);
243244
let {stdout: commits} = await exec(
244-
`git log --left-only FETCH_HEAD...${getTagName(fromVersion)} -E ` +
245+
`git log --left-only FETCH_HEAD...${previousTag} -E ` +
245246
'--grep="^(feat|fix|perf)\\((vscode-extension|language-server|language-service)\\):" ' +
246247
'--format="format:- %s ([%h](https://github.com/angular/angular/commit/%H))"',
247248
);
@@ -519,6 +520,40 @@ function getRepoDetails(remoteUrl: string): {owner: string; repo: string} {
519520
};
520521
}
521522

523+
/**
524+
* Gets the previous tag to version from.
525+
*
526+
* It checks if the tag for the `currentVersion` exists. If it does, returning it.
527+
* If not, it finds the latest tag that adheres to the semver versioning of the extension.
528+
*/
529+
async function getPreviousTag(currentVersion: string): Promise<string> {
530+
const currentTag = getTagName(currentVersion);
531+
try {
532+
await exec(`git rev-parse "${currentTag}"`);
533+
return currentTag;
534+
} catch {
535+
// Tag does not exist.
536+
}
537+
538+
const {stdout: tags} = await exec(`git tag --list "${tagPrefix}*"`);
539+
const versions = tags
540+
.trim()
541+
.split('\n')
542+
.map((t) => t.trim())
543+
.filter((t) => t.startsWith(tagPrefix))
544+
.map((t) => t.slice(tagPrefix.length))
545+
.filter((v) => semver.valid(v));
546+
547+
if (versions.length === 0) {
548+
throw new Error('No previous release tags found.');
549+
}
550+
551+
// Sort versions in descending order
552+
versions.sort((a, b) => semver.rcompare(a, b));
553+
554+
return getTagName(versions[0]);
555+
}
556+
522557
/**
523558
* Gets the tag name for the given version.
524559
*

0 commit comments

Comments
 (0)