Skip to content

Commit 9bc74b1

Browse files
henrymercerCopilot
andcommitted
Create a changenote for bundle updates instead of editing the changelog
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent b35c6c6 commit 9bc74b1

3 files changed

Lines changed: 48 additions & 18 deletions

File tree

‎.github/workflows/update-bundle.yml‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,12 @@ jobs:
113113
echo "CLI_VERSION=$cli_version" | tee -a "$GITHUB_ENV"
114114
echo "PR_URL=$pr_url" | tee -a "$GITHUB_ENV"
115115
116-
- name: Create changelog note
116+
- name: Create changenote
117117
run: |
118118
npx tsx pr-checks/bundle-changelog.ts
119119
120-
- name: Push changelog note
120+
- name: Push changenote
121121
run: |
122-
git commit -am "Add changelog note"
122+
git add unreleased-change-notes
123+
git commit -m "Add changenote"
123124
git push

‎pr-checks/bundle-changelog.test.ts‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { afterEach, beforeEach, describe, it } from "node:test";
1010

1111
import {
1212
CLI_VERSION_ENV_VAR,
13+
getChangenote,
1314
getCLIVersion,
1415
getPRNumber,
1516
getPRUrl,
@@ -21,6 +22,7 @@ import {
2122
NO_CHANGES_STR,
2223
UNRELEASED_PLACEHOLDER,
2324
} from "./changelog";
25+
import { isValidChangenoteContent } from "./changelog/validate";
2426

2527
let testDir: string;
2628

@@ -140,3 +142,16 @@ describe("updateChangelog", async () => {
140142
assert.deepEqual(result, expectedChangelog);
141143
});
142144
});
145+
146+
describe("getChangenote", async () => {
147+
await it("returns a note linking to the bundle release and the PR", async () => {
148+
assert.equal(
149+
getChangenote("1.2.3", testPrUrl),
150+
"- Update default CodeQL bundle version to [1.2.3](https://github.com/github/codeql-action/releases/tag/codeql-bundle-v1.2.3). [#42](https://github.com/github/codeql-action/pulls/42)\n",
151+
);
152+
});
153+
154+
await it("returns valid changenote content", async () => {
155+
assert.ok(isValidChangenoteContent(getChangenote("1.2.3", testPrUrl)));
156+
});
157+
});

‎pr-checks/bundle-changelog.ts‎

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
#!/usr/bin/env npx tsx
22

33
/**
4-
* Updates the changelog with a change note for an updated CodeQL CLI bundle.
4+
* Creates a changenote file for an update to the default CodeQL CLI bundle.
55
*/
66

77
import * as fs from "node:fs";
8+
import * as path from "node:path";
89

910
import {
1011
parseChangelog,
1112
renderChangelog,
1213
UNRELEASED_PLACEHOLDER,
1314
} from "./changelog";
14-
import { CHANGELOG_FILE, CLI_BUNDLE_RELEASE_URL_PREFIX } from "./config";
15+
import { CHANGENOTES_DIR, CLI_BUNDLE_RELEASE_URL_PREFIX } from "./config";
1516
import { getErrorMessage } from "./util";
1617

1718
export const CLI_VERSION_ENV_VAR = "CLI_VERSION";
@@ -96,27 +97,40 @@ export function updateChangelog(contents: string, changelogNote: string) {
9697
return renderChangelog(changelog);
9798
}
9899

100+
/**
101+
* Returns the contents of the changenote file for an update to the default
102+
* CodeQL CLI bundle.
103+
*
104+
* @param cliVersion The CodeQL CLI version of the new default bundle.
105+
* @param prUrl The URL of the PR that updates the default bundle.
106+
* @throws If the PR number can't be determined from `prUrl`.
107+
*/
108+
export function getChangenote(cliVersion: string, prUrl: string): string {
109+
// The GitHub Release for the new bundle version.
110+
const bundleReleaseUrl = `${CLI_BUNDLE_RELEASE_URL_PREFIX}${cliVersion}`;
111+
112+
const prNumber = getPRNumber(prUrl);
113+
return `- Update default CodeQL bundle version to [${cliVersion}](${bundleReleaseUrl}). [#${prNumber}](${prUrl})\n`;
114+
}
115+
99116
function main() {
100117
try {
101118
const cliVersion = getCLIVersion();
102119
const prUrl = getPRUrl();
103120

104-
// The GitHub Release for the new bundle version.
105-
const bundleReleaseUrl = `${CLI_BUNDLE_RELEASE_URL_PREFIX}${cliVersion}`;
106-
107-
// Get the PR number from the PR URL.
108-
const prNumber = getPRNumber(prUrl);
109-
const changelogNote = `- Update default CodeQL bundle version to [${cliVersion}](${bundleReleaseUrl}). [#${prNumber}](${prUrl})`;
110-
111-
let changelog = fs.readFileSync(CHANGELOG_FILE, "utf-8");
112-
113-
changelog = updateChangelog(changelog, changelogNote);
114-
115-
fs.writeFileSync(CHANGELOG_FILE, changelog);
121+
// Include the CLI version in the file name so that changenotes for
122+
// different bundle updates don't conflict.
123+
const changenotePath = path.join(
124+
CHANGENOTES_DIR,
125+
`update-bundle-${cliVersion}.md`,
126+
);
127+
fs.writeFileSync(changenotePath, getChangenote(cliVersion, prUrl));
116128

117129
return 0;
118130
} catch (err) {
119-
console.error(`Failed to bundle changelog: ${getErrorMessage(err)}`);
131+
console.error(
132+
`Failed to create changenote for bundle update: ${getErrorMessage(err)}`,
133+
);
120134
return -1;
121135
}
122136
}

0 commit comments

Comments
 (0)