-
Notifications
You must be signed in to change notification settings - Fork 537
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(build-cli): New command transform:releaseNotes (#22466)
## The problem Our goal is to automate the release process as much as possible. To that end, now that we have a release notes generator, we'd like to automatically upload those notes to the GitHub release as part of the automated release. Unfortunately, when we generate changelogs as part of release, we consume and delete all the changesets for the release. However, we generate a markdown file with the release notes as part of the release, and that gets committed to the repo. Alas, we need the markdown to be slightly different when posted to GitHub releases, and we don't have the input changesets anymore, so we can't easily regenerate them in automation (we'd need to find the commit in which the changesets were consumed, go to the commit before, regenerate - it's not trivial). ## The proposed change Since we have the release notes files in the repo, I have created a new command, `transform:releaseNotes`, which takes the in-repo release notes file as input, and outputs a modified markdown file for use in the release pipeline. For example: `flub transform releaseNotes --inFile RELEASE_NOTES/2.2.0.md --outFile out.md` --------- Co-authored-by: Alex Villarreal <[email protected]> Co-authored-by: jzaffiro <[email protected]>
- Loading branch information
1 parent
23163ef
commit d2995da
Showing
8 changed files
with
249 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
`flub transform` | ||
================ | ||
|
||
Transform commands are used to transform code, docs, etc. into alternative forms. | ||
|
||
* [`flub transform releaseNotes`](#flub-transform-releasenotes) | ||
|
||
## `flub transform releaseNotes` | ||
|
||
Transforms a markdown release notes file into a format appropriate for use in a GitHub Release. This is used to transform in-repo release notes such that they can be automatically posted to our GitHub Releases. | ||
|
||
``` | ||
USAGE | ||
$ flub transform releaseNotes --inFile <value> --outFile <value> [-v | --quiet] | ||
FLAGS | ||
--inFile=<value> (required) A release notes file that was generated using 'flub generate releaseNotes'. | ||
--outFile=<value> (required) Output the transformed content to this file. | ||
LOGGING FLAGS | ||
-v, --verbose Enable verbose logging. | ||
--quiet Disable all logging. | ||
EXAMPLES | ||
Transform the release notes from version 2.2.0 and output the results to out.md. | ||
$ flub transform releaseNotes --inFile RELEASE_NOTES/2.2.0.md --outFile out.md | ||
``` | ||
|
||
_See code: [src/commands/transform/releaseNotes.ts](https://github.com/microsoft/FluidFramework/blob/main/build-tools/packages/build-cli/src/commands/transform/releaseNotes.ts)_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
build-tools/packages/build-cli/src/commands/transform/releaseNotes.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
/*! | ||
* Copyright (c) Microsoft Corporation and contributors. All rights reserved. | ||
* Licensed under the MIT License. | ||
*/ | ||
|
||
import { readFile, writeFile } from "node:fs/promises"; | ||
import { Flags } from "@oclif/core"; | ||
import { format as prettier } from "prettier"; | ||
import { remark } from "remark"; | ||
import remarkGfm from "remark-gfm"; | ||
import remarkGithub, { defaultBuildUrl } from "remark-github"; | ||
import admonitions from "remark-github-beta-blockquote-admonitions"; | ||
import remarkToc from "remark-toc"; | ||
|
||
import { BaseCommand } from "../../library/index.js"; | ||
import { | ||
addHeadingLinks, | ||
removeHeadingsAtLevel, | ||
removeSectionContent, | ||
stripSoftBreaks, | ||
updateTocLinks, | ||
// eslint-disable-next-line import/no-internal-modules | ||
} from "../../library/markdown.js"; | ||
// eslint-disable-next-line import/no-internal-modules | ||
import { RELEASE_NOTES_TOC_LINK_TEXT } from "../../library/releaseNotes.js"; | ||
|
||
/** | ||
* Transforms a markdown release notes file into a format appropriate for use in a GitHub Release. | ||
*/ | ||
export default class TransformReleaseNotesCommand extends BaseCommand< | ||
typeof TransformReleaseNotesCommand | ||
> { | ||
static readonly summary = | ||
`Transforms a markdown release notes file into a format appropriate for use in a GitHub Release. This is used to transform in-repo release notes such that they can be automatically posted to our GitHub Releases.`; | ||
|
||
static readonly flags = { | ||
inFile: Flags.file({ | ||
description: `A release notes file that was generated using 'flub generate releaseNotes'.`, | ||
required: true, | ||
exists: true, | ||
}), | ||
outFile: Flags.file({ | ||
description: `Output the transformed content to this file.`, | ||
required: true, | ||
}), | ||
...BaseCommand.flags, | ||
} as const; | ||
|
||
static readonly examples = [ | ||
{ | ||
description: `Transform the release notes from version 2.2.0 and output the results to out.md.`, | ||
command: | ||
"<%= config.bin %> <%= command.id %> --inFile RELEASE_NOTES/2.2.0.md --outFile out.md", | ||
}, | ||
]; | ||
|
||
public async run(): Promise<string> { | ||
const { inFile, outFile } = this.flags; | ||
const input = await readFile(inFile, { encoding: "utf8" }); | ||
const processor = remark() | ||
// Remove the H1 if it exists. | ||
.use(removeHeadingsAtLevel, { level: 1 }) | ||
// Remove the existing TOC section because its links are incorrect; we'll regenerate it. | ||
.use(removeSectionContent, { heading: "Contents" }) | ||
// Update the "back to TOC" links to prepend 'user-content-' because that's what GH Releases does. | ||
.use(updateTocLinks, { | ||
checkValue: RELEASE_NOTES_TOC_LINK_TEXT, | ||
newUrl: "#user-content-contents", | ||
}) | ||
// Parse the markdown as GitHub-Flavored Markdown | ||
.use(remarkGfm) | ||
// Strip any single-line breaks. See the docs for the stripSoftBreaks function for more details. | ||
.use(stripSoftBreaks) | ||
// Parse any GitHub admonitions/alerts/callouts | ||
.use(admonitions, { | ||
titleTextMap: (title) => ({ | ||
// By default the `[!` prefix and `]` suffix are removed; we don't want that, so we override the default and | ||
// return the title as-is. | ||
displayTitle: title, | ||
checkedTitle: title, | ||
}), | ||
}) | ||
// Regenerate the TOC with the user-content- prefix. | ||
.use(remarkToc, { | ||
maxDepth: 3, | ||
skip: ".*Start Building Today.*", | ||
// Add the user-content- prefix to the links when we generate our own headingLinks, because GitHub will | ||
// prepend that to all our custom anchor IDs. | ||
prefix: "user-content-", | ||
}) | ||
// Transform any issue and commit references into links. | ||
.use(remarkGithub, { | ||
buildUrl(values) { | ||
// Disable linking mentions | ||
return values.type === "mention" ? false : defaultBuildUrl(values); | ||
}, | ||
}) | ||
// Add custom anchor tags with IDs to all the headings. | ||
.use(addHeadingLinks); | ||
|
||
const contents = String(await processor.process(input)); | ||
|
||
this.info(`Writing output file: ${outFile}`); | ||
await writeFile( | ||
outFile, | ||
await prettier(contents, { proseWrap: "never", parser: "markdown" }), | ||
); | ||
|
||
return contents; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/*! | ||
* Copyright (c) Microsoft Corporation and contributors. All rights reserved. | ||
* Licensed under the MIT License. | ||
*/ | ||
|
||
/** | ||
* The text used in release notes links that point back to the table of contents in the document. | ||
*/ | ||
export const RELEASE_NOTES_TOC_LINK_TEXT = "⬆️ Table of contents"; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.