Skip to content

Commit 18fc37b

Browse files
committed
Create new section in changelog when updating version
1 parent e9f1c7f commit 18fc37b

File tree

3 files changed

+44
-4
lines changed

3 files changed

+44
-4
lines changed

.github/workflows/branch-snap.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ jobs:
2525
- name: Install dependencies
2626
run: npm ci
2727
- name: Update version.json
28-
run: npx gulp incrementVersionJson
29-
- name: Create version.json update PR
28+
run: npx gulp incrementVersion
29+
- name: Create version update PR
3030
uses: peter-evans/create-pull-request@v4
3131
with:
3232
token: ${{ secrets.GITHUB_TOKEN }}

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
- Diagnostics related feature requests and improvements [#5951](https://github.com/dotnet/vscode-csharp/issues/5951)
44
- Debug from .csproj and .sln [#5876](https://github.com/dotnet/vscode-csharp/issues/5876)
55

6-
# Latest
6+
# 2.54.x
77
* Bumped xamlTools to 17.13.35422.31 (PR: [#7685](https://github.com/dotnet/vscode-csharp/pull/7685))
88

99
# 2.53.x

tasks/snapTasks.ts

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,61 @@
66
import * as gulp from 'gulp';
77
import * as fs from 'fs';
88
import * as path from 'path';
9+
import * as os from 'os';
910

10-
gulp.task('incrementVersionJson', async (): Promise<void> => {
11+
gulp.task('incrementVersion', async (): Promise<void> => {
12+
// Get the current version from version.json
1113
const versionFilePath = path.join(path.resolve(__dirname, '..'), 'version.json');
1214
const file = fs.readFileSync(versionFilePath, 'utf8');
1315
const versionJson = JSON.parse(file);
1416

17+
// Increment the minor version
1518
const version = versionJson.version as string;
1619
const split = version.split('.');
1720
const newVersion = `${split[0]}.${parseInt(split[1]) + 1}`;
1821

1922
console.log(`Updating ${version} to ${newVersion}`);
2023

24+
// Write the new version back to version.json
2125
versionJson.version = newVersion;
2226
const newJson = JSON.stringify(versionJson, null, 4);
2327
console.log(`New json: ${newJson}`);
2428

2529
fs.writeFileSync(versionFilePath, newJson);
30+
31+
// Add a new changelog section for the new version.
32+
console.log('Adding new version header to changelog');
33+
34+
const changelogPath = path.join(path.resolve(__dirname, '..'), 'CHANGELOG.md');
35+
const changelogContent = fs.readFileSync(changelogPath, 'utf8');
36+
const changelogLines = changelogContent.split(os.EOL);
37+
38+
// Find all the headers in the changelog (and their line numbers)
39+
const headerRegex = /^#+\s+.*$/gm;
40+
const matches = [];
41+
for (let i = 0; i < changelogLines.length; i++) {
42+
const line = changelogLines.at(i);
43+
const match = headerRegex.exec(line!);
44+
if (match) {
45+
matches.push({ line: i, text: match[0] });
46+
}
47+
}
48+
49+
// Find the known issues header, then find the next header after it.
50+
const knownIssuesHeader = matches.find((m) => m.text.includes('Known Issues'));
51+
if (knownIssuesHeader === undefined) {
52+
throw new Error('Could not find the known issues header in the changelog.');
53+
}
54+
const knownIssuesIndex = matches.indexOf(knownIssuesHeader);
55+
if (knownIssuesIndex === -1) {
56+
throw new Error('Could not find the known issues index in the matches.');
57+
}
58+
59+
// Insert a new header for the new version after the known issues header but before the next header.
60+
const lineToInsertAt = matches[knownIssuesIndex + 1].line - 1;
61+
console.log(`Inserting new version header at line ${lineToInsertAt}`);
62+
const linesToInsert = ['', `# ${newVersion}.x`];
63+
64+
changelogLines.splice(lineToInsertAt, 0, ...linesToInsert);
65+
fs.writeFileSync(changelogPath, changelogLines.join(os.EOL));
2666
});

0 commit comments

Comments
 (0)