Skip to content
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

Replace changelog versions in ./scripts/draft-blog-post.js #9058

Merged
merged 3 commits into from Aug 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
46 changes: 30 additions & 16 deletions scripts/draft-blog-post.js
Expand Up @@ -5,10 +5,12 @@
const fs = require("fs");
const path = require("path");
const rimraf = require("rimraf");
const semver = require("semver");

const changelogUnreleasedDir = path.join(__dirname, "../changelog_unreleased");
const blogDir = path.join(__dirname, "../website/blog");
const introFile = path.join(changelogUnreleasedDir, "blog-post-intro.md");
const previousVersion = require("prettier/package.json").version;
const version = require("../package.json").version.replace(/-.+/, "");
const postGlob = path.join(blogDir, `????-??-??-${version}.md`);
const postFile = path.join(
Expand Down Expand Up @@ -80,22 +82,24 @@ rimraf.sync(postGlob);

fs.writeFileSync(
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we run prettier.format on this file?

Copy link
Sponsor Member

@fisker fisker Aug 25, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is created when repo linting with stable, and merge when master already released and updated, so there is a chance this file will fail on lint?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There may be a chance. But we use this script when before release. So I'm not sure if the problem is fixed with using prettier.format on this script.

Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we use stable prettier format it, it will fail after merge.
If we use master prettier format it, it will fail when sending PR.

😄

Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's keep as it is, for now.

postFile,
[
fs.readFileSync(introFile, "utf8").trim(),
"<!--truncate-->",
...printEntries({
title: "Highlights",
filter: (entry) => entry.highlight,
}),
...printEntries({
title: "Breaking changes",
filter: (entry) => entry.breaking && !entry.highlight,
}),
...printEntries({
title: "Other changes",
filter: (entry) => !entry.breaking && !entry.highlight,
}),
].join("\n\n") + "\n"
replaceVersions(
[
fs.readFileSync(introFile, "utf8").trim(),
"<!--truncate-->",
...printEntries({
title: "Highlights",
filter: (entry) => entry.highlight,
}),
...printEntries({
title: "Breaking changes",
filter: (entry) => entry.breaking && !entry.highlight,
}),
...printEntries({
title: "Other changes",
filter: (entry) => !entry.breaking && !entry.highlight,
}),
].join("\n\n") + "\n"
)
);

function printEntries({ title, filter }) {
Expand All @@ -115,3 +119,13 @@ function printEntries({ title, filter }) {

return result;
}

function formatVersion(version) {
return `${semver.major(version)}.${semver.minor(version)}`;
}

function replaceVersions(data) {
return data
.replace(/prettier stable/gi, `Prettier ${formatVersion(previousVersion)}`)
.replace(/prettier master/gi, `Prettier ${formatVersion(version)}`);
}
17 changes: 0 additions & 17 deletions scripts/release/steps/update-changelog.js
Expand Up @@ -30,18 +30,6 @@ function writeChangelog({ version, previousVersion, releaseNotes }) {
fs.writeFileSync("CHANGELOG.md", newEntry + "\n\n" + changelog);
}

function formatVersion(version) {
return `${semver.major(version)}.${semver.minor(version)}`;
}

function replaceVersionsInBlogPost({ blogPost, version, previousVersion }) {
const blogPostData = fs.readFileSync(blogPost, "utf-8");
const newBlogPostData = blogPostData
.replace(/prettier stable/gi, `Prettier ${formatVersion(previousVersion)}`)
.replace(/prettier master/gi, `Prettier ${formatVersion(version)}`);
fs.writeFileSync(blogPost, newBlogPostData);
}

module.exports = async function ({ version, previousVersion }) {
const semverDiff = semver.diff(version, previousVersion);

Expand All @@ -53,11 +41,6 @@ module.exports = async function ({ version, previousVersion }) {
releaseNotes: `🔗 [Release Notes](https://prettier.io/${blogPost.path})`,
});
if (fs.existsSync(blogPost.file)) {
replaceVersionsInBlogPost({
blogPost: blogPost.file,
version,
previousVersion,
});
// Everything is fine, this step is finished
return;
}
Expand Down