|
1 | 1 | #!/usr/bin/env npx tsx |
2 | 2 |
|
3 | 3 | /** |
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. |
5 | 5 | */ |
6 | 6 |
|
7 | 7 | import * as fs from "node:fs"; |
| 8 | +import * as path from "node:path"; |
8 | 9 |
|
9 | 10 | import { |
10 | 11 | parseChangelog, |
11 | 12 | renderChangelog, |
12 | 13 | UNRELEASED_PLACEHOLDER, |
13 | 14 | } from "./changelog"; |
14 | | -import { CHANGELOG_FILE, CLI_BUNDLE_RELEASE_URL_PREFIX } from "./config"; |
| 15 | +import { CHANGENOTES_DIR, CLI_BUNDLE_RELEASE_URL_PREFIX } from "./config"; |
15 | 16 | import { getErrorMessage } from "./util"; |
16 | 17 |
|
17 | 18 | export const CLI_VERSION_ENV_VAR = "CLI_VERSION"; |
@@ -96,27 +97,40 @@ export function updateChangelog(contents: string, changelogNote: string) { |
96 | 97 | return renderChangelog(changelog); |
97 | 98 | } |
98 | 99 |
|
| 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 | + |
99 | 116 | function main() { |
100 | 117 | try { |
101 | 118 | const cliVersion = getCLIVersion(); |
102 | 119 | const prUrl = getPRUrl(); |
103 | 120 |
|
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)); |
116 | 128 |
|
117 | 129 | return 0; |
118 | 130 | } 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 | + ); |
120 | 134 | return -1; |
121 | 135 | } |
122 | 136 | } |
|
0 commit comments