-
Notifications
You must be signed in to change notification settings - Fork 75
feat(release): auto-generate blog posts #213
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
avivkeller
wants to merge
6
commits into
main
Choose a base branch
from
release-post
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9eb1cfa
fix(homepage): align code boxes
avivkeller bd41b4a
fixup!
avivkeller d38641e
Update index.md
avivkeller fdd1fc9
fixup!
avivkeller dd801c9
feat(release): auto-generate blog posts
avivkeller f7c8f72
Merge branch 'main' into release-post
avivkeller File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -8,4 +8,5 @@ out | |
| /pages/docs/plugins/* | ||
| !/pages/docs/plugins/index.md | ||
| versions.json | ||
| /generated | ||
| /generated | ||
| *.hbs | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,82 @@ | ||
| import { readFile, writeFile } from 'node:fs/promises'; | ||
| import { parseArgs } from 'node:util'; | ||
|
|
||
| import Handlebars from 'handlebars'; | ||
| import matter from 'gray-matter'; | ||
|
|
||
| import { fetchWithAuth } from '../../utils/fetch.mjs'; | ||
|
|
||
| const { values } = parseArgs({ | ||
| options: { | ||
| // Author | ||
| author: { type: 'string', default: 'avivkeller' }, | ||
| }, | ||
| }); | ||
|
|
||
| const API_BASE = 'https://api.github.com/repos/webpack/webpack'; | ||
| const TEMPLATE_PATH = new URL('./template.md.hbs', import.meta.url); | ||
|
|
||
| const fetchJSON = url => fetchWithAuth(url).then(r => r.json()); | ||
|
|
||
| const getLatestVersion = async () => { | ||
| const { tag_name } = await fetchJSON(`${API_BASE}/releases/latest`); | ||
| return tag_name; | ||
| }; | ||
|
|
||
| const getRemovedChangesets = async version => { | ||
| const { files = [] } = await fetchJSON(`${API_BASE}/commits/${version}`); | ||
|
|
||
| return files.filter( | ||
| file => | ||
| file.status === 'removed' && | ||
| file.filename.startsWith('.changeset/') && | ||
| file.patch | ||
| ); | ||
| }; | ||
|
|
||
| const stripPatchMarkers = patch => patch.replace(/^@@.*\n|^[- ]/gm, ''); | ||
| const capitalize = value => value.charAt(0).toUpperCase() + value.slice(1); | ||
|
|
||
| const parseChangeset = file => { | ||
| const { data, content } = matter(stripPatchMarkers(file.patch)); | ||
| const [title, ...paragraphs] = content.trim().split(/\n{2,}/); | ||
|
|
||
| return { | ||
| notable: data.notable === true, | ||
| semver: capitalize(data.webpack), | ||
| title, | ||
| description: paragraphs.join('\n\n'), | ||
| }; | ||
| }; | ||
|
|
||
| async function renderReleaseNotes(version, changes, date) { | ||
| Handlebars.registerHelper('filter', (items, property, expected) => | ||
| items.filter(item => item[property] === expected) | ||
| ); | ||
|
|
||
| Handlebars.registerHelper('groupBy', (items, property) => | ||
| Object.groupBy(items, item => item[property]) | ||
| ); | ||
|
|
||
| const source = await readFile(TEMPLATE_PATH, 'utf8'); | ||
| const render = Handlebars.compile(source, { noEscape: true }); | ||
|
|
||
| return render({ | ||
| changes, | ||
| version, | ||
| date, | ||
| ...values, | ||
| }); | ||
| } | ||
|
|
||
| const date = new Date().toISOString().slice(0, 10); | ||
| const version = await getLatestVersion(); | ||
| const changesets = await getRemovedChangesets(version); | ||
| const changes = changesets.map(parseChangeset); | ||
| const post = await renderReleaseNotes(version, changes, date); | ||
| writeFile( | ||
| new URL( | ||
| import.meta.resolve(`../../../pages/blog/${date}-webpack-${version}.md`) | ||
| ), | ||
| post | ||
| ); | ||
This file contains hidden or 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,38 @@ | ||
| --- | ||
| date: '{{date}}' | ||
| category: release | ||
| title: 'webpack {{version}}' | ||
| layout: blog-post | ||
| author: '{{author}}' | ||
| --- | ||
|
|
||
| # webpack {{version}} | ||
|
|
||
| <!-- Hey Releaser! Add your super awesome description here. --> | ||
|
|
||
| {{#with (filter changes "notable" true) as |notableChanges|}} | ||
| {{#if notableChanges.length}} | ||
| ## Notable Changes | ||
|
|
||
| {{#each notableChanges}} | ||
| ### _({{semver}})_ {{title}} | ||
|
|
||
| {{description}} | ||
|
|
||
| {{/each}} | ||
| {{/if}} | ||
| {{/with}} | ||
| {{#with (filter changes "notable" false) as |otherChanges|}} | ||
| {{#if otherChanges.length}} | ||
| ## Other Changes | ||
|
|
||
| {{#each (groupBy otherChanges "semver")}} | ||
| ### {{@key}} | ||
|
|
||
| {{#each this}} | ||
| - {{title}} | ||
| {{/each}} | ||
|
|
||
| {{/each}} | ||
| {{/if}} | ||
| {{/with}} |
File renamed without changes.
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I'd rather open it about a week before the release, or whenever Alex says we're getting close, so we have time to make any necessary changes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can do that, but the idea behind automating is that you need to make minimal changes to the document
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep, although I guess I could get used to writing the blog post after the release and making any necessary changes afterward
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, if it's easier to run before, I'm happy to make that change, you are the author, just keep in mind I don't think there's a way for us to automate "1 week before" without a manual trigger.
I can do:
mainreleasetriggered, run automatically?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I think that would be the right workflow.